зеркало из https://github.com/mozilla/pjs.git
Checking in initial version of Keith Visco's (kvisco@ziplink.net) XSL processor, Transformiix. Some glue code to interface it with mozilla is #ifdef MOZILLA protected.
This commit is contained in:
Родитель
06209ff65d
Коммит
1f47bc0cb5
|
@ -0,0 +1,238 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "primitives.h"
|
||||
|
||||
//----------------------------/
|
||||
//- Implementation of Double -/
|
||||
//----------------------------/
|
||||
/**
|
||||
* A wrapper for the primitive double type, and provides some simple
|
||||
* floating point related routines
|
||||
* @author <a href="mailto:lef@opentext.com">Larry Fitzpatrick</a>
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
|
||||
double d0 = 0.0;
|
||||
|
||||
const double Double::NaN = (d0/d0);
|
||||
const double Double::NEGATIVE_INFINITY = (-1.0/d0);
|
||||
const double Double::POSITIVE_INFINITY = (1.0/d0);
|
||||
|
||||
/**
|
||||
* Creates a new Double with it's value initialized to 0;
|
||||
**/
|
||||
Double::Double() {
|
||||
value = 0;
|
||||
} //-- Double
|
||||
|
||||
/**
|
||||
* Creates a new Double with it's value initialized to the given double
|
||||
**/
|
||||
Double::Double(double dbl) {
|
||||
this->value = dbl;
|
||||
} //-- Double
|
||||
|
||||
/**
|
||||
* Creates a new Double with it's value initialized from the given String.
|
||||
* The String will be converted to a double. If the String does not
|
||||
* represent an IEEE 754 double, the value will be initialized to NaN
|
||||
**/
|
||||
Double::Double(const String& string) {
|
||||
this->value = toDouble(string);
|
||||
} //-- Double
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the value of this Double as a double
|
||||
**/
|
||||
double Double::doubleValue() {
|
||||
return this->value;
|
||||
} //-- doubleValue
|
||||
|
||||
/**
|
||||
* Returns the value of this Double as an int
|
||||
**/
|
||||
int Double::intValue() {
|
||||
return (int)value;
|
||||
} //-- intValue
|
||||
|
||||
/**
|
||||
* Determins whether the given double represents positive or negative
|
||||
* inifinity
|
||||
**/
|
||||
MBool Double::isInfinite(double dbl) {
|
||||
return (MBool)((dbl == POSITIVE_INFINITY ) || (dbl == NEGATIVE_INFINITY));
|
||||
} //-- isInfinite
|
||||
|
||||
/**
|
||||
* Determins whether this Double's value represents positive or
|
||||
* negative inifinty
|
||||
**/
|
||||
MBool Double::isInfinite() {
|
||||
return (MBool)(( value == POSITIVE_INFINITY ) || (value == NEGATIVE_INFINITY));
|
||||
} //-- isInfinite
|
||||
|
||||
/**
|
||||
* Determins whether the given double is NaN
|
||||
**/
|
||||
MBool Double::isNaN(double dbl) {
|
||||
#ifdef MOZILLA
|
||||
return (MBool) _isnan(dbl);
|
||||
#else
|
||||
return (MBool) isnan(dbl);
|
||||
#endif
|
||||
} //-- isNaN
|
||||
|
||||
/**
|
||||
* Determins whether this Double's value is NaN
|
||||
**/
|
||||
MBool Double::isNaN() {
|
||||
#ifdef MOZILLA
|
||||
return (MBool) _isnan(value);
|
||||
#else
|
||||
return (MBool) isnan(value);
|
||||
#endif
|
||||
} //-- isNaN
|
||||
|
||||
/**
|
||||
* Converts the given String to a double, if the String value does not
|
||||
* represent a double, NaN will be returned
|
||||
**/
|
||||
double Double::toDouble(const String& src) {
|
||||
|
||||
double dbl = 0.0;
|
||||
double fraction = 1.0;
|
||||
double multiplier = 10.0;
|
||||
Int32 idx = 0;
|
||||
|
||||
double sign = 1.0;
|
||||
|
||||
//-- trim leading whitespace
|
||||
for ( ; idx < src.length(); idx++ )
|
||||
if ( src.charAt(idx) != ' ' ) break;
|
||||
|
||||
//-- check first character for sign
|
||||
if ( idx < src.length() ) {
|
||||
Int32 ch = src.charAt(idx);
|
||||
if ( ch == '-' ) {
|
||||
sign = -1.0;
|
||||
++idx;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return Double::NaN;
|
||||
}
|
||||
|
||||
//-- convert remaining to number
|
||||
for ( ; idx < src.length(); idx++ ) {
|
||||
|
||||
Int32 ch = src.charAt(idx);
|
||||
|
||||
if (( ch >= '0') && (ch <= '9')) {
|
||||
if ( multiplier > 1.0 ) {
|
||||
dbl = dbl*multiplier;
|
||||
dbl += (double) (ch-48);
|
||||
}
|
||||
else {
|
||||
dbl += multiplier * (ch-48);
|
||||
multiplier = multiplier * 0.1;
|
||||
}
|
||||
}
|
||||
else if ( ch == '.') {
|
||||
if ( multiplier < 1.0 ) return Double::NaN;
|
||||
multiplier = 0.1;
|
||||
}
|
||||
else return Double::NaN;
|
||||
}
|
||||
dbl = dbl*sign;
|
||||
return dbl;
|
||||
} //-- toDouble
|
||||
|
||||
|
||||
/**
|
||||
* Converts the value of this Double to a String, and places
|
||||
* The result into the destination String.
|
||||
* @return the given dest string
|
||||
**/
|
||||
String& Double::toString(String& dest) {
|
||||
return toString(value, dest);
|
||||
} //-- toString
|
||||
|
||||
/**
|
||||
* Converts the value of the given double to a String, and places
|
||||
* The result into the destination String.
|
||||
* @return the given dest string
|
||||
**/
|
||||
String& Double::toString(double value, String& dest) {
|
||||
|
||||
//-- check for special cases
|
||||
|
||||
if ( isNaN(value) ) {
|
||||
dest.append("NaN");
|
||||
return dest;
|
||||
}
|
||||
if ( isInfinite(value) ) {
|
||||
if (value < 0) dest.append('-');
|
||||
dest.append("Infinity");
|
||||
return dest;
|
||||
}
|
||||
|
||||
MBool isNegative = (MBool)(value<0.0);
|
||||
double val = value;
|
||||
if ( isNegative ) val = val * -1.0;
|
||||
|
||||
double ival = 0;
|
||||
double fval = modf(val, &ival);
|
||||
|
||||
String iStr;
|
||||
|
||||
int temp = (int)ival;
|
||||
|
||||
|
||||
if ( temp > 0.0 ) {
|
||||
while ( temp > 0.0 ) {
|
||||
iStr.append( (char) ((temp % 10)+48) );
|
||||
temp = temp / 10;
|
||||
}
|
||||
if ( isNegative ) iStr.append('-');
|
||||
iStr.reverse();
|
||||
}
|
||||
else iStr.append('0');
|
||||
|
||||
iStr.append('.');
|
||||
if ( fval > 0.0 ) {
|
||||
while ( fval > 0.0000001 ) {
|
||||
fval = fval*10.0;
|
||||
fval = modf(fval, &ival);
|
||||
iStr.append( (char) (ival+48) );
|
||||
}
|
||||
}
|
||||
else iStr.append('0');
|
||||
|
||||
dest.append(iStr);
|
||||
return dest;
|
||||
} //-- toString
|
||||
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MITRE_ERROROBSERVER_H
|
||||
#define MITRE_ERROROBSERVER_H
|
||||
|
||||
#include "baseutils.h"
|
||||
#include "String.h"
|
||||
#include "iostream.h"
|
||||
|
||||
/**
|
||||
* A simple interface for observing errors
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
class ErrorObserver {
|
||||
|
||||
public:
|
||||
|
||||
enum ErrorLevel {FATAL = 0, NORMAL, WARNING};
|
||||
|
||||
/**
|
||||
* Default Destructor for ErrorObserver
|
||||
**/
|
||||
virtual ~ErrorObserver() {};
|
||||
|
||||
/**
|
||||
* Notifies this Error observer of a new error, with default
|
||||
* level of NORMAL
|
||||
**/
|
||||
virtual void recieveError(String& errorMessage) = 0;
|
||||
|
||||
/**
|
||||
* Notifies this Error observer of a new error using the given error level
|
||||
**/
|
||||
virtual void recieveError(String& errorMessage, ErrorLevel level) = 0;
|
||||
|
||||
}; //-- ErrorObserver
|
||||
|
||||
/**
|
||||
* A simple ErrorObserver which allows printing error messages to a stream
|
||||
**/
|
||||
class SimpleErrorObserver : public ErrorObserver {
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new SimpleErrorObserver.
|
||||
* All errors will be printed to the console (cout).
|
||||
**/
|
||||
SimpleErrorObserver();
|
||||
|
||||
/**
|
||||
* Creates a new SimpleErrorObserver.
|
||||
* All errors will be printed to the given ostream.
|
||||
**/
|
||||
SimpleErrorObserver(ostream& errStream);
|
||||
|
||||
virtual ~SimpleErrorObserver() {};
|
||||
|
||||
/**
|
||||
* Notifies this Error observer of a new error, with default
|
||||
* level of NORMAL
|
||||
**/
|
||||
virtual void recieveError(String& errorMessage);
|
||||
|
||||
/**
|
||||
* Notifies this Error observer of a new error using the given error level
|
||||
**/
|
||||
virtual void recieveError(String& errorMessage, ErrorLevel level);
|
||||
|
||||
virtual void supressWarnings(MBool supress);
|
||||
|
||||
private:
|
||||
|
||||
ostream* errStream;
|
||||
MBool hideWarnings;
|
||||
}; //-- SimpleErrorObserver
|
||||
#endif
|
|
@ -0,0 +1,319 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "List.h"
|
||||
#include <iostream.h>
|
||||
//--------------------------/
|
||||
//- Implementation of List -/
|
||||
//--------------------------/
|
||||
|
||||
/**
|
||||
* Default constructor for a List;
|
||||
**/
|
||||
List::List() {
|
||||
firstItem = 0;
|
||||
lastItem = 0;
|
||||
itemCount = 0;
|
||||
} //-- List;
|
||||
|
||||
/**
|
||||
* List destructor, cleans up List Items, but will not delete the Object
|
||||
* references
|
||||
*/
|
||||
List::~List() {
|
||||
ListItem* item = firstItem;
|
||||
while (item) {
|
||||
ListItem* tItem = item;
|
||||
item = item->nextItem;
|
||||
delete tItem;
|
||||
}
|
||||
} //-- ~List
|
||||
|
||||
void List::insert(int index, void* objPtr) {
|
||||
|
||||
if ( index >= itemCount ) {
|
||||
insertBefore(objPtr, 0);
|
||||
}
|
||||
else {
|
||||
//-- add to middle of list
|
||||
ListItem* nextItem = firstItem;
|
||||
for ( int i = 0; i < index; i++ ) nextItem = nextItem->nextItem;
|
||||
insertBefore(objPtr, nextItem);
|
||||
}
|
||||
} //-- insert
|
||||
|
||||
void List::add(void* objPtr) {
|
||||
insert(itemCount, objPtr);
|
||||
} //-- add
|
||||
|
||||
List::ListItem* List::getFirstItem() {
|
||||
return firstItem;
|
||||
} //-- getFirstItem
|
||||
|
||||
List::ListItem* List::getLastItem() {
|
||||
return lastItem;
|
||||
} //-- getLastItem
|
||||
|
||||
/**
|
||||
* Returns the number of items in this List
|
||||
**/
|
||||
Int32 List::getLength() {
|
||||
return itemCount;
|
||||
} //-- getLength
|
||||
|
||||
|
||||
/**
|
||||
* Inserts the given Object pointer as the item just after refItem.
|
||||
* If refItem is a null pointer the Object will be inserted at the
|
||||
* beginning of the List (ie, insert after nothing).
|
||||
* This method assumes refItem is a member of this list, and since this
|
||||
* is a private method, I feel that's a valid assumption
|
||||
**/
|
||||
void List::insertAfter(void* objPtr, ListItem* refItem) {
|
||||
//-- if refItem == null insert at front
|
||||
if (!refItem) insertBefore(objPtr, firstItem);
|
||||
else insertBefore(objPtr, refItem->nextItem);
|
||||
} //-- insertAfter
|
||||
|
||||
/**
|
||||
* Inserts the given Object pointer as the item just before refItem.
|
||||
* If refItem is a null pointer the Object will be inserted at the
|
||||
* end of the List (ie, insert before nothing).
|
||||
* This method assumes refItem is a member of this list, and since this
|
||||
* is a private method, I feel that's a valid assumption
|
||||
**/
|
||||
void List::insertBefore(void* objPtr, ListItem* refItem) {
|
||||
|
||||
ListItem* item = new ListItem;
|
||||
item->objPtr = objPtr;
|
||||
item->nextItem = 0;
|
||||
item->prevItem = 0;
|
||||
|
||||
//-- if refItem == null insert at end
|
||||
if (!refItem) {
|
||||
//-- add to back of list
|
||||
if ( lastItem ) {
|
||||
lastItem->nextItem = item;
|
||||
item->prevItem = lastItem;
|
||||
}
|
||||
lastItem = item;
|
||||
if ( !firstItem ) firstItem = item;
|
||||
}
|
||||
else {
|
||||
//-- insert before given item
|
||||
item->nextItem = refItem;
|
||||
item->prevItem = refItem->prevItem;
|
||||
refItem->prevItem = item;
|
||||
|
||||
if (refItem == firstItem) firstItem = item;
|
||||
if (itemCount == 0) lastItem = item; // <-should we ever see this?
|
||||
}
|
||||
|
||||
// increase the item count
|
||||
++itemCount;
|
||||
} //-- insertBefore
|
||||
|
||||
/**
|
||||
* Returns a ListIterator for this List
|
||||
**/
|
||||
ListIterator* List::iterator() {
|
||||
return new ListIterator(this);
|
||||
}
|
||||
|
||||
void* List::remove(void* objPtr) {
|
||||
ListItem* item = firstItem;
|
||||
while (item) {
|
||||
if (item->objPtr == objPtr) {
|
||||
remove(item);
|
||||
delete item;
|
||||
return objPtr;
|
||||
}
|
||||
item = item->nextItem;
|
||||
}
|
||||
// not in list
|
||||
return 0;
|
||||
} //-- remove
|
||||
|
||||
List::ListItem* List::remove(ListItem* item) {
|
||||
|
||||
if ( !item ) return item;
|
||||
|
||||
//-- adjust the previous item's next pointer
|
||||
if (item->prevItem) {
|
||||
item->prevItem->nextItem = item->nextItem;
|
||||
}
|
||||
//-- adjust the next item's previous pointer
|
||||
if ( item->nextItem ) {
|
||||
item->nextItem->prevItem = item->prevItem;
|
||||
}
|
||||
|
||||
//-- adjust first and last items
|
||||
if (item == firstItem) firstItem = item->nextItem;
|
||||
if (item == lastItem) lastItem = item->prevItem;
|
||||
|
||||
//-- decrease Item count
|
||||
--itemCount;
|
||||
return item;
|
||||
} //-- remove
|
||||
|
||||
//----------------------------------/
|
||||
//- Implementation of ListIterator -/
|
||||
//----------------------------------/
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new ListIterator for the given List
|
||||
* @param list, the List to create an Iterator for
|
||||
**/
|
||||
ListIterator::ListIterator(List* list) {
|
||||
this->list = list;
|
||||
currentItem = 0;
|
||||
allowRemove = MB_FALSE;
|
||||
moveForward = MB_TRUE;
|
||||
done = MB_FALSE;
|
||||
count = 0;
|
||||
} //-- ListIterator
|
||||
|
||||
ListIterator::~ListIterator() {
|
||||
//-- overrides default destructor to do nothing
|
||||
} //-- ~ListIterator
|
||||
|
||||
/**
|
||||
* Adds the Object pointer to the List pointed to by this ListIterator.
|
||||
* The Object pointer is inserted as the next item in the List
|
||||
* based on the current position within the List
|
||||
* @param objPtr the Object pointer to add to the list
|
||||
**/
|
||||
void ListIterator::add(void* objPtr) {
|
||||
|
||||
list->insertAfter(objPtr,currentItem);
|
||||
allowRemove = MB_FALSE;
|
||||
|
||||
} //-- add
|
||||
|
||||
/**
|
||||
* Returns true if a sucessful call to the next() method can be made
|
||||
* @return MB_TRUE if a sucessful call to the next() method can be made,
|
||||
* otherwise MB_FALSE
|
||||
**/
|
||||
MBool ListIterator::hasNext() {
|
||||
MBool hasNext = MB_FALSE;
|
||||
if ( done ) return hasNext;
|
||||
else if ( currentItem ) {
|
||||
if (moveForward) hasNext = (MBool) currentItem->nextItem;
|
||||
else hasNext = (MBool)currentItem->prevItem;
|
||||
}
|
||||
else {
|
||||
if (moveForward) hasNext = (MBool) list->firstItem;
|
||||
else hasNext = (MBool) list->lastItem;
|
||||
}
|
||||
return hasNext;
|
||||
} //-- hasNext
|
||||
|
||||
/**
|
||||
* Returns true if a sucessful call to the previous() method can be made
|
||||
* @return MB_TRUE if a sucessful call to the previous() method can be made,
|
||||
* otherwise MB_FALSE
|
||||
**/
|
||||
MBool ListIterator::hasPrevious() {
|
||||
MBool hasPrevious = MB_FALSE;
|
||||
if (currentItem) {
|
||||
if (moveForward) hasPrevious = (MBool)(currentItem->prevItem);
|
||||
else hasPrevious = (MBool) (currentItem->nextItem);
|
||||
}
|
||||
return hasPrevious;
|
||||
} //-- hasPrevious
|
||||
|
||||
/**
|
||||
* Returns the next Object pointer in the list
|
||||
**/
|
||||
void* ListIterator::next() {
|
||||
|
||||
void* obj = 0;
|
||||
if ( done ) return obj;
|
||||
|
||||
if (currentItem) {
|
||||
if ( moveForward ) currentItem = currentItem->nextItem;
|
||||
else currentItem = currentItem->prevItem;
|
||||
}
|
||||
else {
|
||||
if ( moveForward ) currentItem = list->firstItem;
|
||||
else currentItem = list->lastItem;
|
||||
}
|
||||
|
||||
if ( currentItem ) {
|
||||
obj = currentItem->objPtr;
|
||||
allowRemove = MB_TRUE;
|
||||
}
|
||||
else done = MB_TRUE;
|
||||
|
||||
return obj;
|
||||
} //-- next
|
||||
|
||||
/**
|
||||
* Returns the previous Object in the list
|
||||
**/
|
||||
void* ListIterator::previous() {
|
||||
|
||||
void* obj = 0;
|
||||
|
||||
if (currentItem) {
|
||||
if ( moveForward ) currentItem = currentItem->prevItem;
|
||||
else currentItem = currentItem->nextItem;
|
||||
if ( currentItem ) obj = currentItem->objPtr;
|
||||
}
|
||||
return obj;
|
||||
} //-- previous
|
||||
|
||||
/**
|
||||
* Removes the Object last returned by the next() or previous() methods;
|
||||
* @return the removed Object pointer
|
||||
**/
|
||||
void* ListIterator::remove() {
|
||||
|
||||
if (!allowRemove) return 0;
|
||||
allowRemove = MB_FALSE;
|
||||
|
||||
void* obj = 0;
|
||||
if (currentItem) {
|
||||
obj = currentItem->objPtr;
|
||||
List::ListItem* item = currentItem;
|
||||
previous(); //-- make previous item the current item
|
||||
list->remove(item);
|
||||
}
|
||||
return obj;
|
||||
} //-- remove
|
||||
|
||||
/**
|
||||
* Resets the current location within the List to the beginning of the List
|
||||
**/
|
||||
void ListIterator::reset() {
|
||||
done = MB_FALSE;
|
||||
currentItem = 0;
|
||||
} //-- reset
|
||||
|
||||
/**
|
||||
* sets this iterator to operate in the reverse direction
|
||||
**/
|
||||
void ListIterator::reverse() {
|
||||
moveForward = (MBool)(!moveForward);
|
||||
} //-- reverse
|
||||
|
|
@ -0,0 +1,188 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "baseutils.h"
|
||||
|
||||
#ifndef MITRE_LIST_H
|
||||
#define MITRE_LIST_H
|
||||
|
||||
/**
|
||||
* Represents an ordered list of Object pointers. Modeled after a Java 2 List.
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
class List {
|
||||
|
||||
friend class ListIterator;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates an empty List
|
||||
**/
|
||||
List();
|
||||
|
||||
/**
|
||||
* List destructor, object references will not be deleted.
|
||||
**/
|
||||
virtual ~List();
|
||||
|
||||
/**
|
||||
* Returns the number of items in this List
|
||||
**/
|
||||
Int32 getLength();
|
||||
|
||||
/**
|
||||
* Returns a ListIterator for this List
|
||||
**/
|
||||
ListIterator* iterator();
|
||||
|
||||
/**
|
||||
* Adds the given Object to the specified position in the list
|
||||
**/
|
||||
void insert(int index, void* objPtr);
|
||||
|
||||
/**
|
||||
* Adds the given Object to the list
|
||||
**/
|
||||
void add(void* objPtr);
|
||||
|
||||
/**
|
||||
* Removes the given Object pointer from the list
|
||||
**/
|
||||
void* remove(void* objPtr);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
struct ListItem {
|
||||
ListItem* nextItem;
|
||||
ListItem* prevItem;
|
||||
void* objPtr;
|
||||
};
|
||||
|
||||
ListItem* getFirstItem();
|
||||
ListItem* getLastItem();
|
||||
|
||||
/**
|
||||
* Removes the given ListItem pointer from the list
|
||||
**/
|
||||
ListItem* remove(ListItem* sItem);
|
||||
|
||||
private:
|
||||
|
||||
ListItem* firstItem;
|
||||
ListItem* lastItem;
|
||||
Int32 itemCount;
|
||||
|
||||
void insertAfter(void* objPtr, ListItem* sItem);
|
||||
void insertBefore(void* objPtr, ListItem* sItem);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* An Iterator for the List Class
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
class ListIterator {
|
||||
|
||||
public:
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new ListIterator for the given List
|
||||
* @param list, the List to create an Iterator for
|
||||
**/
|
||||
ListIterator(List* list);
|
||||
|
||||
/**
|
||||
* Destructor, destroys a given instance of a ListIterator
|
||||
**/
|
||||
virtual ~ListIterator();
|
||||
|
||||
/**
|
||||
* Adds the Object pointer to the List pointed to by this ListIterator.
|
||||
* The Object pointer is inserted as the next item in the List
|
||||
* based on the current position within the List
|
||||
* @param objPtr the Object pointer to add to the list
|
||||
**/
|
||||
|
||||
virtual void add(void* objPtr);
|
||||
|
||||
/**
|
||||
* Returns true if a sucessful call to the next() method can be made
|
||||
* @return MB_TRUE if a sucessful call to the next() method can be made,
|
||||
* otherwise MB_FALSE
|
||||
**/
|
||||
virtual MBool hasNext();
|
||||
|
||||
/**
|
||||
* Returns true if a sucessful call to the previous() method can be made
|
||||
* @return MB_TRUE if a sucessful call to the previous() method can be made,
|
||||
* otherwise MB_FALSE
|
||||
**/
|
||||
virtual MBool hasPrevious();
|
||||
|
||||
/**
|
||||
* Returns the next Object pointer from the list
|
||||
**/
|
||||
virtual void* next();
|
||||
|
||||
/**
|
||||
* Returns the previous Object pointer from the list
|
||||
**/
|
||||
virtual void* previous();
|
||||
|
||||
/**
|
||||
* Removes the Object last returned by the next() or previous() methods;
|
||||
* @return the removed Object pointer
|
||||
**/
|
||||
virtual void* remove();
|
||||
|
||||
/**
|
||||
* Resets the current location within the List to the beginning of the List
|
||||
**/
|
||||
virtual void reset();
|
||||
|
||||
/**
|
||||
* sets this iterator to operate in the reverse direction
|
||||
**/
|
||||
void reverse();
|
||||
|
||||
private:
|
||||
|
||||
int count;
|
||||
//-- points to the current list item
|
||||
List::ListItem* currentItem;
|
||||
|
||||
//-- points to the list to iterator over
|
||||
List* list;
|
||||
|
||||
//-- determins if we can remove the current item from the list
|
||||
MBool allowRemove;
|
||||
|
||||
MBool done;
|
||||
|
||||
MBool moveForward;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "ErrorObserver.h"
|
||||
|
||||
/**
|
||||
* Creates a new SimpleErrorObserver.
|
||||
* All errors will be printed to the console (cout).
|
||||
**/
|
||||
SimpleErrorObserver::SimpleErrorObserver() {
|
||||
errStream = &cout;
|
||||
hideWarnings = MB_FALSE;
|
||||
} //-- SimpleErrorObserver
|
||||
|
||||
/**
|
||||
* Creates a new SimpleErrorObserver.
|
||||
* All errors will be printed to the given ostream.
|
||||
**/
|
||||
SimpleErrorObserver::SimpleErrorObserver(ostream& errStream) {
|
||||
this->errStream = &errStream;
|
||||
hideWarnings = MB_FALSE;
|
||||
} //-- SimpleErrorObserver
|
||||
|
||||
/**
|
||||
* Notifies this Error observer of a new error, with default
|
||||
* level of NORMAL
|
||||
**/
|
||||
void SimpleErrorObserver::recieveError(String& errorMessage) {
|
||||
*errStream << "error: " << errorMessage << endl;
|
||||
errStream->flush();
|
||||
} //-- recieveError
|
||||
|
||||
/**
|
||||
* Notifies this Error observer of a new error using the given error level
|
||||
**/
|
||||
void SimpleErrorObserver::recieveError(String& errorMessage, ErrorLevel level) {
|
||||
|
||||
|
||||
switch ( level ) {
|
||||
case ErrorObserver::FATAL :
|
||||
*errStream << "fatal error: ";
|
||||
break;
|
||||
case ErrorObserver::WARNING :
|
||||
if ( hideWarnings ) return;
|
||||
*errStream << "warning: ";
|
||||
break;
|
||||
default:
|
||||
*errStream << "error: ";
|
||||
break;
|
||||
}
|
||||
|
||||
*errStream << errorMessage << endl;
|
||||
errStream->flush();
|
||||
} //-- recieveError
|
||||
|
||||
void SimpleErrorObserver::supressWarnings(MBool supress) {
|
||||
this->hideWarnings = supress;
|
||||
} //-- supressWarnings
|
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "XSLProcessor.h"
|
||||
|
||||
//--------------/
|
||||
//- Prototypes -/
|
||||
//--------------/
|
||||
|
||||
/**
|
||||
* Prints the command line help screen to the console
|
||||
**/
|
||||
void printHelp();
|
||||
|
||||
/**
|
||||
* prints the command line usage information to the console
|
||||
**/
|
||||
void printUsage();
|
||||
|
||||
/**
|
||||
* The TransforMiiX command line interface
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
XSLProcessor xslProcessor;
|
||||
|
||||
String copyright("(C) 1999 The MITRE Corporation");
|
||||
cout << xslProcessor.getAppName() << " ";
|
||||
cout << xslProcessor.getAppVersion() << copyright <<endl;
|
||||
|
||||
//-- print banner line
|
||||
Int32 fillSize = 1;
|
||||
fillSize += xslProcessor.getAppName().length();
|
||||
fillSize += xslProcessor.getAppVersion().length() + copyright.length();
|
||||
String fill;
|
||||
fill.setLength(fillSize, '-');
|
||||
cout << fill <<endl<<endl;
|
||||
|
||||
//-- add ErrorObserver
|
||||
SimpleErrorObserver seo;
|
||||
xslProcessor.addErrorObserver(seo);
|
||||
|
||||
//-- available flags
|
||||
StringList flags;
|
||||
flags.add(new String("i")); // XML input
|
||||
flags.add(new String("s")); // XSL input
|
||||
flags.add(new String("o")); // Output filename
|
||||
|
||||
NamedMap options;
|
||||
options.setObjectDeletion(MB_TRUE);
|
||||
CommandLineUtils::getOptions(options, argc, argv, flags);
|
||||
|
||||
if ( options.get("h") ) {
|
||||
printHelp();
|
||||
return 0;
|
||||
}
|
||||
String* xmlFilename = (String*)options.get("i");
|
||||
String* xslFilename = (String*)options.get("s");
|
||||
String* outFilename = (String*)options.get("o");
|
||||
|
||||
if ( !xmlFilename ) {
|
||||
cout << " missing XML filename."<<endl <<endl;
|
||||
printUsage();
|
||||
return -1;
|
||||
}
|
||||
char* chars = 0;
|
||||
|
||||
//-- open XML file
|
||||
chars = new char[xmlFilename->length()+1];
|
||||
ifstream xmlInput(xmlFilename->toChar(chars), ios::in);
|
||||
delete chars;
|
||||
|
||||
//-- create document base
|
||||
String documentBase;
|
||||
URIUtils::getDocumentBase(*xmlFilename, documentBase);
|
||||
|
||||
//-- handle output stream
|
||||
ostream* resultOutput = &cout;
|
||||
ofstream resultFileStream;
|
||||
if ( outFilename ) {
|
||||
chars = new char[outFilename->length()+1];
|
||||
resultFileStream.open(outFilename->toChar(chars), ios::out);
|
||||
delete chars;
|
||||
if ( !resultFileStream ) {
|
||||
cout << "error opening output file: " << *xmlFilename << endl;
|
||||
return -1;
|
||||
}
|
||||
resultOutput = &resultFileStream;
|
||||
}
|
||||
//-- process
|
||||
if ( !xslFilename ) {
|
||||
xslProcessor.process(xmlInput, documentBase, *resultOutput);
|
||||
}
|
||||
else {
|
||||
//-- open XSL file
|
||||
chars = new char[xslFilename->length()+1];
|
||||
ifstream xslInput(xslFilename->toChar(chars), ios::in);
|
||||
delete chars;
|
||||
xslProcessor.process(xmlInput, xslInput, *resultOutput);
|
||||
}
|
||||
resultFileStream.close();
|
||||
return 0;
|
||||
} //-- main
|
||||
|
||||
void printHelp() {
|
||||
cout << "The following flags are available for use with TransforMiiX -";
|
||||
cout<<endl<<endl;
|
||||
cout << "-i filename : The XML file to process" << endl;
|
||||
cout << "-o filename : The Output file to create" << endl;
|
||||
cout << "-s filename : The XSL file to use for processing (Optional)" << endl;
|
||||
cout << "-h : This help screen (Optional)" << endl;
|
||||
cout << endl;
|
||||
}
|
||||
void printUsage() {
|
||||
cout << endl;
|
||||
cout << "usage:";
|
||||
cout << "transfrmx -i xml-file [-s xsl-file] [-o output-file]"<<endl;
|
||||
cout << endl;
|
||||
cout << "for more infomation use the -h flag"<<endl;
|
||||
} //-- printUsage
|
||||
|
|
@ -0,0 +1,252 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* An XML utility class
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
|
||||
#include "XMLUtils.h"
|
||||
|
||||
//------------------------------/
|
||||
//- Implementation of XMLUtils -/
|
||||
//------------------------------/
|
||||
|
||||
const String XMLUtils::XMLNS = "xmlns";
|
||||
|
||||
void XMLUtils::getNameSpace(const String& src, String& dest) {
|
||||
|
||||
//-- anything preceding ':' is the namespace part of the name
|
||||
int idx = src.indexOf(':');
|
||||
if ( idx > 0 ) {
|
||||
//-- create new String to prevent any chars in dest from being
|
||||
//-- lost
|
||||
String tmp;
|
||||
src.subString(0,idx, tmp);
|
||||
dest.append(tmp);
|
||||
}
|
||||
else dest.append("");
|
||||
|
||||
} //-- getNameSpace
|
||||
|
||||
void XMLUtils::getLocalPart(const String& src, String& dest) {
|
||||
|
||||
//-- anything after ':' is the local part of the name
|
||||
int idx = src.indexOf(':');
|
||||
if ( idx < -1 ) idx = -1;
|
||||
//-- create new String to prevent any chars in dest from being
|
||||
//-- lost
|
||||
String tmp;
|
||||
src.subString(idx+1, tmp);
|
||||
dest.append(tmp);
|
||||
|
||||
} //-- getLocalPart
|
||||
|
||||
/**
|
||||
* Returns true if the given character represents an Alpha letter
|
||||
**/
|
||||
MBool XMLUtils::isAlphaChar(Int32 ch) {
|
||||
if ((ch >= 'a' ) && (ch <= 'z' )) return MB_TRUE;
|
||||
if ((ch >= 'A' ) && (ch <= 'Z' )) return MB_TRUE;
|
||||
return MB_FALSE;
|
||||
} //-- isAlphaChar
|
||||
|
||||
/**
|
||||
* Returns true if the given character represents a numeric letter (digit)
|
||||
**/
|
||||
MBool XMLUtils::isDigit(Int32 ch) {
|
||||
if ((ch >= '0') && (ch <= '9')) return MB_TRUE;
|
||||
return MB_FALSE;
|
||||
} //-- isDigit
|
||||
|
||||
/**
|
||||
* Returns true if the given character is an allowable QName character
|
||||
**/
|
||||
MBool XMLUtils::isNCNameChar(Int32 ch) {
|
||||
if (isDigit(ch) || isAlphaChar(ch)) return MB_TRUE;
|
||||
return (MBool) ((ch == '.') ||(ch == '_') || (ch == '-'));
|
||||
} //-- isNCNameChar
|
||||
|
||||
/**
|
||||
* Returns true if the given character is an allowable NCName character
|
||||
**/
|
||||
MBool XMLUtils::isQNameChar(Int32 ch) {
|
||||
return (MBool) (( ch == ':') || isNCNameChar(ch));
|
||||
} //-- isQNameChar
|
||||
|
||||
/**
|
||||
* Returns true if the given String is a valid XML QName
|
||||
**/
|
||||
MBool XMLUtils::isValidQName(String& name) {
|
||||
|
||||
int size = name.length();
|
||||
if ( size == 0 ) return MB_FALSE;
|
||||
else if ( !isAlphaChar(name.charAt(0))) return MB_FALSE;
|
||||
else {
|
||||
for ( int i = 1; i < size; i++) {
|
||||
if ( ! isQNameChar(name.charAt(i))) return MB_FALSE;
|
||||
}
|
||||
}
|
||||
return MB_TRUE;
|
||||
} //-- isValidQName
|
||||
|
||||
/**
|
||||
* Normalizes the value of an XML attribute
|
||||
**/
|
||||
void XMLUtils::normalizeAttributeValue(String& attValue) {
|
||||
Int32 size = attValue.length();
|
||||
//-- make copy of chars
|
||||
char* chars = new char[size+1];
|
||||
attValue.toChar(chars);
|
||||
//-- clear attValue
|
||||
attValue.clear();
|
||||
|
||||
Int32 cc = 0;
|
||||
MBool addSpace = MB_FALSE;
|
||||
while ( cc < size) {
|
||||
char ch = chars[cc++];
|
||||
switch (ch) {
|
||||
case ' ':
|
||||
if ( attValue.length() > 0) addSpace = MB_TRUE;
|
||||
break;
|
||||
case '\r':
|
||||
break;
|
||||
case '\n':
|
||||
attValue.append("
");
|
||||
break;
|
||||
default:
|
||||
if ( addSpace) {
|
||||
attValue.append(' ');
|
||||
addSpace = MB_FALSE;
|
||||
}
|
||||
attValue.append(ch);
|
||||
break;
|
||||
}
|
||||
}
|
||||
delete chars;
|
||||
} //-- normalizeAttributeValue
|
||||
|
||||
/**
|
||||
* Normalizes the value of a XML processing instruction
|
||||
**/
|
||||
void XMLUtils::normalizePIValue(String& piValue) {
|
||||
Int32 size = piValue.length();
|
||||
//-- make copy of chars
|
||||
char* chars = new char[size+1];
|
||||
piValue.toChar(chars);
|
||||
//-- clear attValue
|
||||
piValue.clear();
|
||||
|
||||
Int32 cc = 0;
|
||||
char prevCh = '\0';
|
||||
while ( cc < size) {
|
||||
char ch = chars[cc++];
|
||||
switch (ch) {
|
||||
case '>':
|
||||
if ( prevCh == '?' ) {
|
||||
piValue.append(' ');
|
||||
}
|
||||
piValue.append(ch);
|
||||
break;
|
||||
default:
|
||||
piValue.append(ch);
|
||||
break;
|
||||
}
|
||||
prevCh = ch;
|
||||
}
|
||||
delete chars;
|
||||
} //-- noramlizePIValue
|
||||
|
||||
/**
|
||||
* Strips whitespace from the given String.
|
||||
* Newlines (#xD), tabs (#x9), and consecutive spaces (#x20) are
|
||||
* converted to a single space (#x20).
|
||||
* @param data the String to strip whitespace from
|
||||
* @param dest the destination String to append the result to
|
||||
**/
|
||||
void XMLUtils::stripSpace (const String& data, String& dest) {
|
||||
stripSpace(data,dest,MB_FALSE,MB_FALSE);
|
||||
} //-- stripSpace
|
||||
|
||||
/**
|
||||
* Strips whitespace from the given String.
|
||||
* Newlines (#xD), tabs (#x9), and consecutive spaces (#x20) are
|
||||
* converted to a single space (#x20).
|
||||
* @param data the String to strip whitespace from
|
||||
* @param dest the destination String to append the result to
|
||||
* @param stripAllLeadSpace, a boolean indicating whether or not to
|
||||
* strip all leading space. If true all whitespace from the start of the
|
||||
* given String will be stripped. If false, all whitespace from the start
|
||||
* of the given String will be converted to a single space.
|
||||
* @param stripAllTrailSpace, a boolean indicating whether or not to
|
||||
* strip all trailing space. If true all whitespace at the end of the
|
||||
* given String will be stripped. If false, all whitespace at the end
|
||||
* of the given String will be converted to a single space.
|
||||
**/
|
||||
void XMLUtils::stripSpace
|
||||
( const String& data,
|
||||
String& dest,
|
||||
MBool stripAllLeadSpace,
|
||||
MBool stripAllTrailSpace )
|
||||
{
|
||||
|
||||
char lastToken, token;
|
||||
Int32 oldSize = data.length();
|
||||
char* chars = new char[oldSize+1];
|
||||
data.toChar(chars);
|
||||
|
||||
lastToken = '\0';
|
||||
Int32 total = 0;
|
||||
|
||||
// indicates we have seen at least one
|
||||
// non whitespace charater
|
||||
MBool validChar = MB_FALSE;
|
||||
|
||||
for (int i = 0; i < oldSize; i++) {
|
||||
token = chars[i];
|
||||
switch(token) {
|
||||
case ' ':
|
||||
case '\t':
|
||||
case '\n':
|
||||
case '\r':
|
||||
token = ' ';
|
||||
if (stripAllLeadSpace && (!validChar)) break;
|
||||
if (lastToken != token) chars[total++] = token;
|
||||
break;
|
||||
default:
|
||||
chars[total++] = token;
|
||||
validChar = MB_TRUE;
|
||||
break;
|
||||
}
|
||||
lastToken = token;
|
||||
}
|
||||
|
||||
//-- remove last trailing space if necessary
|
||||
if (stripAllTrailSpace)
|
||||
if ((total > 0) && (chars[total-1] == ' ')) --total;
|
||||
|
||||
if (validChar) {
|
||||
chars[total] = '\0'; //-- add Null terminator
|
||||
dest.append(chars);
|
||||
}
|
||||
delete chars;
|
||||
} //-- stripSpace
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* An XML Utility class
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
|
||||
#include "String.h"
|
||||
#include "baseutils.h"
|
||||
|
||||
#ifndef MITRE_XMLUTILS_H
|
||||
#define MITRE_XMLUTILS_H
|
||||
|
||||
class XMLUtils {
|
||||
|
||||
public:
|
||||
|
||||
static const String XMLNS;
|
||||
|
||||
static void getNameSpace(const String& src, String& dest);
|
||||
static void getLocalPart(const String& src, String& dest);
|
||||
|
||||
/**
|
||||
* Returns true if the given String is a valid XML QName
|
||||
**/
|
||||
static MBool isValidQName(String& name);
|
||||
|
||||
/**
|
||||
* Normalizes the value of an XML attribute
|
||||
**/
|
||||
static void normalizeAttributeValue(String& attValue);
|
||||
|
||||
/**
|
||||
* Normalizes the value of a XML processingInstruction
|
||||
**/
|
||||
static void normalizePIValue(String& attValue);
|
||||
|
||||
/**
|
||||
* Strips whitespace from the given String.
|
||||
* Newlines (#xD), tabs (#x9), and consecutive spaces (#x20) are
|
||||
* converted to a single space (#x20).
|
||||
* @param data the String to strip whitespace from
|
||||
* @param dest the destination String to append the result to
|
||||
**/
|
||||
static void stripSpace (const String& data, String& dest);
|
||||
|
||||
/**
|
||||
* Strips whitespace from the given String.
|
||||
* Newlines (#xD), tabs (#x9), and consecutive spaces (#x20) are
|
||||
* converted to a single space (#x20).
|
||||
* @param data the String to strip whitespace from
|
||||
* @param dest the destination String to append the result to
|
||||
* @param stripAllLeadSpace, a boolean indicating whether or not to
|
||||
* strip all leading space. If true all whitespace from the start of the
|
||||
* given String will be stripped. If false, all whitespace from the start
|
||||
* of the given String will be converted to a single space.
|
||||
* @param stripAllTrailSpace, a boolean indicating whether or not to
|
||||
* strip all trailing space. If true all whitespace at the end of the
|
||||
* given String will be stripped. If false, all whitespace at the end
|
||||
* of the given String will be converted to a single space.
|
||||
**/
|
||||
static void stripSpace (const String& data,
|
||||
String& dest,
|
||||
MBool stripAllLeadSpace,
|
||||
MBool stripAllTrailSpace);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Returns true if the given character represents an Alpha letter
|
||||
**/
|
||||
static MBool isAlphaChar(Int32 ch);
|
||||
|
||||
/**
|
||||
* Returns true if the given character represents a numeric letter (digit)
|
||||
**/
|
||||
static MBool isDigit(Int32 ch);
|
||||
|
||||
/**
|
||||
* Returns true if the given character is an allowable QName character
|
||||
**/
|
||||
static MBool isQNameChar(Int32 ch);
|
||||
|
||||
/**
|
||||
* Returns true if the given character is an allowable NCName character
|
||||
**/
|
||||
static MBool isNCNameChar(Int32 ch);
|
||||
|
||||
}; //-- XMLUtils
|
||||
#endif
|
|
@ -0,0 +1,67 @@
|
|||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..\..\..
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
DEFINES=-DMOZILLA
|
||||
|
||||
MODULE=transformix
|
||||
REQUIRES=xpcom raptor
|
||||
IS_COMPONENT = 1
|
||||
|
||||
CPPSRCS= \
|
||||
XSLProcessorFactory.cpp \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS= \
|
||||
.\$(OBJDIR)\XSLProcessorFactory.obj \
|
||||
$(NULL)
|
||||
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
DLLNAME = transformiix
|
||||
DLL=.\$(OBJDIR)\$(DLLNAME).dll
|
||||
|
||||
LCFLAGS = \
|
||||
$(LCFLAGS) \
|
||||
$(DEFINES) \
|
||||
$(NULL)
|
||||
|
||||
LINCS= -I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \
|
||||
-I..\source\xml\dom \
|
||||
-I..\source\xsl\expr -I..\source\xsl\util -I..\source\xml -I..\source\xsl \
|
||||
-I..\source\base \
|
||||
|
||||
# These are the libraries we need to link with to create the dll
|
||||
LLIBS= \
|
||||
$(DIST)\lib\xpcom.lib \
|
||||
$(DIST)\lib\transformix_base.lib \
|
||||
$(DIST)\lib\transformix_xml.lib \
|
||||
$(DIST)\lib\transformix_xml_dom_mozImpl.lib \
|
||||
$(DIST)\lib\transformix_xsl.lib \
|
||||
$(DIST)\lib\transformix_xsl_expr.lib \
|
||||
$(DIST)\lib\transformix_xsl_util.lib
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\bin\$(DLLNAME).dll
|
||||
rm -f $(DIST)\lib\$(DLLNAME).lib
|
|
@ -0,0 +1,122 @@
|
|||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>MITRE TransforMiiX(tm) Contributors</TITLE>
|
||||
<META name="author" content="Keith Visco">
|
||||
</HEAD>
|
||||
<BODY Text="#000000">
|
||||
<!-- OUTER TABLE -->
|
||||
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="640">
|
||||
<TR>
|
||||
<TD WIDTH="80"></TD>
|
||||
<TD WIDTH="80">
|
||||
<B><I><FONT SIZE="+2" COLOR="BLUE">MITRE</FONT></I></B>
|
||||
</TD>
|
||||
<TD WIDTH="480" ALIGN="RIGHT">
|
||||
<B><FONT SIZE="+2">Transfor<FONT Color="blue">Mii</FONT>X</FONT></B>
|
||||
<SUP>TM</SUP>
|
||||
</TD>
|
||||
</TR>
|
||||
<TD WIDTH="80"><BR></TD>
|
||||
<TD WIDTH="560" COLSPAN="2">
|
||||
<!-- Contents -->
|
||||
<HR SIZE="1" />
|
||||
<BR/>
|
||||
<P>
|
||||
Much of the <B>Transfor<FONT Color="blue">Mii</FONT>X</B> code was ported
|
||||
from <A HREF="http://www.clc-marketing.com/xslp">XSL:P</A>,
|
||||
an open source XSLT processor. Thanks to all the contributors of
|
||||
that project.
|
||||
<P>
|
||||
<P>
|
||||
<B>Core Developers</B><P>
|
||||
The following people have contributed substantial time and
|
||||
effort to the development.
|
||||
<TABLE WIDTH="100%" CELLSPACING="1">
|
||||
<TR BGColor="#EEEEEE"><TH>Name</TH><TH>Contribution</TH><TH>Company</TH></TR>
|
||||
<!-- Entry -->
|
||||
<TR BGColor="#EEEEEE">
|
||||
<TD VALIGN="TOP">
|
||||
<A href="mailto:kvisco@mitre.org">Visco, Keith</a>
|
||||
</TD>
|
||||
<TD>
|
||||
Software design and most of the implementation
|
||||
</TD>
|
||||
<TD VALIGN="TOP">
|
||||
<A HREF="http://www.mitre.org">The MITRE Corporation</A>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- Entry -->
|
||||
<TR BGColor="#EEEEEE">
|
||||
<TD VALIGN="TOP">
|
||||
<A href="mailto:tomk@mitre.org">Kneeland, Tom</a>
|
||||
</TD>
|
||||
<TD>
|
||||
DOM Implementation, Most of the String class
|
||||
</TD>
|
||||
<TD VALIGN="TOP">
|
||||
<A HREF="http://www.mitre.org">The MITRE Corporation</A>
|
||||
</TD>
|
||||
</TR>
|
||||
|
||||
</TABLE>
|
||||
</P>
|
||||
<P>
|
||||
<P>
|
||||
<B>Additional Developers</B><P>
|
||||
The following people have contributed to the development.
|
||||
<BR>(appearing in alphabetical order)
|
||||
<TABLE WIDTH="100%" CELLSPACING="1">
|
||||
<TR BGColor="#EEEEEE"><TH>Name</TH><TH>Contribution</TH><TH>Company</TH></TR>
|
||||
<!-- Entry -->
|
||||
<TR BGColor="#EEEEEE">
|
||||
<TD VALIGN="TOP">
|
||||
<A HREF="mailto:lef@opentext.com">Fitzpatrick, Larry</A>
|
||||
</TD>
|
||||
<TD WIDTH="300">
|
||||
C++ porting issues with Visual C++, design influences
|
||||
</TD>
|
||||
<TD VALIGN="TOP">
|
||||
<A HREF="http://www.opentext.com">OpenText</A>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- Entry -->
|
||||
<TR BGColor="#EEEEEE">
|
||||
<TD VALIGN="TOP">
|
||||
<A HREF="mailto:mclee@oblix.com">Lee, Michele</A>
|
||||
</TD>
|
||||
<TD WIDTH="300">
|
||||
C++ porting issues
|
||||
</TD>
|
||||
<TD VALIGN="TOP">
|
||||
<A HREF="http://www.oblix.com">Oblix</A>
|
||||
</TD>
|
||||
</TR>
|
||||
|
||||
</TABLE>
|
||||
|
||||
<P><B>Testing/Feedback (Suggestions/Bug Reports)</B><P>
|
||||
The following people have used TransforMiiX and provided feedback that has been
|
||||
beneficial to the development.
|
||||
<BR>(appearing in alphabetical order)
|
||||
<TABLE BORDER="0" WIDTH="100%">
|
||||
<TR BGColor="#EEEEEE"><TD><B>Name</B></TD><TD><B>Company</B></TD></TR>
|
||||
<!-- Entry -->
|
||||
<TR BGColor="#EEEEEE">
|
||||
<TD><A HREF="mailto:costello@mitre.org">Costello, Roger</A></TD>
|
||||
<TD><A HREF="http://www.mitre.org">The MITRE Corporation</A></TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
<!-- End Contents -->
|
||||
|
||||
<!-- Footer -->
|
||||
<HR SIZE="1">
|
||||
<FONT SIZE="-1">
|
||||
The MITRE Corporation, (C) Copyright 1999, All rights reserved<BR>
|
||||
Email:<A HREF="mailto:kvisco@mitre.org">kvisco@mitre.org</A>
|
||||
</FONT>
|
||||
<!-- End Footer -->
|
||||
</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
<!-- End Outer Table -->
|
||||
</HTML>
|
|
@ -0,0 +1,22 @@
|
|||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..\..
|
||||
|
||||
DIRS=source build
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
|
@ -0,0 +1,24 @@
|
|||
TransforMiiX (TM) (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
|
||||
All source and compiled binaries are considered the "program".
|
||||
|
||||
The contents of all source files in distributed with this
|
||||
program are subject to the Mozilla Public License
|
||||
Version 1.0 (the "License"); you may not use those files except in
|
||||
compliance with the License. You may obtain a copy of the License at
|
||||
http://www.mozilla.org/MPL/
|
||||
|
||||
The program provided "as is" without any warranty express or
|
||||
implied, including the warranty of non-infringement and the implied
|
||||
warranties of merchantibility and fitness for a particular purpose.
|
||||
The Copyright owner will not be liable for any damages suffered by
|
||||
you as a result of using the Program. In no event will the Copyright
|
||||
owner be liable for any special, indirect or consequential damages or
|
||||
lost profits even if the Copyright owner has been advised of the
|
||||
possibility of their occurrence.
|
||||
|
||||
Much of the source code was ported from XSL:P [http://xslp.kvisco.com],
|
||||
an open source Java XSL processor written by Keith Visco.
|
||||
There were a number of contributors to XSL:P and therefor many of
|
||||
those contributors have indirectly contributed to this project.
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
target: TransforMiiX
|
||||
|
||||
CC = g++
|
||||
|
||||
ROOT_PATH = .
|
||||
XML_PATH = $(ROOT_PATH)/xml
|
||||
XSL_PATH = $(ROOT_PATH)/xsl
|
||||
BASE_PATH = $(ROOT_PATH)/base
|
||||
DOM_PATH = $(XML_PATH)/dom
|
||||
NET_PATH = $(ROOT_PATH)/net
|
||||
EXPR_PATH = $(XSL_PATH)/expr
|
||||
XSLUTIL_PATH = $(XSL_PATH)/util
|
||||
XMLPRINTER_PATH = $(XML_PATH)/printer
|
||||
XMLPARSER_PATH = $(XML_PATH)/parser
|
||||
EXPAT_PARSER_PATH = $(XMLPARSER_PATH)/xmlparse
|
||||
EXPAT_TOKEN_PATH = $(XMLPARSER_PATH)/xmltok
|
||||
|
||||
|
||||
INCLUDE_PATHS = -I $(BASE_PATH) \
|
||||
-I $(NET_PATH) \
|
||||
-I $(DOM_PATH) \
|
||||
-I $(XML_PATH) \
|
||||
-I $(EXPR_PATH) \
|
||||
-I $(XSL_PATH) \
|
||||
-I $(XSLUTIL_PATH) \
|
||||
-I $(XMLPARSER_PATH) \
|
||||
-I $(XMLPRINTER_PATH) \
|
||||
-I $(EXPAT_PARSER_PATH) -I-
|
||||
|
||||
BASE_OBJS = $(BASE_PATH)/*.o
|
||||
|
||||
NET_OBJS = $(NET_PATH)/*.o
|
||||
|
||||
DOM_OBJS = $(DOM_PATH)/*.o
|
||||
|
||||
EXPR_OBJS = $(EXPR_PATH)/*.o
|
||||
|
||||
XML_OBJS = $(XML_PATH)/*.o
|
||||
|
||||
XMLPRINTER_OBJS = $(XMLPRINTER_PATH)/*.o
|
||||
|
||||
XMLPARSER_OBJS = $(XMLPARSER_PATH)/*.o
|
||||
EXPAT_TOKEN_OBJS = $(EXPAT_TOKEN_PATH)/*.o
|
||||
EXPAT_PARSER_OBJS = $(EXPAT_PARSER_PATH)/*.o
|
||||
|
||||
XSLUTIL_OBJS = $(XSLUTIL_PATH)/*.o
|
||||
XSL_OBJS = $(XSL_PATH)/*.o
|
||||
|
||||
ALL_OBJS = $(BASE_OBJS) \
|
||||
$(NET_OBJS) \
|
||||
$(DOM_OBJS) \
|
||||
$(XSLUTIL_OBJS) \
|
||||
$(EXPR_OBJS) \
|
||||
$(XML_OBJS) \
|
||||
$(XMLPRINTER_OBJS) \
|
||||
$(XMLPARSER_OBJS) \
|
||||
$(EXPAT_TOKEN_OBJS) \
|
||||
$(EXPAT_PARSER_OBJS) \
|
||||
$(XSL_OBJS)
|
||||
|
||||
MAIN_CPP = main/transformiix.cpp
|
||||
|
||||
TransforMiiX: $(ALL_OBJS)
|
||||
$(CC) $(INCLUDE_PATHS) $(ALL_OBJS) $(MAIN_CPP) -o transfrmx.exe
|
||||
|
||||
|
||||
$(BASE_OBJS): $(BASE_PATH)/*.cpp $(BASE_PATH)/*.h
|
||||
cd $(BASE_PATH); make
|
||||
|
||||
$(DOM_OBJS): $(DOM_PATH)/*.cpp $(DOM_PATH)/dom.h
|
||||
cd $(DOM_PATH); make
|
||||
|
||||
|
||||
$(XML_OBJS): $(XML_PATH)/*.cpp $(XML_PATH)/*.h
|
||||
cd $(XML_PATH); make
|
||||
|
||||
$(EXPAT_TOKEN_OBJS):
|
||||
cd $(XMLPARSER_PATH); make -f expat.mk
|
||||
|
||||
$(EXPAT_PARSER_OBJS):
|
||||
cd $(XMLPARSER_PATH); make -f expat.mk
|
||||
|
||||
$(XMLPARSER_OBJS):
|
||||
cd $(XMLPARSER_PATH); make
|
||||
|
||||
$(XMLPRINTER_OBJS):
|
||||
cd $(XMLPRINTER_PATH); make
|
||||
|
||||
$(NET_OBJS):
|
||||
cd $(NET_PATH); make
|
||||
|
||||
$(XSLUTIL_OBJS):
|
||||
cd $(XSLUTIL_PATH); make
|
||||
|
||||
$(EXPR_OBJS):
|
||||
cd $(EXPR_PATH); make
|
||||
|
||||
$(XSL_OBJS):
|
||||
cd $(XSL_PATH); make
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "CommandLineUtils.h"
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
void CommandLineUtils::getOptions
|
||||
(NamedMap& options, int argc, char** argv, StringList& flags)
|
||||
{
|
||||
String arg;
|
||||
String flag;
|
||||
for (int i = 0; i < argc; i++) {
|
||||
arg.clear();
|
||||
arg.append(argv[i]);
|
||||
|
||||
if ((arg.length()>0) && (arg.charAt(0) == '-')) {
|
||||
|
||||
// clean up previous flag
|
||||
if (flag.length()>0) {
|
||||
options.put(flag, new String(arg));
|
||||
flag.clear();
|
||||
}
|
||||
// get next flag
|
||||
arg.subString(1,flag);
|
||||
|
||||
//-- check full flag, otherwise try to find
|
||||
//-- flag within string
|
||||
if (!flags.contains(flag)) {
|
||||
Int32 idx = 1;
|
||||
String tmpFlag;
|
||||
while(idx <= flag.length()) {
|
||||
flag.subString(0,idx, tmpFlag);
|
||||
if (flags.contains(tmpFlag)) {
|
||||
if (idx < flag.length()) {
|
||||
String* value = new String();
|
||||
flag.subString(idx, *value);
|
||||
options.put(tmpFlag,value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (idx == flag.length()) {
|
||||
cout << "invalid option: -" << flag << endl;
|
||||
}
|
||||
++idx;
|
||||
}// end while
|
||||
}
|
||||
}// if flag char '-'
|
||||
else {
|
||||
// Store both flag key and number key
|
||||
if (flag.length() > 0) options.put(flag, new String(arg));
|
||||
flag.clear();
|
||||
}
|
||||
|
||||
}// end for
|
||||
if (flag.length()>0) options.put(flag, new String("no value"));
|
||||
} //-- getOptions
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "baseutils.h"
|
||||
#include "StringList.h"
|
||||
#include "NamedMap.h"
|
||||
|
||||
#ifndef MITRE_COMMANDLINEUTILS_H
|
||||
#define MITRE_COMMANDLINEUTILS_H
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
class CommandLineUtils {
|
||||
|
||||
public:
|
||||
static void getOptions
|
||||
(NamedMap& options, int argc, char** argv, StringList& flags);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,238 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "primitives.h"
|
||||
|
||||
//----------------------------/
|
||||
//- Implementation of Double -/
|
||||
//----------------------------/
|
||||
/**
|
||||
* A wrapper for the primitive double type, and provides some simple
|
||||
* floating point related routines
|
||||
* @author <a href="mailto:lef@opentext.com">Larry Fitzpatrick</a>
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
|
||||
double d0 = 0.0;
|
||||
|
||||
const double Double::NaN = (d0/d0);
|
||||
const double Double::NEGATIVE_INFINITY = (-1.0/d0);
|
||||
const double Double::POSITIVE_INFINITY = (1.0/d0);
|
||||
|
||||
/**
|
||||
* Creates a new Double with it's value initialized to 0;
|
||||
**/
|
||||
Double::Double() {
|
||||
value = 0;
|
||||
} //-- Double
|
||||
|
||||
/**
|
||||
* Creates a new Double with it's value initialized to the given double
|
||||
**/
|
||||
Double::Double(double dbl) {
|
||||
this->value = dbl;
|
||||
} //-- Double
|
||||
|
||||
/**
|
||||
* Creates a new Double with it's value initialized from the given String.
|
||||
* The String will be converted to a double. If the String does not
|
||||
* represent an IEEE 754 double, the value will be initialized to NaN
|
||||
**/
|
||||
Double::Double(const String& string) {
|
||||
this->value = toDouble(string);
|
||||
} //-- Double
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the value of this Double as a double
|
||||
**/
|
||||
double Double::doubleValue() {
|
||||
return this->value;
|
||||
} //-- doubleValue
|
||||
|
||||
/**
|
||||
* Returns the value of this Double as an int
|
||||
**/
|
||||
int Double::intValue() {
|
||||
return (int)value;
|
||||
} //-- intValue
|
||||
|
||||
/**
|
||||
* Determins whether the given double represents positive or negative
|
||||
* inifinity
|
||||
**/
|
||||
MBool Double::isInfinite(double dbl) {
|
||||
return (MBool)((dbl == POSITIVE_INFINITY ) || (dbl == NEGATIVE_INFINITY));
|
||||
} //-- isInfinite
|
||||
|
||||
/**
|
||||
* Determins whether this Double's value represents positive or
|
||||
* negative inifinty
|
||||
**/
|
||||
MBool Double::isInfinite() {
|
||||
return (MBool)(( value == POSITIVE_INFINITY ) || (value == NEGATIVE_INFINITY));
|
||||
} //-- isInfinite
|
||||
|
||||
/**
|
||||
* Determins whether the given double is NaN
|
||||
**/
|
||||
MBool Double::isNaN(double dbl) {
|
||||
#ifdef MOZILLA
|
||||
return (MBool) _isnan(dbl);
|
||||
#else
|
||||
return (MBool) isnan(dbl);
|
||||
#endif
|
||||
} //-- isNaN
|
||||
|
||||
/**
|
||||
* Determins whether this Double's value is NaN
|
||||
**/
|
||||
MBool Double::isNaN() {
|
||||
#ifdef MOZILLA
|
||||
return (MBool) _isnan(value);
|
||||
#else
|
||||
return (MBool) isnan(value);
|
||||
#endif
|
||||
} //-- isNaN
|
||||
|
||||
/**
|
||||
* Converts the given String to a double, if the String value does not
|
||||
* represent a double, NaN will be returned
|
||||
**/
|
||||
double Double::toDouble(const String& src) {
|
||||
|
||||
double dbl = 0.0;
|
||||
double fraction = 1.0;
|
||||
double multiplier = 10.0;
|
||||
Int32 idx = 0;
|
||||
|
||||
double sign = 1.0;
|
||||
|
||||
//-- trim leading whitespace
|
||||
for ( ; idx < src.length(); idx++ )
|
||||
if ( src.charAt(idx) != ' ' ) break;
|
||||
|
||||
//-- check first character for sign
|
||||
if ( idx < src.length() ) {
|
||||
Int32 ch = src.charAt(idx);
|
||||
if ( ch == '-' ) {
|
||||
sign = -1.0;
|
||||
++idx;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return Double::NaN;
|
||||
}
|
||||
|
||||
//-- convert remaining to number
|
||||
for ( ; idx < src.length(); idx++ ) {
|
||||
|
||||
Int32 ch = src.charAt(idx);
|
||||
|
||||
if (( ch >= '0') && (ch <= '9')) {
|
||||
if ( multiplier > 1.0 ) {
|
||||
dbl = dbl*multiplier;
|
||||
dbl += (double) (ch-48);
|
||||
}
|
||||
else {
|
||||
dbl += multiplier * (ch-48);
|
||||
multiplier = multiplier * 0.1;
|
||||
}
|
||||
}
|
||||
else if ( ch == '.') {
|
||||
if ( multiplier < 1.0 ) return Double::NaN;
|
||||
multiplier = 0.1;
|
||||
}
|
||||
else return Double::NaN;
|
||||
}
|
||||
dbl = dbl*sign;
|
||||
return dbl;
|
||||
} //-- toDouble
|
||||
|
||||
|
||||
/**
|
||||
* Converts the value of this Double to a String, and places
|
||||
* The result into the destination String.
|
||||
* @return the given dest string
|
||||
**/
|
||||
String& Double::toString(String& dest) {
|
||||
return toString(value, dest);
|
||||
} //-- toString
|
||||
|
||||
/**
|
||||
* Converts the value of the given double to a String, and places
|
||||
* The result into the destination String.
|
||||
* @return the given dest string
|
||||
**/
|
||||
String& Double::toString(double value, String& dest) {
|
||||
|
||||
//-- check for special cases
|
||||
|
||||
if ( isNaN(value) ) {
|
||||
dest.append("NaN");
|
||||
return dest;
|
||||
}
|
||||
if ( isInfinite(value) ) {
|
||||
if (value < 0) dest.append('-');
|
||||
dest.append("Infinity");
|
||||
return dest;
|
||||
}
|
||||
|
||||
MBool isNegative = (MBool)(value<0.0);
|
||||
double val = value;
|
||||
if ( isNegative ) val = val * -1.0;
|
||||
|
||||
double ival = 0;
|
||||
double fval = modf(val, &ival);
|
||||
|
||||
String iStr;
|
||||
|
||||
int temp = (int)ival;
|
||||
|
||||
|
||||
if ( temp > 0.0 ) {
|
||||
while ( temp > 0.0 ) {
|
||||
iStr.append( (char) ((temp % 10)+48) );
|
||||
temp = temp / 10;
|
||||
}
|
||||
if ( isNegative ) iStr.append('-');
|
||||
iStr.reverse();
|
||||
}
|
||||
else iStr.append('0');
|
||||
|
||||
iStr.append('.');
|
||||
if ( fval > 0.0 ) {
|
||||
while ( fval > 0.0000001 ) {
|
||||
fval = fval*10.0;
|
||||
fval = modf(fval, &ival);
|
||||
iStr.append( (char) (ival+48) );
|
||||
}
|
||||
}
|
||||
else iStr.append('0');
|
||||
|
||||
dest.append(iStr);
|
||||
return dest;
|
||||
} //-- toString
|
||||
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MITRE_ERROROBSERVER_H
|
||||
#define MITRE_ERROROBSERVER_H
|
||||
|
||||
#include "baseutils.h"
|
||||
#include "String.h"
|
||||
#include "iostream.h"
|
||||
|
||||
/**
|
||||
* A simple interface for observing errors
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
class ErrorObserver {
|
||||
|
||||
public:
|
||||
|
||||
enum ErrorLevel {FATAL = 0, NORMAL, WARNING};
|
||||
|
||||
/**
|
||||
* Default Destructor for ErrorObserver
|
||||
**/
|
||||
virtual ~ErrorObserver() {};
|
||||
|
||||
/**
|
||||
* Notifies this Error observer of a new error, with default
|
||||
* level of NORMAL
|
||||
**/
|
||||
virtual void recieveError(String& errorMessage) = 0;
|
||||
|
||||
/**
|
||||
* Notifies this Error observer of a new error using the given error level
|
||||
**/
|
||||
virtual void recieveError(String& errorMessage, ErrorLevel level) = 0;
|
||||
|
||||
}; //-- ErrorObserver
|
||||
|
||||
/**
|
||||
* A simple ErrorObserver which allows printing error messages to a stream
|
||||
**/
|
||||
class SimpleErrorObserver : public ErrorObserver {
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new SimpleErrorObserver.
|
||||
* All errors will be printed to the console (cout).
|
||||
**/
|
||||
SimpleErrorObserver();
|
||||
|
||||
/**
|
||||
* Creates a new SimpleErrorObserver.
|
||||
* All errors will be printed to the given ostream.
|
||||
**/
|
||||
SimpleErrorObserver(ostream& errStream);
|
||||
|
||||
virtual ~SimpleErrorObserver() {};
|
||||
|
||||
/**
|
||||
* Notifies this Error observer of a new error, with default
|
||||
* level of NORMAL
|
||||
**/
|
||||
virtual void recieveError(String& errorMessage);
|
||||
|
||||
/**
|
||||
* Notifies this Error observer of a new error using the given error level
|
||||
**/
|
||||
virtual void recieveError(String& errorMessage, ErrorLevel level);
|
||||
|
||||
virtual void supressWarnings(MBool supress);
|
||||
|
||||
private:
|
||||
|
||||
ostream* errStream;
|
||||
MBool hideWarnings;
|
||||
}; //-- SimpleErrorObserver
|
||||
#endif
|
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "primitives.h"
|
||||
#include "baseutils.h"
|
||||
|
||||
//-----------------------------/
|
||||
//- Implementation of Integer -/
|
||||
//-----------------------------/
|
||||
|
||||
/**
|
||||
* A wrapper for the primitive int type, and provides some simple
|
||||
* integer related routines
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
|
||||
/**
|
||||
* Creates a new Integer initialized to 0.
|
||||
**/
|
||||
Integer::Integer() {
|
||||
value = 0;
|
||||
} //-- Integer
|
||||
|
||||
/**
|
||||
* Creates a new Integer initialized to the given int value.
|
||||
**/
|
||||
Integer::Integer(int value) {
|
||||
this->value = value;
|
||||
} //-- Integer
|
||||
|
||||
/**
|
||||
* Creates a new Integer based on the value of the given String
|
||||
**/
|
||||
Integer::Integer(const String& str) {
|
||||
Int32 val = 0;
|
||||
for (Int32 i = 0; i < str.length(); i++) {
|
||||
val = (val * 10) + (str.charAt(i) - 48);
|
||||
}
|
||||
} //-- Integer
|
||||
|
||||
/**
|
||||
* Returns the int value of this Integer
|
||||
**/
|
||||
|
||||
Int32 Integer::intValue() {
|
||||
return value;
|
||||
} //-- intValue;
|
||||
|
||||
/**
|
||||
* Converts the given String to an integer
|
||||
**/
|
||||
int Integer::intValue(const String& src) {
|
||||
|
||||
int result = 0;
|
||||
Int32 idx = 0;
|
||||
int sign = 1;
|
||||
|
||||
//-- trim leading whitespace
|
||||
for ( ; idx < src.length(); idx++ )
|
||||
if ( src.charAt(idx) != ' ' ) break;
|
||||
|
||||
//-- check first character for sign
|
||||
if ( idx < src.length() ) {
|
||||
Int32 ch = src.charAt(idx);
|
||||
if ( ch == '-' ) {
|
||||
sign = -1;
|
||||
++idx;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 0; //-- we should return NaN here
|
||||
}
|
||||
|
||||
//-- convert remaining to number
|
||||
for ( ; idx < src.length(); idx++ ) {
|
||||
Int32 ch = src.charAt(idx);
|
||||
if (( ch >= '0') && (ch <= '9')) {
|
||||
result = result*10;
|
||||
result += (ch-48);
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
result = result*sign;
|
||||
return result;
|
||||
} //-- toInteger
|
||||
|
||||
/**
|
||||
* Converts the given int to a String
|
||||
**/
|
||||
String& Integer::toString(int value, String& dest) {
|
||||
|
||||
String result;
|
||||
UNICODE_CHAR charDigit;
|
||||
Int32 tempVal = value;
|
||||
MBool isNegative = (value < 0);
|
||||
if ( isNegative ) tempVal = -value;
|
||||
|
||||
if ( tempVal > 0 ) {
|
||||
while (tempVal) {
|
||||
charDigit = (tempVal % 10) + 48;
|
||||
result.append(charDigit);
|
||||
tempVal /=10;
|
||||
}
|
||||
if ( isNegative ) result.append('-');
|
||||
result.reverse();
|
||||
}
|
||||
else result.append('0');
|
||||
dest.append(result);
|
||||
return dest;
|
||||
} //-- toString
|
||||
|
||||
/**
|
||||
* Converts the given the value of this Integer to a String
|
||||
**/
|
||||
String& Integer::toString(String& dest) {
|
||||
return Integer::toString(value, dest);
|
||||
} //-- toString
|
||||
|
|
@ -0,0 +1,319 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "List.h"
|
||||
#include <iostream.h>
|
||||
//--------------------------/
|
||||
//- Implementation of List -/
|
||||
//--------------------------/
|
||||
|
||||
/**
|
||||
* Default constructor for a List;
|
||||
**/
|
||||
List::List() {
|
||||
firstItem = 0;
|
||||
lastItem = 0;
|
||||
itemCount = 0;
|
||||
} //-- List;
|
||||
|
||||
/**
|
||||
* List destructor, cleans up List Items, but will not delete the Object
|
||||
* references
|
||||
*/
|
||||
List::~List() {
|
||||
ListItem* item = firstItem;
|
||||
while (item) {
|
||||
ListItem* tItem = item;
|
||||
item = item->nextItem;
|
||||
delete tItem;
|
||||
}
|
||||
} //-- ~List
|
||||
|
||||
void List::insert(int index, void* objPtr) {
|
||||
|
||||
if ( index >= itemCount ) {
|
||||
insertBefore(objPtr, 0);
|
||||
}
|
||||
else {
|
||||
//-- add to middle of list
|
||||
ListItem* nextItem = firstItem;
|
||||
for ( int i = 0; i < index; i++ ) nextItem = nextItem->nextItem;
|
||||
insertBefore(objPtr, nextItem);
|
||||
}
|
||||
} //-- insert
|
||||
|
||||
void List::add(void* objPtr) {
|
||||
insert(itemCount, objPtr);
|
||||
} //-- add
|
||||
|
||||
List::ListItem* List::getFirstItem() {
|
||||
return firstItem;
|
||||
} //-- getFirstItem
|
||||
|
||||
List::ListItem* List::getLastItem() {
|
||||
return lastItem;
|
||||
} //-- getLastItem
|
||||
|
||||
/**
|
||||
* Returns the number of items in this List
|
||||
**/
|
||||
Int32 List::getLength() {
|
||||
return itemCount;
|
||||
} //-- getLength
|
||||
|
||||
|
||||
/**
|
||||
* Inserts the given Object pointer as the item just after refItem.
|
||||
* If refItem is a null pointer the Object will be inserted at the
|
||||
* beginning of the List (ie, insert after nothing).
|
||||
* This method assumes refItem is a member of this list, and since this
|
||||
* is a private method, I feel that's a valid assumption
|
||||
**/
|
||||
void List::insertAfter(void* objPtr, ListItem* refItem) {
|
||||
//-- if refItem == null insert at front
|
||||
if (!refItem) insertBefore(objPtr, firstItem);
|
||||
else insertBefore(objPtr, refItem->nextItem);
|
||||
} //-- insertAfter
|
||||
|
||||
/**
|
||||
* Inserts the given Object pointer as the item just before refItem.
|
||||
* If refItem is a null pointer the Object will be inserted at the
|
||||
* end of the List (ie, insert before nothing).
|
||||
* This method assumes refItem is a member of this list, and since this
|
||||
* is a private method, I feel that's a valid assumption
|
||||
**/
|
||||
void List::insertBefore(void* objPtr, ListItem* refItem) {
|
||||
|
||||
ListItem* item = new ListItem;
|
||||
item->objPtr = objPtr;
|
||||
item->nextItem = 0;
|
||||
item->prevItem = 0;
|
||||
|
||||
//-- if refItem == null insert at end
|
||||
if (!refItem) {
|
||||
//-- add to back of list
|
||||
if ( lastItem ) {
|
||||
lastItem->nextItem = item;
|
||||
item->prevItem = lastItem;
|
||||
}
|
||||
lastItem = item;
|
||||
if ( !firstItem ) firstItem = item;
|
||||
}
|
||||
else {
|
||||
//-- insert before given item
|
||||
item->nextItem = refItem;
|
||||
item->prevItem = refItem->prevItem;
|
||||
refItem->prevItem = item;
|
||||
|
||||
if (refItem == firstItem) firstItem = item;
|
||||
if (itemCount == 0) lastItem = item; // <-should we ever see this?
|
||||
}
|
||||
|
||||
// increase the item count
|
||||
++itemCount;
|
||||
} //-- insertBefore
|
||||
|
||||
/**
|
||||
* Returns a ListIterator for this List
|
||||
**/
|
||||
ListIterator* List::iterator() {
|
||||
return new ListIterator(this);
|
||||
}
|
||||
|
||||
void* List::remove(void* objPtr) {
|
||||
ListItem* item = firstItem;
|
||||
while (item) {
|
||||
if (item->objPtr == objPtr) {
|
||||
remove(item);
|
||||
delete item;
|
||||
return objPtr;
|
||||
}
|
||||
item = item->nextItem;
|
||||
}
|
||||
// not in list
|
||||
return 0;
|
||||
} //-- remove
|
||||
|
||||
List::ListItem* List::remove(ListItem* item) {
|
||||
|
||||
if ( !item ) return item;
|
||||
|
||||
//-- adjust the previous item's next pointer
|
||||
if (item->prevItem) {
|
||||
item->prevItem->nextItem = item->nextItem;
|
||||
}
|
||||
//-- adjust the next item's previous pointer
|
||||
if ( item->nextItem ) {
|
||||
item->nextItem->prevItem = item->prevItem;
|
||||
}
|
||||
|
||||
//-- adjust first and last items
|
||||
if (item == firstItem) firstItem = item->nextItem;
|
||||
if (item == lastItem) lastItem = item->prevItem;
|
||||
|
||||
//-- decrease Item count
|
||||
--itemCount;
|
||||
return item;
|
||||
} //-- remove
|
||||
|
||||
//----------------------------------/
|
||||
//- Implementation of ListIterator -/
|
||||
//----------------------------------/
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new ListIterator for the given List
|
||||
* @param list, the List to create an Iterator for
|
||||
**/
|
||||
ListIterator::ListIterator(List* list) {
|
||||
this->list = list;
|
||||
currentItem = 0;
|
||||
allowRemove = MB_FALSE;
|
||||
moveForward = MB_TRUE;
|
||||
done = MB_FALSE;
|
||||
count = 0;
|
||||
} //-- ListIterator
|
||||
|
||||
ListIterator::~ListIterator() {
|
||||
//-- overrides default destructor to do nothing
|
||||
} //-- ~ListIterator
|
||||
|
||||
/**
|
||||
* Adds the Object pointer to the List pointed to by this ListIterator.
|
||||
* The Object pointer is inserted as the next item in the List
|
||||
* based on the current position within the List
|
||||
* @param objPtr the Object pointer to add to the list
|
||||
**/
|
||||
void ListIterator::add(void* objPtr) {
|
||||
|
||||
list->insertAfter(objPtr,currentItem);
|
||||
allowRemove = MB_FALSE;
|
||||
|
||||
} //-- add
|
||||
|
||||
/**
|
||||
* Returns true if a sucessful call to the next() method can be made
|
||||
* @return MB_TRUE if a sucessful call to the next() method can be made,
|
||||
* otherwise MB_FALSE
|
||||
**/
|
||||
MBool ListIterator::hasNext() {
|
||||
MBool hasNext = MB_FALSE;
|
||||
if ( done ) return hasNext;
|
||||
else if ( currentItem ) {
|
||||
if (moveForward) hasNext = (MBool) currentItem->nextItem;
|
||||
else hasNext = (MBool)currentItem->prevItem;
|
||||
}
|
||||
else {
|
||||
if (moveForward) hasNext = (MBool) list->firstItem;
|
||||
else hasNext = (MBool) list->lastItem;
|
||||
}
|
||||
return hasNext;
|
||||
} //-- hasNext
|
||||
|
||||
/**
|
||||
* Returns true if a sucessful call to the previous() method can be made
|
||||
* @return MB_TRUE if a sucessful call to the previous() method can be made,
|
||||
* otherwise MB_FALSE
|
||||
**/
|
||||
MBool ListIterator::hasPrevious() {
|
||||
MBool hasPrevious = MB_FALSE;
|
||||
if (currentItem) {
|
||||
if (moveForward) hasPrevious = (MBool)(currentItem->prevItem);
|
||||
else hasPrevious = (MBool) (currentItem->nextItem);
|
||||
}
|
||||
return hasPrevious;
|
||||
} //-- hasPrevious
|
||||
|
||||
/**
|
||||
* Returns the next Object pointer in the list
|
||||
**/
|
||||
void* ListIterator::next() {
|
||||
|
||||
void* obj = 0;
|
||||
if ( done ) return obj;
|
||||
|
||||
if (currentItem) {
|
||||
if ( moveForward ) currentItem = currentItem->nextItem;
|
||||
else currentItem = currentItem->prevItem;
|
||||
}
|
||||
else {
|
||||
if ( moveForward ) currentItem = list->firstItem;
|
||||
else currentItem = list->lastItem;
|
||||
}
|
||||
|
||||
if ( currentItem ) {
|
||||
obj = currentItem->objPtr;
|
||||
allowRemove = MB_TRUE;
|
||||
}
|
||||
else done = MB_TRUE;
|
||||
|
||||
return obj;
|
||||
} //-- next
|
||||
|
||||
/**
|
||||
* Returns the previous Object in the list
|
||||
**/
|
||||
void* ListIterator::previous() {
|
||||
|
||||
void* obj = 0;
|
||||
|
||||
if (currentItem) {
|
||||
if ( moveForward ) currentItem = currentItem->prevItem;
|
||||
else currentItem = currentItem->nextItem;
|
||||
if ( currentItem ) obj = currentItem->objPtr;
|
||||
}
|
||||
return obj;
|
||||
} //-- previous
|
||||
|
||||
/**
|
||||
* Removes the Object last returned by the next() or previous() methods;
|
||||
* @return the removed Object pointer
|
||||
**/
|
||||
void* ListIterator::remove() {
|
||||
|
||||
if (!allowRemove) return 0;
|
||||
allowRemove = MB_FALSE;
|
||||
|
||||
void* obj = 0;
|
||||
if (currentItem) {
|
||||
obj = currentItem->objPtr;
|
||||
List::ListItem* item = currentItem;
|
||||
previous(); //-- make previous item the current item
|
||||
list->remove(item);
|
||||
}
|
||||
return obj;
|
||||
} //-- remove
|
||||
|
||||
/**
|
||||
* Resets the current location within the List to the beginning of the List
|
||||
**/
|
||||
void ListIterator::reset() {
|
||||
done = MB_FALSE;
|
||||
currentItem = 0;
|
||||
} //-- reset
|
||||
|
||||
/**
|
||||
* sets this iterator to operate in the reverse direction
|
||||
**/
|
||||
void ListIterator::reverse() {
|
||||
moveForward = (MBool)(!moveForward);
|
||||
} //-- reverse
|
||||
|
|
@ -0,0 +1,188 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "baseutils.h"
|
||||
|
||||
#ifndef MITRE_LIST_H
|
||||
#define MITRE_LIST_H
|
||||
|
||||
/**
|
||||
* Represents an ordered list of Object pointers. Modeled after a Java 2 List.
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
class List {
|
||||
|
||||
friend class ListIterator;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates an empty List
|
||||
**/
|
||||
List();
|
||||
|
||||
/**
|
||||
* List destructor, object references will not be deleted.
|
||||
**/
|
||||
virtual ~List();
|
||||
|
||||
/**
|
||||
* Returns the number of items in this List
|
||||
**/
|
||||
Int32 getLength();
|
||||
|
||||
/**
|
||||
* Returns a ListIterator for this List
|
||||
**/
|
||||
ListIterator* iterator();
|
||||
|
||||
/**
|
||||
* Adds the given Object to the specified position in the list
|
||||
**/
|
||||
void insert(int index, void* objPtr);
|
||||
|
||||
/**
|
||||
* Adds the given Object to the list
|
||||
**/
|
||||
void add(void* objPtr);
|
||||
|
||||
/**
|
||||
* Removes the given Object pointer from the list
|
||||
**/
|
||||
void* remove(void* objPtr);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
struct ListItem {
|
||||
ListItem* nextItem;
|
||||
ListItem* prevItem;
|
||||
void* objPtr;
|
||||
};
|
||||
|
||||
ListItem* getFirstItem();
|
||||
ListItem* getLastItem();
|
||||
|
||||
/**
|
||||
* Removes the given ListItem pointer from the list
|
||||
**/
|
||||
ListItem* remove(ListItem* sItem);
|
||||
|
||||
private:
|
||||
|
||||
ListItem* firstItem;
|
||||
ListItem* lastItem;
|
||||
Int32 itemCount;
|
||||
|
||||
void insertAfter(void* objPtr, ListItem* sItem);
|
||||
void insertBefore(void* objPtr, ListItem* sItem);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* An Iterator for the List Class
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
class ListIterator {
|
||||
|
||||
public:
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new ListIterator for the given List
|
||||
* @param list, the List to create an Iterator for
|
||||
**/
|
||||
ListIterator(List* list);
|
||||
|
||||
/**
|
||||
* Destructor, destroys a given instance of a ListIterator
|
||||
**/
|
||||
virtual ~ListIterator();
|
||||
|
||||
/**
|
||||
* Adds the Object pointer to the List pointed to by this ListIterator.
|
||||
* The Object pointer is inserted as the next item in the List
|
||||
* based on the current position within the List
|
||||
* @param objPtr the Object pointer to add to the list
|
||||
**/
|
||||
|
||||
virtual void add(void* objPtr);
|
||||
|
||||
/**
|
||||
* Returns true if a sucessful call to the next() method can be made
|
||||
* @return MB_TRUE if a sucessful call to the next() method can be made,
|
||||
* otherwise MB_FALSE
|
||||
**/
|
||||
virtual MBool hasNext();
|
||||
|
||||
/**
|
||||
* Returns true if a sucessful call to the previous() method can be made
|
||||
* @return MB_TRUE if a sucessful call to the previous() method can be made,
|
||||
* otherwise MB_FALSE
|
||||
**/
|
||||
virtual MBool hasPrevious();
|
||||
|
||||
/**
|
||||
* Returns the next Object pointer from the list
|
||||
**/
|
||||
virtual void* next();
|
||||
|
||||
/**
|
||||
* Returns the previous Object pointer from the list
|
||||
**/
|
||||
virtual void* previous();
|
||||
|
||||
/**
|
||||
* Removes the Object last returned by the next() or previous() methods;
|
||||
* @return the removed Object pointer
|
||||
**/
|
||||
virtual void* remove();
|
||||
|
||||
/**
|
||||
* Resets the current location within the List to the beginning of the List
|
||||
**/
|
||||
virtual void reset();
|
||||
|
||||
/**
|
||||
* sets this iterator to operate in the reverse direction
|
||||
**/
|
||||
void reverse();
|
||||
|
||||
private:
|
||||
|
||||
int count;
|
||||
//-- points to the current list item
|
||||
List::ListItem* currentItem;
|
||||
|
||||
//-- points to the list to iterator over
|
||||
List* list;
|
||||
|
||||
//-- determins if we can remove the current item from the list
|
||||
MBool allowRemove;
|
||||
|
||||
MBool done;
|
||||
|
||||
MBool moveForward;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MITRE_MITREOBJECT_H
|
||||
#define MITRE_MITREOBJECT_H
|
||||
|
||||
/**
|
||||
* A standard base class for many of the Class definitions in this
|
||||
* application
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
class MITREObject {
|
||||
public:
|
||||
MITREObject() {};
|
||||
virtual ~MITREObject() {};
|
||||
};
|
||||
|
||||
/**
|
||||
* A Simple MITREObject wrapper class
|
||||
**/
|
||||
class MITREObjectWrapper : public MITREObject {
|
||||
public:
|
||||
MITREObjectWrapper();
|
||||
virtual ~MITREObjectWrapper();
|
||||
void* object;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "MITREObject.h"
|
||||
|
||||
//--------------------------------------/
|
||||
//- A Simple MITREObject wrapper class -/
|
||||
//--------------------------------------/
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
**/
|
||||
MITREObjectWrapper::MITREObjectWrapper() {
|
||||
this->object = 0;
|
||||
} //-- MITREObjectWrapper
|
||||
|
||||
/**
|
||||
* Default destructor
|
||||
**/
|
||||
MITREObjectWrapper::~MITREObjectWrapper() {
|
||||
this->object = 0;
|
||||
} //-- ~MITREObjectWrapper
|
|
@ -0,0 +1,50 @@
|
|||
target: make_base
|
||||
|
||||
CC = g++
|
||||
|
||||
BASE_OBJS = CommandLineUtils.o \
|
||||
Double.o \
|
||||
Integer.o \
|
||||
List.o \
|
||||
MITREObjectWrapper.o \
|
||||
NamedMap.o \
|
||||
SimpleErrorObserver.o \
|
||||
Stack.o \
|
||||
String.o \
|
||||
StringList.o \
|
||||
Tokenizer.o
|
||||
|
||||
make_base: $(BASE_OBJS)
|
||||
|
||||
CommandLineUtils.o: CommandLineUtils.h CommandLineUtils.cpp
|
||||
$(CC) -c CommandLineUtils.cpp
|
||||
|
||||
Double.o: primitives.h Double.cpp
|
||||
$(CC) -c Double.cpp
|
||||
|
||||
Integer.o: primitives.h Integer.cpp
|
||||
$(CC) -c Integer.cpp
|
||||
|
||||
List.o: List.h List.cpp
|
||||
$(CC) -c List.cpp
|
||||
|
||||
MITREObjectWrapper.o: MITREObject.h MITREObjectWrapper.cpp
|
||||
$(CC) -c MITREObjectWrapper.cpp
|
||||
|
||||
NamedMap.o: String.h NamedMap.h NamedMap.cpp
|
||||
$(CC) -c NamedMap.cpp
|
||||
|
||||
SimpleErrorObserver.o: String.h baseutils.h ErrorObserver.h SimpleErrorObserver.cpp
|
||||
$(CC) -c SimpleErrorObserver.cpp
|
||||
|
||||
Stack.o: List.h Stack.h Stack.cpp
|
||||
$(CC) -c Stack.cpp
|
||||
|
||||
String.o: String.h String.cpp
|
||||
$(CC) -c String.cpp
|
||||
|
||||
StringList.o: String.h StringList.h StringList.cpp
|
||||
$(CC) -c StringList.cpp
|
||||
|
||||
Tokenizer.o: Tokenizer.h Tokenizer.cpp
|
||||
$(CC) -c Tokenizer.cpp
|
|
@ -0,0 +1,313 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* A Named Map for MITREObjects
|
||||
* @author <a href="kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
|
||||
#include "NamedMap.h"
|
||||
|
||||
//-------------/
|
||||
//- Constants -/
|
||||
//-------------/
|
||||
|
||||
const int NamedMap::DEFAULT_SIZE = 17;
|
||||
|
||||
//----------------/
|
||||
//- Constructors -/
|
||||
//----------------/
|
||||
|
||||
/**
|
||||
* Creates a new NamedMap with the default Size
|
||||
**/
|
||||
NamedMap::NamedMap() {
|
||||
initialize(DEFAULT_SIZE);
|
||||
} //-- NamedMap
|
||||
|
||||
/**
|
||||
* Creates a new NamedMap with the specified number of buckets
|
||||
**/
|
||||
NamedMap::NamedMap(int size) {
|
||||
initialize(size);
|
||||
} //-- NamedMap
|
||||
|
||||
/**
|
||||
* Helper method for Constructors
|
||||
**/
|
||||
void NamedMap::initialize(Int32 size) {
|
||||
|
||||
//-- by default the NamedMap will not delete it's
|
||||
//-- object references
|
||||
doObjectDeletion = MB_FALSE;
|
||||
|
||||
//-- create a new array of bucket pointers
|
||||
elements = new BucketItem*[size];
|
||||
|
||||
//-- initialize all elements to 0;
|
||||
for ( Int32 i = 0; i < size; i++ ) elements[i] = 0;
|
||||
|
||||
numberOfBuckets = size;
|
||||
numberOfElements = 0;
|
||||
} //-- initialize
|
||||
|
||||
/**
|
||||
* Destructor for NamedMap
|
||||
**/
|
||||
NamedMap::~NamedMap() {
|
||||
//cout << "~NamedMap() - start"<<endl;
|
||||
clear();
|
||||
delete [] elements;
|
||||
//cout << "~NamedMap() - done"<<endl;
|
||||
} //-- ~NamedMap
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Removes all elements from the NamedMap. If the object deletion flag
|
||||
* has been set to true (by a call to setObjectDeletion) objects
|
||||
* will also be deleted as they are removed from the map
|
||||
**/
|
||||
void NamedMap::clear() {
|
||||
clear(doObjectDeletion);
|
||||
} //-- clear
|
||||
|
||||
/**
|
||||
* Removes all elements from the NamedMap
|
||||
**/
|
||||
void NamedMap::clear(MBool deleteObjects) {
|
||||
|
||||
for (int i = 0; i < numberOfBuckets; i++) {
|
||||
|
||||
BucketItem* bktItem = elements[i];
|
||||
while (bktItem) {
|
||||
BucketItem* tItem = bktItem;
|
||||
bktItem = bktItem->next;
|
||||
//-- repoint item to 0 to prevent deletion
|
||||
if ( ! deleteObjects ) tItem->item = 0;
|
||||
else {
|
||||
delete tItem->item;
|
||||
}
|
||||
//--delete tItem;
|
||||
delete tItem;
|
||||
}
|
||||
}
|
||||
numberOfElements = 0;
|
||||
} //-- clear
|
||||
|
||||
void NamedMap::dumpMap() {
|
||||
|
||||
|
||||
cout << "#NamedMap -------- { "<<endl;
|
||||
|
||||
for (int i = 0; i < numberOfBuckets; i++) {
|
||||
|
||||
cout << "[";
|
||||
if (i < 10 ) cout << '0';
|
||||
cout << i << "]->{";
|
||||
|
||||
BucketItem* item = elements[i];
|
||||
MBool hasPrevItem = MB_FALSE;
|
||||
while (item) {
|
||||
if (hasPrevItem) cout << ", ";
|
||||
cout << item->key;
|
||||
hasPrevItem = MB_TRUE;
|
||||
item = item->next;
|
||||
}
|
||||
cout << "}"<<endl;
|
||||
}
|
||||
cout <<"} #NamedMap"<<endl;
|
||||
} //-- dumpMap
|
||||
|
||||
/**
|
||||
* Compares the specified object with this NamedMap for equality.
|
||||
* Returns true if and only if the specified Object is a NamedMap
|
||||
* that hashes to the same value as this NamedMap
|
||||
* @return true if and only if the specified Object is a NamedMap
|
||||
* that hashes to the same value as this NamedMap
|
||||
**/
|
||||
MBool NamedMap::equals(NamedMap* namedMap) {
|
||||
//-- currently does nothing
|
||||
return MB_FALSE;
|
||||
} //-- equals
|
||||
|
||||
/**
|
||||
* Returns the object reference in this Map associated with the given name
|
||||
* @return the object reference in this Map associated with the given name
|
||||
**/
|
||||
MITREObject* NamedMap::get(const char* key) {
|
||||
String sKey = key;
|
||||
return get(sKey);
|
||||
} //-- get
|
||||
|
||||
/**
|
||||
* Returns the object reference in this Map associated with the given name
|
||||
* @return the object reference in this Map associated with the given name
|
||||
**/
|
||||
MITREObject* NamedMap::get(const String& key) {
|
||||
BucketItem* item = getBucketItem(key);
|
||||
if ( item ) return item->item;
|
||||
return 0;
|
||||
} //-- get
|
||||
|
||||
/**
|
||||
* Returns true if there are no Nodes in the NodeStack.
|
||||
* @return true if there are no Nodes in the NodeStack.
|
||||
**/
|
||||
MBool NamedMap::isEmpty() {
|
||||
return (numberOfElements == 0) ? MB_TRUE : MB_FALSE;
|
||||
} //-- isEmpty
|
||||
|
||||
/**
|
||||
* Adds the specified Node to the top of this Stack.
|
||||
* @param node the Node to add to the top of the Stack
|
||||
**/
|
||||
void NamedMap::put(const char* key, MITREObject* obj) {
|
||||
String sKey = key;
|
||||
put(sKey, obj);
|
||||
} //-- put
|
||||
|
||||
/**
|
||||
* Adds the specified Node to the top of this Stack.
|
||||
* @param node the Node to add to the top of the Stack
|
||||
**/
|
||||
void NamedMap::put(const String& key, MITREObject* obj) {
|
||||
|
||||
//-- compute hash for key
|
||||
unsigned long hashCode = hashKey(key);
|
||||
//-- calculate index
|
||||
int idx = hashCode % numberOfBuckets;
|
||||
|
||||
//-- fetch first item in bucket
|
||||
BucketItem* bktItem = elements[idx];
|
||||
|
||||
//-- if bktItem is 0 then there are no items is this Bucket,
|
||||
//-- add to front of list
|
||||
if ( !bktItem ) {
|
||||
elements[idx] = createBucketItem(key, obj);
|
||||
++numberOfElements;
|
||||
}
|
||||
//-- find current item, or add to end of list
|
||||
else {
|
||||
BucketItem* prevItem = bktItem;
|
||||
//-- advance to next spot
|
||||
while ( bktItem ) {
|
||||
//-- if current key equals desired key, break
|
||||
if ( bktItem->key.isEqual(key) ) {
|
||||
break;
|
||||
}
|
||||
prevItem = bktItem;
|
||||
bktItem = bktItem->next;
|
||||
}
|
||||
//-- if we did not find a bucket Item create a new one
|
||||
if ( !bktItem) {
|
||||
bktItem = createBucketItem(key, obj);
|
||||
prevItem->next = bktItem;
|
||||
bktItem->prev = prevItem;
|
||||
++numberOfElements;
|
||||
}
|
||||
//-- we found bucket item, just set value
|
||||
else bktItem->item = obj;
|
||||
}
|
||||
} //-- put
|
||||
/**
|
||||
* Removes the the specified Object from the NamedMap
|
||||
* @param key the key of the Object to remove from the NamedMap
|
||||
* @return the Object being removed
|
||||
**/
|
||||
MITREObject* NamedMap::remove(String& key) {
|
||||
|
||||
BucketItem* bktItem = getBucketItem(key);
|
||||
|
||||
if ( bktItem ) {
|
||||
bktItem->prev->next = bktItem->next;
|
||||
numberOfElements--;
|
||||
return bktItem->item;
|
||||
}
|
||||
return 0;
|
||||
|
||||
} //-- remove
|
||||
|
||||
/**
|
||||
* Sets the object deletion flag. If set to true, objects in
|
||||
* the NamedMap will be deleted upon calling the clear() method, or
|
||||
* upon destruction. By default this is false.
|
||||
**/
|
||||
void NamedMap::setObjectDeletion(MBool deleteObjects) {
|
||||
doObjectDeletion = deleteObjects;
|
||||
} //-- setObjectDeletion
|
||||
|
||||
/**
|
||||
* Returns the number of elements in the NodeStack
|
||||
* @return the number of elements in the NodeStack
|
||||
**/
|
||||
int NamedMap::size() {
|
||||
return numberOfElements;
|
||||
} //-- size
|
||||
|
||||
//-------------------/
|
||||
//- Private Methods -/
|
||||
//-------------------/
|
||||
|
||||
NamedMap::BucketItem* NamedMap::createBucketItem(const String& key, MITREObject* objPtr)
|
||||
{
|
||||
BucketItem* bktItem = new BucketItem;
|
||||
bktItem->next = 0;
|
||||
bktItem->prev = 0;
|
||||
bktItem->key = key;
|
||||
bktItem->item = objPtr;
|
||||
return bktItem;
|
||||
} //-- createBucketItem
|
||||
|
||||
NamedMap::BucketItem* NamedMap::getBucketItem(const String& key) {
|
||||
// compute hash for key
|
||||
long hashCode = hashKey(key);
|
||||
|
||||
int idx = hashCode % numberOfBuckets;
|
||||
|
||||
BucketItem* bktItem = elements[idx];
|
||||
|
||||
while ( bktItem ) {
|
||||
if ( bktItem->key.isEqual(key) ) return bktItem;
|
||||
bktItem = bktItem->next;
|
||||
}
|
||||
|
||||
return bktItem;
|
||||
|
||||
} //-- getBucketItem
|
||||
|
||||
/**
|
||||
**/
|
||||
unsigned long NamedMap::hashKey(const String& key) {
|
||||
|
||||
Int32 len = key.length();
|
||||
UNICODE_CHAR* chars = new UNICODE_CHAR[len];
|
||||
key.toUnicode(chars);
|
||||
|
||||
unsigned long hashCode = 0;
|
||||
for (Int32 i = 0; i < len; i++) {
|
||||
hashCode += ((Int32)chars[i]) << 3;
|
||||
}
|
||||
|
||||
return hashCode;
|
||||
} //-- hashKey
|
||||
|
||||
|
|
@ -0,0 +1,177 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* A Named Map for MITREObjects
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
|
||||
#ifndef MITREXSL_NAMEDMAP_H
|
||||
#define MITREXSL_NAMEDMAP_H
|
||||
|
||||
#include "String.h"
|
||||
#include "baseutils.h"
|
||||
#include "MITREObject.h"
|
||||
|
||||
class NamedMap : public MITREObject {
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//----------------/
|
||||
//- Constructors -/
|
||||
//----------------/
|
||||
|
||||
/**
|
||||
* Creates a new NodeStack with the default Size
|
||||
**/
|
||||
NamedMap();
|
||||
|
||||
/**
|
||||
* Creates a new NodeStack with the specified number of buckets
|
||||
**/
|
||||
NamedMap(int size);
|
||||
|
||||
/**
|
||||
* Destructor for a NamedMap table, will not delete references unless
|
||||
* The setObjectDeletion flag has been set to MB_TRUE
|
||||
**/
|
||||
virtual ~NamedMap();
|
||||
|
||||
/**
|
||||
* Returns the object reference in this Map associated with the given name
|
||||
* @return the object reference in this Map associated with the given name
|
||||
**/
|
||||
MITREObject* get(const String& name);
|
||||
|
||||
/**
|
||||
* Returns the object reference in this Map associated with the given name
|
||||
* @return the object reference in this Map associated with the given name
|
||||
**/
|
||||
MITREObject* get(const char* name);
|
||||
|
||||
/**
|
||||
* Adds the Object reference to the map and associates it with the given name
|
||||
**/
|
||||
void put(const String& name, MITREObject* obj);
|
||||
|
||||
/**
|
||||
* Adds the Object reference to the map and associates it with the given name
|
||||
**/
|
||||
void put(const char* name, MITREObject* obj);
|
||||
|
||||
/**
|
||||
* Removes all elements from the Map table
|
||||
**/
|
||||
void clear();
|
||||
|
||||
void clear(MBool doObjectDeletion);
|
||||
|
||||
/**
|
||||
* Returns true if the specified Node is contained in the set.
|
||||
* if the specfied Node is null, then if the NodeSet contains a null
|
||||
* value, true will be returned.
|
||||
* @param node the element to search the NodeSet for
|
||||
* @return true if specified Node is contained in the NodeSet
|
||||
**/
|
||||
//MBool contains(Node* node);
|
||||
|
||||
/**
|
||||
* Compares the specified object with this NamedMap for equality.
|
||||
* Returns true if and only if the specified Object is a NamedMap
|
||||
* that hashes to the same value as this NamedMap
|
||||
* @return true if and only if the specified Object is a NamedMap
|
||||
* that hashes to the same value as this NamedMap
|
||||
**/
|
||||
MBool equals(NamedMap* namedMap);
|
||||
|
||||
/**
|
||||
* Returns true if there are no Nodes in the NodeSet.
|
||||
* @return true if there are no Nodes in the NodeSet.
|
||||
**/
|
||||
MBool isEmpty();
|
||||
|
||||
/**
|
||||
* Removes the Node at the specified index from the NodeSet
|
||||
* @param index the position in the NodeSet to remove the Node from
|
||||
* @return the Node that was removed from the list
|
||||
**/
|
||||
MITREObject* remove(String& key);
|
||||
|
||||
/**
|
||||
* Sets the object deletion flag. If set to true, objects in
|
||||
* the NamedMap will be deleted upon calling the clear() method, or
|
||||
* upon destruction. By default this is false.
|
||||
**/
|
||||
void setObjectDeletion(MBool deleteObjects);
|
||||
|
||||
/**
|
||||
* Returns the number of key-element pairs in the NamedMap
|
||||
* @return the number of key-element in the NamedMap
|
||||
**/
|
||||
int size();
|
||||
|
||||
void dumpMap();
|
||||
|
||||
|
||||
|
||||
|
||||
//-------------------/
|
||||
//- Private Members -/
|
||||
//-------------------/
|
||||
|
||||
|
||||
private:
|
||||
|
||||
struct BucketItem {
|
||||
String key;
|
||||
MITREObject* item;
|
||||
BucketItem* next;
|
||||
BucketItem* prev;
|
||||
};
|
||||
|
||||
static const int DEFAULT_SIZE;
|
||||
|
||||
// map table
|
||||
BucketItem** elements;
|
||||
|
||||
Int32 numberOfBuckets;
|
||||
Int32 numberOfElements;
|
||||
MBool doObjectDeletion;
|
||||
|
||||
//-------------------/
|
||||
//- Private Methods -/
|
||||
//-------------------/
|
||||
|
||||
BucketItem* createBucketItem(const String& key, MITREObject* objPtr);
|
||||
|
||||
BucketItem* getBucketItem(const String& key);
|
||||
|
||||
unsigned long hashKey(const String& key);
|
||||
|
||||
/**
|
||||
* Helper method for constructors
|
||||
**/
|
||||
void initialize(int size);
|
||||
|
||||
}; //-- NamedMap
|
||||
|
||||
#endif
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "ErrorObserver.h"
|
||||
|
||||
/**
|
||||
* Creates a new SimpleErrorObserver.
|
||||
* All errors will be printed to the console (cout).
|
||||
**/
|
||||
SimpleErrorObserver::SimpleErrorObserver() {
|
||||
errStream = &cout;
|
||||
hideWarnings = MB_FALSE;
|
||||
} //-- SimpleErrorObserver
|
||||
|
||||
/**
|
||||
* Creates a new SimpleErrorObserver.
|
||||
* All errors will be printed to the given ostream.
|
||||
**/
|
||||
SimpleErrorObserver::SimpleErrorObserver(ostream& errStream) {
|
||||
this->errStream = &errStream;
|
||||
hideWarnings = MB_FALSE;
|
||||
} //-- SimpleErrorObserver
|
||||
|
||||
/**
|
||||
* Notifies this Error observer of a new error, with default
|
||||
* level of NORMAL
|
||||
**/
|
||||
void SimpleErrorObserver::recieveError(String& errorMessage) {
|
||||
*errStream << "error: " << errorMessage << endl;
|
||||
errStream->flush();
|
||||
} //-- recieveError
|
||||
|
||||
/**
|
||||
* Notifies this Error observer of a new error using the given error level
|
||||
**/
|
||||
void SimpleErrorObserver::recieveError(String& errorMessage, ErrorLevel level) {
|
||||
|
||||
|
||||
switch ( level ) {
|
||||
case ErrorObserver::FATAL :
|
||||
*errStream << "fatal error: ";
|
||||
break;
|
||||
case ErrorObserver::WARNING :
|
||||
if ( hideWarnings ) return;
|
||||
*errStream << "warning: ";
|
||||
break;
|
||||
default:
|
||||
*errStream << "error: ";
|
||||
break;
|
||||
}
|
||||
|
||||
*errStream << errorMessage << endl;
|
||||
errStream->flush();
|
||||
} //-- recieveError
|
||||
|
||||
void SimpleErrorObserver::supressWarnings(MBool supress) {
|
||||
this->hideWarnings = supress;
|
||||
} //-- supressWarnings
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Stack
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
* <BR/>
|
||||
* <PRE>
|
||||
* Modifications:
|
||||
* 19990806: Larry Fitzpatrick
|
||||
* - in method #peek():
|
||||
* - Changed ListItem::ListItem to List::ListItem
|
||||
* </PRE>
|
||||
**/
|
||||
|
||||
#include "Stack.h"
|
||||
|
||||
//-------------/
|
||||
//- Stack.cpp -/
|
||||
//-------------/
|
||||
|
||||
/**
|
||||
* Creates a new Stack
|
||||
**/
|
||||
Stack::Stack() : List() {
|
||||
} //-- Stack
|
||||
|
||||
|
||||
/**
|
||||
* Destructor for Stack, will not delete Object references
|
||||
**/
|
||||
Stack::~Stack() {
|
||||
//-- the base destructor for List will do all clean up
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator that will iterator over the Stack, from the topmost
|
||||
* element to the bottom element.
|
||||
* You will need to delete this Iterator when you are done
|
||||
**/
|
||||
StackIterator* Stack::iterator() {
|
||||
StackIterator* iter = (StackIterator*)List::iterator();
|
||||
iter->reverse();
|
||||
return iter;
|
||||
} //-- iterator
|
||||
|
||||
/**
|
||||
* Returns the specified Object from the top of this Stack,
|
||||
* without removing it from the stack.
|
||||
* @return a pointer to the object that is the top of this Stack
|
||||
**/
|
||||
void* Stack::peek() {
|
||||
void* obj = 0;
|
||||
List::ListItem* item = getLastItem();
|
||||
if ( item ) obj = item->objPtr;
|
||||
return obj;
|
||||
} //-- peek
|
||||
|
||||
/**
|
||||
* Adds the specified Object to the top of this Stack.
|
||||
* @param obj a pointer to the object that is to be added to the
|
||||
* top of this Stack
|
||||
**/
|
||||
void Stack::push(void* obj) {
|
||||
add(obj);
|
||||
} //-- push
|
||||
|
||||
/**
|
||||
* Removes and returns the specified Object from the top of this Stack.
|
||||
* @return a pointer to the object that was the top of this Stack
|
||||
**/
|
||||
void* Stack::pop() {
|
||||
void* obj = 0;
|
||||
ListItem* item = getLastItem();
|
||||
if ( item ) obj = item->objPtr;
|
||||
item = remove(item);
|
||||
item->objPtr = 0;
|
||||
delete item;
|
||||
return obj;
|
||||
} //-- pop
|
||||
|
||||
/**
|
||||
* Returns true if there are no objects in the Stack.
|
||||
* @return true if there are no objects in the Stack.
|
||||
**/
|
||||
MBool Stack::empty() {
|
||||
return (MBool) (getLength() == 0);
|
||||
} //-- empty
|
||||
|
||||
/**
|
||||
* Returns the number of elements in the Stack
|
||||
* @return the number of elements in the Stack
|
||||
**/
|
||||
int Stack::size() {
|
||||
return getLength();
|
||||
} //-- size
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Stack
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
|
||||
#include "List.h"
|
||||
#include "baseutils.h"
|
||||
|
||||
|
||||
#ifndef MITRE_STACK_H
|
||||
#define MITRE_STACK_H
|
||||
|
||||
typedef ListIterator StackIterator;
|
||||
|
||||
class Stack : private List {
|
||||
|
||||
public:
|
||||
|
||||
//----------------/
|
||||
//- Constructors -/
|
||||
//----------------/
|
||||
|
||||
/**
|
||||
* Creates a new Stack
|
||||
**/
|
||||
Stack();
|
||||
|
||||
|
||||
/**
|
||||
* Destructor for Stack, will not delete Object references
|
||||
**/
|
||||
virtual ~Stack();
|
||||
|
||||
StackIterator* iterator();
|
||||
|
||||
/**
|
||||
* Returns the specified Object from the top of this Stack,
|
||||
* without removing it from the stack.
|
||||
* @return a pointer to the object that is the top of this Stack
|
||||
**/
|
||||
void* peek();
|
||||
|
||||
/**
|
||||
* Adds the specified Object to the top of this Stack.
|
||||
* @param obj a pointer to the object that is to be added to the
|
||||
* top of this Stack
|
||||
**/
|
||||
void push(void* obj);
|
||||
|
||||
/**
|
||||
* Removes and returns the specified Object from the top of this Stack.
|
||||
* @return a pointer to the object that was the top of this Stack
|
||||
**/
|
||||
void* pop();
|
||||
|
||||
/**
|
||||
* Returns true if there are no objects in the Stack.
|
||||
* @return true if there are no objects in the Stack.
|
||||
**/
|
||||
MBool empty();
|
||||
|
||||
/**
|
||||
* Returns the number of elements in the Stack
|
||||
* @return the number of elements in the Stack
|
||||
**/
|
||||
int size();
|
||||
|
||||
private:
|
||||
|
||||
}; //-- Stack
|
||||
|
||||
|
||||
#endif
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,220 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
// Tom Kneeland (3/17/99)
|
||||
//
|
||||
// Implementation of a simple string class
|
||||
//
|
||||
// Modification History:
|
||||
// Who When What
|
||||
// TK 03/17/99 Created
|
||||
// TK 03/23/99 Released without "lastIndexOf" functions
|
||||
// TK 04/02/99 Added support for 'const' strings, and added
|
||||
// 'operator=' for constant char*.
|
||||
// TK 04/09/99 Overloaded the output operator (<<). Currently it only
|
||||
// supports outputing the String to a C sytle character based
|
||||
// stream.
|
||||
// TK 04/09/99 Provided support for the extraction of the DOM_CHAR
|
||||
// representation of the string. The new method, "toDomChar()"
|
||||
// returns a constant pointer to the internal DOM_CHAR string
|
||||
// buffer.
|
||||
// TK 04/10/99 Added the implementation for appending an array of DOM_CHARs
|
||||
// to a string. It should be noted that a length needs to be
|
||||
// provided in order to determine the length of the source
|
||||
// array.
|
||||
// TK 04/22/99 Fixed a bug where setting a string equal to NULL would cause
|
||||
// a core dump. Also added support for constructing a string
|
||||
// using the NULL identifier.
|
||||
// Modified the output operator (<<) to accept a const String
|
||||
// reference. This eliminates a wasteful copy constructor call.
|
||||
// TK 04/28/99 Modified the clear() method to leave the DOM_CHAR array
|
||||
// in place.
|
||||
// TK 04/28/99 Added 3 new member functions: insert, deleteChars, and
|
||||
// replace.
|
||||
// TK 05/05/99 Added support for implicit integer conversion. This allows
|
||||
// integers to be appended, inserted, and used as replacements
|
||||
// for DOM_CHARs. To support this feature, ConvertInt has been
|
||||
// added which converts the given integer to a string and stores
|
||||
// it in the target.
|
||||
// TK 05/05/99 Converted the typedef DOM_CHAR to UNICODE_CHAR.
|
||||
//
|
||||
// KV 07/29/99 Added lastIndexOf methods
|
||||
// KV 07/29/99 Changed indexOf methods with no offset, to call the
|
||||
// indexOf methods with offset of 0. This allows re-use of
|
||||
// code, makes it easier to debug, and minimizes the size of
|
||||
// the implementation
|
||||
// LF 08/06/1999 In method #operator=,
|
||||
// added line: return *this
|
||||
// KV 08/11/1999 changed charAt to return -1, if index is out of bounds, instead of 0,
|
||||
// since 0, is a valid character, and this makes my code more compatible
|
||||
// with Java
|
||||
// KV 08/11/1999 removed PRBool, uses baseutils.h (MBool)
|
||||
|
||||
#ifndef MITRE_STRING
|
||||
#define MITRE_STRING
|
||||
|
||||
#include "MITREObject.h"
|
||||
#include "baseutils.h"
|
||||
#include <iostream.h>
|
||||
|
||||
|
||||
typedef unsigned short UNICODE_CHAR;
|
||||
|
||||
#ifndef NULL
|
||||
typedef 0 NULL;
|
||||
#endif
|
||||
|
||||
#define NOT_FOUND -1
|
||||
|
||||
class String : public MITREObject
|
||||
{
|
||||
//Translate UNICODE_CHARs to Chars and output to the provided stream
|
||||
friend ostream& operator<<(ostream& output, const String& source);
|
||||
|
||||
public:
|
||||
String(); //Default Constructor, create an empty string
|
||||
String(Int32 initSize); //Create an empty string of a specific size
|
||||
String(const String& source); //Create a copy of the source string
|
||||
String(const char* source); //Create a string from the characters
|
||||
String(const UNICODE_CHAR* source);
|
||||
|
||||
~String(); //Destroy the string, and free memory
|
||||
|
||||
|
||||
//Assign source to this string
|
||||
String& operator=(const String& source);
|
||||
String& operator=(const char* source);
|
||||
String& operator=(const UNICODE_CHAR* source);
|
||||
String& operator=(Int32 source);
|
||||
|
||||
//Grow buffer if necessary and append the source
|
||||
void append(const UNICODE_CHAR source);
|
||||
void append(const char source);
|
||||
void append(const String& source);
|
||||
void append(const char* source);
|
||||
void append(const UNICODE_CHAR* source);
|
||||
void append(const UNICODE_CHAR* source, Int32 length);
|
||||
void append(Int32 source);
|
||||
|
||||
//Provide the ability to insert data into the middle of a string
|
||||
void insert(Int32 offset, const UNICODE_CHAR source);
|
||||
void insert(Int32 offset, const char source);
|
||||
void insert(Int32 offset, const String& source);
|
||||
void insert(Int32 offset, const char* source);
|
||||
void insert(Int32 offset, const UNICODE_CHAR* source);
|
||||
void insert(Int32 offset, Int32 source);
|
||||
|
||||
//Provide the ability to replace one or more characters
|
||||
void replace(Int32 offset, const UNICODE_CHAR source);
|
||||
void replace(Int32 offset, const char source);
|
||||
void replace(Int32 offset, const String& source);
|
||||
void replace(Int32 offset, const char* source);
|
||||
void replace(Int32 offset, const UNICODE_CHAR* source);
|
||||
void replace(Int32 offset, Int32 source);
|
||||
|
||||
//Provide the ability to delete a range of charactes
|
||||
void deleteChars(Int32 offset, Int32 count);
|
||||
|
||||
/**
|
||||
* Returns the character at index.
|
||||
* If the index is out of bounds, -1 will be returned.
|
||||
**/
|
||||
UNICODE_CHAR charAt(Int32 index) const;
|
||||
|
||||
void clear(); //Clear string
|
||||
|
||||
void ensureCapacity(Int32 capacity); //Make sure buffer is at least 'size'
|
||||
|
||||
//Returns index of first occurrence of data
|
||||
Int32 indexOf(UNICODE_CHAR data) const;
|
||||
Int32 indexOf(UNICODE_CHAR data, Int32 offset) const;
|
||||
Int32 indexOf(const String& data) const;
|
||||
Int32 indexOf(const String& data, Int32 offset) const;
|
||||
|
||||
MBool isEqual(const String& data) const; //Check equality between strings
|
||||
|
||||
//Returns index of last occurrence of data
|
||||
Int32 lastIndexOf(UNICODE_CHAR data) const;
|
||||
Int32 lastIndexOf(UNICODE_CHAR data, Int32 offset) const;
|
||||
Int32 lastIndexOf(const String& data) const;
|
||||
Int32 lastIndexOf(const String& data, Int32 offset) const;
|
||||
|
||||
Int32 length() const; //Returns the length of the string
|
||||
|
||||
/**
|
||||
* Sets the Length of this String, if length is less than 0, it will
|
||||
* be set to 0; if length > current length, the string will be extended
|
||||
* and padded with '\0' null characters. Otherwise the String
|
||||
* will be truncated
|
||||
**/
|
||||
void setLength(Int32 length);
|
||||
|
||||
/**
|
||||
* Sets the Length of this String, if length is less than 0, it will
|
||||
* be set to 0; if length > current length, the string will be extended
|
||||
* and padded with given pad character. Otherwise the String
|
||||
* will be truncated
|
||||
**/
|
||||
void setLength(Int32 length, UNICODE_CHAR padChar);
|
||||
|
||||
/**
|
||||
* Returns a substring starting at start
|
||||
* Note: the dest String is cleared before use
|
||||
**/
|
||||
String& subString(Int32 start, String& dest) const;
|
||||
|
||||
/**
|
||||
* Returns the subString starting at start and ending at end
|
||||
* Note: the dest String is cleared before use
|
||||
**/
|
||||
String& subString(Int32 start, Int32 end, String& dest) const;
|
||||
|
||||
//Convert the internal rep. to a char buffer
|
||||
char* toChar(char* dest) const;
|
||||
UNICODE_CHAR* toUnicode(UNICODE_CHAR* dest) const;
|
||||
|
||||
void toLowerCase(); //Convert string to lowercase
|
||||
void toUpperCase(); //Convert string to uppercase
|
||||
void trim(); //Trim whitespace from both ends of string
|
||||
|
||||
void reverse(); //Reverse the string
|
||||
|
||||
private:
|
||||
Int32 strLength;
|
||||
Int32 bufferLength;
|
||||
UNICODE_CHAR* strBuffer;
|
||||
|
||||
//String copies itself to the destination
|
||||
void copyString(UNICODE_CHAR* dest);
|
||||
|
||||
//Compare the two string representations for equality
|
||||
MBool isEqual(const UNICODE_CHAR* data, const UNICODE_CHAR* search,
|
||||
Int32 length) const;
|
||||
|
||||
//Convert an Int into a String
|
||||
String& ConvertInt(Int32 value, String& target);
|
||||
|
||||
//Calculates the length of a null terminated UNICODE_CHAR array
|
||||
Int32 UnicodeLength(const UNICODE_CHAR* data);
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream& output, const String& source);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,306 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* StringList
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
|
||||
#include <iostream.h>
|
||||
#include "StringList.h"
|
||||
|
||||
/**
|
||||
* Creates an empty list
|
||||
**/
|
||||
StringList::StringList() {
|
||||
firstItem = 0;
|
||||
lastItem = 0;
|
||||
itemCount = 0;
|
||||
} //-- StringList;
|
||||
|
||||
/**
|
||||
* StringList Destructor, Cleans up pointers and will delete the String
|
||||
* references, make sure you make copies of any needed Strings
|
||||
*/
|
||||
StringList::~StringList() {
|
||||
StringListItem* item = firstItem;
|
||||
while (item) {
|
||||
StringListItem* tItem = item;
|
||||
item = item->nextItem;
|
||||
delete tItem->strptr;
|
||||
delete tItem;
|
||||
}
|
||||
} //-- ~StringList
|
||||
|
||||
void StringList::add(String* strptr) {
|
||||
StringListItem* sItem = new StringListItem;
|
||||
sItem->strptr = strptr;
|
||||
sItem->nextItem = 0;
|
||||
sItem->prevItem = lastItem;
|
||||
if (lastItem) lastItem->nextItem = sItem;
|
||||
lastItem = sItem;
|
||||
if (!firstItem) firstItem = sItem;
|
||||
|
||||
// increase the item count
|
||||
++itemCount;
|
||||
} //-- add
|
||||
|
||||
MBool StringList::contains(String& search) {
|
||||
StringListItem* sItem = firstItem;
|
||||
while ( sItem ) {
|
||||
if ( search.isEqual(*sItem->strptr)) return MB_TRUE;
|
||||
sItem = sItem->nextItem;
|
||||
}
|
||||
return MB_FALSE;
|
||||
} //-- contains
|
||||
|
||||
/**
|
||||
* Returns the number of Strings in this List
|
||||
**/
|
||||
Int32 StringList::getLength() {
|
||||
return itemCount;
|
||||
} //-- getLength
|
||||
|
||||
|
||||
/**
|
||||
* Inserts the given String pointer as the item just after refItem.
|
||||
* If refItem is a null pointer the String will inserted at the
|
||||
* beginning of the List (ie, insert after nothing).
|
||||
* This method assumes refItem is a member of this list, and since this
|
||||
* is a private method, I feel that's a valid assumption
|
||||
**/
|
||||
void StringList::insertAfter(String* strptr, StringListItem* refItem) {
|
||||
|
||||
//-- if refItem == null insert at end
|
||||
if (!refItem) {
|
||||
if (firstItem) insertBefore(strptr, firstItem);
|
||||
else add(strptr);
|
||||
return;
|
||||
}
|
||||
|
||||
//-- if inserting at end of list
|
||||
if (refItem == lastItem) {
|
||||
add(strptr);
|
||||
return;
|
||||
}
|
||||
|
||||
//-- insert into middle of list
|
||||
StringListItem* sItem = new StringListItem;
|
||||
sItem->strptr = strptr;
|
||||
sItem->prevItem = refItem;
|
||||
sItem->nextItem = refItem->nextItem;
|
||||
refItem->nextItem = sItem;
|
||||
|
||||
// increase the item count
|
||||
++itemCount;
|
||||
} //-- insertAfter
|
||||
|
||||
/**
|
||||
* Inserts the given String pointer as the item just before refItem.
|
||||
* If refItem is a null pointer the String will inserted at the
|
||||
* end of the List (ie, insert before nothing).
|
||||
* This method assumes refItem is a member of this list, and since this
|
||||
* is a private method, I feel that's a valid assumption
|
||||
**/
|
||||
void StringList::insertBefore(String* strptr, StringListItem* refItem) {
|
||||
|
||||
//-- if refItem == null insert at end
|
||||
if (!refItem) {
|
||||
add(strptr);
|
||||
return;
|
||||
}
|
||||
|
||||
StringListItem* sItem = new StringListItem;
|
||||
sItem->strptr = strptr;
|
||||
sItem->nextItem = refItem;
|
||||
sItem->prevItem = refItem->prevItem;
|
||||
refItem->prevItem = sItem;
|
||||
|
||||
if (refItem == firstItem) firstItem = sItem;
|
||||
if (itemCount == 0) lastItem = sItem;
|
||||
|
||||
// increase the item count
|
||||
++itemCount;
|
||||
} //-- insertBefore
|
||||
|
||||
/**
|
||||
* Returns a StringListIterator for this StringList
|
||||
**/
|
||||
StringListIterator& StringList::iterator() {
|
||||
return *(new StringListIterator(this));
|
||||
}
|
||||
|
||||
String* StringList::remove(String* strptr) {
|
||||
StringListItem* sItem = firstItem;
|
||||
while (sItem) {
|
||||
if (sItem->strptr == strptr) {
|
||||
remove(sItem);
|
||||
delete sItem;
|
||||
return strptr;
|
||||
}
|
||||
sItem = sItem->nextItem;
|
||||
}
|
||||
// not in list
|
||||
return 0;
|
||||
} //-- remove
|
||||
|
||||
StringList::StringListItem* StringList::remove(StringList::StringListItem* sItem) {
|
||||
if (sItem->prevItem) {
|
||||
sItem->prevItem->nextItem = sItem->nextItem;
|
||||
}
|
||||
if (sItem == firstItem) firstItem = sItem->nextItem;
|
||||
if (sItem == lastItem) lastItem = sItem->prevItem;
|
||||
//-- decrease Item count
|
||||
--itemCount;
|
||||
return sItem;
|
||||
} //-- remove
|
||||
|
||||
/**
|
||||
* Removes all Strings equal to the given String from the list
|
||||
* All removed strings will be destroyed
|
||||
**/
|
||||
void StringList::remove(String& search) {
|
||||
StringListItem* sItem = firstItem;
|
||||
while (sItem) {
|
||||
if (sItem->strptr->isEqual(search)) {
|
||||
delete sItem->strptr;
|
||||
StringListItem* temp = remove(sItem);
|
||||
sItem = sItem->nextItem;
|
||||
delete temp;
|
||||
}
|
||||
else sItem = sItem->nextItem;
|
||||
}
|
||||
} //-- remove
|
||||
|
||||
//----------------------------------------/
|
||||
//- Implementation of StringListIterator -/
|
||||
//----------------------------------------/
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new StringListIterator for the given StringList
|
||||
**/
|
||||
StringListIterator::StringListIterator(StringList* list) {
|
||||
stringList = list;
|
||||
currentItem = 0;
|
||||
allowRemove = MB_FALSE;
|
||||
} //-- StringListIterator
|
||||
|
||||
StringListIterator::~StringListIterator() {
|
||||
//-- overrides default destructor to do nothing
|
||||
} //-- ~StringListIterator
|
||||
|
||||
/**
|
||||
* Adds the String pointer to the StringList of this StringListIterator.
|
||||
* The String pointer is inserted as the next item in the StringList
|
||||
* based on the current position within the StringList
|
||||
**/
|
||||
void StringListIterator::add(String* strptr) {
|
||||
|
||||
stringList->insertAfter(strptr,currentItem);
|
||||
allowRemove = MB_FALSE;
|
||||
|
||||
} //-- add
|
||||
|
||||
/**
|
||||
* Returns true if a sucessful call to the next() method can be made
|
||||
**/
|
||||
MBool StringListIterator::hasNext() {
|
||||
if (currentItem) {
|
||||
return (MBool)(currentItem->nextItem);
|
||||
}
|
||||
return (MBool)(stringList->firstItem);
|
||||
} //-- hasNext
|
||||
|
||||
/**
|
||||
* Returns true if a successful call to the previous() method can be made
|
||||
**/
|
||||
MBool StringListIterator::hasPrevious() {
|
||||
if (currentItem) {
|
||||
return (MBool)(currentItem->prevItem);
|
||||
}
|
||||
return MB_FALSE;
|
||||
} //-- hasPrevious
|
||||
|
||||
/**
|
||||
* Returns the next String in the list
|
||||
**/
|
||||
String* StringListIterator::next() {
|
||||
|
||||
if (currentItem) {
|
||||
if (currentItem->nextItem) {
|
||||
currentItem = currentItem->nextItem;
|
||||
allowRemove = MB_TRUE;
|
||||
return currentItem->strptr;
|
||||
}
|
||||
}
|
||||
else {
|
||||
currentItem = stringList->firstItem;
|
||||
allowRemove = MB_TRUE;
|
||||
return currentItem->strptr;
|
||||
}
|
||||
return 0;
|
||||
} //-- next
|
||||
|
||||
/**
|
||||
* Returns the previous String in the list
|
||||
**/
|
||||
String* StringListIterator::previous() {
|
||||
|
||||
if (currentItem) {
|
||||
if (currentItem->prevItem) {
|
||||
currentItem = currentItem->prevItem;
|
||||
allowRemove = MB_TRUE;
|
||||
return currentItem->strptr;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
//-- prev
|
||||
|
||||
/**
|
||||
* Removes the String last return by the next() or previous();
|
||||
* The removed String* is returned
|
||||
**/
|
||||
String* StringListIterator::remove() {
|
||||
|
||||
if (allowRemove == MB_FALSE) return 0;
|
||||
|
||||
allowRemove = MB_FALSE;
|
||||
|
||||
StringList::StringListItem* sItem = 0;
|
||||
if (currentItem) {
|
||||
// Make previous Item the current Item or null
|
||||
sItem = currentItem;
|
||||
if (stringList->firstItem == sItem) currentItem = 0;
|
||||
stringList->remove(sItem);
|
||||
return sItem->strptr;
|
||||
}
|
||||
return 0;
|
||||
} //-- remove
|
||||
|
||||
/**
|
||||
* Resets the current location within the StringList to the beginning
|
||||
**/
|
||||
void StringListIterator::reset() {
|
||||
currentItem = 0;
|
||||
} //-- reset
|
|
@ -0,0 +1,131 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* A class for keeping an ordered list of Strings
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
|
||||
#include "String.h"
|
||||
#include "baseutils.h"
|
||||
|
||||
#ifndef MITREXSL_STRINGLIST_H
|
||||
#define MITREXSL_STRINGLIST_H
|
||||
|
||||
class StringList {
|
||||
friend class StringListIterator;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates an empty StringList
|
||||
**/
|
||||
StringList();
|
||||
|
||||
/**
|
||||
* StringList destructor
|
||||
**/
|
||||
~StringList();
|
||||
|
||||
MBool contains(String& search);
|
||||
|
||||
/**
|
||||
* Returns the number of Strings in this List
|
||||
**/
|
||||
Int32 getLength();
|
||||
|
||||
/**
|
||||
* Returns a StringListIterator for this StringList
|
||||
**/
|
||||
StringListIterator& iterator();
|
||||
|
||||
/**
|
||||
* Adds the given String to the list
|
||||
**/
|
||||
void add(String* strptr);
|
||||
|
||||
/**
|
||||
* Removes the given String pointer from the list
|
||||
**/
|
||||
String* remove(String* strptr);
|
||||
|
||||
/**
|
||||
* Removes all Strings equal to the given String from the list
|
||||
* All removed strings will be destroyed
|
||||
**/
|
||||
void remove(String& search);
|
||||
|
||||
protected:
|
||||
struct StringListItem {
|
||||
StringListItem* nextItem;
|
||||
StringListItem* prevItem;
|
||||
String* strptr;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
StringListItem* firstItem;
|
||||
StringListItem* lastItem;
|
||||
Int32 itemCount;
|
||||
|
||||
void insertAfter(String* strptr, StringListItem* sItem);
|
||||
void insertBefore(String* strptr, StringListItem* sItem);
|
||||
|
||||
/**
|
||||
* Removes the given StringListItem pointer from the list
|
||||
**/
|
||||
StringListItem* remove(StringListItem* sItem);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class StringListIterator {
|
||||
|
||||
public:
|
||||
|
||||
|
||||
StringListIterator(StringList* list);
|
||||
~StringListIterator();
|
||||
|
||||
void add(String* strptr);
|
||||
|
||||
MBool hasNext();
|
||||
|
||||
MBool hasPrevious();
|
||||
|
||||
String* next();
|
||||
|
||||
String* previous();
|
||||
|
||||
String* remove();
|
||||
|
||||
void reset();
|
||||
|
||||
private:
|
||||
|
||||
StringList::StringListItem* currentItem;
|
||||
|
||||
StringList* stringList;
|
||||
MBool allowRemove;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tokenizer
|
||||
* A simple String tokenizer
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
* <BR/>
|
||||
* <PRE>
|
||||
* Modifications:
|
||||
* 19990806: Larry Fitzpatrick
|
||||
* - in method #nextToken():
|
||||
* - added void return type declaration
|
||||
* - added proper casts from Int32 to char
|
||||
* </PRE>
|
||||
*
|
||||
**/
|
||||
|
||||
#include "Tokenizer.h"
|
||||
|
||||
/**
|
||||
* Creates a new Tokenizer
|
||||
**/
|
||||
Tokenizer::Tokenizer() {
|
||||
currentPos = 0;
|
||||
size = 0;
|
||||
} //-- tokenizer
|
||||
|
||||
/**
|
||||
* Creates a new Tokenizer using the given source string,
|
||||
* uses the default set of delimiters {' ', '\r', '\n', '\t'};
|
||||
**/
|
||||
Tokenizer::Tokenizer(const String& source) {
|
||||
currentPos = 0;
|
||||
//-- copy source
|
||||
str = source;
|
||||
size = str.length();
|
||||
delimiters.append(" \n\r\t");
|
||||
} //-- Tokenizer
|
||||
|
||||
/**
|
||||
* Creates a new Tokenizer using the given source string
|
||||
* and set of character delimiters
|
||||
**/
|
||||
Tokenizer::Tokenizer(const String& source, const String& delimiters) {
|
||||
currentPos = 0;
|
||||
// copy source
|
||||
str = source;
|
||||
size = str.length();
|
||||
// copy tokens
|
||||
this->delimiters.append(delimiters);
|
||||
} //-- Tokenizer
|
||||
|
||||
|
||||
/**
|
||||
* Default Destructor
|
||||
**/
|
||||
Tokenizer::~Tokenizer() {};
|
||||
|
||||
MBool Tokenizer::hasMoreTokens() {
|
||||
return (MBool)(currentPos < size);
|
||||
} //-- hasMoreTokens
|
||||
|
||||
void Tokenizer::nextToken(String& buffer) {
|
||||
buffer.clear();
|
||||
while ( currentPos < size) {
|
||||
char ch = (char)str.charAt(currentPos);
|
||||
//-- if character is not a delimiter..append
|
||||
if (delimiters.indexOf(ch) < 0) buffer.append(ch);
|
||||
else break;
|
||||
++currentPos;
|
||||
}
|
||||
//-- advance to next start pos
|
||||
while ( currentPos < size ) {
|
||||
char ch = (char)str.charAt(currentPos);
|
||||
//-- if character is not a delimiter, we are at
|
||||
//-- start of next token
|
||||
if (delimiters.indexOf(ch) < 0) break;
|
||||
++currentPos;
|
||||
}
|
||||
} //-- nextToken
|
||||
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tokenizer
|
||||
* A simple String tokenizer
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
* <BR/>
|
||||
* <PRE>
|
||||
* Modifications:
|
||||
* 19990806: Larry Fitzpatrick
|
||||
* - for method #nextToken():
|
||||
* - added void return type declaration
|
||||
* </PRE>
|
||||
*
|
||||
**/
|
||||
|
||||
|
||||
#include "baseutils.h"
|
||||
#include "String.h"
|
||||
|
||||
|
||||
#ifndef MITRE_TOKENIZER_H
|
||||
#define MITRE_TOKENIZER_H
|
||||
|
||||
class Tokenizer {
|
||||
|
||||
public:
|
||||
|
||||
//----------------/
|
||||
//- Constructors -/
|
||||
//----------------/
|
||||
|
||||
/**
|
||||
* Creates a new Tokenizer
|
||||
**/
|
||||
Tokenizer();
|
||||
|
||||
/**
|
||||
* Creates a new Tokenizer using the given source string,
|
||||
* uses the default set of tokens (' ', '\r', '\n', '\t');
|
||||
**/
|
||||
Tokenizer(const String& source);
|
||||
|
||||
/**
|
||||
* Creates a new Tokenizer using the given source string
|
||||
* and set of character tokens
|
||||
**/
|
||||
Tokenizer(const String& source, const String& tokens);
|
||||
|
||||
|
||||
/**
|
||||
* Default Destructor
|
||||
**/
|
||||
virtual ~Tokenizer();
|
||||
|
||||
MBool hasMoreTokens();
|
||||
|
||||
void nextToken(String& buffer);
|
||||
|
||||
private:
|
||||
|
||||
Int32 currentPos;
|
||||
Int32 size;
|
||||
String str;
|
||||
String delimiters;
|
||||
|
||||
}; //-- Tokenizer
|
||||
#endif
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
// Basic Definitions used throughout many of these classes
|
||||
|
||||
#ifndef MITRE_BASEUTILS_H
|
||||
#define MITRE_BASEUTILS_H
|
||||
|
||||
typedef int Int32;
|
||||
|
||||
typedef Int32 MBool;
|
||||
|
||||
#define MB_TRUE (MBool)1
|
||||
#define MB_FALSE (MBool)0
|
||||
|
||||
#endif
|
|
@ -0,0 +1,70 @@
|
|||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..\..\..\..
|
||||
|
||||
LIBRARY_NAME=transformix_base
|
||||
MODULE=transformix
|
||||
REQUIRES=xpcom raptor
|
||||
|
||||
DEFINES=-DMOZILLA
|
||||
|
||||
CPPSRCS= \
|
||||
CommandLineUtils.cpp \
|
||||
Double.cpp \
|
||||
Integer.cpp \
|
||||
List.cpp \
|
||||
MITREObjectWrapper.cpp \
|
||||
NamedMap.cpp \
|
||||
SimpleErrorObserver.cpp \
|
||||
Stack.cpp \
|
||||
String.cpp \
|
||||
StringList.cpp \
|
||||
Tokenizer.cpp \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS= \
|
||||
.\$(OBJDIR)\CommandLineUtils.obj \
|
||||
.\$(OBJDIR)\Double.obj \
|
||||
.\$(OBJDIR)\Integer.obj \
|
||||
.\$(OBJDIR)\List.obj \
|
||||
.\$(OBJDIR)\MITREObjectWrapper.obj \
|
||||
.\$(OBJDIR)\NamedMap.obj \
|
||||
.\$(OBJDIR)\SimpleErrorObserver.obj \
|
||||
.\$(OBJDIR)\Stack.obj \
|
||||
.\$(OBJDIR)\String.obj \
|
||||
.\$(OBJDIR)\StringList.obj \
|
||||
.\$(OBJDIR)\Tokenizer.obj \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
$(NULL)
|
||||
|
||||
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor
|
||||
|
||||
LCFLAGS = \
|
||||
$(LCFLAGS) \
|
||||
$(DEFINES) \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
libs:: $(LIBRARY)
|
||||
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib
|
|
@ -0,0 +1,173 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef MITRE_PRIMITIVES_H
|
||||
#define MITRE_PRIMITIVES_H
|
||||
|
||||
#include "MITREObject.h"
|
||||
#include "baseutils.h"
|
||||
#include "String.h"
|
||||
#include <math.h>
|
||||
|
||||
#ifdef MOZILLA
|
||||
#include <float.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A wrapper for the primitive double type, and provides some simple
|
||||
* floating point related routines
|
||||
* @author <a href="mailto:lef@opentext.com">Larry Fitzpatrick</a>
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
class Double : public MITREObject {
|
||||
|
||||
public:
|
||||
|
||||
static const double NaN;
|
||||
static const double POSITIVE_INFINITY;
|
||||
static const double NEGATIVE_INFINITY;
|
||||
|
||||
/**
|
||||
* Creates a new Double with it's value initialized to 0;
|
||||
**/
|
||||
Double();
|
||||
|
||||
/**
|
||||
* Creates a new Double with it's value initialized to the given double
|
||||
**/
|
||||
Double(double dbl);
|
||||
|
||||
/**
|
||||
* Creates a new Double with it's value initialized from the given String.
|
||||
* The String will be converted to a double. If the String does not
|
||||
* represent an IEEE 754 double, the value will be initialized to NaN
|
||||
**/
|
||||
Double(const String& string);
|
||||
|
||||
/**
|
||||
* Returns the value of this Double as a double
|
||||
**/
|
||||
double doubleValue();
|
||||
|
||||
/**
|
||||
* Returns the value of this Double as an int
|
||||
**/
|
||||
int intValue();
|
||||
|
||||
/**
|
||||
* Determins whether the given double represents positive or negative
|
||||
* inifinity
|
||||
**/
|
||||
static MBool isInfinite(double dbl);
|
||||
|
||||
/**
|
||||
* Determins whether this Double's value represents positive or
|
||||
* negative inifinty
|
||||
**/
|
||||
MBool isInfinite();
|
||||
|
||||
/**
|
||||
* Determins whether the given double is NaN
|
||||
**/
|
||||
static MBool isNaN(double dbl);
|
||||
|
||||
/**
|
||||
* Determins whether this Double's value is NaN
|
||||
**/
|
||||
MBool isNaN();
|
||||
|
||||
/**
|
||||
* Converts the value of this Double to a String, and places
|
||||
* The result into the destination String.
|
||||
* @return the given dest string
|
||||
**/
|
||||
String& toString(String& dest);
|
||||
|
||||
/**
|
||||
* Converts the value of the given double to a String, and places
|
||||
* The result into the destination String.
|
||||
* @return the given dest string
|
||||
**/
|
||||
static String& Double::toString(double value, String& dest);
|
||||
|
||||
|
||||
private:
|
||||
double value;
|
||||
/**
|
||||
* Converts the given String to a double, if the String value does not
|
||||
* represent a double, NaN will be returned
|
||||
**/
|
||||
static double toDouble(const String& str);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* A wrapper for the primitive int type, and provides some simple
|
||||
* integer related routines
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
class Integer : public MITREObject {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new Integer initialized to 0.
|
||||
**/
|
||||
Integer();
|
||||
|
||||
/**
|
||||
* Creates a new Integer initialized to the given int value.
|
||||
**/
|
||||
Integer(Int32 integer);
|
||||
|
||||
/**
|
||||
* Creates a new Integer based on the value of the given String
|
||||
**/
|
||||
Integer::Integer(const String& str);
|
||||
|
||||
/**
|
||||
* Returns the int value of this Integer
|
||||
**/
|
||||
int intValue();
|
||||
|
||||
/**
|
||||
* Converts the value of this Integer to a String
|
||||
**/
|
||||
String& toString(String& dest);
|
||||
|
||||
/**
|
||||
* Converts the given int to a String
|
||||
**/
|
||||
static String& toString(int value, String& dest);
|
||||
|
||||
private:
|
||||
|
||||
Int32 value;
|
||||
|
||||
/**
|
||||
* converts the given String to an int
|
||||
**/
|
||||
static int intValue(const String& src);
|
||||
|
||||
}; //-- Integer
|
||||
|
||||
#endif
|
|
@ -0,0 +1,30 @@
|
|||
target: clean
|
||||
|
||||
CC = g++
|
||||
|
||||
PROJ_PATH = ${PWD}
|
||||
ROOT_PATH = $(PROJ_PATH)
|
||||
XML_PATH = $(ROOT_PATH)/xml
|
||||
XSL_PATH = $(ROOT_PATH)/xsl
|
||||
BASE_PATH = $(ROOT_PATH)/base
|
||||
DOM_PATH = $(XML_PATH)/dom
|
||||
NET_PATH = $(ROOT_PATH)/net
|
||||
EXPR_PATH = $(XSL_PATH)/expr
|
||||
XSLUTIL_PATH = $(XSL_PATH)/util
|
||||
XMLPRINTER_PATH = $(XML_PATH)/printer
|
||||
XMLPARSER_PATH = $(XML_PATH)/parser
|
||||
EXPAT_PARSER_PATH = $(XMLPARSER_PATH)/xmlparse
|
||||
EXPAT_TOKEN_PATH = $(XMLPARSER_PATH)/xmltok
|
||||
|
||||
clean:
|
||||
cd $(BASE_PATH); rm *.o; \
|
||||
cd $(NET_PATH); rm *.o; \
|
||||
cd $(XML_PATH); rm *.o; \
|
||||
cd $(DOM_PATH); rm *.o; \
|
||||
cd $(XMLPARSER_PATH); rm *.o; \
|
||||
cd $(EXPAT_PARSER_PATH); rm *.o; \
|
||||
cd $(EXPAT_TOKEN_PATH); rm *.o; \
|
||||
cd $(XMLPRINTER_PATH); rm *.o; \
|
||||
cd $(XSL_PATH); rm *.o; \
|
||||
cd $(XSLUTIL_PATH); rm *.o; \
|
||||
cd $(EXPR_PATH); rm *.o
|
|
@ -0,0 +1,986 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/REC-html40/loose.dtd">
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>MII TransforMiiX Test Cases</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
<CENTER>
|
||||
<FONT COLOR="BLUE" FACE="Arial">
|
||||
<B>MITRE</B>
|
||||
</FONT>
|
||||
<BR>
|
||||
<B>MII Transfor<FONT COLOR="blue">Mii</FONT>X Test Cases</B>
|
||||
</CENTER>
|
||||
<P>This document serves to test XPath and XSL functions.</P>
|
||||
<TABLE>
|
||||
<TR BGColor="#E0E0FF">
|
||||
<TD Colspan="2" ALIGN="CENTER">
|
||||
<B>Boolean Functions</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<B>Function:</B>
|
||||
</TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>boolean</I>
|
||||
<B> boolean(</B>
|
||||
<I>object</I>
|
||||
<B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="boolean(descendant::z)"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">true</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">true</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="boolean(*)"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">true</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">true</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<B>Function:</B>
|
||||
</TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>boolean</I>
|
||||
<B> false()</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="false()"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">false</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">false</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<B>Function:</B>
|
||||
</TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>boolean</I>
|
||||
<B> true()</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="true()"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">true</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">true</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<B>Function:</B>
|
||||
</TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>boolean</I>
|
||||
<B> not(</B>
|
||||
<I>boolean</I>
|
||||
<B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="not(true())"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">false</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">false</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
<TABLE>
|
||||
<TR BGColor="#E0E0FF">
|
||||
<TD Colspan="2" ALIGN="CENTER">
|
||||
<B>NodeSet Functions</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<B>Function:</B>
|
||||
</TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>number</I>
|
||||
<B> count(</B>
|
||||
<I>node-set</I>
|
||||
<B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="count(*)"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">4</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">4</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<B>Function:</B>
|
||||
</TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>number</I>
|
||||
<B> position()</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="*[position()=3]"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">z</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">z</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<B>Function:</B>
|
||||
</TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>number</I>
|
||||
<B> last()</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="*[last()-1]"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">z</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">z</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<B>Function:</B>
|
||||
</TD>
|
||||
<TD BGColor="#EEEEEE">String<B> local-part(</B>
|
||||
<I>node-set?</I>
|
||||
<B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="local-part(names/abc:test-name)"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">test-name</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">test-name</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<B>Function:</B>
|
||||
</TD>
|
||||
<TD BGColor="#EEEEEE">String<B> local-part(</B>
|
||||
<I>node-set?</I>
|
||||
<B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="local-part()"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">document</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">document</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<B>Function:</B>
|
||||
</TD>
|
||||
<TD BGColor="#EEEEEE">String<B>name(</B>
|
||||
<I>node-set?</I>
|
||||
<B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="name(names/abc:test-name)"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">abc:test-name</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">abc:test-name</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<B>Function:</B>
|
||||
</TD>
|
||||
<TD BGColor="#EEEEEE">String<B>namespace(</B>
|
||||
<I>node-set?</I>
|
||||
<B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="namespace(names/abc:test-name)"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">abc</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">abc</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
<TABLE>
|
||||
<TR BGColor="#E0E0FF">
|
||||
<TD Colspan="2" ALIGN="CENTER">
|
||||
<B>String Functions</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<B>Function:</B>
|
||||
</TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>string</I>
|
||||
<B> string(</B>
|
||||
<I>object?</I>
|
||||
<B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="string()"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">x y z</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue"> x y z </FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="string('xyz')"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">xyz</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">xyz</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<B>Function:</B>
|
||||
</TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>string</I>
|
||||
<B> concat(</B>
|
||||
<I>string, string, string*</I>
|
||||
<B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="concat('abc', 'def')"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">abcdef</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">abcdef</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<B>Function:</B>
|
||||
</TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>boolean</I>
|
||||
<B> contains(</B>
|
||||
<I>string, string</I>
|
||||
<B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="contains('abcdef', 'efg')"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">false</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">false</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="contains('abcdef', 'bcd')"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">true</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">true</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<B>Function:</B>
|
||||
</TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>boolean</I>
|
||||
<B> starts-with(</B>
|
||||
<I>string, string</I>
|
||||
<B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="starts-with('abcdef', 'abc')"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">true</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">true</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="starts-with('abcdef', 'xyz')"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">false</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">false</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<B>Function:</B>
|
||||
</TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>number</I>
|
||||
<B> string-length(</B>
|
||||
<I>string?</I>
|
||||
<B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="string-length(name())"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">8</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">8</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="string-length('abcdef')"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">6</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">6</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<B>Function:</B>
|
||||
</TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>string</I>
|
||||
<B> substring(</B>
|
||||
<I>string, number, number?</I>
|
||||
<B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="substring('12345', 1.5, 2.6)"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">234</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">234</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="substring('12345', 0, 3)"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">12</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">12</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="substring('12345', 0 div 0, 3)"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue"></FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue"></FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="substring('12345', 1, 0 div 0)"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue"></FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue"></FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="substring('12345', -42, 1 div 0)"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">12345</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">12345</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="substring('12345', -1 div 0, 1 div 0)"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue"></FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue"></FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<B>Function:</B>
|
||||
</TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>string</I>
|
||||
<B> substring-after(</B>
|
||||
<I>string, string</I>
|
||||
<B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="substring-after('1999/04/01', '/')"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">04/01</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">04/01</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<B>Function:</B>
|
||||
</TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>string</I>
|
||||
<B> substring-before(</B>
|
||||
<I>string, string</I>
|
||||
<B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="substring-before('1999/04/01', '/')"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">1999</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">1999</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<B>Function:</B>
|
||||
</TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>string</I>
|
||||
<B> translate(</B>
|
||||
<I>string, string, string</I>
|
||||
<B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="translate('bar', 'abc', 'ABC')"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">BAr</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">BAr</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="translate('---aaa---', 'abc-', 'ABC')"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">AAA</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">AAA</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
</BODY>
|
||||
</HTML>
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet type="text/xsl" href="functions.xsl"?>
|
||||
<!-- this is a test document -->
|
||||
<document>
|
||||
<!-- test comment -->
|
||||
<x name="x">x</x>
|
||||
<y name="y">y</y>
|
||||
<z name="z">z</z>
|
||||
<names>
|
||||
<abc:test-name/>
|
||||
</names>
|
||||
</document>
|
|
@ -0,0 +1,869 @@
|
|||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is a test stylesheet used for testing MITRE's XSL processor
|
||||
**/
|
||||
-->
|
||||
<xsl:stylesheet
|
||||
xmlns:xsl="http://www.w3.org/XSL/Transform/1.0"
|
||||
result-ns="http://www.w3.org/TR/REC-html40"
|
||||
default-space="strip">
|
||||
|
||||
<!-- root rule -->
|
||||
<xsl:template match="/">
|
||||
<xsl:apply-templates/>
|
||||
</xsl:template>
|
||||
|
||||
<!-- supress non-selected nodes-->
|
||||
<xsl:template match="*"/>
|
||||
|
||||
<!-- variable tests -->
|
||||
<xsl:variable name="product-name">
|
||||
<B>Transfor<FONT COLOR="blue">Mii</FONT>X</B>
|
||||
</xsl:variable>
|
||||
|
||||
<!-- main rule for document element -->
|
||||
<xsl:template match="document">
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>MII TransforMiiX Test Cases</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
<CENTER>
|
||||
<FONT COLOR="BLUE" FACE="Arial"><B>MITRE</B></FONT><BR/>
|
||||
<B>MII Transfor<FONT COLOR="blue">Mii</FONT>X Test Cases</B>
|
||||
</CENTER>
|
||||
<P>
|
||||
This document serves to test XPath and XSL functions.
|
||||
</P>
|
||||
<TABLE>
|
||||
<TR BGColor="#E0E0FF">
|
||||
<TD Colspan="2" ALIGN="CENTER">
|
||||
<B>Boolean Functions</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE"><B>Function:</B></TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>boolean</I><B> boolean(</B><I>object</I><B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="boolean(descendant::z)"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">true</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="boolean(descendant::z)"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="boolean(*)"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">true</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="boolean(*)"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE"><B>Function:</B></TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>boolean</I><B> false()</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="false()"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">false</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="false()"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE"><B>Function:</B></TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>boolean</I><B> true()</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="true()"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">true</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="true()"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE"><B>Function:</B></TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>boolean</I><B> not(</B><I>boolean</I><B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="not(true())"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">false</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="not(true())"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
<!-- ********************* -->
|
||||
<!-- * NodeSet Functions * -->
|
||||
<!-- ********************* -->
|
||||
<TABLE>
|
||||
<TR BGColor="#E0E0FF">
|
||||
<TD Colspan="2" ALIGN="CENTER">
|
||||
<B>NodeSet Functions</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE"><B>Function:</B></TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>number</I><B> count(</B><I>node-set</I><B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="count(*)"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">4</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="count(*)"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE"><B>Function:</B></TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>number</I><B> position()</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="*[position()=3]"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">z</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="*[position()=3]"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE"><B>Function:</B></TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>number</I><B> last()</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="*[last()-1]"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">z</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="*[last()-1]"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE"><B>Function:</B></TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
String <B> local-part(</B><I>node-set?</I><B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="local-part(names/abc:test-name)"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">test-name</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="local-part(names/abc:test-name)"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE"><B>Function:</B></TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
String <B> local-part(</B><I>node-set?</I><B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="local-part()"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">document</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="local-part()"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE"><B>Function:</B></TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
String <B>name(</B><I>node-set?</I><B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="name(names/abc:test-name)"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">abc:test-name</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="name(names/abc:test-name)"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE"><B>Function:</B></TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
String <B>namespace(</B><I>node-set?</I><B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="namespace(names/abc:test-name)"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">abc</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="namespace(names/abc:test-name)"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
|
||||
</TABLE>
|
||||
<!-- ******************** -->
|
||||
<!-- * String Functions * -->
|
||||
<!-- ******************** -->
|
||||
<TABLE>
|
||||
<TR BGColor="#E0E0FF">
|
||||
<TD Colspan="2" ALIGN="CENTER">
|
||||
<B>String Functions</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE"><B>Function:</B></TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>string</I><B> string(</B><I>object?</I><B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="string()"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">x y z</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="string()"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="string('xyz')"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">xyz</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="string('xyz')"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE"><B>Function:</B></TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>string</I><B> concat(</B><I>string, string, string*</I><B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="concat('abc', 'def')"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">abcdef</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="concat('abc','def')"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE"><B>Function:</B></TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>boolean</I><B> contains(</B><I>string, string</I><B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="contains('abcdef', 'efg')"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">false</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="contains('abcdef', 'efg')"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="contains('abcdef', 'bcd')"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">true</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="contains('abcdef', 'bcd')"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE"><B>Function:</B></TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>boolean</I><B> starts-with(</B><I>string, string</I><B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="starts-with('abcdef', 'abc')"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">true</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="starts-with('abcdef', 'abc')"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="starts-with('abcdef', 'xyz')"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">false</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="starts-with('abcdef', 'xyz')"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE"><B>Function:</B></TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>number</I><B> string-length(</B><I>string?</I><B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="string-length(name())"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">8</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="string-length(name())"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="string-length('abcdef')"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">6</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="string-length('abcdef')"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test: substring() #1 -->
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE"><B>Function:</B></TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>string</I><B> substring(</B><I>string, number, number?</I><B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="substring('12345', 1.5, 2.6)"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">234</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="substring('12345', 1.5, 2.6)"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test: substring() #2 -->
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="substring('12345', 0, 3)"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">12</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="substring('12345', 0, 3)"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test: substring() #3 -->
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="substring('12345', 0 div 0, 3)"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue"></FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="substring('12345', 0 div 0, 3)"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test: substring() #4 -->
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="substring('12345', 1, 0 div 0)"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue"></FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="substring('12345', 1, 0 div 0)"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test: substring() #5 -->
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="substring('12345', -42, 1 div 0)"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">12345</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="substring('12345',-42, 1 div 0)"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test: substring() #6 -->
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="substring('12345', -1 div 0, 1 div 0)"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue"></FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="substring('12345', -1 div 0, 1 div 0)"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE"><B>Function:</B></TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>string</I><B> substring-after(</B><I>string, string</I><B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="substring-after('1999/04/01', '/')"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">04/01</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="substring-after('1999/04/01', '/')"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE"><B>Function:</B></TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>string</I><B> substring-before(</B><I>string, string</I><B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="substring-before('1999/04/01', '/')"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">1999</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="substring-before('1999/04/01', '/')"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD BGColor="#EEEEEE"><B>Function:</B></TD>
|
||||
<TD BGColor="#EEEEEE">
|
||||
<I>string</I><B> translate(</B><I>string, string, string</I><B>)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="translate('bar', 'abc', 'ABC')"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">BAr</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="translate('bar', 'abc', 'ABC')"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="translate('---aaa---', 'abc-', 'ABC')"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">AAA</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="translate('---aaa---', 'abc-', 'ABC')"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
|
||||
</TABLE>
|
||||
</BODY>
|
||||
</HTML>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet type="text/xsl" href="identity.xsl"?>
|
||||
<document>
|
||||
|
||||
<x name="x">x</x>
|
||||
<y name="y">y</y>
|
||||
<z name="z">z</z>
|
||||
</document>
|
|
@ -0,0 +1,44 @@
|
|||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is a test stylesheet used for testing MITRE's XSL processor
|
||||
**/
|
||||
-->
|
||||
<xsl:stylesheet
|
||||
xmlns:xsl="http://www.w3.org/XSL/Transform/1.0"
|
||||
indent-result="yes">
|
||||
|
||||
<!-- root rule -->
|
||||
<xsl:template match="/">
|
||||
<xsl:apply-templates select="node()"/>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="@* | node()">
|
||||
<xsl:copy>
|
||||
<xsl:apply-templates select="@* | node()"/>
|
||||
</xsl:copy>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
|
|
@ -0,0 +1,486 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/REC-html40/loose.dtd">
|
||||
<?foo this is a test processing ? > instruction?>
|
||||
<!-- MITRE TransforMiiX Test cases, written by Keith Visco. -->
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>MII TransforMiiX Test Cases</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
<CENTER>
|
||||
<FONT COLOR="BLUE" FACE="Arial">
|
||||
<B>MITRE</B>
|
||||
</FONT>
|
||||
<BR>
|
||||
<B>MII Transfor<FONT COLOR="blue">Mii</FONT>X Test Cases</B>
|
||||
</CENTER>
|
||||
<P>This document serves to test basic XSL expressions.</P>
|
||||
<P>
|
||||
<B>Testing xsl:variable</B>
|
||||
<BR>
|
||||
<B>Test:</B><xsl:value-of select="$product-name"/><BR>
|
||||
<B>Desired Result:</B>TransforMiiX<BR>
|
||||
<B>Result:</B>TransforMiiX</P>
|
||||
<P>
|
||||
<B>Testing xsl:if</B>
|
||||
<BR>
|
||||
<B>Test:</B><xsl:if test="x | y | z">true</xsl:if><BR>
|
||||
<B>Desired Result:</B>true<BR>
|
||||
<B>Result:</B>true</P>
|
||||
<P>
|
||||
<B>Testing xsl:choose</B>
|
||||
<BR>
|
||||
<B>Test:</B>see source<BR>
|
||||
<B>Desired Result:</B>true<BR>
|
||||
<B>Result:</B>true</P>
|
||||
<P>
|
||||
<B>Testing parent and ancestor ops</B>
|
||||
<BR>
|
||||
<B>Test:</B>see source<BR>
|
||||
<B>Desired Result:</B>true<BR>
|
||||
<B>Result:</B>true<BR>
|
||||
</P>
|
||||
<P>
|
||||
<B>Testing basic xsl:apply-templates</B>
|
||||
<BR>
|
||||
<B>Test:</B><xsl:apply-templates/><BR>
|
||||
<B>Desired Result:</B>element x, element y, element z<BR>
|
||||
<B>Result:</B>element<B> x</B>,element<B> y</B>,element<B> z</B>
|
||||
</P>
|
||||
<P>
|
||||
<B>Testing basic xsl:apply-templates with mode</B>
|
||||
<BR>
|
||||
<B>Test:</B><xsl:apply-templates mode="mode-test"/><BR>
|
||||
<B>Desired Result:</B>x, y, z<BR>
|
||||
<B>Result:</B>x, y, z</P>
|
||||
<P>
|
||||
<B>Testing predicates</B>
|
||||
<BR>
|
||||
<B>Test:</B>see source<BR>
|
||||
<B>Desired Result:</B>
|
||||
<B>z</B>
|
||||
<BR>
|
||||
<B>Result:</B>
|
||||
<B>z</B>
|
||||
</P>
|
||||
<P>
|
||||
<B>Testing predicates</B>
|
||||
<BR>
|
||||
<B>Test:</B>see source<BR>
|
||||
<B>Desired Result:</B>
|
||||
<BR>
|
||||
<B>Result:</B>
|
||||
</P>
|
||||
<P>
|
||||
<B>Named Template/Call Template</B>
|
||||
<BR>
|
||||
<B>Test:</B><xsl:call-template name="named-template-test"/><BR>
|
||||
<B>Desired Result:</B>named template processed!<BR>
|
||||
<B>Result:</B>named template processed!</P>
|
||||
<P>
|
||||
<B>Attribute Value Templates and variables</B>
|
||||
<BR>
|
||||
<B>Test:</B>
|
||||
<UL><xsl:variable name="color">red</xsl:variable><BR><FONT COLOR="{$color}">Red Text</FONT></UL>
|
||||
<B>Desired Result:</B>
|
||||
<FONT COLOR="red">Red Text</FONT>
|
||||
<BR>
|
||||
<B>Result:</B>
|
||||
<FONT COLOR="red">Red Text</FONT>
|
||||
</P>
|
||||
<HR>
|
||||
<TABLE>
|
||||
<TR BGColor="#E0E0FF">
|
||||
<TD Colspan="2" ALIGN="CENTER">
|
||||
<B>Axis Identifiers (these should work, I need more test cases though)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:if test="descendant::z">true</xsl:if><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">true</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">true</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:if test="not(descendant-or-self::no-element)">true</xsl:if><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">true</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">true</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
<HR>
|
||||
<TABLE>
|
||||
<TR BGColor="#E0E0FF">
|
||||
<TD Colspan="2" ALIGN="CENTER">
|
||||
<B>Creating Elements with xsl:element and xsl:attribute</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:element name="FONT"><BR><xsl:attribute name="COLOR">blue</xsl:attribute><BR>Passed<BR></xsl:element></TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">Passed</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">Passed</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR BGCOLOR="#E0E0FF" ALIGN="CENTER">
|
||||
<TD COLSPAN="2">
|
||||
<B>Using Attribute Sets</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><FONT xsl:use-attribute-sets="style1"><BR>Passed<BR></FONT></TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">Passed</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue" SIZE="+0">Passed</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:element name="FONT" use-attribute-sets="style1 style2"><BR>Passed<BR></xsl:element></TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="red">Passed</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="red" SIZE="+0">Passed</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
<HR>
|
||||
<TABLE>
|
||||
<TR BGColor="#E0E0FF">
|
||||
<TD Colspan="2" ALIGN="CENTER">
|
||||
<B>Additive Expressions</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="70+4"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">74</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">74</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="-70+4"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">-66</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">-66</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="1900+70+8-4"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">1974</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">1974</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="(4+5)-(9+9)"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">-9</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">-9</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
<HR>
|
||||
<TABLE>
|
||||
<TR BGColor="#E0E0FF">
|
||||
<TD Colspan="2" ALIGN="CENTER">
|
||||
<B>Multiplicative Expressions</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="7*4"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">28</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">28</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="7mod4"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">3</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">3</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="7div4"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">1.75</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">1.75</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="7div0"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">Infinity</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">Infinity</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:value-of select="0 div 0"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">NaN</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">NaN</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP">
|
||||
<B>Test:</B>
|
||||
</TD>
|
||||
<TD><xsl:variable name="x" expr="7*3"/><BR><xsl:variable name="y" expr="3"/><BR><xsl:value-of select="$x div $y"/><BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Desired Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">7</FONT>
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<B>Result:</B>
|
||||
</TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">7</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
</BODY>
|
||||
</HTML>
|
|
@ -0,0 +1,557 @@
|
|||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is a test stylesheet used for testing MITRE's XSL processor
|
||||
**/
|
||||
-->
|
||||
<xsl:stylesheet
|
||||
xmlns:xsl="http://www.w3.org/XSL/Transform/1.0"
|
||||
result-ns="http://www.w3.org/TR/REC-html40">
|
||||
|
||||
<!-- AttributeSet -->
|
||||
<xsl:attribute-set name="style1">
|
||||
<xsl:attribute name="COLOR">blue</xsl:attribute>
|
||||
<xsl:attribute name="SIZE">+0</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
|
||||
<xsl:attribute-set name="style2">
|
||||
<xsl:attribute name="COLOR">red</xsl:attribute>
|
||||
<xsl:attribute name="SIZE">+0</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
|
||||
<!-- root rule -->
|
||||
<xsl:template match="/">
|
||||
<xsl:processing-instruction name="foo">
|
||||
this is a test processing ?> instruction
|
||||
</xsl:processing-instruction>
|
||||
<xsl:comment>MITRE TransforMiiX Test cases, written by Keith Visco.</xsl:comment>
|
||||
<xsl:apply-templates/>
|
||||
</xsl:template>
|
||||
|
||||
<!-- named template -->
|
||||
<xsl:template name="named-template-test">
|
||||
named template processed!
|
||||
</xsl:template>
|
||||
|
||||
<!-- supress non-selected nodes-->
|
||||
<xsl:template match="*"/>
|
||||
|
||||
<!-- variable tests -->
|
||||
<xsl:variable name="product-name">
|
||||
Transfor<FONT COLOR="blue">Mii</FONT>X
|
||||
</xsl:variable>
|
||||
<!-- main rule for document element -->
|
||||
<xsl:template match="document">
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>MII TransforMiiX Test Cases</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
<CENTER>
|
||||
<FONT COLOR="BLUE" FACE="Arial"><B>MITRE</B></FONT><BR/>
|
||||
<B>MII Transfor<FONT COLOR="blue">Mii</FONT>X Test Cases</B>
|
||||
</CENTER>
|
||||
<P>
|
||||
This document serves to test basic XSL expressions.
|
||||
</P>
|
||||
<!-- new test -->
|
||||
<P>
|
||||
<B>Testing xsl:variable</B><BR/>
|
||||
<B>Test:</B> <xsl:value-of select="$product-name"/><BR/>
|
||||
<B>Desired Result:</B>TransforMiiX<BR/>
|
||||
<B>Result:</B><xsl:value-of select="$product-name"/>
|
||||
</P>
|
||||
<!-- new test -->
|
||||
<P>
|
||||
<B>Testing xsl:if</B><BR/>
|
||||
<B>Test:</B> <xsl:if test="x | y | z">true</xsl:if><BR/>
|
||||
<B>Desired Result:</B> true<BR/>
|
||||
<B>Result:</B> <xsl:if test="x | y | z">true</xsl:if>
|
||||
</P>
|
||||
|
||||
<!-- new test -->
|
||||
<P>
|
||||
<B>Testing xsl:choose</B><BR/>
|
||||
<B>Test:</B>see source<BR/>
|
||||
<B>Desired Result:</B> true<BR/>
|
||||
<B>Result:</B>
|
||||
<xsl:choose>
|
||||
<xsl:when test="a">error - a</xsl:when>
|
||||
<xsl:when test="abc/def">true</xsl:when>
|
||||
<xsl:when test="b">error - b</xsl:when>
|
||||
<xsl:otherwise>false</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</P>
|
||||
<!-- new test -->
|
||||
<P>
|
||||
<B>Testing parent and ancestor ops</B><BR/>
|
||||
<B>Test:</B>see source<BR/>
|
||||
<B>Desired Result:</B> true<BR/>
|
||||
<B>Result:</B><xsl:if test="//def">true</xsl:if><BR/>
|
||||
|
||||
</P>
|
||||
<!-- new test -->
|
||||
|
||||
<P>
|
||||
<B>Testing basic xsl:apply-templates</B><BR/>
|
||||
<B>Test:</B><xsl:apply-templates/><BR/>
|
||||
<B>Desired Result:</B>element x, element y, element z<BR/>
|
||||
<B>Result:</B><xsl:apply-templates/>
|
||||
</P>
|
||||
<!-- new test -->
|
||||
|
||||
<P>
|
||||
<B>Testing basic xsl:apply-templates with mode</B><BR/>
|
||||
<B>Test:</B><xsl:apply-templates mode="mode-test"/><BR/>
|
||||
<B>Desired Result:</B>x, y, z<BR/>
|
||||
<B>Result:</B><xsl:apply-templates mode="mode-test"/>
|
||||
</P>
|
||||
<!-- new test -->
|
||||
<P>
|
||||
<B>Testing predicates</B><BR/>
|
||||
<B>Test:</B>see source<BR/>
|
||||
<B>Desired Result:</B> <B>z</B><BR/>
|
||||
<B>Result:</B>
|
||||
<xsl:for-each select="*[position()=3]">
|
||||
<B><xsl:value-of select="."/></B>
|
||||
</xsl:for-each>
|
||||
</P>
|
||||
<!-- new test -->
|
||||
<P>
|
||||
<B>Testing predicates</B><BR/>
|
||||
<B>Test:</B>see source<BR/>
|
||||
<B>Desired Result:</B><BR/>
|
||||
<B>Result:</B>
|
||||
<xsl:for-each select="*[false()]">
|
||||
<B><xsl:value-of select="."/></B>
|
||||
</xsl:for-each>
|
||||
</P>
|
||||
<!-- new test -->
|
||||
<P>
|
||||
<B>Named Template/Call Template</B><BR/>
|
||||
<B>Test:</B><xsl:call-template name="named-template-test"/><BR/>
|
||||
<B>Desired Result:</B>named template processed!<BR/>
|
||||
<B>Result:</B><xsl:call-template name="named-template-test"/>
|
||||
</P>
|
||||
<!-- new test -->
|
||||
<P>
|
||||
<B>Attribute Value Templates and variables</B><BR/>
|
||||
<B>Test:</B>
|
||||
<UL>
|
||||
<xsl:variable name="color">red</xsl:variable><BR/>
|
||||
<FONT COLOR="{$color}">Red Text</FONT>
|
||||
</UL>
|
||||
<B>Desired Result:</B>
|
||||
<FONT COLOR="red">Red Text</FONT><BR/>
|
||||
<B>Result:</B>
|
||||
<xsl:variable name="color">red</xsl:variable>
|
||||
<FONT COLOR="{$color}">Red Text</FONT>
|
||||
</P>
|
||||
<HR/>
|
||||
<TABLE>
|
||||
<TR BGColor="#E0E0FF">
|
||||
<TD Colspan="2" ALIGN="CENTER">
|
||||
<B>Axis Identifiers (these should work, I need more test cases though)</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:if test="descendant::z">true</xsl:if><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">true</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<xsl:if test="descendant::z">
|
||||
<FONT COLOR="blue">true</FONT>
|
||||
</xsl:if>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:if test="not(descendant-or-self::no-element)">true</xsl:if><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">true</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<xsl:if test="not(descendant-or-self::no-element)">
|
||||
<FONT COLOR="blue">true</FONT>
|
||||
</xsl:if>
|
||||
</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
|
||||
<HR/>
|
||||
<TABLE>
|
||||
<TR BGColor="#E0E0FF">
|
||||
<TD Colspan="2" ALIGN="CENTER">
|
||||
<B>Creating Elements with xsl:element and xsl:attribute</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:element name="FONT"><BR />
|
||||
<xsl:attribute name="COLOR">blue</xsl:attribute> <BR/>
|
||||
Passed <BR/>
|
||||
</xsl:element>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">Passed</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<xsl:element name="FONT">
|
||||
<xsl:attribute name="COLOR">blue</xsl:attribute>
|
||||
Passed
|
||||
</xsl:element>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR BGCOLOR="#E0E0FF" ALIGN="CENTER">
|
||||
<TD COLSPAN="2"><B>Using Attribute Sets</B></TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<FONT xsl:use-attribute-sets="style1"><BR />
|
||||
Passed <BR/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">Passed</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT xsl:use-attribute-sets="style1">
|
||||
Passed
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:element name="FONT" use-attribute-sets="style1 style2"><BR />
|
||||
Passed <BR/>
|
||||
</xsl:element>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="red">Passed</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<xsl:element name="FONT" use-attribute-sets="style1 style2">
|
||||
Passed
|
||||
</xsl:element>
|
||||
</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
|
||||
<HR/>
|
||||
<!-- ADDITIVE EXPRESSION TESTS -->
|
||||
<TABLE>
|
||||
<TR BGColor="#E0E0FF">
|
||||
<TD Colspan="2" ALIGN="CENTER">
|
||||
<B>Additive Expressions</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="70+4"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">74</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="70+4"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="-70+4"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">-66</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="-70+4"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="1900+70+8-4"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">1974</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="1900+70+8-4"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="(4+5)-(9+9)"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">-9</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="(4+5)-(9+9)"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
|
||||
</TABLE>
|
||||
<HR/>
|
||||
<!-- MULTIPLICATIVE EXPRESSION TESTS -->
|
||||
<TABLE>
|
||||
<TR BGColor="#E0E0FF">
|
||||
<TD Colspan="2" ALIGN="CENTER">
|
||||
<B>Multiplicative Expressions</B>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="7*4"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">28</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="7*4"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="7mod4"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">3</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="7mod4"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="7div4"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">1.75</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="7div4"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="7div0"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">Infinity</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="7div0"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:value-of select="0 div 0"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">NaN</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:value-of select="0 div 0"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
|
||||
<!-- new test -->
|
||||
<TR>
|
||||
<TD VALIGN="TOP"><B>Test:</B></TD>
|
||||
<TD>
|
||||
<xsl:variable name="x" expr="7*3"/><BR />
|
||||
<xsl:variable name="y" expr="3"/><BR />
|
||||
<xsl:value-of select="$x div $y"/><BR />
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Desired Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">7</FONT><BR/>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><B>Result:</B></TD>
|
||||
<TD>
|
||||
<FONT COLOR="blue">
|
||||
<xsl:variable name="x" expr="7*3"/>
|
||||
<xsl:variable name="y" expr="3"/>
|
||||
<xsl:value-of select="$x div $y"/>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
</BODY>
|
||||
</HTML>
|
||||
</xsl:template>
|
||||
|
||||
<!-- simple union expressions -->
|
||||
<xsl:template match="x | y | z" priority="1.0">
|
||||
<xsl:if test="not(position()=1)">,</xsl:if>
|
||||
element<B><xsl:text> </xsl:text><xsl:value-of select="@*"/></B>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="x | y | z" mode="mode-test">
|
||||
<xsl:if test="not(position()=1)"><xsl:text>, </xsl:text></xsl:if>
|
||||
<xsl:value-of select="@*"/>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="z">
|
||||
element (z): <B><xsl:value-of select="."/></B>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
|
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "XSLProcessor.h"
|
||||
|
||||
//--------------/
|
||||
//- Prototypes -/
|
||||
//--------------/
|
||||
|
||||
/**
|
||||
* Prints the command line help screen to the console
|
||||
**/
|
||||
void printHelp();
|
||||
|
||||
/**
|
||||
* prints the command line usage information to the console
|
||||
**/
|
||||
void printUsage();
|
||||
|
||||
/**
|
||||
* The TransforMiiX command line interface
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
XSLProcessor xslProcessor;
|
||||
|
||||
String copyright("(C) 1999 The MITRE Corporation");
|
||||
cout << xslProcessor.getAppName() << " ";
|
||||
cout << xslProcessor.getAppVersion() << copyright <<endl;
|
||||
|
||||
//-- print banner line
|
||||
Int32 fillSize = 1;
|
||||
fillSize += xslProcessor.getAppName().length();
|
||||
fillSize += xslProcessor.getAppVersion().length() + copyright.length();
|
||||
String fill;
|
||||
fill.setLength(fillSize, '-');
|
||||
cout << fill <<endl<<endl;
|
||||
|
||||
//-- add ErrorObserver
|
||||
SimpleErrorObserver seo;
|
||||
xslProcessor.addErrorObserver(seo);
|
||||
|
||||
//-- available flags
|
||||
StringList flags;
|
||||
flags.add(new String("i")); // XML input
|
||||
flags.add(new String("s")); // XSL input
|
||||
flags.add(new String("o")); // Output filename
|
||||
|
||||
NamedMap options;
|
||||
options.setObjectDeletion(MB_TRUE);
|
||||
CommandLineUtils::getOptions(options, argc, argv, flags);
|
||||
|
||||
if ( options.get("h") ) {
|
||||
printHelp();
|
||||
return 0;
|
||||
}
|
||||
String* xmlFilename = (String*)options.get("i");
|
||||
String* xslFilename = (String*)options.get("s");
|
||||
String* outFilename = (String*)options.get("o");
|
||||
|
||||
if ( !xmlFilename ) {
|
||||
cout << " missing XML filename."<<endl <<endl;
|
||||
printUsage();
|
||||
return -1;
|
||||
}
|
||||
char* chars = 0;
|
||||
|
||||
//-- open XML file
|
||||
chars = new char[xmlFilename->length()+1];
|
||||
ifstream xmlInput(xmlFilename->toChar(chars), ios::in);
|
||||
delete chars;
|
||||
|
||||
//-- create document base
|
||||
String documentBase;
|
||||
URIUtils::getDocumentBase(*xmlFilename, documentBase);
|
||||
|
||||
//-- handle output stream
|
||||
ostream* resultOutput = &cout;
|
||||
ofstream resultFileStream;
|
||||
if ( outFilename ) {
|
||||
chars = new char[outFilename->length()+1];
|
||||
resultFileStream.open(outFilename->toChar(chars), ios::out);
|
||||
delete chars;
|
||||
if ( !resultFileStream ) {
|
||||
cout << "error opening output file: " << *xmlFilename << endl;
|
||||
return -1;
|
||||
}
|
||||
resultOutput = &resultFileStream;
|
||||
}
|
||||
//-- process
|
||||
if ( !xslFilename ) {
|
||||
xslProcessor.process(xmlInput, documentBase, *resultOutput);
|
||||
}
|
||||
else {
|
||||
//-- open XSL file
|
||||
chars = new char[xslFilename->length()+1];
|
||||
ifstream xslInput(xslFilename->toChar(chars), ios::in);
|
||||
delete chars;
|
||||
xslProcessor.process(xmlInput, xslInput, *resultOutput);
|
||||
}
|
||||
resultFileStream.close();
|
||||
return 0;
|
||||
} //-- main
|
||||
|
||||
void printHelp() {
|
||||
cout << "The following flags are available for use with TransforMiiX -";
|
||||
cout<<endl<<endl;
|
||||
cout << "-i filename : The XML file to process" << endl;
|
||||
cout << "-o filename : The Output file to create" << endl;
|
||||
cout << "-s filename : The XSL file to use for processing (Optional)" << endl;
|
||||
cout << "-h : This help screen (Optional)" << endl;
|
||||
cout << endl;
|
||||
}
|
||||
void printUsage() {
|
||||
cout << endl;
|
||||
cout << "usage:";
|
||||
cout << "transfrmx -i xml-file [-s xsl-file] [-o output-file]"<<endl;
|
||||
cout << endl;
|
||||
cout << "for more infomation use the -h flag"<<endl;
|
||||
} //-- printUsage
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..\..\..
|
||||
|
||||
DIRS=base xml xsl
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
|
@ -0,0 +1,22 @@
|
|||
target: make_netlib
|
||||
|
||||
CC = g++
|
||||
|
||||
#ifndef PROJ_PATH
|
||||
BASE_PATH = ../base
|
||||
#endif
|
||||
|
||||
INCLUDE_PATHS = -I . -I$(BASE_PATH) -I-
|
||||
|
||||
BASE_OBJS = $(BASE_PATH)/String.o
|
||||
|
||||
NET_OBJS = URIUtils.o
|
||||
|
||||
ALL_OBJS = $(BASE_OBJS) \
|
||||
$(NET_OBJS)
|
||||
|
||||
|
||||
make_netlib: $(ALL_OBJS)
|
||||
|
||||
URIUtils.o: URIUtils.h URIUtils.cpp
|
||||
$(CC) $(INCLUDE_PATHS) -c URIUtils.cpp
|
|
@ -0,0 +1,335 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
//package com.kvisco.net;
|
||||
|
||||
#include "URIUtils.h"
|
||||
|
||||
/**
|
||||
* URIUtils
|
||||
* A set of utilities for handling URIs
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
* <BR/>
|
||||
* <PRE>
|
||||
* Modifications:
|
||||
* 19990806: Larry Fitzpatrick
|
||||
* - moved initialization of contanst shorts and chars from
|
||||
* URIUtils.h to here
|
||||
* </PRE>
|
||||
*
|
||||
**/
|
||||
|
||||
//- Constants -/
|
||||
|
||||
const String URIUtils::HTTP_PROTOCOL = "http";
|
||||
const String URIUtils::FILE_PROTOCOL = "file";
|
||||
const char URIUtils::HREF_PATH_SEP = '/';
|
||||
const char URIUtils::DEVICE_SEP = '|';
|
||||
const char URIUtils::PORT_SEP = ':';
|
||||
const char URIUtils::PROTOCOL_SEP = ':';
|
||||
const short URIUtils::PROTOCOL_MODE = 1;
|
||||
const short URIUtils::HOST_MODE = 2;
|
||||
const short URIUtils::PORT_MODE = 3;
|
||||
const short URIUtils::PATH_MODE = 4;
|
||||
|
||||
|
||||
/**
|
||||
* Returns an InputStream for the file represented by the href
|
||||
* argument
|
||||
* @param href the href of the file to get the input stream for.
|
||||
* @param documentBase the document base of the href argument, if it
|
||||
* is a relative href
|
||||
* set documentBase to null if there is none.
|
||||
* @return an InputStream to the desired resource
|
||||
* @exception java.io.FileNotFoundException when the file could not be
|
||||
* found
|
||||
**/
|
||||
istream* URIUtils::getInputStream
|
||||
(String& href, String& documentBase, String& errMsg)
|
||||
{
|
||||
|
||||
istream* inStream = 0;
|
||||
|
||||
//-- check for URL
|
||||
ParsedURI* uri = parseURI(href);
|
||||
if ( !uri->isMalformed ) {
|
||||
inStream = openStream(uri);
|
||||
delete uri;
|
||||
return inStream;
|
||||
}
|
||||
delete uri;
|
||||
|
||||
//-- join document base + href
|
||||
String xHref;
|
||||
if (documentBase.length() > 0) {
|
||||
xHref.append(documentBase);
|
||||
if (documentBase.charAt(documentBase.length()-1) != HREF_PATH_SEP)
|
||||
xHref.append(HREF_PATH_SEP);
|
||||
}
|
||||
xHref.append(href);
|
||||
|
||||
//-- check new href
|
||||
uri = parseURI(xHref);
|
||||
if ( !uri->isMalformed ) {
|
||||
inStream = openStream(uri);
|
||||
}
|
||||
else {
|
||||
// Try local files
|
||||
char* fchars = new char[xHref.length()+1];
|
||||
ifstream* inFile = new ifstream(xHref.toChar(fchars), ios::in);
|
||||
delete fchars;
|
||||
if ( ! *inFile ) {
|
||||
fchars = new char[href.length()+1];
|
||||
(*inFile).open(href.toChar(fchars), ios::in);
|
||||
delete fchars;
|
||||
}
|
||||
inStream = inFile;
|
||||
}
|
||||
delete uri;
|
||||
|
||||
return inStream;
|
||||
|
||||
} //-- getInputStream
|
||||
|
||||
/**
|
||||
* Returns the document base of the href argument
|
||||
* @return the document base of the given href
|
||||
**/
|
||||
void URIUtils::getDocumentBase(String& href, String& dest) {
|
||||
|
||||
//-- use temp str so the subString method doesn't destroy dest
|
||||
String docBase("");
|
||||
|
||||
if (href.length() != 0) {
|
||||
|
||||
int idx = -1;
|
||||
//-- check for URL
|
||||
ParsedURI* uri = parseURI(href);
|
||||
if ( !uri->isMalformed ) {
|
||||
idx = href.lastIndexOf(HREF_PATH_SEP);
|
||||
}
|
||||
else {
|
||||
//-- The following contains a fix from Shane Hathaway
|
||||
//-- to handle the case when both "\" and "/" appear in filename
|
||||
int idx2 = href.lastIndexOf(HREF_PATH_SEP);
|
||||
//idx = href.lastIndexOf(File.separator);
|
||||
idx = -1; //-- hack change later
|
||||
if (idx2 > idx) idx = idx2;
|
||||
}
|
||||
if (idx >= 0) href.subString(0,idx, docBase);
|
||||
delete uri;
|
||||
}
|
||||
dest.append(docBase);
|
||||
|
||||
} //-- getDocumentBase
|
||||
|
||||
/**
|
||||
* Resolves the given href argument, using the given documentBase
|
||||
* if necessary.
|
||||
* The new resolved href will be appended to the given dest String
|
||||
**/
|
||||
void URIUtils::resolveHref(String& href, String& documentBase, String& dest) {
|
||||
|
||||
|
||||
//-- check for URL
|
||||
ParsedURI* uri = parseURI(href);
|
||||
if ( !uri->isMalformed ) {
|
||||
dest.append(href);
|
||||
delete uri;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//-- join document base + href
|
||||
String xHref;
|
||||
if (documentBase.length() > 0) {
|
||||
xHref.append(documentBase);
|
||||
if (documentBase.charAt(documentBase.length()-1) != HREF_PATH_SEP)
|
||||
xHref.append(HREF_PATH_SEP);
|
||||
}
|
||||
xHref.append(href);
|
||||
|
||||
//-- check new href
|
||||
ParsedURI* newUri = parseURI(xHref);
|
||||
if ( !newUri->isMalformed ) {
|
||||
dest.append(xHref);
|
||||
}
|
||||
else {
|
||||
// Try local files
|
||||
char* xHrefChars = new char[xHref.length()+1];
|
||||
ifstream inFile(xHref.toChar(xHrefChars), ios::in);
|
||||
if ( inFile ) dest.append(xHref);
|
||||
else dest.append(href);
|
||||
inFile.close();
|
||||
delete xHrefChars;
|
||||
}
|
||||
delete uri;
|
||||
delete newUri;
|
||||
|
||||
} //-- resolveHref
|
||||
|
||||
istream* URIUtils::openStream(ParsedURI* uri) {
|
||||
if ( !uri ) return 0;
|
||||
// check protocol
|
||||
|
||||
istream* inStream = 0;
|
||||
if ( FILE_PROTOCOL.isEqual(uri->protocol) ) {
|
||||
char* fchars = new char[uri->path.length()+1];
|
||||
ifstream* inFile = new ifstream(uri->path.toChar(fchars), ios::in);
|
||||
delete fchars;
|
||||
inStream = inFile;
|
||||
}
|
||||
|
||||
return inStream;
|
||||
} //-- openStream
|
||||
|
||||
/* */
|
||||
|
||||
URIUtils::ParsedURI* URIUtils::parseURI(const String& uri) {
|
||||
|
||||
ParsedURI* uriTokens = new ParsedURI;
|
||||
uriTokens->isMalformed = MB_FALSE;
|
||||
|
||||
short mode = PROTOCOL_MODE;
|
||||
|
||||
// look for protocol
|
||||
int totalCount = uri.length();
|
||||
int charCount = 0;
|
||||
char prevCh = '\0';
|
||||
int fslash = 0;
|
||||
String buffer(uri.length());
|
||||
while ( charCount < totalCount ) {
|
||||
char ch = uri.charAt(charCount++);
|
||||
switch(ch) {
|
||||
case '.' :
|
||||
if ( mode == PROTOCOL_MODE ) {
|
||||
uriTokens->isMalformed = MB_TRUE;
|
||||
mode = HOST_MODE;
|
||||
}
|
||||
buffer.append(ch);
|
||||
break;
|
||||
case ':' :
|
||||
{
|
||||
switch ( mode ) {
|
||||
case PROTOCOL_MODE :
|
||||
uriTokens->protocol = buffer;
|
||||
buffer.clear();
|
||||
mode = HOST_MODE;
|
||||
break;
|
||||
case HOST_MODE :
|
||||
|
||||
uriTokens->host = buffer;
|
||||
buffer.clear();
|
||||
mode = PORT_MODE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case '/' :
|
||||
switch ( mode ) {
|
||||
case HOST_MODE :
|
||||
if ( buffer.length() != 0 ) {
|
||||
mode = PATH_MODE;
|
||||
buffer.append(ch);
|
||||
}
|
||||
else if ( fslash == 2 ) mode = PATH_MODE;
|
||||
else ++fslash;
|
||||
break;
|
||||
case PORT_MODE :
|
||||
mode = PATH_MODE;
|
||||
uriTokens->port.append(buffer);
|
||||
buffer.clear();
|
||||
break;
|
||||
default:
|
||||
buffer.append(ch);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
buffer.append(ch);
|
||||
}
|
||||
prevCh = ch;
|
||||
}
|
||||
|
||||
if ( mode == PROTOCOL_MODE ) {
|
||||
uriTokens->isMalformed = MB_TRUE;
|
||||
}
|
||||
//-- finish remaining mode
|
||||
if ( buffer.length() > 0 ) {
|
||||
switch ( mode ) {
|
||||
case PROTOCOL_MODE :
|
||||
uriTokens->protocol.append(buffer);
|
||||
break;
|
||||
case HOST_MODE :
|
||||
uriTokens->host.append(buffer);
|
||||
break;
|
||||
case PORT_MODE :
|
||||
uriTokens->port.append(buffer);
|
||||
break;
|
||||
case PATH_MODE :
|
||||
uriTokens->path.append(buffer);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return uriTokens;
|
||||
} //-- parseURI
|
||||
|
||||
/**
|
||||
*
|
||||
**
|
||||
void URIUtils::test(const String& str) {
|
||||
cout << "parsing: " << str << endl;
|
||||
ParsedURI* uri = parseURI(str);
|
||||
cout << "protocol : " << uri->protocol << endl;
|
||||
cout << "host : " << uri->host << endl;
|
||||
cout << "port : " << uri->port << endl;
|
||||
cout << "path : " << uri->path << endl;
|
||||
cout << "malformed: " << uri->isMalformed << endl;
|
||||
delete uri;
|
||||
} //-- test
|
||||
|
||||
/**
|
||||
* The test class for the URIUtils
|
||||
**
|
||||
void main(int argc, char** argv) {
|
||||
URIUtils::test("file:///c|\\test");
|
||||
URIUtils::test("http://my.domain.com");
|
||||
URIUtils::test("my.domain.com");
|
||||
URIUtils::test("http://my.domain.com:80");
|
||||
URIUtils::test("http://my.domain.com:88/foo.html");
|
||||
|
||||
String url("http://my.domain.com:88/foo.html");
|
||||
String docBase;
|
||||
URIUtils::getDocumentBase(url, docBase);
|
||||
cout << "url : " << url <<endl;
|
||||
cout << "document base: " << docBase <<endl;
|
||||
String localPart("foo.html");
|
||||
url.clear();
|
||||
URIUtils::resolveHref(localPart, docBase, url);
|
||||
cout << "local part : " << localPart << endl;
|
||||
cout << "resolved url : " << url << endl;
|
||||
|
||||
}
|
||||
/* -*- */
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
//package com.kvisco.net;
|
||||
|
||||
#include "String.h"
|
||||
#include "baseutils.h"
|
||||
#include <iostream.h>
|
||||
#include <fstream.h>
|
||||
|
||||
/**
|
||||
* A utility class for URI handling
|
||||
* Not yet finished, only handles file URI at this point
|
||||
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
|
||||
* <BR/>
|
||||
* <PRE>
|
||||
* Modifications:
|
||||
* 19990806: Larry Fitzpatrick
|
||||
* - moved initialization of contanst shorts and chars to URIUtils.cpp
|
||||
* </PRE>
|
||||
*
|
||||
**/
|
||||
|
||||
class URIUtils {
|
||||
|
||||
|
||||
public:
|
||||
|
||||
static const String HTTP_PROTOCOL;
|
||||
static const String FILE_PROTOCOL;
|
||||
|
||||
/**
|
||||
* the path separator for an URI
|
||||
**/
|
||||
static const char HREF_PATH_SEP;
|
||||
|
||||
/**
|
||||
* The Device separator for an URI
|
||||
**/
|
||||
static const char DEVICE_SEP;
|
||||
|
||||
/**
|
||||
* The Port separator for an URI
|
||||
**/
|
||||
static const char PORT_SEP;
|
||||
|
||||
/**
|
||||
* The Protocal separator for an URI
|
||||
**/
|
||||
static const char PROTOCOL_SEP;
|
||||
|
||||
|
||||
static istream* URIUtils::getInputStream
|
||||
(String& href, String& documentBase, String& errMsg);
|
||||
|
||||
/**
|
||||
* Returns the document base of the href argument
|
||||
* The document base will be appended to the given dest String
|
||||
**/
|
||||
static void getDocumentBase(String& href, String& dest);
|
||||
|
||||
/**
|
||||
* Resolves the given href argument, using the given documentBase
|
||||
* if necessary.
|
||||
* The new resolved href will be appended to the given dest String
|
||||
**/
|
||||
static void resolveHref(String& href, String& documentBase, String& dest);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
static const short PROTOCOL_MODE;
|
||||
static const short HOST_MODE;
|
||||
static const short PORT_MODE;
|
||||
static const short PATH_MODE;
|
||||
|
||||
struct ParsedURI {
|
||||
MBool isMalformed;
|
||||
String fragmentIdentifier;
|
||||
String host;
|
||||
String protocol;
|
||||
String port;
|
||||
String path;
|
||||
};
|
||||
|
||||
static istream* openStream(ParsedURI* uri);
|
||||
static ParsedURI* parseURI(const String& uri);
|
||||
|
||||
|
||||
|
||||
}; //-- URIUtils
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
BASE_PATH = ../base
|
||||
DOM_PATH = dom
|
||||
|
||||
INCLUDE_PATH = -I . -I $(BASE_PATH) -I $(DOM_PATH) -I-
|
||||
|
||||
|
||||
ALL_OBJS = XMLDOMUtils.o \
|
||||
XMLUtils.o
|
||||
|
||||
|
||||
CC = g++ $(INCLUDE_PATH)
|
||||
|
||||
target: $(ALL_OBJS)
|
||||
|
||||
XMLDOMUtils.o: XMLDOMUtils.h XMLDOMUtils.cpp
|
||||
$(CC) -c XMLDOMUtils.cpp
|
||||
|
||||
XMLUtils.o: XMLUtils.h XMLUtils.cpp
|
||||
$(CC) -c XMLUtils.cpp
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* XMLDOMUtils
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
|
||||
#include "XMLDOMUtils.h"
|
||||
|
||||
void XMLDOMUtils::getNodeValue(Node* node, DOMString* target) {
|
||||
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
|
||||
int nodeType = node->getNodeType();
|
||||
Element* element = 0;
|
||||
NodeList* nl = 0;
|
||||
|
||||
switch ( nodeType ) {
|
||||
case Node::ATTRIBUTE_NODE :
|
||||
target->append( ((Attr*)node)->getValue() );
|
||||
break;
|
||||
case Node::DOCUMENT_NODE :
|
||||
getNodeValue( ((Document*)node)->getDocumentElement(), target);
|
||||
break;
|
||||
case Node::DOCUMENT_FRAGMENT_NODE :
|
||||
case Node::ELEMENT_NODE :
|
||||
{
|
||||
nl = node->getChildNodes();
|
||||
for ( int i = 0; i < nl->getLength(); i++) {
|
||||
getNodeValue(nl->item(i),target);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Node::TEXT_NODE :
|
||||
target->append ( ((Text*)node)->getData() );
|
||||
break;
|
||||
} //-- switch
|
||||
|
||||
} //-- getNodeValue
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* A utility class for use with XML DOM implementations
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
#include "dom.h"
|
||||
|
||||
#ifndef MITRE_XMLDOMUTILS_H
|
||||
#define MITRE_XMLDOMUTILS_H
|
||||
|
||||
class XMLDOMUtils {
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Appends the value of the given Node to the target DOMString
|
||||
**/
|
||||
static void XMLDOMUtils::getNodeValue(Node* node, DOMString* target);
|
||||
}; //-- XMLDOMUtils
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,252 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* An XML utility class
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
|
||||
#include "XMLUtils.h"
|
||||
|
||||
//------------------------------/
|
||||
//- Implementation of XMLUtils -/
|
||||
//------------------------------/
|
||||
|
||||
const String XMLUtils::XMLNS = "xmlns";
|
||||
|
||||
void XMLUtils::getNameSpace(const String& src, String& dest) {
|
||||
|
||||
//-- anything preceding ':' is the namespace part of the name
|
||||
int idx = src.indexOf(':');
|
||||
if ( idx > 0 ) {
|
||||
//-- create new String to prevent any chars in dest from being
|
||||
//-- lost
|
||||
String tmp;
|
||||
src.subString(0,idx, tmp);
|
||||
dest.append(tmp);
|
||||
}
|
||||
else dest.append("");
|
||||
|
||||
} //-- getNameSpace
|
||||
|
||||
void XMLUtils::getLocalPart(const String& src, String& dest) {
|
||||
|
||||
//-- anything after ':' is the local part of the name
|
||||
int idx = src.indexOf(':');
|
||||
if ( idx < -1 ) idx = -1;
|
||||
//-- create new String to prevent any chars in dest from being
|
||||
//-- lost
|
||||
String tmp;
|
||||
src.subString(idx+1, tmp);
|
||||
dest.append(tmp);
|
||||
|
||||
} //-- getLocalPart
|
||||
|
||||
/**
|
||||
* Returns true if the given character represents an Alpha letter
|
||||
**/
|
||||
MBool XMLUtils::isAlphaChar(Int32 ch) {
|
||||
if ((ch >= 'a' ) && (ch <= 'z' )) return MB_TRUE;
|
||||
if ((ch >= 'A' ) && (ch <= 'Z' )) return MB_TRUE;
|
||||
return MB_FALSE;
|
||||
} //-- isAlphaChar
|
||||
|
||||
/**
|
||||
* Returns true if the given character represents a numeric letter (digit)
|
||||
**/
|
||||
MBool XMLUtils::isDigit(Int32 ch) {
|
||||
if ((ch >= '0') && (ch <= '9')) return MB_TRUE;
|
||||
return MB_FALSE;
|
||||
} //-- isDigit
|
||||
|
||||
/**
|
||||
* Returns true if the given character is an allowable QName character
|
||||
**/
|
||||
MBool XMLUtils::isNCNameChar(Int32 ch) {
|
||||
if (isDigit(ch) || isAlphaChar(ch)) return MB_TRUE;
|
||||
return (MBool) ((ch == '.') ||(ch == '_') || (ch == '-'));
|
||||
} //-- isNCNameChar
|
||||
|
||||
/**
|
||||
* Returns true if the given character is an allowable NCName character
|
||||
**/
|
||||
MBool XMLUtils::isQNameChar(Int32 ch) {
|
||||
return (MBool) (( ch == ':') || isNCNameChar(ch));
|
||||
} //-- isQNameChar
|
||||
|
||||
/**
|
||||
* Returns true if the given String is a valid XML QName
|
||||
**/
|
||||
MBool XMLUtils::isValidQName(String& name) {
|
||||
|
||||
int size = name.length();
|
||||
if ( size == 0 ) return MB_FALSE;
|
||||
else if ( !isAlphaChar(name.charAt(0))) return MB_FALSE;
|
||||
else {
|
||||
for ( int i = 1; i < size; i++) {
|
||||
if ( ! isQNameChar(name.charAt(i))) return MB_FALSE;
|
||||
}
|
||||
}
|
||||
return MB_TRUE;
|
||||
} //-- isValidQName
|
||||
|
||||
/**
|
||||
* Normalizes the value of an XML attribute
|
||||
**/
|
||||
void XMLUtils::normalizeAttributeValue(String& attValue) {
|
||||
Int32 size = attValue.length();
|
||||
//-- make copy of chars
|
||||
char* chars = new char[size+1];
|
||||
attValue.toChar(chars);
|
||||
//-- clear attValue
|
||||
attValue.clear();
|
||||
|
||||
Int32 cc = 0;
|
||||
MBool addSpace = MB_FALSE;
|
||||
while ( cc < size) {
|
||||
char ch = chars[cc++];
|
||||
switch (ch) {
|
||||
case ' ':
|
||||
if ( attValue.length() > 0) addSpace = MB_TRUE;
|
||||
break;
|
||||
case '\r':
|
||||
break;
|
||||
case '\n':
|
||||
attValue.append("
");
|
||||
break;
|
||||
default:
|
||||
if ( addSpace) {
|
||||
attValue.append(' ');
|
||||
addSpace = MB_FALSE;
|
||||
}
|
||||
attValue.append(ch);
|
||||
break;
|
||||
}
|
||||
}
|
||||
delete chars;
|
||||
} //-- normalizeAttributeValue
|
||||
|
||||
/**
|
||||
* Normalizes the value of a XML processing instruction
|
||||
**/
|
||||
void XMLUtils::normalizePIValue(String& piValue) {
|
||||
Int32 size = piValue.length();
|
||||
//-- make copy of chars
|
||||
char* chars = new char[size+1];
|
||||
piValue.toChar(chars);
|
||||
//-- clear attValue
|
||||
piValue.clear();
|
||||
|
||||
Int32 cc = 0;
|
||||
char prevCh = '\0';
|
||||
while ( cc < size) {
|
||||
char ch = chars[cc++];
|
||||
switch (ch) {
|
||||
case '>':
|
||||
if ( prevCh == '?' ) {
|
||||
piValue.append(' ');
|
||||
}
|
||||
piValue.append(ch);
|
||||
break;
|
||||
default:
|
||||
piValue.append(ch);
|
||||
break;
|
||||
}
|
||||
prevCh = ch;
|
||||
}
|
||||
delete chars;
|
||||
} //-- noramlizePIValue
|
||||
|
||||
/**
|
||||
* Strips whitespace from the given String.
|
||||
* Newlines (#xD), tabs (#x9), and consecutive spaces (#x20) are
|
||||
* converted to a single space (#x20).
|
||||
* @param data the String to strip whitespace from
|
||||
* @param dest the destination String to append the result to
|
||||
**/
|
||||
void XMLUtils::stripSpace (const String& data, String& dest) {
|
||||
stripSpace(data,dest,MB_FALSE,MB_FALSE);
|
||||
} //-- stripSpace
|
||||
|
||||
/**
|
||||
* Strips whitespace from the given String.
|
||||
* Newlines (#xD), tabs (#x9), and consecutive spaces (#x20) are
|
||||
* converted to a single space (#x20).
|
||||
* @param data the String to strip whitespace from
|
||||
* @param dest the destination String to append the result to
|
||||
* @param stripAllLeadSpace, a boolean indicating whether or not to
|
||||
* strip all leading space. If true all whitespace from the start of the
|
||||
* given String will be stripped. If false, all whitespace from the start
|
||||
* of the given String will be converted to a single space.
|
||||
* @param stripAllTrailSpace, a boolean indicating whether or not to
|
||||
* strip all trailing space. If true all whitespace at the end of the
|
||||
* given String will be stripped. If false, all whitespace at the end
|
||||
* of the given String will be converted to a single space.
|
||||
**/
|
||||
void XMLUtils::stripSpace
|
||||
( const String& data,
|
||||
String& dest,
|
||||
MBool stripAllLeadSpace,
|
||||
MBool stripAllTrailSpace )
|
||||
{
|
||||
|
||||
char lastToken, token;
|
||||
Int32 oldSize = data.length();
|
||||
char* chars = new char[oldSize+1];
|
||||
data.toChar(chars);
|
||||
|
||||
lastToken = '\0';
|
||||
Int32 total = 0;
|
||||
|
||||
// indicates we have seen at least one
|
||||
// non whitespace charater
|
||||
MBool validChar = MB_FALSE;
|
||||
|
||||
for (int i = 0; i < oldSize; i++) {
|
||||
token = chars[i];
|
||||
switch(token) {
|
||||
case ' ':
|
||||
case '\t':
|
||||
case '\n':
|
||||
case '\r':
|
||||
token = ' ';
|
||||
if (stripAllLeadSpace && (!validChar)) break;
|
||||
if (lastToken != token) chars[total++] = token;
|
||||
break;
|
||||
default:
|
||||
chars[total++] = token;
|
||||
validChar = MB_TRUE;
|
||||
break;
|
||||
}
|
||||
lastToken = token;
|
||||
}
|
||||
|
||||
//-- remove last trailing space if necessary
|
||||
if (stripAllTrailSpace)
|
||||
if ((total > 0) && (chars[total-1] == ' ')) --total;
|
||||
|
||||
if (validChar) {
|
||||
chars[total] = '\0'; //-- add Null terminator
|
||||
dest.append(chars);
|
||||
}
|
||||
delete chars;
|
||||
} //-- stripSpace
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* An XML Utility class
|
||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
||||
**/
|
||||
|
||||
#include "String.h"
|
||||
#include "baseutils.h"
|
||||
|
||||
#ifndef MITRE_XMLUTILS_H
|
||||
#define MITRE_XMLUTILS_H
|
||||
|
||||
class XMLUtils {
|
||||
|
||||
public:
|
||||
|
||||
static const String XMLNS;
|
||||
|
||||
static void getNameSpace(const String& src, String& dest);
|
||||
static void getLocalPart(const String& src, String& dest);
|
||||
|
||||
/**
|
||||
* Returns true if the given String is a valid XML QName
|
||||
**/
|
||||
static MBool isValidQName(String& name);
|
||||
|
||||
/**
|
||||
* Normalizes the value of an XML attribute
|
||||
**/
|
||||
static void normalizeAttributeValue(String& attValue);
|
||||
|
||||
/**
|
||||
* Normalizes the value of a XML processingInstruction
|
||||
**/
|
||||
static void normalizePIValue(String& attValue);
|
||||
|
||||
/**
|
||||
* Strips whitespace from the given String.
|
||||
* Newlines (#xD), tabs (#x9), and consecutive spaces (#x20) are
|
||||
* converted to a single space (#x20).
|
||||
* @param data the String to strip whitespace from
|
||||
* @param dest the destination String to append the result to
|
||||
**/
|
||||
static void stripSpace (const String& data, String& dest);
|
||||
|
||||
/**
|
||||
* Strips whitespace from the given String.
|
||||
* Newlines (#xD), tabs (#x9), and consecutive spaces (#x20) are
|
||||
* converted to a single space (#x20).
|
||||
* @param data the String to strip whitespace from
|
||||
* @param dest the destination String to append the result to
|
||||
* @param stripAllLeadSpace, a boolean indicating whether or not to
|
||||
* strip all leading space. If true all whitespace from the start of the
|
||||
* given String will be stripped. If false, all whitespace from the start
|
||||
* of the given String will be converted to a single space.
|
||||
* @param stripAllTrailSpace, a boolean indicating whether or not to
|
||||
* strip all trailing space. If true all whitespace at the end of the
|
||||
* given String will be stripped. If false, all whitespace at the end
|
||||
* of the given String will be converted to a single space.
|
||||
**/
|
||||
static void stripSpace (const String& data,
|
||||
String& dest,
|
||||
MBool stripAllLeadSpace,
|
||||
MBool stripAllTrailSpace);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Returns true if the given character represents an Alpha letter
|
||||
**/
|
||||
static MBool isAlphaChar(Int32 ch);
|
||||
|
||||
/**
|
||||
* Returns true if the given character represents a numeric letter (digit)
|
||||
**/
|
||||
static MBool isDigit(Int32 ch);
|
||||
|
||||
/**
|
||||
* Returns true if the given character is an allowable QName character
|
||||
**/
|
||||
static MBool isQNameChar(Int32 ch);
|
||||
|
||||
/**
|
||||
* Returns true if the given character is an allowable NCName character
|
||||
**/
|
||||
static MBool isNCNameChar(Int32 ch);
|
||||
|
||||
}; //-- XMLUtils
|
||||
#endif
|
|
@ -0,0 +1,143 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
// Tom Kneeland (3/29/99)
|
||||
//
|
||||
// Implementation of the Document Object Model Level 1 Core
|
||||
// Implementation of the Attr class
|
||||
//
|
||||
// Modification History:
|
||||
// Who When What
|
||||
// TK 03/29/99 Created
|
||||
// LF 08/06/1999 fixed typo: defalut to default
|
||||
|
||||
//
|
||||
|
||||
#include "dom.h"
|
||||
|
||||
//
|
||||
//Construct an Attribute object using the specified name and document owner
|
||||
//
|
||||
Attr::Attr(const DOMString& name, Document* owner):
|
||||
NodeDefinition(Node::ATTRIBUTE_NODE, name, NULL_STRING, owner)
|
||||
{
|
||||
specified = MB_FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
//Retrieve the name of the attribute from the nodeName data member
|
||||
//
|
||||
const DOMString& Attr::getName() const
|
||||
{
|
||||
return nodeName;
|
||||
}
|
||||
|
||||
//
|
||||
//Retrieve the specified flag
|
||||
//
|
||||
MBool Attr::getSpecified() const
|
||||
{
|
||||
return specified;
|
||||
}
|
||||
|
||||
//
|
||||
//Retrieve the value of the attribute. This is a comma-deliminated string
|
||||
//representation of the Attribute's children.
|
||||
//
|
||||
const DOMString& Attr::getValue()
|
||||
{
|
||||
Int32 valueLoop;
|
||||
nodeValue = NULL_STRING;
|
||||
NodeList* childList = getChildNodes();
|
||||
Int32 numChildren = childList->getLength();
|
||||
|
||||
for (valueLoop=0;valueLoop<numChildren;valueLoop++)
|
||||
{
|
||||
if (childList->item(valueLoop)->getNodeType() != Node::ENTITY_REFERENCE_NODE)
|
||||
{
|
||||
nodeValue.append(childList->item(valueLoop)->getNodeValue());
|
||||
if (valueLoop < (numChildren-1))
|
||||
nodeValue.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
return nodeValue;
|
||||
}
|
||||
|
||||
//
|
||||
//Create a new Text node and add it to the Attribute's list of children. Also
|
||||
//set the Specified flag to true.
|
||||
//
|
||||
void Attr::setValue(const DOMString& newValue)
|
||||
{
|
||||
NodeDefinition::DeleteChildren();
|
||||
|
||||
appendChild(getOwnerDocument()->createTextNode(newValue));
|
||||
|
||||
specified = MB_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//Override the set node value member function to create a new TEXT node with
|
||||
//the DOMString and to add it as the Attribute's child.
|
||||
// NOTE: Not currently impemented, just execute the default setNodeValue
|
||||
//
|
||||
void Attr::setNodeValue(const DOMString& nodeValue)
|
||||
{
|
||||
setValue(nodeValue);
|
||||
}
|
||||
|
||||
//
|
||||
//Return a DOMString represening the value of this node. If the value is an
|
||||
//Entity Reference then return the value of the reference. Otherwise, it is a
|
||||
//simple conversion of the text value.
|
||||
// NOTE: Not currently implemented, just execute the default getNodeValue
|
||||
//
|
||||
const DOMString& Attr::getNodeValue()
|
||||
{
|
||||
return getValue();
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//First check to see if the new node is an allowable child for an Attr. If it
|
||||
//is, call NodeDefinition's implementation of Insert Before. If not, return
|
||||
//null as an error.
|
||||
//
|
||||
Node* Attr::insertBefore(Node* newChild, Node* refChild)
|
||||
{
|
||||
Node* returnVal = NULL;
|
||||
|
||||
switch (newChild->getNodeType())
|
||||
{
|
||||
case Node::TEXT_NODE :
|
||||
case Node::ENTITY_REFERENCE_NODE:
|
||||
returnVal = NodeDefinition::insertBefore(newChild, refChild);
|
||||
|
||||
if (returnVal)
|
||||
specified = MB_TRUE;
|
||||
break;
|
||||
default:
|
||||
returnVal = NULL;
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
// Tom Kneeland (3/29/99)
|
||||
//
|
||||
// Implementation of the Document Object Model Level 1 Core
|
||||
// Implementation of the CDATASection class
|
||||
//
|
||||
// Modification History:
|
||||
// Who When What
|
||||
// TK 03/29/99 Created
|
||||
//
|
||||
|
||||
#include "dom.h"
|
||||
|
||||
//
|
||||
//Construct a text object with the specified document owner and data
|
||||
//
|
||||
CDATASection::CDATASection(const DOMString& theData, Document* owner) :
|
||||
Text(Node::CDATA_SECTION_NODE, "#cdata-section", theData, owner)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
//CDATASection nodes can not have any children, so just return null from all child
|
||||
//manipulation functions.
|
||||
//
|
||||
|
||||
Node* CDATASection::insertBefore(Node* newChild, Node* refChild)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Node* CDATASection::replaceChild(Node* newChild, Node* oldChild)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Node* CDATASection::removeChild(Node* oldChild)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Node* CDATASection::appendChild(Node* newChild)
|
||||
{
|
||||
return NULL;
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
// Tom Kneeland (3/29/99)
|
||||
//
|
||||
// Implementation of the Document Object Model Level 1 Core
|
||||
// Implementation of the CharacterData class
|
||||
//
|
||||
// Modification History:
|
||||
// Who When What
|
||||
// TK 03/29/99 Created
|
||||
//
|
||||
|
||||
#include "dom.h"
|
||||
|
||||
//
|
||||
//Protected constructor. Just pass parameters onto NodeDefinition.
|
||||
//
|
||||
CharacterData::CharacterData(NodeType type, const DOMString& name,
|
||||
const DOMString& value, Document* owner) :
|
||||
NodeDefinition(type, name, value, owner)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
//Return a constant reference to the data stored by this object.
|
||||
//
|
||||
const DOMString& CharacterData::getData() const
|
||||
{
|
||||
return nodeValue;
|
||||
}
|
||||
|
||||
//
|
||||
//Set the data stored by this object to the string represented by "source".
|
||||
//
|
||||
void CharacterData::setData(const DOMString& source)
|
||||
{
|
||||
nodeValue = source;
|
||||
}
|
||||
|
||||
//
|
||||
//Returns the length of the data object.
|
||||
//
|
||||
Int32 CharacterData::getLength() const
|
||||
{
|
||||
return nodeValue.length();
|
||||
}
|
||||
|
||||
//
|
||||
//Retreive the substring starting at offset anc ending count number of
|
||||
//characters away.
|
||||
// NOTE: An empty string will be returned in the event of an error.
|
||||
//
|
||||
DOMString& CharacterData::substringData(Int32 offset, Int32 count, DOMString& dest)
|
||||
{
|
||||
if ((offset >= 0) && (offset < nodeValue.length()) && (count > 0))
|
||||
return nodeValue.subString(offset, offset+count, dest);
|
||||
else
|
||||
{
|
||||
dest.clear();
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
void CharacterData::appendData(const DOMString& arg)
|
||||
{
|
||||
nodeValue.append(arg);
|
||||
}
|
||||
|
||||
void CharacterData::insertData(Int32 offset, const DOMString& arg)
|
||||
{
|
||||
if ((offset >= 0) && (offset < nodeValue.length()))
|
||||
nodeValue.insert(offset, arg);
|
||||
}
|
||||
|
||||
void CharacterData::deleteData(Int32 offset, Int32 count)
|
||||
{
|
||||
if ((offset >= 0) && (offset < nodeValue.length()) && (count > 0))
|
||||
nodeValue.deleteChars(offset, count);
|
||||
}
|
||||
|
||||
void CharacterData::replaceData(Int32 offset, Int32 count, const DOMString& arg)
|
||||
{
|
||||
DOMString tempString;
|
||||
|
||||
if ((offset >= 0) && (offset < nodeValue.length()) && (count > 0))
|
||||
{
|
||||
if (count < arg.length())
|
||||
{
|
||||
tempString = arg.subString(0, count, tempString);
|
||||
nodeValue.replace(offset, tempString);
|
||||
}
|
||||
else
|
||||
nodeValue.replace(offset, arg);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
// Tom Kneeland (3/29/99)
|
||||
//
|
||||
// Implementation of the Document Object Model Level 1 Core
|
||||
// Implementation of the Comment class
|
||||
//
|
||||
// Modification History:
|
||||
// Who When What
|
||||
// TK 03/29/99 Created
|
||||
//
|
||||
|
||||
#include "dom.h"
|
||||
|
||||
//
|
||||
//Construct a text object with the specified document owner and data
|
||||
//
|
||||
Comment::Comment(const DOMString& theData, Document* owner) :
|
||||
CharacterData(Node::COMMENT_NODE, "#comment", theData, owner)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
//Comment nodes can not have any children, so just return null from all child
|
||||
//manipulation functions.
|
||||
//
|
||||
|
||||
Node* Comment::insertBefore(Node* newChild, Node* refChild)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Node* Comment::replaceChild(Node* newChild, Node* oldChild)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Node* Comment::removeChild(Node* oldChild)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Node* Comment::appendChild(Node* newChild)
|
||||
{
|
||||
return NULL;
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
// Tom Kneeland (3/29/99)
|
||||
//
|
||||
// Implementation of the Document Object Model Level 1 Core
|
||||
// Implementation of the DOMImplementation class
|
||||
//
|
||||
// Modification History:
|
||||
// Who When What
|
||||
// TK 03/29/99 Created
|
||||
//
|
||||
|
||||
#include "dom.h"
|
||||
|
||||
DOMImplementation::DOMImplementation()
|
||||
{
|
||||
implFeature = "XML";
|
||||
implVersion = "1.0";
|
||||
}
|
||||
|
||||
DOMImplementation::~DOMImplementation()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
//Perform a case insensitive comparison between "feature" and the
|
||||
//functionality of this DOM implementation/version.
|
||||
//
|
||||
MBool DOMImplementation::hasFeature(DOMString feature,
|
||||
const DOMString& version) const
|
||||
{
|
||||
feature.toUpperCase();
|
||||
|
||||
if (feature.isEqual(implFeature) && version.isEqual(implVersion))
|
||||
return MB_TRUE;
|
||||
else
|
||||
return MB_FALSE;
|
||||
}
|
|
@ -0,0 +1,258 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
// Tom Kneeland (3/29/99)
|
||||
//
|
||||
// Implementation of the Document Object Model Level 1 Core
|
||||
// Implementation of the Document class
|
||||
//
|
||||
// Modification History:
|
||||
// Who When What
|
||||
// TK 03/29/99 Created
|
||||
// LF 08/06/1999 Removed Default argument initializer from
|
||||
// Document() constructor
|
||||
// LF 08/06/1999 fixed typo: defalut to default
|
||||
//
|
||||
|
||||
#include "dom.h"
|
||||
|
||||
//
|
||||
//Construct a Document. Currently no parameters are required, but the the
|
||||
//node constructor is called to identify the node type.
|
||||
//
|
||||
Document::Document(DocumentType* theDoctype) :
|
||||
NodeDefinition(Node::DOCUMENT_NODE, "#document", NULL_STRING, NULL)
|
||||
{
|
||||
documentElement = NULL;
|
||||
doctype = theDoctype;
|
||||
}
|
||||
|
||||
//
|
||||
//Return the one and only element for this document
|
||||
//
|
||||
Element* Document::getDocumentElement()
|
||||
{
|
||||
return documentElement;
|
||||
}
|
||||
|
||||
//
|
||||
//Return the document type of this document object
|
||||
//
|
||||
DocumentType* Document::getDoctype()
|
||||
{
|
||||
return doctype;
|
||||
}
|
||||
|
||||
//
|
||||
//Return a constant reference to the DOM's Implementation
|
||||
//
|
||||
const DOMImplementation& Document::getImplementation()
|
||||
{
|
||||
return implementation;
|
||||
}
|
||||
|
||||
//
|
||||
//Ensure that no Element node is inserted if the document already has an
|
||||
//associated Element child.
|
||||
//
|
||||
Node* Document::insertBefore(Node* newChild, Node* refChild)
|
||||
{
|
||||
Node* returnVal = NULL;
|
||||
|
||||
NodeDefinition* pCurrentNode = NULL;
|
||||
NodeDefinition* pNextNode = NULL;
|
||||
|
||||
//Convert to a NodeDefinition Pointer
|
||||
NodeDefinition* pNewChild = (NodeDefinition*)newChild;
|
||||
NodeDefinition* pRefChild = (NodeDefinition*)refChild;
|
||||
|
||||
//Check to see if the reference node is a child of this node
|
||||
if ((refChild != NULL) && (pRefChild->getParentNode() != this))
|
||||
return NULL;
|
||||
|
||||
switch (pNewChild->getNodeType())
|
||||
{
|
||||
case Node::DOCUMENT_FRAGMENT_NODE :
|
||||
pCurrentNode = (NodeDefinition*)pNewChild->getFirstChild();
|
||||
while (pCurrentNode)
|
||||
{
|
||||
pNextNode = (NodeDefinition*)pCurrentNode->getNextSibling();
|
||||
|
||||
//Make sure that if the current node is an Element, the document
|
||||
//doesn't already have one.
|
||||
if ((pCurrentNode->getNodeType() != Node::ELEMENT_NODE) ||
|
||||
((pCurrentNode->getNodeType() == Node::ELEMENT_NODE) &&
|
||||
(documentElement == NULL)))
|
||||
{
|
||||
pCurrentNode = (NodeDefinition*)pNewChild->removeChild(pCurrentNode);
|
||||
implInsertBefore(pCurrentNode, pRefChild);
|
||||
|
||||
if (pCurrentNode->getNodeType() == Node::ELEMENT_NODE)
|
||||
documentElement = (Element*)pCurrentNode;
|
||||
}
|
||||
pCurrentNode = pNextNode;
|
||||
}
|
||||
returnVal = newChild;
|
||||
break;
|
||||
|
||||
case Node::PROCESSING_INSTRUCTION_NODE :
|
||||
case Node::COMMENT_NODE :
|
||||
case Node::DOCUMENT_TYPE_NODE :
|
||||
returnVal = implInsertBefore(pNewChild, pRefChild);
|
||||
break;
|
||||
|
||||
case Node::ELEMENT_NODE :
|
||||
if (!documentElement)
|
||||
{
|
||||
documentElement = (Element*)pNewChild;
|
||||
returnVal = implInsertBefore(pNewChild, pRefChild);
|
||||
}
|
||||
else
|
||||
returnVal = NULL;
|
||||
break;
|
||||
default:
|
||||
returnVal = NULL;
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
//
|
||||
//Ensure that if the newChild is an Element and the Document already has an
|
||||
//element, then oldChild should be specifying the existing element. If not
|
||||
//then the replacement can not take place.
|
||||
//
|
||||
Node* Document::replaceChild(Node* newChild, Node* oldChild)
|
||||
{
|
||||
Node* replacedChild = NULL;
|
||||
|
||||
if (newChild->getNodeType() != Node::ELEMENT_NODE)
|
||||
{
|
||||
//The new child is not an Element, so perform replacement
|
||||
replacedChild = NodeDefinition::replaceChild(newChild, oldChild);
|
||||
|
||||
//If old node was an Element, then the document's element has been
|
||||
//replaced with a non-element node. Therefore clear the documentElement
|
||||
//pointer
|
||||
if (replacedChild && (oldChild->getNodeType() == Node::ELEMENT_NODE))
|
||||
documentElement = NULL;
|
||||
|
||||
return replacedChild;
|
||||
}
|
||||
else
|
||||
{
|
||||
//A node is being replaced with an Element. If the document does not
|
||||
//have an elemet yet, then just allow the replacemetn to take place.
|
||||
if (!documentElement)
|
||||
replacedChild = NodeDefinition::replaceChild(newChild, oldChild);
|
||||
else if (oldChild->getNodeType() == Node::ELEMENT_NODE)
|
||||
replacedChild = NodeDefinition::replaceChild(newChild, oldChild);
|
||||
|
||||
if (replacedChild)
|
||||
documentElement = (Element*)newChild;
|
||||
|
||||
return replacedChild;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//Update the documentElement pointer if the associated Element node is being
|
||||
//removed.
|
||||
//
|
||||
Node* Document::removeChild(Node* oldChild)
|
||||
{
|
||||
Node* removedChild = NULL;
|
||||
|
||||
removedChild = NodeDefinition::removeChild(oldChild);
|
||||
|
||||
if (removedChild && (removedChild->getNodeType() == Node::ELEMENT_NODE))
|
||||
documentElement = NULL;
|
||||
|
||||
return removedChild;
|
||||
}
|
||||
|
||||
//
|
||||
//Construct an empty document fragment.
|
||||
// NOTE: The caller is responsible for cleaning up this fragment's memory
|
||||
// when it is no longer needed.
|
||||
//
|
||||
DocumentFragment* Document::createDocumentFragment()
|
||||
{
|
||||
return new DocumentFragment("#document-fragment", NULL_STRING, this);
|
||||
}
|
||||
|
||||
//
|
||||
//Construct an element with the specified tag name.
|
||||
// NOTE: The caller is responsible for cleaning up the element's menory
|
||||
//
|
||||
Element* Document::createElement(const DOMString& tagName)
|
||||
{
|
||||
return new Element(tagName, this);
|
||||
}
|
||||
|
||||
//
|
||||
//Construct an attribute with the specified name
|
||||
//
|
||||
Attr* Document::createAttribute(const DOMString& name)
|
||||
{
|
||||
return new Attr(name, this);
|
||||
}
|
||||
|
||||
//
|
||||
//Construct a text node with the given data
|
||||
//
|
||||
Text* Document::createTextNode(const DOMString& theData)
|
||||
{
|
||||
return new Text(theData, this);
|
||||
}
|
||||
|
||||
//
|
||||
//Construct a comment node with the given data
|
||||
//
|
||||
Comment* Document::createComment(const DOMString& theData)
|
||||
{
|
||||
return new Comment(theData, this);
|
||||
}
|
||||
|
||||
//
|
||||
//Construct a CDATASection node with the given data
|
||||
//
|
||||
CDATASection* Document::createCDATASection(const DOMString& theData)
|
||||
{
|
||||
return new CDATASection(theData, this);
|
||||
}
|
||||
|
||||
//
|
||||
//Construct a ProcessingInstruction node with the given targe and data.
|
||||
//
|
||||
ProcessingInstruction*
|
||||
Document::createProcessingInstruction(const DOMString& target,
|
||||
const DOMString& data)
|
||||
{
|
||||
return new ProcessingInstruction(target, data, this);
|
||||
}
|
||||
|
||||
//
|
||||
//Construct an EntityReference with the given name
|
||||
//
|
||||
EntityReference* Document::createEntityReference(const DOMString& name)
|
||||
{
|
||||
return new EntityReference(name, this);
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
// Tom Kneeland (3/29/99)
|
||||
//
|
||||
// Implementation of the Document Object Model Level 1 Core
|
||||
// Implementation of the DocumentFragment class
|
||||
//
|
||||
// Modification History:
|
||||
// Who When What
|
||||
// TK 03/29/99 Created
|
||||
// LF 08/06/1999 fixed typo: defalut to default
|
||||
//
|
||||
|
||||
#include "dom.h"
|
||||
|
||||
//
|
||||
//Construct a DocumentFragment with the specified name and value. Call the
|
||||
//constructor for NodeDefinition and specify the DocumentFragment Type.
|
||||
//
|
||||
DocumentFragment::DocumentFragment(const DOMString& name,
|
||||
const DOMString& value, Document* owner) :
|
||||
NodeDefinition(Node::DOCUMENT_FRAGMENT_NODE, name, value, owner)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
//First check to see if the new node is an allowable child for a
|
||||
//DocumentFragment. If it is, call NodeDefinition's implementation of Insert
|
||||
//Before. If not, return null as an error.
|
||||
//
|
||||
Node* DocumentFragment::insertBefore(Node* newChild, Node* refChild)
|
||||
{
|
||||
Node* returnVal = NULL;
|
||||
|
||||
switch (newChild->getNodeType())
|
||||
{
|
||||
case Node::ELEMENT_NODE :
|
||||
case Node::PROCESSING_INSTRUCTION_NODE :
|
||||
case Node::COMMENT_NODE :
|
||||
case Node::TEXT_NODE :
|
||||
case Node::CDATA_SECTION_NODE :
|
||||
case Node::ENTITY_REFERENCE_NODE:
|
||||
returnVal = NodeDefinition::insertBefore(newChild, refChild);
|
||||
break;
|
||||
default:
|
||||
returnVal = NULL;
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
// Tom Kneeland (3/29/99)
|
||||
//
|
||||
// Implementation of the Document Object Model Level 1 Core
|
||||
// Implementation of the DocumentType class
|
||||
//
|
||||
// Modification History:
|
||||
// Who When What
|
||||
// TK 03/29/99 Created
|
||||
//
|
||||
|
||||
#include "dom.h"
|
||||
|
||||
//
|
||||
//Construct a text object with the specified document owner and data
|
||||
//
|
||||
DocumentType::DocumentType(const DOMString& name, NamedNodeMap* theEntities,
|
||||
NamedNodeMap* theNotations) :
|
||||
NodeDefinition(Node::DOCUMENT_TYPE_NODE, name, NULL_STRING, NULL)
|
||||
{
|
||||
entities = theEntities;
|
||||
notations = theNotations;
|
||||
}
|
||||
|
||||
//
|
||||
//When destroying the DocumentType, the entities and notations must be
|
||||
//destroyed too.
|
||||
//
|
||||
DocumentType::~DocumentType()
|
||||
{
|
||||
if (entities)
|
||||
delete entities;
|
||||
|
||||
if (notations)
|
||||
delete notations;
|
||||
}
|
||||
|
||||
//
|
||||
//Return a pointer to the entities contained in this Document Type
|
||||
//
|
||||
NamedNodeMap* DocumentType::getEntities()
|
||||
{
|
||||
return entities;
|
||||
}
|
||||
|
||||
//
|
||||
//Return a pointer to the notations contained in this Document Type
|
||||
//
|
||||
NamedNodeMap* DocumentType::getNotations()
|
||||
{
|
||||
return notations;
|
||||
}
|
||||
|
||||
//
|
||||
//Comment nodes can not have any children, so just return null from all child
|
||||
//manipulation functions.
|
||||
//
|
||||
|
||||
Node* DocumentType::insertBefore(Node* newChild, Node* refChild)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Node* DocumentType::replaceChild(Node* newChild, Node* oldChild)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Node* DocumentType::removeChild(Node* oldChild)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Node* DocumentType::appendChild(Node* newChild)
|
||||
{
|
||||
return NULL;
|
||||
}
|
|
@ -0,0 +1,161 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
// Tom Kneeland (3/29/99)
|
||||
//
|
||||
// Implementation of the Document Object Model Level 1 Core
|
||||
// Implementation of the Element class
|
||||
//
|
||||
// Modification History:
|
||||
// Who When What
|
||||
// TK 03/29/99 Created
|
||||
// LF 08/06/1999 fixed typo: defalut to default
|
||||
//
|
||||
|
||||
#include "dom.h"
|
||||
|
||||
//
|
||||
//Construct a new element with the specified tagName and Document owner.
|
||||
//Simply call the constructor for NodeDefinition, and specify the proper node
|
||||
//type.
|
||||
//
|
||||
Element::Element(const DOMString& tagName, Document* owner) :
|
||||
NodeDefinition(Node::ELEMENT_NODE, tagName, NULL_STRING, owner)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
//First check to see if the new node is an allowable child for an Element. If
|
||||
//it is, call NodeDefinition's implementation of Insert Before. If not, return
|
||||
//null as an error
|
||||
//
|
||||
Node* Element::insertBefore(Node* newChild, Node* refChild)
|
||||
{
|
||||
Node* returnVal = NULL;
|
||||
|
||||
switch (newChild->getNodeType())
|
||||
{
|
||||
case Node::ELEMENT_NODE :
|
||||
case Node::TEXT_NODE :
|
||||
case Node::COMMENT_NODE :
|
||||
case Node::PROCESSING_INSTRUCTION_NODE :
|
||||
case Node::CDATA_SECTION_NODE :
|
||||
case Node::ENTITY_REFERENCE_NODE:
|
||||
returnVal = NodeDefinition::insertBefore(newChild, refChild);
|
||||
break;
|
||||
default:
|
||||
returnVal = NULL;
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
//
|
||||
//Return the tagName for this element. This is simply the nodeName.
|
||||
//
|
||||
const DOMString& Element::getTagName()
|
||||
{
|
||||
return nodeName;
|
||||
}
|
||||
|
||||
//
|
||||
//Retreive an attribute's value by name. If the attribute does not exist,
|
||||
//return a reference to the pre-created, constatnt "NULL STRING".
|
||||
//
|
||||
const DOMString& Element::getAttribute(const DOMString& name)
|
||||
{
|
||||
Node* tempNode = attributes.getNamedItem(name);
|
||||
|
||||
if (tempNode)
|
||||
return attributes.getNamedItem(name)->getNodeValue();
|
||||
else
|
||||
return NULL_STRING;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//Add an attribute to this Element. Create a new Attr object using the
|
||||
//name and value specified. Then add the Attr to the the Element's
|
||||
//attributes NamedNodeMap.
|
||||
//
|
||||
void Element::setAttribute(const DOMString& name, const DOMString& value)
|
||||
{
|
||||
Attr* tempAttribute;
|
||||
|
||||
//Check to see if an attribute with this name already exists. If it does
|
||||
//over write its value, if not, add it.
|
||||
tempAttribute = getAttributeNode(name);
|
||||
if (tempAttribute)
|
||||
tempAttribute->setNodeValue(value);
|
||||
else
|
||||
{
|
||||
tempAttribute = getOwnerDocument()->createAttribute(name);
|
||||
tempAttribute->setNodeValue(value);
|
||||
attributes.setNamedItem(tempAttribute);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//Remove an attribute from the attributes NamedNodeMap, and free its memory.
|
||||
// NOTE: How do default values enter into this picture
|
||||
//
|
||||
void Element::removeAttribute(const DOMString& name)
|
||||
{
|
||||
delete attributes.removeNamedItem(name);
|
||||
}
|
||||
|
||||
//
|
||||
//Return the attribute specified by name
|
||||
//
|
||||
Attr* Element::getAttributeNode(const DOMString& name)
|
||||
{
|
||||
return (Attr*)attributes.getNamedItem(name);
|
||||
}
|
||||
|
||||
//
|
||||
//Set a new attribute specifed by the newAttr node. If an attribute with that
|
||||
//name already exists, the existing Attr is removed from the list and return to
|
||||
//the caller, else NULL is returned.
|
||||
//
|
||||
Attr* Element::setAttributeNode(Attr* newAttr)
|
||||
{
|
||||
Attr* pOldAttr = (Attr*)attributes.removeNamedItem(newAttr->getNodeName());
|
||||
|
||||
attributes.setNamedItem(newAttr);
|
||||
return pOldAttr;
|
||||
}
|
||||
|
||||
//
|
||||
//Remove the Attribute from the attributes list and return to the caller. If
|
||||
//the node is not found, return NULL.
|
||||
//
|
||||
Attr* Element::removeAttributeNode(Attr* oldAttr)
|
||||
{
|
||||
return (Attr*)attributes.removeNamedItem(oldAttr->getNodeName());
|
||||
}
|
||||
|
||||
NodeList* Element::getElementsByTagName(const DOMString& name)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Element::normalize()
|
||||
{
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
// Tom Kneeland (3/29/99)
|
||||
//
|
||||
// Implementation of the Document Object Model Level 1 Core
|
||||
// Implementation of the Entity class
|
||||
//
|
||||
// Modification History:
|
||||
// Who When What
|
||||
// TK 03/29/99 Created
|
||||
// LF 08/06/1999 fixed typo: defalut to default
|
||||
|
||||
//
|
||||
|
||||
#include "dom.h"
|
||||
|
||||
//
|
||||
//Construct a text object with the specified document owner and data
|
||||
//
|
||||
Entity::Entity(const DOMString& name, const DOMString& pubID,
|
||||
const DOMString& sysID, const DOMString& notName) :
|
||||
NodeDefinition(Node::ENTITY_NODE, name, NULL_STRING, NULL)
|
||||
{
|
||||
publicId = pubID;
|
||||
systemId = sysID;
|
||||
notationName = notName;
|
||||
}
|
||||
|
||||
//
|
||||
//Return the Public ID of the Entity
|
||||
//
|
||||
const DOMString& Entity::getPublicId() const
|
||||
{
|
||||
return publicId;
|
||||
}
|
||||
|
||||
//
|
||||
//Return the System ID of the Entity
|
||||
//
|
||||
const DOMString& Entity::getSystemId() const
|
||||
{
|
||||
return systemId;
|
||||
}
|
||||
|
||||
//
|
||||
//Return the Notation Name of the Entity
|
||||
//
|
||||
const DOMString& Entity::getNotationName() const
|
||||
{
|
||||
return notationName;
|
||||
}
|
||||
|
||||
//
|
||||
//First check to see if the new node is an allowable child for an Entity. If
|
||||
//it is, call NodeDefinition's implementation of Insert Before. If not, return
|
||||
//null as an error.
|
||||
//
|
||||
Node* Entity::insertBefore(Node* newChild, Node* refChild)
|
||||
{
|
||||
Node* returnVal = NULL;
|
||||
|
||||
switch (newChild->getNodeType())
|
||||
{
|
||||
case Node::ELEMENT_NODE:
|
||||
case Node::PROCESSING_INSTRUCTION_NODE:
|
||||
case Node::COMMENT_NODE:
|
||||
case Node::TEXT_NODE :
|
||||
case Node::CDATA_SECTION_NODE:
|
||||
case Node::ENTITY_REFERENCE_NODE:
|
||||
returnVal = NodeDefinition::insertBefore(newChild, refChild);
|
||||
break;
|
||||
default:
|
||||
returnVal = NULL;
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
// Tom Kneeland (3/29/99)
|
||||
//
|
||||
// Implementation of the Document Object Model Level 1 Core
|
||||
// Implementation of the EntityReference class
|
||||
//
|
||||
// Modification History:
|
||||
// Who When What
|
||||
// TK 03/29/99 Created
|
||||
// LF 08/06/1999 fixed typo: defalut to default
|
||||
//
|
||||
|
||||
#include "dom.h"
|
||||
|
||||
//
|
||||
//Construct a text object with the specified document owner and data
|
||||
//
|
||||
EntityReference::EntityReference(const DOMString& name, Document* owner) :
|
||||
NodeDefinition(Node::ENTITY_REFERENCE_NODE, name, NULL_STRING, owner)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
//First check to see if the new node is an allowable child for an
|
||||
//EntityReference. If it is, call NodeDefinition's implementation of Insert
|
||||
//Before. If not, return null as an error.
|
||||
//
|
||||
Node* EntityReference::insertBefore(Node* newChild, Node* refChild)
|
||||
{
|
||||
Node* returnVal = NULL;
|
||||
|
||||
switch (newChild->getNodeType())
|
||||
{
|
||||
case Node::ELEMENT_NODE:
|
||||
case Node::PROCESSING_INSTRUCTION_NODE:
|
||||
case Node::COMMENT_NODE:
|
||||
case Node::TEXT_NODE :
|
||||
case Node::CDATA_SECTION_NODE:
|
||||
case Node::ENTITY_REFERENCE_NODE:
|
||||
returnVal = NodeDefinition::insertBefore(newChild, refChild);
|
||||
break;
|
||||
default:
|
||||
returnVal = NULL;
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
|
||||
#ifndef PROJ_PATH
|
||||
BASE_PATH = ../../base
|
||||
DOM_PATH = .
|
||||
#endif
|
||||
|
||||
INCLUDE_PATHS = -I$(BASE_PATH) -I . -I-
|
||||
|
||||
|
||||
CC = g++ $(INCLUDE_PATHS)
|
||||
|
||||
DOM_OBJS = NodeDefinition.o \
|
||||
Document.o \
|
||||
DocumentFragment.o \
|
||||
NamedNodeMap.o \
|
||||
NodeListDefinition.o \
|
||||
Element.o \
|
||||
Attr.o \
|
||||
CharacterData.o \
|
||||
Text.o \
|
||||
Comment.o \
|
||||
CDATASection.o \
|
||||
ProcessingInstruction.o \
|
||||
Notation.o \
|
||||
Entity.o \
|
||||
EntityReference.o \
|
||||
DocumentType.o \
|
||||
DOMImplementation.o
|
||||
|
||||
target: $(DOM_OBJS)
|
||||
|
||||
NodeDefinition.o: NodeDefinition.cpp dom.h
|
||||
$(CC) -c NodeDefinition.cpp
|
||||
|
||||
Document.o: Document.cpp dom.h
|
||||
$(CC) -c Document.cpp
|
||||
|
||||
DocumentFragment.o: DocumentFragment.cpp dom.h
|
||||
$(CC) -c DocumentFragment.cpp
|
||||
|
||||
NamedNodeMap.o: NamedNodeMap.cpp dom.h
|
||||
$(CC) -c NamedNodeMap.cpp
|
||||
|
||||
NodeListDefinition.o: NodeListDefinition.cpp dom.h
|
||||
$(CC) -c NodeListDefinition.cpp
|
||||
|
||||
Element.o: Element.cpp dom.h
|
||||
$(CC) -c Element.cpp
|
||||
|
||||
Attr.o: Attr.cpp dom.h
|
||||
$(CC) -c Attr.cpp
|
||||
|
||||
CharacterData.o: CharacterData.cpp dom.h
|
||||
$(CC) -c CharacterData.cpp
|
||||
|
||||
Text.o: Text.cpp dom.h
|
||||
$(CC) -c Text.cpp
|
||||
|
||||
Comment.o: Comment.cpp dom.h
|
||||
$(CC) -c Comment.cpp
|
||||
|
||||
CDATASection.o: CDATASection.cpp dom.h
|
||||
$(CC) -c CDATASection.cpp
|
||||
|
||||
ProcessingInstruction.o: ProcessingInstruction.cpp dom.h
|
||||
$(CC) -c ProcessingInstruction.cpp
|
||||
|
||||
Notation.o: Notation.cpp dom.h
|
||||
$(CC) -c Notation.cpp
|
||||
|
||||
Entity.o: Entity.cpp dom.h
|
||||
$(CC) -c Entity.cpp
|
||||
|
||||
EntityReference.o: EntityReference.cpp dom.h
|
||||
$(CC) -c EntityReference.cpp
|
||||
|
||||
DocumentType.o: DocumentType.cpp dom.h
|
||||
$(CC) -c DocumentType.cpp
|
||||
|
||||
DOMImplementation.o: DOMImplementation.cpp dom.h
|
||||
$(CC) -c DOMImplementation.cpp
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
// Tom Kneeland (3/29/99)
|
||||
//
|
||||
// Implementation of the Document Object Model Level 1 Core
|
||||
// Implementation of the NamedNodeMap class
|
||||
//
|
||||
// Modification History:
|
||||
// Who When What
|
||||
// TK 03/29/99 Created
|
||||
//
|
||||
|
||||
#include "dom.h"
|
||||
|
||||
NamedNodeMap::NamedNodeMap()
|
||||
{
|
||||
}
|
||||
|
||||
NamedNodeMap::~NamedNodeMap()
|
||||
{
|
||||
}
|
||||
|
||||
Node* NamedNodeMap::getNamedItem(const DOMString& name)
|
||||
{
|
||||
ListItem* pSearchItem = findListItemByName(name);
|
||||
|
||||
if (pSearchItem)
|
||||
return pSearchItem->node;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Node* NamedNodeMap::setNamedItem(Node* arg)
|
||||
{
|
||||
//Since the DOM does not specify any ording for the NamedNodeMap, just
|
||||
//try and remove the new node (arg). If successful, return a pointer to
|
||||
//the removed item. Reguardless of wheter the node already existed or not,
|
||||
//insert the new node at the end of the list.
|
||||
Node* pReplacedNode = removeNamedItem(arg->getNodeName());
|
||||
|
||||
NodeListDefinition::append(arg);
|
||||
|
||||
return pReplacedNode;
|
||||
}
|
||||
|
||||
Node* NamedNodeMap::removeNamedItem(const DOMString& name)
|
||||
{
|
||||
NodeListDefinition::ListItem* pSearchItem;
|
||||
Node* returnNode;
|
||||
|
||||
pSearchItem = findListItemByName(name);
|
||||
|
||||
if (pSearchItem)
|
||||
{
|
||||
if (pSearchItem != firstItem)
|
||||
pSearchItem->prev->next = pSearchItem->next;
|
||||
else
|
||||
firstItem = pSearchItem->next;
|
||||
|
||||
if (pSearchItem != lastItem)
|
||||
pSearchItem->next->prev = pSearchItem->prev;
|
||||
else
|
||||
lastItem = pSearchItem->prev;
|
||||
|
||||
pSearchItem->next = NULL;
|
||||
pSearchItem->prev = NULL;
|
||||
|
||||
length--;
|
||||
returnNode = pSearchItem->node;
|
||||
delete pSearchItem;
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NodeListDefinition::ListItem*
|
||||
NamedNodeMap::findListItemByName(const DOMString& name)
|
||||
{
|
||||
NodeListDefinition::ListItem* pSearchItem = firstItem;
|
||||
|
||||
while (pSearchItem)
|
||||
{
|
||||
if (name.isEqual(pSearchItem->node->getNodeName()))
|
||||
return pSearchItem;
|
||||
|
||||
pSearchItem = pSearchItem->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
|
@ -0,0 +1,356 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
// Tom Kneeland (3/29/99)
|
||||
//
|
||||
// Implementation of the Document Object Model Level 1 Core
|
||||
// Implementation of the NodeDefinition Class
|
||||
//
|
||||
// Modification History:
|
||||
// Who When What
|
||||
// TK 03/29/99 Created
|
||||
//
|
||||
|
||||
#include "dom.h"
|
||||
|
||||
NodeDefinition::NodeDefinition(NodeType type, const DOMString& name,
|
||||
const DOMString& value, Document* owner)
|
||||
{
|
||||
|
||||
nodeName = name;
|
||||
nodeValue = value;
|
||||
nodeType = type;
|
||||
|
||||
parentNode = NULL;
|
||||
previousSibling = NULL;
|
||||
nextSibling = NULL;;
|
||||
firstChild = NULL;
|
||||
lastChild = NULL;
|
||||
|
||||
ownerDocument = owner;
|
||||
length = 0;
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// This node is being destroyed, so loop through and destroy all the children.
|
||||
// Also, destroy all attributes stored in the attributes NamedNodeMap.
|
||||
//
|
||||
NodeDefinition::~NodeDefinition()
|
||||
{
|
||||
Int32 numAttributes = attributes.getLength();
|
||||
Int32 killAttrLoop;
|
||||
|
||||
DeleteChildren();
|
||||
|
||||
for (killAttrLoop=0;killAttrLoop<numAttributes;killAttrLoop++)
|
||||
delete attributes.removeNamedItem(attributes.item(0)->getNodeName());
|
||||
}
|
||||
|
||||
//
|
||||
//Remove and delete all children of this node
|
||||
//
|
||||
void NodeDefinition::DeleteChildren()
|
||||
{
|
||||
NodeDefinition* pCurrent = firstChild;
|
||||
NodeDefinition* pDestroyer;
|
||||
|
||||
while (pCurrent)
|
||||
{
|
||||
pDestroyer = pCurrent;
|
||||
pCurrent = pCurrent->nextSibling;
|
||||
delete pDestroyer;
|
||||
}
|
||||
|
||||
length = 0;
|
||||
firstChild = NULL;
|
||||
lastChild = NULL;
|
||||
}
|
||||
|
||||
const DOMString& NodeDefinition::getNodeName() const
|
||||
{
|
||||
return nodeName;
|
||||
}
|
||||
|
||||
const DOMString& NodeDefinition::getNodeValue() const
|
||||
{
|
||||
return nodeValue;
|
||||
}
|
||||
|
||||
const DOMString& NodeDefinition::getNodeValue()
|
||||
{
|
||||
return nodeValue;
|
||||
}
|
||||
|
||||
unsigned short NodeDefinition::getNodeType() const
|
||||
{
|
||||
return nodeType;
|
||||
}
|
||||
|
||||
Node* NodeDefinition::getParentNode() const
|
||||
{
|
||||
return parentNode;
|
||||
}
|
||||
|
||||
NodeList* NodeDefinition::getChildNodes()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
Node* NodeDefinition::getFirstChild() const
|
||||
{
|
||||
return firstChild;
|
||||
}
|
||||
|
||||
Node* NodeDefinition::getLastChild() const
|
||||
{
|
||||
return lastChild;
|
||||
}
|
||||
|
||||
Node* NodeDefinition::getPreviousSibling() const
|
||||
{
|
||||
return previousSibling;
|
||||
}
|
||||
|
||||
Node* NodeDefinition::getNextSibling() const
|
||||
{
|
||||
return nextSibling;
|
||||
}
|
||||
|
||||
NamedNodeMap* NodeDefinition::getAttributes()
|
||||
{
|
||||
return &attributes;
|
||||
}
|
||||
|
||||
Document* NodeDefinition::getOwnerDocument() const
|
||||
{
|
||||
return ownerDocument;
|
||||
}
|
||||
|
||||
Node* NodeDefinition::item(Int32 index)
|
||||
{
|
||||
Int32 selectLoop;
|
||||
NodeDefinition* pSelectNode = firstChild;
|
||||
|
||||
if (index < length)
|
||||
{
|
||||
for (selectLoop=0;selectLoop<index;selectLoop++)
|
||||
pSelectNode = pSelectNode->nextSibling;
|
||||
|
||||
return pSelectNode;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Int32 NodeDefinition::getLength()
|
||||
{
|
||||
return length;
|
||||
}
|
||||
|
||||
void NodeDefinition::setNodeValue(const DOMString& newNodeValue)
|
||||
{
|
||||
nodeValue = newNodeValue;
|
||||
}
|
||||
|
||||
//
|
||||
//Insert the "newChild" node before the "refChild" node. Return a pointer to
|
||||
//the inserted child. If the node to insert is a document fragment, then
|
||||
//insert each child of the document fragment, and return the document fragment
|
||||
//which should be empty if all the inserts suceeded.
|
||||
//This function's responsibility is to check for and handle document fragments
|
||||
//vs. plain nodes.
|
||||
// *** NOTE: Need to check the document types before inserting.
|
||||
//
|
||||
// The decision to return the possibly empty document fragment
|
||||
// was an implementation choice. The spec did not dictate what
|
||||
// whould occur.
|
||||
//
|
||||
Node* NodeDefinition::insertBefore(Node* newChild,
|
||||
Node* refChild)
|
||||
{
|
||||
NodeDefinition* pCurrentNode = NULL;
|
||||
NodeDefinition* pNextNode = NULL;
|
||||
|
||||
//Convert to a NodeDefinition Pointer
|
||||
NodeDefinition* pNewChild = (NodeDefinition*)newChild;
|
||||
NodeDefinition* pRefChild = (NodeDefinition*)refChild;
|
||||
|
||||
//Check to see if the reference node is a child of this node
|
||||
if ((refChild != NULL) && (pRefChild->parentNode != this))
|
||||
return NULL;
|
||||
|
||||
if (pNewChild->getNodeType() == Node::DOCUMENT_FRAGMENT_NODE)
|
||||
{
|
||||
pCurrentNode = pNewChild->firstChild;
|
||||
while (pCurrentNode)
|
||||
{
|
||||
pNextNode = pCurrentNode->nextSibling;
|
||||
pCurrentNode = (NodeDefinition*)pNewChild->removeChild(pCurrentNode);
|
||||
implInsertBefore(pCurrentNode, pRefChild);
|
||||
pCurrentNode = pNextNode;
|
||||
}
|
||||
return newChild;
|
||||
}
|
||||
else
|
||||
return implInsertBefore(pNewChild, pRefChild);
|
||||
}
|
||||
|
||||
//
|
||||
//The code that actually insert one node before another.
|
||||
//
|
||||
Node* NodeDefinition::implInsertBefore(NodeDefinition* pNewChild,
|
||||
NodeDefinition* pRefChild)
|
||||
{
|
||||
//Remove the "newChild" if it is already a child of this node
|
||||
if (pNewChild->parentNode == this)
|
||||
pNewChild = (NodeDefinition*)removeChild(pNewChild);
|
||||
|
||||
//The new child should not be a child of any other node
|
||||
if ((pNewChild->previousSibling == NULL) &&
|
||||
(pNewChild->nextSibling == NULL) &&
|
||||
(pNewChild->parentNode == NULL))
|
||||
{
|
||||
if (pRefChild == NULL)
|
||||
{
|
||||
//Append
|
||||
pNewChild->previousSibling = lastChild;
|
||||
|
||||
if (lastChild)
|
||||
lastChild->nextSibling = pNewChild;
|
||||
|
||||
lastChild = pNewChild;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Insert before the reference node
|
||||
if (pRefChild->previousSibling)
|
||||
pRefChild->previousSibling->nextSibling = pNewChild;
|
||||
pNewChild->nextSibling = pRefChild;
|
||||
pNewChild->previousSibling = pRefChild->previousSibling;
|
||||
pRefChild->previousSibling = pNewChild;
|
||||
}
|
||||
|
||||
pNewChild->parentNode = this;
|
||||
|
||||
if (pNewChild->previousSibling == NULL)
|
||||
firstChild = pNewChild;
|
||||
|
||||
length++;
|
||||
|
||||
return pNewChild;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//Replace "oldChild" with "newChild". Return the replaced node, or NULL
|
||||
//otherwise.
|
||||
// *** NOTE: Need to check that the documents match ***
|
||||
//
|
||||
Node* NodeDefinition::replaceChild(Node* newChild,
|
||||
Node* oldChild)
|
||||
{
|
||||
NodeDefinition* pOldChild = (NodeDefinition*)oldChild;
|
||||
NodeDefinition* pNextSibling = NULL;
|
||||
|
||||
//If the newChild is replacing itself then we don't need to do anything
|
||||
if (pOldChild == newChild)
|
||||
return pOldChild;
|
||||
|
||||
//If "oldChild" is a child of this node, remove it from the list.
|
||||
pOldChild = (NodeDefinition*)removeChild(oldChild);
|
||||
|
||||
//If the removal was successful... Else, return null
|
||||
if (pOldChild)
|
||||
{
|
||||
//Try to insert the new node before the old node's next sibling. If
|
||||
//successful, just returned the replaced child. If not succesful,
|
||||
//reinsert the old node, and return NULL.
|
||||
pNextSibling = pOldChild->nextSibling;
|
||||
if (!insertBefore(newChild, pNextSibling))
|
||||
{
|
||||
insertBefore(pOldChild, pNextSibling);
|
||||
pOldChild = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return pOldChild;
|
||||
}
|
||||
|
||||
//
|
||||
//Remove the specified "oldChild" from this node's children. First make sure
|
||||
//the specified node is a child of this node. Return the removed node, NULL
|
||||
//otherwise.
|
||||
//
|
||||
Node* NodeDefinition::removeChild(Node* oldChild)
|
||||
{
|
||||
NodeDefinition* pOldChild = (NodeDefinition*)oldChild;
|
||||
|
||||
//If "oldChild" is a child of this node, adjust pointers to remove it, and
|
||||
//clear "oldChild"'s sibling and parent pointers.
|
||||
if (pOldChild->parentNode == this)
|
||||
{
|
||||
if (pOldChild != firstChild)
|
||||
pOldChild->previousSibling->nextSibling = pOldChild->nextSibling;
|
||||
else
|
||||
firstChild = pOldChild->nextSibling;
|
||||
|
||||
if (pOldChild != lastChild)
|
||||
pOldChild->nextSibling->previousSibling = pOldChild->previousSibling;
|
||||
else
|
||||
lastChild = pOldChild->previousSibling;
|
||||
|
||||
pOldChild->nextSibling = NULL;
|
||||
pOldChild->previousSibling = NULL;
|
||||
pOldChild->parentNode = NULL;
|
||||
|
||||
length--;
|
||||
|
||||
return pOldChild;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//
|
||||
//Append a new child node. First make sure the new child is not already a
|
||||
//child of another node. Return the appended node.
|
||||
// *** NOTE *** Need to eventually check to make sure the documents match ***
|
||||
//
|
||||
Node* NodeDefinition::appendChild(Node* newChild)
|
||||
{
|
||||
return insertBefore(newChild, NULL);
|
||||
}
|
||||
|
||||
Node* NodeDefinition::cloneNode(MBool deep, Node* dest)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
MBool NodeDefinition::hasChildNodes() const
|
||||
{
|
||||
if (firstChild != NULL)
|
||||
return MB_TRUE;
|
||||
else
|
||||
return MB_FALSE;
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
// Tom Kneeland (3/29/99)
|
||||
//
|
||||
// Implementation of the Document Object Model Level 1 Core
|
||||
// Implementation of the NodeListDefinition class
|
||||
//
|
||||
// Modification History:
|
||||
// Who When What
|
||||
// TK 03/29/99 Created
|
||||
//
|
||||
|
||||
#include "dom.h"
|
||||
|
||||
//
|
||||
//Create an empty node list.
|
||||
//
|
||||
NodeListDefinition::NodeListDefinition()
|
||||
{
|
||||
firstItem = NULL;
|
||||
lastItem = NULL;
|
||||
length = 0;
|
||||
}
|
||||
|
||||
//
|
||||
//Free up the memory used by the List of Items. Don't delete the actual nodes
|
||||
//though.
|
||||
//
|
||||
NodeListDefinition::~NodeListDefinition()
|
||||
{
|
||||
ListItem* pDeleteItem;
|
||||
ListItem* pListTraversal = firstItem;
|
||||
|
||||
while (pListTraversal)
|
||||
{
|
||||
pDeleteItem = pListTraversal;
|
||||
pListTraversal = pListTraversal->next;
|
||||
delete pDeleteItem;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//Create a new ListItem, point it to the newNode, and append it to the current
|
||||
//list of nodes.
|
||||
//
|
||||
void NodeListDefinition::append(Node* newNode)
|
||||
{
|
||||
append(*newNode);
|
||||
}
|
||||
|
||||
void NodeListDefinition::append(Node& newNode)
|
||||
{
|
||||
ListItem* newListItem = new ListItem;
|
||||
|
||||
// Setup the new list item
|
||||
newListItem->node = &newNode;
|
||||
newListItem->prev = lastItem;
|
||||
newListItem->next = NULL;
|
||||
|
||||
//Append the list item
|
||||
if (lastItem)
|
||||
lastItem->next = newListItem;
|
||||
|
||||
lastItem = newListItem;
|
||||
|
||||
//Adjust firstItem if this new item is being added to an empty list
|
||||
if (!firstItem)
|
||||
firstItem = lastItem;
|
||||
|
||||
//Need to increment the length of the list. Inherited from NodeList
|
||||
length++;
|
||||
}
|
||||
|
||||
//
|
||||
// Return the Node contained in the item specified
|
||||
//
|
||||
Node* NodeListDefinition::item(Int32 index)
|
||||
{
|
||||
Int32 selectLoop;
|
||||
ListItem* pListItem = firstItem;
|
||||
|
||||
if (index < length)
|
||||
{
|
||||
for (selectLoop=0;selectLoop<index;selectLoop++)
|
||||
pListItem = pListItem->next;
|
||||
|
||||
return pListItem->node;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// Return the number of items in the list
|
||||
//
|
||||
Int32 NodeListDefinition::getLength()
|
||||
{
|
||||
return length;
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
// Tom Kneeland (3/29/99)
|
||||
//
|
||||
// Implementation of the Document Object Model Level 1 Core
|
||||
// Implementation of the Notation class
|
||||
//
|
||||
// Modification History:
|
||||
// Who When What
|
||||
// TK 03/29/99 Created
|
||||
//
|
||||
|
||||
#include "dom.h"
|
||||
|
||||
//
|
||||
//Construct a text object with the specified document owner and data
|
||||
//
|
||||
Notation::Notation(const DOMString& name, const DOMString& pubID,
|
||||
const DOMString& sysID) :
|
||||
NodeDefinition(Node::NOTATION_NODE, name, NULL_STRING, NULL)
|
||||
{
|
||||
publicId = pubID;
|
||||
systemId = sysID;
|
||||
}
|
||||
|
||||
//
|
||||
//Return the Public ID of the Notation
|
||||
//
|
||||
const DOMString& Notation::getPublicId() const
|
||||
{
|
||||
return publicId;
|
||||
}
|
||||
|
||||
//Return the System ID of the Notation
|
||||
const DOMString& Notation::getSystemId() const
|
||||
{
|
||||
return systemId;
|
||||
}
|
||||
|
||||
//
|
||||
//Notation nodes can not have any children, so just return null from all child
|
||||
//manipulation functions.
|
||||
//
|
||||
|
||||
Node* Notation::insertBefore(Node* newChild, Node* refChild)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Node* Notation::replaceChild(Node* newChild, Node* oldChild)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Node* Notation::removeChild(Node* oldChild)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Node* Notation::appendChild(Node* newChild)
|
||||
{
|
||||
return NULL;
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
// Tom Kneeland (3/29/99)
|
||||
//
|
||||
// Implementation of the Document Object Model Level 1 Core
|
||||
// Implementation of the ProcessingInstruction class
|
||||
//
|
||||
// Modification History:
|
||||
// Who When What
|
||||
// TK 03/29/99 Created
|
||||
//
|
||||
|
||||
#include "dom.h"
|
||||
|
||||
//
|
||||
//Construct a text object with the specified document owner and data
|
||||
//
|
||||
ProcessingInstruction::ProcessingInstruction(const DOMString& theTarget,
|
||||
const DOMString& theData,
|
||||
Document* owner) :
|
||||
NodeDefinition(Node::PROCESSING_INSTRUCTION_NODE,
|
||||
theTarget, theData, owner)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
//Return the Target of the processing instruction. This is simply the
|
||||
//nodeName.
|
||||
//
|
||||
const DOMString& ProcessingInstruction::getTarget() const
|
||||
{
|
||||
return nodeName;
|
||||
}
|
||||
|
||||
//
|
||||
//Return the Data of the processing instruction. This is simply the value
|
||||
//of the node, "nodeValue"
|
||||
//
|
||||
const DOMString& ProcessingInstruction::getData() const
|
||||
{
|
||||
return nodeValue;
|
||||
}
|
||||
|
||||
//
|
||||
//Set the Data element of the processing instruction.
|
||||
void ProcessingInstruction::setData(const DOMString& theData)
|
||||
{
|
||||
nodeValue = theData;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//ProcessingInstruction nodes can not have any children, so just return null
|
||||
//from all child manipulation functions.
|
||||
//
|
||||
|
||||
Node* ProcessingInstruction::insertBefore(Node* newChild, Node* refChild)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Node* ProcessingInstruction::replaceChild(Node* newChild, Node* oldChild)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Node* ProcessingInstruction::removeChild(Node* oldChild)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Node* ProcessingInstruction::appendChild(Node* newChild)
|
||||
{
|
||||
return NULL;
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* The program provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*
|
||||
* Please see release.txt distributed with this file for more information.
|
||||
*
|
||||
*/
|
||||
// Tom Kneeland (3/29/99)
|
||||
//
|
||||
// Implementation of the Document Object Model Level 1 Core
|
||||
// Implementation of the Text class
|
||||
//
|
||||
// Modification History:
|
||||
// Who When What
|
||||
// TK 03/29/99 Created
|
||||
//
|
||||
|
||||
#include "dom.h"
|
||||
|
||||
//
|
||||
//Construct a text object with the specified document owner and data
|
||||
//
|
||||
Text::Text(const DOMString& theData, Document* owner) :
|
||||
CharacterData(Node::TEXT_NODE, "#text", theData, owner)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
//Protected constructor for children of the Text Class. Currently only
|
||||
//CDATASection needs to use this function.
|
||||
Text::Text(NodeType type, const DOMString& name, const DOMString& value,
|
||||
Document* owner) :
|
||||
CharacterData(type, name, value, owner)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//Split the text node at Offset into two siblings. Return a pointer to the new
|
||||
//sibling.
|
||||
//
|
||||
Text* Text::splitText(Int32 offset)
|
||||
{
|
||||
Text* newTextSibling = NULL;
|
||||
DOMString newData;
|
||||
|
||||
if ((offset >= 0) && (offset < nodeValue.length()))
|
||||
{
|
||||
newTextSibling = getOwnerDocument()->createTextNode(nodeValue.subString(offset, newData));
|
||||
getParentNode()->insertBefore(newTextSibling, getNextSibling());
|
||||
nodeValue.deleteChars(offset, nodeValue.length() - offset);
|
||||
}
|
||||
|
||||
return newTextSibling;
|
||||
}
|
||||
|
||||
//
|
||||
//Text nodes can not have any children, so just return null from all child
|
||||
//manipulation functions.
|
||||
//
|
||||
|
||||
Node* Text::insertBefore(Node* newChild, Node* refChild)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Node* Text::replaceChild(Node* newChild, Node* oldChild)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Node* Text::removeChild(Node* oldChild)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Node* Text::appendChild(Node* newChild)
|
||||
{
|
||||
return NULL;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..\..\..\..\..
|
||||
|
||||
DIRS=mozImpl
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
|
@ -0,0 +1,80 @@
|
|||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..\..\..\..\..\..
|
||||
|
||||
LIBRARY_NAME=transformix_xml_dom_mozImpl
|
||||
MODULE=transformix
|
||||
REQUIRES=xpcom raptor
|
||||
|
||||
CPPSRCS= \
|
||||
Attr.cpp \
|
||||
CDATASection.cpp \
|
||||
CharacterData.cpp \
|
||||
Comment.cpp \
|
||||
Document.cpp \
|
||||
DocumentFragment.cpp \
|
||||
DocumentType.cpp \
|
||||
DOMImplementation.cpp \
|
||||
Element.cpp \
|
||||
Entity.cpp \
|
||||
EntityReference.cpp \
|
||||
NamedNodeMap.cpp \
|
||||
NodeDefinition.cpp \
|
||||
NodeListDefinition.cpp \
|
||||
Notation.cpp \
|
||||
ProcessingInstruction.cpp \
|
||||
Text.cpp \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS= \
|
||||
.\$(OBJDIR)\Attr.obj \
|
||||
.\$(OBJDIR)\CDATASection.obj \
|
||||
.\$(OBJDIR)\CharacterData.obj \
|
||||
.\$(OBJDIR)\Comment.obj \
|
||||
.\$(OBJDIR)\Document.obj \
|
||||
.\$(OBJDIR)\DocumentFragment.obj \
|
||||
.\$(OBJDIR)\DocumentType.obj \
|
||||
.\$(OBJDIR)\DOMImplementation.obj \
|
||||
.\$(OBJDIR)\Element.obj \
|
||||
.\$(OBJDIR)\Entity.obj \
|
||||
.\$(OBJDIR)\EntityReference.obj \
|
||||
.\$(OBJDIR)\NamedNodeMap.obj \
|
||||
.\$(OBJDIR)\NodeDefinition.obj \
|
||||
.\$(OBJDIR)\NodeListDefinition.obj \
|
||||
.\$(OBJDIR)\Notation.obj \
|
||||
.\$(OBJDIR)\ProcessingInstruction.obj \
|
||||
.\$(OBJDIR)\Text.obj \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
$(NULL)
|
||||
|
||||
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I..\..\..\base -I..\..\dom
|
||||
|
||||
LCFLAGS = \
|
||||
$(LCFLAGS) \
|
||||
$(DEFINES) \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
libs:: $(LIBRARY)
|
||||
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib
|
|
@ -0,0 +1,52 @@
|
|||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..\..\..\..
|
||||
|
||||
DIRS=dom
|
||||
|
||||
LIBRARY_NAME=transformix_xml
|
||||
MODULE=transformix
|
||||
REQUIRES=xpcom raptor
|
||||
|
||||
CPPSRCS= \
|
||||
XMLDOMUtils.cpp \
|
||||
XMLUtils.cpp \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS= \
|
||||
.\$(OBJDIR)\XMLDOMUtils.obj \
|
||||
.\$(OBJDIR)\XMLUtils.obj \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
$(NULL)
|
||||
|
||||
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I..\base -Idom
|
||||
|
||||
LCFLAGS = \
|
||||
$(LCFLAGS) \
|
||||
$(DEFINES) \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
libs:: $(LIBRARY)
|
||||
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib
|
|
@ -0,0 +1,57 @@
|
|||
target: xml_parser
|
||||
|
||||
|
||||
BASE_PATH = ../../base
|
||||
DOM_PATH = ../dom
|
||||
PARSER_PATH = .
|
||||
|
||||
EXPAT_PARSER_PATH = xmlparse
|
||||
EXPAT_TOKEN_PATH = xmltok
|
||||
|
||||
INCLUDE_PATH = -I $(PARSER_PATH) -I $(BASE_PATH) -I $(DOM_PATH) \
|
||||
-I $(EXPAT_TOKEN_PATH) -I $(EXPAT_PARSER_PATH) -I-
|
||||
|
||||
BASE_OBJS = $(BASE_PATH)/String.o
|
||||
|
||||
DOM_OBJS = $(DOM_PATH)/NodeDefinition.o \
|
||||
$(DOM_PATH)/Document.o \
|
||||
$(DOM_PATH)/DocumentFragment.o \
|
||||
$(DOM_PATH)/NamedNodeMap.o \
|
||||
$(DOM_PATH)/NodeListDefinition.o \
|
||||
$(DOM_PATH)/Element.o \
|
||||
$(DOM_PATH)/Attr.o \
|
||||
$(DOM_PATH)/CharacterData.o \
|
||||
$(DOM_PATH)/Text.o \
|
||||
$(DOM_PATH)/Comment.o \
|
||||
$(DOM_PATH)/CDATASection.o \
|
||||
$(DOM_PATH)/ProcessingInstruction.o \
|
||||
$(DOM_PATH)/Notation.o \
|
||||
$(DOM_PATH)/Entity.o $(DOM_PATH)EntityReference.o \
|
||||
$(DOM_PATH)/DocumentType.o \
|
||||
$(DOM_PATH)/DOMImplementation.o
|
||||
|
||||
EXPAT_OBJS = $(EXPAT_TOKEN_PATH)/xmltok.o \
|
||||
$(EXPAT_TOKEN_PATH)/xmlrole.o \
|
||||
$(EXPAT_PARSER_PATH)/xmlparse.o \
|
||||
$(EXPAT_PARSER_PATH)/hashtable.o
|
||||
|
||||
PARSER_OBJS = $(PARSER_PATH)/XMLParser.o
|
||||
|
||||
ALL_OBJS = $(BASE_OBJS) $(DOM_OBJS) $(EXPAT_OBJS) $(PARSER_OBJS)
|
||||
|
||||
|
||||
CC = g++ -D XML_UNICODE -D __cplusplus
|
||||
|
||||
xml_parser: $(ALL_OBJS)
|
||||
|
||||
XMLParser.o: XMLParser.h XMLParser.cpp
|
||||
$(CC) $(INCLUDE_PATH) -c XMLParser.cpp
|
||||
|
||||
$(EXPAT_OBJS):
|
||||
make -f expat.mk
|
||||
|
||||
$(DOM_OBJS):
|
||||
cd $(DOM_PATH); make
|
||||
|
||||
$(BASE_OBJS):
|
||||
cd $(BASE_PATH); make
|
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*/
|
||||
|
||||
#include "xmlparser.h"
|
||||
|
||||
/**
|
||||
* Implementation of an In-Memory DOM based XML parser. The actual XML
|
||||
* parsing is provided by EXPAT.
|
||||
*
|
||||
* @author <a href="tomk@mitre.org">Tom Kneeland</a>
|
||||
* @author <a href="kvisco@mitre.org">Keith Visco</a>
|
||||
*
|
||||
* Modification History:
|
||||
* Who When What
|
||||
* TK 05/03/99 Created
|
||||
* KV 06/15/1999 Fixed bug in parse method which read from cin instead of
|
||||
* the istream parameter.
|
||||
* KV 06/15/1999 Changed #parse method to return a Document
|
||||
* KV 06/17/1999 made a bunch of changes
|
||||
*
|
||||
**/
|
||||
|
||||
/**
|
||||
* Creates a new XMLParser
|
||||
**/
|
||||
XMLParser::XMLParser()
|
||||
{
|
||||
errorState = MB_FALSE;
|
||||
} //-- XMLParser
|
||||
|
||||
|
||||
XMLParser::~XMLParser()
|
||||
{
|
||||
//-- clean up
|
||||
} //-- ~XMLParser
|
||||
|
||||
/**
|
||||
* Parses the given input stream and returns a DOM Document.
|
||||
* A NULL pointer will be returned if errors occurred
|
||||
**/
|
||||
Document* XMLParser::parse(istream& inputStream)
|
||||
{
|
||||
const int bufferSize = 1000;
|
||||
|
||||
char buf[bufferSize];
|
||||
int done;
|
||||
errorState = MB_FALSE;
|
||||
errorString.clear();
|
||||
if ( !inputStream ) {
|
||||
errorString.append("unable to parse xml, invalid or unopen stream");
|
||||
return NULL;
|
||||
}
|
||||
XML_Parser parser = XML_ParserCreate(NULL);
|
||||
ParserState ps;
|
||||
ps.document = new Document();
|
||||
ps.currentNode = ps.document;
|
||||
|
||||
XML_SetUserData(parser, &ps);
|
||||
XML_SetElementHandler(parser, startElement, endElement);
|
||||
XML_SetCharacterDataHandler(parser, charData);
|
||||
XML_SetProcessingInstructionHandler(parser, piHandler);
|
||||
do
|
||||
{
|
||||
inputStream.read(buf, bufferSize);
|
||||
done = inputStream.eof();
|
||||
|
||||
if (!XML_Parse(parser, buf, inputStream.gcount(), done))
|
||||
{
|
||||
errorString.append(XML_ErrorString(XML_GetErrorCode(parser)));
|
||||
errorString.append(" at line ");
|
||||
errorString.append(XML_GetCurrentLineNumber(parser));
|
||||
done = true;
|
||||
errorState = MB_TRUE;
|
||||
delete ps.document;
|
||||
ps.document = NULL;
|
||||
}
|
||||
} while (!done);
|
||||
inputStream.clear();
|
||||
|
||||
//if (currentElement)
|
||||
//theDocument->appendChild(currentElement);
|
||||
|
||||
// clean up
|
||||
XML_ParserFree(parser);
|
||||
|
||||
return ps.document;
|
||||
}
|
||||
|
||||
const DOMString& XMLParser::getErrorString()
|
||||
{
|
||||
return errorString;
|
||||
}
|
||||
|
||||
void startElement(void *userData, const XML_Char *name, const XML_Char **atts)
|
||||
{
|
||||
ParserState* ps = (ParserState*)userData;
|
||||
Element* newElement;
|
||||
Attr* newAttribute;
|
||||
DOM_CHAR* attName;
|
||||
DOM_CHAR* attValue;
|
||||
XML_Char** theAtts = (XML_Char**)atts;
|
||||
|
||||
newElement = ps->document->createElement((DOM_CHAR*) name);
|
||||
|
||||
while (*theAtts)
|
||||
{
|
||||
attName = (DOM_CHAR*)*theAtts++;
|
||||
attValue = (DOM_CHAR*)*theAtts++;
|
||||
newElement->setAttribute(attName, attValue);
|
||||
}
|
||||
|
||||
ps->currentNode->appendChild(newElement);
|
||||
ps->currentNode = newElement;
|
||||
|
||||
} //-- startElement
|
||||
|
||||
void endElement(void *userData, const XML_Char* name)
|
||||
{
|
||||
ParserState* ps = (ParserState*)userData;
|
||||
if (ps->currentNode->getParentNode())
|
||||
ps->currentNode = ps->currentNode->getParentNode();
|
||||
} //-- endElement
|
||||
|
||||
void charData(void* userData, const XML_Char* s, int len)
|
||||
{
|
||||
ParserState* ps = (ParserState*)userData;
|
||||
DOMString data;
|
||||
data.append((const DOM_CHAR*)s, len);
|
||||
ps->currentNode->appendChild(ps->document->createTextNode(data));
|
||||
} //-- charData
|
||||
|
||||
/**
|
||||
* Handles ProcessingInstructions
|
||||
**/
|
||||
void piHandler(void *userData, const XML_Char *target, const XML_Char *data) {
|
||||
ParserState* ps = (ParserState*)userData;
|
||||
DOMString targetStr((const DOM_CHAR*) target);
|
||||
DOMString dataStr((const DOM_CHAR*) data);
|
||||
|
||||
ps->currentNode->appendChild(
|
||||
ps->document->createProcessingInstruction(targetStr, dataStr));
|
||||
|
||||
} //-- piHandler
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* The Copyright owner will not be liable for any damages suffered by
|
||||
* you as a result of using the Program. In no event will the Copyright
|
||||
* owner be liable for any special, indirect or consequential damages or
|
||||
* lost profits even if the Copyright owner has been advised of the
|
||||
* possibility of their occurrence.
|
||||
*/
|
||||
|
||||
#include <iostream.h>
|
||||
#include "baseutils.h"
|
||||
#include "xmlparse.h"
|
||||
#include "DOM.h"
|
||||
|
||||
typedef struct {
|
||||
Document* document;
|
||||
Node* currentNode;
|
||||
} ParserState;
|
||||
|
||||
/**
|
||||
* Implementation of an In-Memory DOM based XML parser. The actual XML
|
||||
* parsing is provided by EXPAT.
|
||||
*
|
||||
* @author <a href="tomk@mitre.org">Tom Kneeland</a>
|
||||
* @author <a href="kvisco@mitre.org">Keith Visco</a>
|
||||
*
|
||||
* Modification History:
|
||||
* Who When What
|
||||
* TK 05/03/99 Created
|
||||
* KV 06/15/1999 Changed #parse method to return document
|
||||
* KV 06/17/1999 Made many changes
|
||||
*
|
||||
**/
|
||||
class XMLParser
|
||||
{
|
||||
/*-----------------6/18/99 12:43PM------------------
|
||||
* Sax related methods for XML parsers
|
||||
* --------------------------------------------------*/
|
||||
friend void charData(void* userData, const XML_Char* s, int len);
|
||||
friend void startElement(void *userData, const XML_Char* name,
|
||||
const XML_Char** atts);
|
||||
friend void endElement(void *userData, const XML_Char* name);
|
||||
|
||||
friend void piHandler(void *userData, const XML_Char *target, const XML_Char *data);
|
||||
|
||||
public:
|
||||
XMLParser();
|
||||
~XMLParser();
|
||||
|
||||
Document* parse(istream& inputStream);
|
||||
const DOMString& getErrorString();
|
||||
|
||||
protected:
|
||||
|
||||
Document* theDocument;
|
||||
Element* currentElement;
|
||||
MBool errorState;
|
||||
DOMString errorString;
|
||||
};
|
||||
|
||||
/*-----------------6/18/99 12:43PM------------------
|
||||
* Sax related methods for XML parsers
|
||||
* --------------------------------------------------*/
|
||||
void charData(void* userData, const XML_Char* s, int len);
|
||||
void startElement(void *userData, const XML_Char* name, const XML_Char** atts);
|
||||
void endElement(void *userData, const XML_Char* name);
|
||||
void piHandler(void *userData, const XML_Char *target, const XML_Char *data);
|
|
@ -0,0 +1,25 @@
|
|||
EXPAT_PARSER_PATH = xmlparse
|
||||
EXPAT_TOKEN_PATH = xmltok
|
||||
|
||||
EXPAT_OBJS = $(EXPAT_TOKEN_PATH)/xmltok.o \
|
||||
$(EXPAT_TOKEN_PATH)/xmlrole.o \
|
||||
$(EXPAT_PARSER_PATH)/xmlparse.o \
|
||||
$(EXPAT_PARSER_PATH)/hashtable.o
|
||||
|
||||
|
||||
INCLUDE_PATH = -I . -I $(EXPAT_PARSER_PATH) -I $(EXPAT_TOKEN_PATH) -I-
|
||||
|
||||
FLAGS = -D XML_UNICODE
|
||||
CC = gcc $(FLAGS) $(INCLUDE_PATH)
|
||||
|
||||
target: $(EXPAT_OBJS)
|
||||
|
||||
|
||||
xmltok.o xmlrole.o:
|
||||
cd $(EXPAT_TOKEN_PATH); \
|
||||
$(CC) -c xmltok.c xmlrole.c
|
||||
|
||||
|
||||
xmlparse.o hashtable.o:
|
||||
cd $(EXPAT_PARSER_PATH); \
|
||||
$(CC) -c xmlparse.c hashtable.c
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче