diff --git a/mozilla/extensions/transformiix/source/base/TxString.cpp b/mozilla/extensions/transformiix/source/base/TxString.cpp index 52f63b2f2f7..13738bfa2e5 100644 --- a/mozilla/extensions/transformiix/source/base/TxString.cpp +++ b/mozilla/extensions/transformiix/source/base/TxString.cpp @@ -1,1273 +1,1273 @@ -/* - * (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 DOM_CHAR to UNICODE_CHAR -// -// KV 07/29/1999 Added lastIndexOf methods -// KV 07/29/1999 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) -// TK 12/03/1999 Made some of the interface functions virtual, to support -// wrapping Mozilla nsStrings in a String interface -// TK 12/09/1999 Since "String" can be extended, we can not be certin of its -// implementation, therefore any function accepting a String -// object as an argument must only deal with its public -// interface. The following member functions have been -// modified: append, insert, replace, indexOf, isEqual, -// lastIndexOf, and subString -// -// Modified subString(Int32 start, String& dest) to simmply -// call subString(Int32 start, Int32 end, String& dest). This -// helps with code reuse. -// -// Made ConvetInt a protected member function so it is -// available to classes derrived from String. This is possible -// since the implementation of ConvertInt only uses the public -// interface of String -// -// Made UnicodeLength a protected member function since it -// only calculates the length of a null terminated UNICODE_CHAR -// array. -// TK 12/17/1999 To support non-null terminated UNICODE_CHAR* arrays, an -// additional insert function has been added that accepts a -// length parameter. -// -// Modified append(const UNICODE_CHAR* source) to simply -// calculate the length of the UNICODE_CHAR array, and then -// defer its processing to -// append(const UNICODE_CHAR* source, Int32 sourceLength) -// TK 12/22/1999 Enhanced Trim() to to remove additional "white space" -// characters (added \n, \t, and \r). -// -// TK 02/14/2000 Added a constructon which accepts a UNICODE_CHAR* array, and -// its associated length. -// -// TK 03/10/2000 Fixed a bug found by Bobbi Guarino where -// String::indexOf(const String& string...) was not RETURNing -// a value. -// -// TK 03/30/2000 Changed toChar to toCharArray and provided an overloaded -// version which will instantiate its own character buffer. - -#include -#include -#include "TxString.h" -#include - -// -//Default Constructor, create an empty String -// -String::String() -{ - strBuffer = NULL; - bufferLength = 0; - strLength = 0; -} - -// -//Create an empty String of a specific size -// -String::String(Int32 initSize) -{ - strBuffer = new UNICODE_CHAR[initSize]; - bufferLength = initSize; - strLength = 0; -} - -// -//Create a copy of the source String -//TK 12/09/1999 - To ensure compatibility with sub classes of String, this -// constructor has been modified to use String's public -// interface only. -// -String::String(const String& source) -{ - Int32 copyLoop; - - //Allocate space for the source string - strLength = source.length(); - - //-- modified by kvisco to only use necessay amount of space - //-- was: bufferLength = source.bufferLength; - bufferLength = strLength; - - strBuffer = new UNICODE_CHAR[bufferLength]; - - //Copy the new string data after the old data - for (copyLoop=0;copyLoop strLength) - { - ensureCapacity(totalOffset - strLength); - strLength += totalOffset - strLength; - } - - for (replaceLoop=0;replaceLoop strLength) - { - ensureCapacity(totalOffset - strLength); - strLength += totalOffset - strLength; - } - - for (replaceLoop=0;replaceLoop strLength) - { - ensureCapacity(totalOffset - strLength); - strLength += totalOffset - strLength; - } - - for (replaceLoop=0;replaceLoop current length, the string will be extended - * and padded with '\0' null characters. Otherwise the String - * will be truncated -**/ -void String::setLength(Int32 length) { - setLength(length, '\0'); -} //-- setLength - -/** - * 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 String::setLength(Int32 length, UNICODE_CHAR padChar) { - if ( length < 0 ) strLength = 0; - else if ( length > strLength ) { - Int32 diff = length-strLength; - ensureCapacity(diff); - for ( Int32 i = strLength; i < length; i++ ) - strBuffer[i] = padChar; - strLength = length; - } - else strLength = length; -} //-- setLength - -// -//Delete the "substring" starting at "offset" and proceeding for "count" number -//of characters (or until the end of the string, whichever comes first). -// -void String::deleteChars(Int32 offset, Int32 count) -{ - Int32 deleteLoop; - Int32 offsetCount; - - offset = offset < 0 ? 0 : offset; - offsetCount = offset + count; - - if (offsetCount < strLength) - { - for (deleteLoop=0;deleteLoop= 0)) - return strBuffer[index]; - else - return (UNICODE_CHAR)-1; -} - -// -//Clear out the string by simply setting the length to zero. The buffer is -//left intact. -// -void String::clear() -{ - strLength = 0; -} - -// -//Make sure the buffer has room for 'capacity' UNICODE_CHARS. -// -void String::ensureCapacity(Int32 capacity) -{ - UNICODE_CHAR* tempStrBuffer = NULL; - - //Check for the desired capacity - Int32 freeSpace = bufferLength - strLength; //(added by kvisco) - - if (freeSpace < capacity) { - - //-- modified by kvisco to only add needed capacity, - //-- not extra bytes as before - //-- old : bufferLength += capacity; - bufferLength += capacity - freeSpace; - - tempStrBuffer = new UNICODE_CHAR[bufferLength]; - copyString(tempStrBuffer); - - //If the old string contained any data, delete it, and save the new. - if (strBuffer) - delete strBuffer; - - strBuffer = tempStrBuffer; - } -} - -/** - * Performs a CASE SENSITIVE search of the string for the first occurence - * of 'data'. If found return the index, else return NOT_FOUND. - * -- changed by kvisco to call indexOf(UNICODE_CHAR, Int32) -**/ -Int32 String::indexOf(UNICODE_CHAR data) const -{ - return indexOf(data, 0); -} //-- indexOf - -// -//Starting at 'offset' perform a CASE SENSITIVE search of the string looking -//for the first occurence of 'data'. If found return the index, else return -//NOT_FOUND. If the offset is less than zero, then start at zero. -// -Int32 String::indexOf(UNICODE_CHAR data, Int32 offset) const -{ - Int32 searchIndex = offset < 0 ? searchIndex = 0 : searchIndex = offset; - - while (1) - { - if (searchIndex >= strLength) - return NOT_FOUND; - else if (strBuffer[searchIndex] == data) - return searchIndex; - else - ++searchIndex; - } -} //-- indexOf - -// -//Returns the index of the first occurence of data -//TK 12/09/1999 - Modified to simply use indexOf(const String&, Int32). -// -Int32 String::indexOf(const String& data) const -{ - return indexOf(data, 0); -} - -// -//Returns the index of the first occurrence of data starting at offset -//TK 12/09/1999 - Modified to use the "data" String's public interface to -// retreive the Unicode Char buffer when calling isEqual. -// This ensures compatibility with classes derrived from String. -// -Int32 String::indexOf(const String& data, Int32 offset) const -{ - Int32 searchIndex = offset < 0 ? 0 : offset; - - while (1) - { - if (searchIndex <= (strLength - data.length())) - { - if (isEqual(&strBuffer[searchIndex], data.toUnicode(), data.length())) - return searchIndex; - } - else - return NOT_FOUND; - - searchIndex++; - } -} - -// -//Check for equality between this string, and data -//TK 12/09/1999 - Modified to use data.toUnicode() public member function -// when working with data's unicode buffer. This ensures -// compatibility with derrived classes. -// -MBool String::isEqual(const String& data) const -{ - if (this == &data) - return MB_TRUE; - else if (strLength != data.length()) - return MB_FALSE; - else - return isEqual(strBuffer, data.toUnicode(), data.length()); -} - -/** - * Returns index of last occurrence of data - *
- * Added implementation 19990729 (kvisco) -**/ -Int32 String::lastIndexOf(UNICODE_CHAR data) const -{ - return lastIndexOf(data, strLength-1); -} //-- lastIndexOf - -/** - * Returns the index of the last occurrence of data starting at offset - *
- * Added implementation 19990729 (kvisco) -**/ -Int32 String::lastIndexOf(UNICODE_CHAR data, Int32 offset) const -{ - if ((offset < 0) || (offset >= strLength)) return NOT_FOUND; - - Int32 searchIndex = offset; - while (searchIndex >= 0) { - if (strBuffer[searchIndex] == data) return searchIndex; - --searchIndex; - } - return NOT_FOUND; - -} //-- lastIndexOf - -/** - * Returns the index of the last occurrence of data - *
- * Added implementation 19990729 (kvisco) -**/ -Int32 String::lastIndexOf(const String& data) const -{ - return lastIndexOf(data, strLength-1); -} //-- lastIndexOf - -/** - * Returns the index of the last occurrence of data starting at offset - *
- * Added implementation 19990729 (kvisco) - * TK 12/09/1999 - Completed implementation... -**/ -Int32 String::lastIndexOf(const String& data, Int32 offset) const -{ - Int32 searchIndex; - const UNICODE_CHAR* dataStrBuffer = NULL; - - if ((offset < 0) || (offset >= strLength)) - return NOT_FOUND; - else - { - searchIndex = offset; - - //If there is not enough space between searchIndex and the length of the of - //the string for "data" to appear, then there is no reason to search it. - if ((strLength - searchIndex) < data.length()) - searchIndex = strLength - data.length(); - - dataStrBuffer = data.toUnicode(); - while (searchIndex >= 0) - { - if (isEqual(&strBuffer[searchIndex], data.toUnicode(), data.length())) - return searchIndex; - --searchIndex; - } - } - return NOT_FOUND; -} - -// -//Returns the length of the String -// -Int32 String::length() const -{ - return strLength; -} - -// -//Returns a subString starting at start -//TK 12/09/1999 - Modified to simply use subString(Int32, Int32, String&) -// -String& String::subString(Int32 start, String& dest) const -{ - return subString(start, strLength, dest); -} - -/** - * Returns the subString starting at start and ending at end - * Note: the dest String is cleared before use - * TK 12/09/1999 - Modified to use the "dest" String's public interface to - * ensure compatibility wtih derrived classes. -**/ -String& String::subString(Int32 start, Int32 end, String& dest) const -{ - Int32 srcLoop; - Int32 destLoop = 0; - - start = start < 0? 0 : start; - end = end > strLength? strLength : end; - - dest.clear(); - if ((start < end)) - { - dest.ensureCapacity(end - start); - for (srcLoop=start;srcLoop= 'A') && - (strBuffer[conversionLoop] <= 'Z')) - strBuffer[conversionLoop] += 32; - } -} - -// -//Convert String to uppercase -// -void String::toUpperCase() -{ - Int32 conversionLoop; - - for (conversionLoop=0;conversionLoop= 'a') && - (strBuffer[conversionLoop] <= 'z')) - strBuffer[conversionLoop] -= 32; - } -} - -// -//Trim whitespace from both ends of String -// -void String::trim() -{ - Int32 trimLoop = strLength - 1; - Int32 cutLoop; - MBool done = MB_FALSE; - - //As long as we are not working on an emtpy string, trim from the right - //first, so we don't have to move useless spaces when we trim from the left. - if (strLength > 0) - { - while (!done) - { - switch (strBuffer[trimLoop]) - { - case ' ' : - case '\t' : - case '\n' : - case '\r' : - --strLength; - --trimLoop; - break; - - default : - done = MB_TRUE; - break; - } - } - } - - //Now, if there are any characters left to the string, Trim to the left. - //First count the number of "left" spaces. Then move all characters to the - //left by that ammount. - if (strLength > 0) - { - done = MB_FALSE; - trimLoop = 0; - while (!done) - { - switch (strBuffer[trimLoop]) - { - case ' ' : - case '\t' : - case '\n' : - case '\r' : - ++trimLoop; - break; - - default : - done = MB_TRUE; - break; - } - } - - if (trimLoop < strLength) - { - for (cutLoop=trimLoop;cutLoop strLength) + { + ensureCapacity(totalOffset - strLength); + strLength += totalOffset - strLength; + } + + for (replaceLoop=0;replaceLoop strLength) + { + ensureCapacity(totalOffset - strLength); + strLength += totalOffset - strLength; + } + + for (replaceLoop=0;replaceLoop strLength) + { + ensureCapacity(totalOffset - strLength); + strLength += totalOffset - strLength; + } + + for (replaceLoop=0;replaceLoop current length, the string will be extended + * and padded with '\0' null characters. Otherwise the String + * will be truncated +**/ +void String::setLength(Int32 length) { + setLength(length, '\0'); +} //-- setLength + +/** + * 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 String::setLength(Int32 length, UNICODE_CHAR padChar) { + if ( length < 0 ) strLength = 0; + else if ( length > strLength ) { + Int32 diff = length-strLength; + ensureCapacity(diff); + for ( Int32 i = strLength; i < length; i++ ) + strBuffer[i] = padChar; + strLength = length; + } + else strLength = length; +} //-- setLength + +// +//Delete the "substring" starting at "offset" and proceeding for "count" number +//of characters (or until the end of the string, whichever comes first). +// +void String::deleteChars(Int32 offset, Int32 count) +{ + Int32 deleteLoop; + Int32 offsetCount; + + offset = offset < 0 ? 0 : offset; + offsetCount = offset + count; + + if (offsetCount < strLength) + { + for (deleteLoop=0;deleteLoop= 0)) + return strBuffer[index]; + else + return (UNICODE_CHAR)-1; +} + +// +//Clear out the string by simply setting the length to zero. The buffer is +//left intact. +// +void String::clear() +{ + strLength = 0; +} + +// +//Make sure the buffer has room for 'capacity' UNICODE_CHARS. +// +void String::ensureCapacity(Int32 capacity) +{ + UNICODE_CHAR* tempStrBuffer = NULL; + + //Check for the desired capacity + Int32 freeSpace = bufferLength - strLength; //(added by kvisco) + + if (freeSpace < capacity) { + + //-- modified by kvisco to only add needed capacity, + //-- not extra bytes as before + //-- old : bufferLength += capacity; + bufferLength += capacity - freeSpace; + + tempStrBuffer = new UNICODE_CHAR[bufferLength]; + copyString(tempStrBuffer); + + //If the old string contained any data, delete it, and save the new. + if (strBuffer) + delete strBuffer; + + strBuffer = tempStrBuffer; + } +} + +/** + * Performs a CASE SENSITIVE search of the string for the first occurence + * of 'data'. If found return the index, else return NOT_FOUND. + * -- changed by kvisco to call indexOf(UNICODE_CHAR, Int32) +**/ +Int32 String::indexOf(UNICODE_CHAR data) const +{ + return indexOf(data, 0); +} //-- indexOf + +// +//Starting at 'offset' perform a CASE SENSITIVE search of the string looking +//for the first occurence of 'data'. If found return the index, else return +//NOT_FOUND. If the offset is less than zero, then start at zero. +// +Int32 String::indexOf(UNICODE_CHAR data, Int32 offset) const +{ + Int32 searchIndex = offset < 0 ? searchIndex = 0 : searchIndex = offset; + + while (1) + { + if (searchIndex >= strLength) + return NOT_FOUND; + else if (strBuffer[searchIndex] == data) + return searchIndex; + else + ++searchIndex; + } +} //-- indexOf + +// +//Returns the index of the first occurence of data +//TK 12/09/1999 - Modified to simply use indexOf(const String&, Int32). +// +Int32 String::indexOf(const String& data) const +{ + return indexOf(data, 0); +} + +// +//Returns the index of the first occurrence of data starting at offset +//TK 12/09/1999 - Modified to use the "data" String's public interface to +// retreive the Unicode Char buffer when calling isEqual. +// This ensures compatibility with classes derrived from String. +// +Int32 String::indexOf(const String& data, Int32 offset) const +{ + Int32 searchIndex = offset < 0 ? 0 : offset; + + while (1) + { + if (searchIndex <= (strLength - data.length())) + { + if (isEqual(&strBuffer[searchIndex], data.toUnicode(), data.length())) + return searchIndex; + } + else + return NOT_FOUND; + + searchIndex++; + } +} + +// +//Check for equality between this string, and data +//TK 12/09/1999 - Modified to use data.toUnicode() public member function +// when working with data's unicode buffer. This ensures +// compatibility with derrived classes. +// +MBool String::isEqual(const String& data) const +{ + if (this == &data) + return MB_TRUE; + else if (strLength != data.length()) + return MB_FALSE; + else + return isEqual(strBuffer, data.toUnicode(), data.length()); +} + +/** + * Returns index of last occurrence of data + *
+ * Added implementation 19990729 (kvisco) +**/ +Int32 String::lastIndexOf(UNICODE_CHAR data) const +{ + return lastIndexOf(data, strLength-1); +} //-- lastIndexOf + +/** + * Returns the index of the last occurrence of data starting at offset + *
+ * Added implementation 19990729 (kvisco) +**/ +Int32 String::lastIndexOf(UNICODE_CHAR data, Int32 offset) const +{ + if ((offset < 0) || (offset >= strLength)) return NOT_FOUND; + + Int32 searchIndex = offset; + while (searchIndex >= 0) { + if (strBuffer[searchIndex] == data) return searchIndex; + --searchIndex; + } + return NOT_FOUND; + +} //-- lastIndexOf + +/** + * Returns the index of the last occurrence of data + *
+ * Added implementation 19990729 (kvisco) +**/ +Int32 String::lastIndexOf(const String& data) const +{ + return lastIndexOf(data, strLength-1); +} //-- lastIndexOf + +/** + * Returns the index of the last occurrence of data starting at offset + *
+ * Added implementation 19990729 (kvisco) + * TK 12/09/1999 - Completed implementation... +**/ +Int32 String::lastIndexOf(const String& data, Int32 offset) const +{ + Int32 searchIndex; + const UNICODE_CHAR* dataStrBuffer = NULL; + + if ((offset < 0) || (offset >= strLength)) + return NOT_FOUND; + else + { + searchIndex = offset; + + //If there is not enough space between searchIndex and the length of the of + //the string for "data" to appear, then there is no reason to search it. + if ((strLength - searchIndex) < data.length()) + searchIndex = strLength - data.length(); + + dataStrBuffer = data.toUnicode(); + while (searchIndex >= 0) + { + if (isEqual(&strBuffer[searchIndex], data.toUnicode(), data.length())) + return searchIndex; + --searchIndex; + } + } + return NOT_FOUND; +} + +// +//Returns the length of the String +// +Int32 String::length() const +{ + return strLength; +} + +// +//Returns a subString starting at start +//TK 12/09/1999 - Modified to simply use subString(Int32, Int32, String&) +// +String& String::subString(Int32 start, String& dest) const +{ + return subString(start, strLength, dest); +} + +/** + * Returns the subString starting at start and ending at end + * Note: the dest String is cleared before use + * TK 12/09/1999 - Modified to use the "dest" String's public interface to + * ensure compatibility wtih derrived classes. +**/ +String& String::subString(Int32 start, Int32 end, String& dest) const +{ + Int32 srcLoop; + Int32 destLoop = 0; + + start = start < 0? 0 : start; + end = end > strLength? strLength : end; + + dest.clear(); + if ((start < end)) + { + dest.ensureCapacity(end - start); + for (srcLoop=start;srcLoop= 'A') && + (strBuffer[conversionLoop] <= 'Z')) + strBuffer[conversionLoop] += 32; + } +} + +// +//Convert String to uppercase +// +void String::toUpperCase() +{ + Int32 conversionLoop; + + for (conversionLoop=0;conversionLoop= 'a') && + (strBuffer[conversionLoop] <= 'z')) + strBuffer[conversionLoop] -= 32; + } +} + +// +//Trim whitespace from both ends of String +// +void String::trim() +{ + Int32 trimLoop = strLength - 1; + Int32 cutLoop; + MBool done = MB_FALSE; + + //As long as we are not working on an emtpy string, trim from the right + //first, so we don't have to move useless spaces when we trim from the left. + if (strLength > 0) + { + while (!done) + { + switch (strBuffer[trimLoop]) + { + case ' ' : + case '\t' : + case '\n' : + case '\r' : + --strLength; + --trimLoop; + break; + + default : + done = MB_TRUE; + break; + } + } + } + + //Now, if there are any characters left to the string, Trim to the left. + //First count the number of "left" spaces. Then move all characters to the + //left by that ammount. + if (strLength > 0) + { + done = MB_FALSE; + trimLoop = 0; + while (!done) + { + switch (strBuffer[trimLoop]) + { + case ' ' : + case '\t' : + case '\n' : + case '\r' : + ++trimLoop; + break; + + default : + done = MB_TRUE; + break; + } + } + + if (trimLoop < strLength) + { + for (cutLoop=trimLoop;cutLoop current length, the string will be extended - * and padded with '\0' null characters. Otherwise the String - * will be truncated - **/ - virtual 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 - **/ - virtual void setLength(Int32 length, UNICODE_CHAR padChar); - - /** - * Returns a substring starting at start - * Note: the dest String is cleared before use - **/ - virtual 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 - **/ - virtual String& subString(Int32 start, Int32 end, String& dest) const; - - //Convert the internal rep. to a char buffer - virtual char* toCharArray() const; - virtual char* toCharArray(char* dest) const; - virtual UNICODE_CHAR* toUnicode(UNICODE_CHAR* dest) const; - virtual const UNICODE_CHAR* toUnicode() const; - - virtual void toLowerCase(); //Convert string to lowercase - virtual void toUpperCase(); //Convert string to uppercase - virtual void trim(); //Trim whitespace from both ends - - virtual void reverse(); //Reverse the string - - protected: - //Convert an Int into a String - //TK 12/09/1999 - Make this function available to Derrived classes - String& ConvertInt(Int32 value, String& target); - - //Calculates the length of a null terminated UNICODE_CHAR array - Int32 UnicodeLength(const UNICODE_CHAR* data); - - 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; - - -}; - -ostream& operator<<(ostream& output, const String& source); - -#endif - +/* + * (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) +// TK 12/03/1999 Made some of the interface functions virtual, to support +// wrapping Mozilla nsStrings in a String interface +// TK 12/09/1999 Since "String" can be extended, we can not be certin of its +// implementation, therefore any function accepting a String +// object as an argument must only deal with its public +// interface. The following member functions have been +// modified: append, insert, replace, indexOf, isEqual, +// lastIndexOf, and subString +// +// Modified subString(Int32 start, String& dest) to simmply +// call subString(Int32 start, Int32 end, String& dest). This +// helps with code reuse. +// +// Made ConvetInt a protected member function so it is +// available to classes derrived from String. This is possible +// since the implementation of ConvertInt only uses the public +// interface of String +// +// Made UnicodeLength a protected member function since it +// only calculates the length of a null terminated UNICODE_CHAR +// array. +// TK 12/17/1999 To support non-null terminated UNICODE_CHAR* arrays, an +// additional insert function has been added that accepts a +// length parameter. +// +// Modified append(const UNICODE_CHAR* source) to simply +// calculate the length of the UNICODE_CHAR array, and then +// defer its processing to +// append(const UNICODE_CHAR* source, Int32 sourceLength) +// TK 12/21/1999 To support non-null terminated UNICODE_CHAR* arrays, an +// additional replace function has been added that accepts a +// length parameter. +// +// Modified replace(Int32 offset, const UNICODE_CHAR* source) +// to simply call the new replace function passing the computed +// length of the null terminated UNICODE_CHAR array. +// TK 12/22/1999 Enhanced Trim() to to remove additional "white space" +// characters (added \n, \t, and \r). +// +// TK 02/14/2000 Added a constructon which accepts a UNICODE_CHAR* array, and +// its associated length. +// +// TK 03/30/2000 Changed toChar to toCharArray and provided an overloaded +// version which will instantiate its own character buffer. + +#ifndef MITRE_STRING +#define MITRE_STRING + +#include "MITREObject.h" +#include "baseutils.h" +#include + +typedef unsigned short UNICODE_CHAR; + +#ifndef NULL + #define NULL 0 +#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(const UNICODE_CHAR* source, Int32 length); + + ~String(); //Destroy the string, and free memory + + + //Assign source to this string + virtual String& operator=(const String& source); + virtual String& operator=(const char* source); + virtual String& operator=(const UNICODE_CHAR* source); + virtual String& operator=(Int32 source); + + //Grow buffer if necessary and append the source + virtual void append(UNICODE_CHAR source); + virtual void append(char source); + virtual void append(const String& source); + virtual void append(const char* source); + virtual void append(const UNICODE_CHAR* source); + virtual void append(const UNICODE_CHAR* source, Int32 length); + virtual void append(Int32 source); + + //Provide the ability to insert data into the middle of a string + virtual void insert(Int32 offset, const UNICODE_CHAR source); + virtual void insert(Int32 offset, const char source); + virtual void insert(Int32 offset, const String& source); + virtual void insert(Int32 offset, const char* source); + virtual void insert(Int32 offset, const UNICODE_CHAR* source); + virtual void insert(Int32 offset, const UNICODE_CHAR* source, + Int32 sourceLength); + virtual void insert(Int32 offset, Int32 source); + + //Provide the ability to replace one or more characters + virtual void replace(Int32 offset, const UNICODE_CHAR source); + virtual void replace(Int32 offset, const char source); + virtual void replace(Int32 offset, const String& source); + virtual void replace(Int32 offset, const char* source); + virtual void replace(Int32 offset, const UNICODE_CHAR* source); + virtual void replace(Int32 offset, const UNICODE_CHAR* source, + Int32 srcLength); + virtual void replace(Int32 offset, Int32 source); + + //Provide the ability to delete a range of charactes + virtual void deleteChars(Int32 offset, Int32 count); + + /** + * Returns the character at index. + * If the index is out of bounds, -1 will be returned. + **/ + virtual UNICODE_CHAR charAt(Int32 index) const; + + virtual void clear(); //Clear string + + virtual void ensureCapacity(Int32 capacity); //Make sure buffer is at least + //'size' + + //Returns index of first occurrence of data + virtual Int32 indexOf(UNICODE_CHAR data) const; + virtual Int32 indexOf(UNICODE_CHAR data, Int32 offset) const; + virtual Int32 indexOf(const String& data) const; + virtual Int32 indexOf(const String& data, Int32 offset) const; + + virtual MBool isEqual(const String& data) const; //Check equality between + //strings + + //Returns index of last occurrence of data + virtual Int32 lastIndexOf(UNICODE_CHAR data) const; + virtual Int32 lastIndexOf(UNICODE_CHAR data, Int32 offset) const; + virtual Int32 lastIndexOf(const String& data) const; + virtual Int32 lastIndexOf(const String& data, Int32 offset) const; + + virtual Int32 length() const; //Returns the 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 '\0' null characters. Otherwise the String + * will be truncated + **/ + virtual 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 + **/ + virtual void setLength(Int32 length, UNICODE_CHAR padChar); + + /** + * Returns a substring starting at start + * Note: the dest String is cleared before use + **/ + virtual 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 + **/ + virtual String& subString(Int32 start, Int32 end, String& dest) const; + + //Convert the internal rep. to a char buffer + virtual char* toCharArray() const; + virtual char* toCharArray(char* dest) const; + virtual UNICODE_CHAR* toUnicode(UNICODE_CHAR* dest) const; + virtual const UNICODE_CHAR* toUnicode() const; + + virtual void toLowerCase(); //Convert string to lowercase + virtual void toUpperCase(); //Convert string to uppercase + virtual void trim(); //Trim whitespace from both ends + + virtual void reverse(); //Reverse the string + + protected: + //Convert an Int into a String + //TK 12/09/1999 - Make this function available to Derrived classes + String& ConvertInt(Int32 value, String& target); + + //Calculates the length of a null terminated UNICODE_CHAR array + Int32 UnicodeLength(const UNICODE_CHAR* data); + + 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; + + +}; + +ostream& operator<<(ostream& output, const String& source); + +#endif + diff --git a/mozilla/extensions/transformiix/source/xml/dom/Attr.cpp b/mozilla/extensions/transformiix/source/xml/dom/Attr.cpp index bb0dfef8ab2..04a4004b76e 100644 --- a/mozilla/extensions/transformiix/source/xml/dom/Attr.cpp +++ b/mozilla/extensions/transformiix/source/xml/dom/Attr.cpp @@ -1,143 +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;valueLoopitem(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; -} +/* + * (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;valueLoopitem(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; +} diff --git a/mozilla/extensions/transformiix/source/xml/dom/CDATASection.cpp b/mozilla/extensions/transformiix/source/xml/dom/CDATASection.cpp index 44586af9d4c..328bba1ca63 100644 --- a/mozilla/extensions/transformiix/source/xml/dom/CDATASection.cpp +++ b/mozilla/extensions/transformiix/source/xml/dom/CDATASection.cpp @@ -1,64 +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; -} +/* + * (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; +} diff --git a/mozilla/extensions/transformiix/source/xml/dom/CharacterData.cpp b/mozilla/extensions/transformiix/source/xml/dom/CharacterData.cpp index 167f9eaebf4..dbdc75c4371 100644 --- a/mozilla/extensions/transformiix/source/xml/dom/CharacterData.cpp +++ b/mozilla/extensions/transformiix/source/xml/dom/CharacterData.cpp @@ -1,113 +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); - } -} +/* + * (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); + } +} diff --git a/mozilla/extensions/transformiix/source/xml/dom/Comment.cpp b/mozilla/extensions/transformiix/source/xml/dom/Comment.cpp index cc26feecf2b..97db4507946 100644 --- a/mozilla/extensions/transformiix/source/xml/dom/Comment.cpp +++ b/mozilla/extensions/transformiix/source/xml/dom/Comment.cpp @@ -1,64 +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; -} +/* + * (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; +} diff --git a/mozilla/extensions/transformiix/source/xml/dom/DOMImplementation.cpp b/mozilla/extensions/transformiix/source/xml/dom/DOMImplementation.cpp index dc30f22ac5a..91d4974c9dd 100644 --- a/mozilla/extensions/transformiix/source/xml/dom/DOMImplementation.cpp +++ b/mozilla/extensions/transformiix/source/xml/dom/DOMImplementation.cpp @@ -1,56 +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; -} +/* + * (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; +} diff --git a/mozilla/extensions/transformiix/source/xml/dom/Document.cpp b/mozilla/extensions/transformiix/source/xml/dom/Document.cpp index 76e77ecbbe3..be9b55500de 100644 --- a/mozilla/extensions/transformiix/source/xml/dom/Document.cpp +++ b/mozilla/extensions/transformiix/source/xml/dom/Document.cpp @@ -1,258 +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); -} +/* + * (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); +} diff --git a/mozilla/extensions/transformiix/source/xml/dom/DocumentFragment.cpp b/mozilla/extensions/transformiix/source/xml/dom/DocumentFragment.cpp index 912d6e5993c..084fe26b543 100644 --- a/mozilla/extensions/transformiix/source/xml/dom/DocumentFragment.cpp +++ b/mozilla/extensions/transformiix/source/xml/dom/DocumentFragment.cpp @@ -1,68 +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; -} +/* + * (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; +} diff --git a/mozilla/extensions/transformiix/source/xml/dom/DocumentType.cpp b/mozilla/extensions/transformiix/source/xml/dom/DocumentType.cpp index 69809ef2536..3c86aa204c2 100644 --- a/mozilla/extensions/transformiix/source/xml/dom/DocumentType.cpp +++ b/mozilla/extensions/transformiix/source/xml/dom/DocumentType.cpp @@ -1,96 +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; -} +/* + * (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; +} diff --git a/mozilla/extensions/transformiix/source/xml/dom/Element.cpp b/mozilla/extensions/transformiix/source/xml/dom/Element.cpp index f0402fdf710..7bb2dde707b 100644 --- a/mozilla/extensions/transformiix/source/xml/dom/Element.cpp +++ b/mozilla/extensions/transformiix/source/xml/dom/Element.cpp @@ -1,162 +1,162 @@ -/* - * (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::DOCUMENT_FRAGMENT_NODE : //-- added 19990813 (kvisco) - 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() -{ -} +/* + * (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::DOCUMENT_FRAGMENT_NODE : //-- added 19990813 (kvisco) + 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() +{ +} diff --git a/mozilla/extensions/transformiix/source/xml/dom/Entity.cpp b/mozilla/extensions/transformiix/source/xml/dom/Entity.cpp index 33f17f806b9..5f690d71e8c 100644 --- a/mozilla/extensions/transformiix/source/xml/dom/Entity.cpp +++ b/mozilla/extensions/transformiix/source/xml/dom/Entity.cpp @@ -1,95 +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; -} +/* + * (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; +} diff --git a/mozilla/extensions/transformiix/source/xml/dom/EntityReference.cpp b/mozilla/extensions/transformiix/source/xml/dom/EntityReference.cpp index e70112d4ab6..2fbe9ee86b1 100644 --- a/mozilla/extensions/transformiix/source/xml/dom/EntityReference.cpp +++ b/mozilla/extensions/transformiix/source/xml/dom/EntityReference.cpp @@ -1,66 +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; -} +/* + * (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; +} diff --git a/mozilla/extensions/transformiix/source/xml/dom/NamedNodeMap.cpp b/mozilla/extensions/transformiix/source/xml/dom/NamedNodeMap.cpp index 0f3d6cb5983..414c05a1e47 100644 --- a/mozilla/extensions/transformiix/source/xml/dom/NamedNodeMap.cpp +++ b/mozilla/extensions/transformiix/source/xml/dom/NamedNodeMap.cpp @@ -1,111 +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; -} +/* + * (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; +} diff --git a/mozilla/extensions/transformiix/source/xml/dom/NodeDefinition.cpp b/mozilla/extensions/transformiix/source/xml/dom/NodeDefinition.cpp index 6b52826d95b..a1a9640cb53 100644 --- a/mozilla/extensions/transformiix/source/xml/dom/NodeDefinition.cpp +++ b/mozilla/extensions/transformiix/source/xml/dom/NodeDefinition.cpp @@ -1,356 +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;killAttrLoopgetNodeName()); -} - -// -//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;selectLoopnextSibling; - - 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 (newChild->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; -} +/* + * (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;killAttrLoopgetNodeName()); +} + +// +//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;selectLoopnextSibling; + + 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 (newChild->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; +} diff --git a/mozilla/extensions/transformiix/source/xml/dom/NodeListDefinition.cpp b/mozilla/extensions/transformiix/source/xml/dom/NodeListDefinition.cpp index 4031610884c..4bb1983ffd1 100644 --- a/mozilla/extensions/transformiix/source/xml/dom/NodeListDefinition.cpp +++ b/mozilla/extensions/transformiix/source/xml/dom/NodeListDefinition.cpp @@ -1,117 +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;selectLoopnext; - - return pListItem->node; - } - - return NULL; -} - -// -// Return the number of items in the list -// -Int32 NodeListDefinition::getLength() -{ - return length; -} +/* + * (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;selectLoopnext; + + return pListItem->node; + } + + return NULL; +} + +// +// Return the number of items in the list +// +Int32 NodeListDefinition::getLength() +{ + return length; +} diff --git a/mozilla/extensions/transformiix/source/xml/dom/Notation.cpp b/mozilla/extensions/transformiix/source/xml/dom/Notation.cpp index d0d5928b796..8aad385b6c5 100644 --- a/mozilla/extensions/transformiix/source/xml/dom/Notation.cpp +++ b/mozilla/extensions/transformiix/source/xml/dom/Notation.cpp @@ -1,81 +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; -} +/* + * (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; +} diff --git a/mozilla/extensions/transformiix/source/xml/dom/ProcessingInstruction.cpp b/mozilla/extensions/transformiix/source/xml/dom/ProcessingInstruction.cpp index 281856da9aa..ffc8e56f001 100644 --- a/mozilla/extensions/transformiix/source/xml/dom/ProcessingInstruction.cpp +++ b/mozilla/extensions/transformiix/source/xml/dom/ProcessingInstruction.cpp @@ -1,93 +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; -} +/* + * (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; +} diff --git a/mozilla/extensions/transformiix/source/xml/dom/Text.cpp b/mozilla/extensions/transformiix/source/xml/dom/Text.cpp index 3980f0760be..71492901491 100644 --- a/mozilla/extensions/transformiix/source/xml/dom/Text.cpp +++ b/mozilla/extensions/transformiix/source/xml/dom/Text.cpp @@ -1,93 +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; -} +/* + * (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; +} diff --git a/mozilla/extensions/transformiix/source/xml/dom/dom.h b/mozilla/extensions/transformiix/source/xml/dom/dom.h index dae6de920c2..1144a3699e6 100644 --- a/mozilla/extensions/transformiix/source/xml/dom/dom.h +++ b/mozilla/extensions/transformiix/source/xml/dom/dom.h @@ -1,1134 +1,568 @@ /* - * (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 - // - // Modification History: - // Who When What - // TK 03/29/99 Created - // LF 08/06/1999 Changed static const short NodeType to enum - // Added "friend NamedNodeMap"; to NodeListDefinition - // - - #ifndef MITRE_DOM - #define MITRE_DOM - - #ifdef __BORLANDC__ - #include - #endif - - #include "TxString.h" - #include "baseutils.h" - #ifndef NULL - typedef 0 NULL; - #endif - - - typedef String DOMString; - typedef UNICODE_CHAR DOM_CHAR; - - class NodeList; - class NamedNodeMap; - class Document; - class Element; - class Attr; - class Text; - class Comment; - class CDATASection; - class ProcessingInstruction; - class EntityReference; - class DocumentType; - - // - //Definition and Implementation the DOMImplementation class - // - class DOMImplementation - { - public: - DOMImplementation(); - ~DOMImplementation(); - - MBool hasFeature(DOMString feature, const DOMString& version) const; - - private: - DOMString implFeature; - DOMString implVersion; - }; - - // - // Abstract Class defining the interface for a Node. See NodeDefinition below - // for the actual implementation of the WC3 node. - // - class Node - { - public: - //Node type constants - //-- LF - changed to enum - enum NodeType { - ELEMENT_NODE = 1, - ATTRIBUTE_NODE, - TEXT_NODE, - CDATA_SECTION_NODE, - ENTITY_REFERENCE_NODE, - ENTITY_NODE, - PROCESSING_INSTRUCTION_NODE, - COMMENT_NODE, - DOCUMENT_NODE, - DOCUMENT_TYPE_NODE, - DOCUMENT_FRAGMENT_NODE, - NOTATION_NODE - }; - - virtual ~Node() {} - - //Read functions - virtual const DOMString& getNodeName() const = 0; - virtual const DOMString& getNodeValue() const = 0; - virtual const DOMString& getNodeValue() = 0; - virtual unsigned short getNodeType() const = 0; - virtual Node* getParentNode() const = 0; - virtual NodeList* getChildNodes() = 0; - virtual Node* getFirstChild() const = 0; - virtual Node* getLastChild() const = 0; - virtual Node* getPreviousSibling() const = 0; - virtual Node* getNextSibling() const = 0; - virtual NamedNodeMap* getAttributes() = 0; - virtual Document* getOwnerDocument() const = 0; - - //Write functions - virtual void setNodeValue(const DOMString& nodeValue) = 0; - - //Node manipulation functions - virtual Node* insertBefore(Node* newChild, Node* refChild) = 0; - virtual Node* replaceChild(Node* newChild, Node* oldChild) = 0; - virtual Node* removeChild(Node* oldChild) = 0; - virtual Node* appendChild(Node* newChild) = 0; - virtual Node* cloneNode(MBool deep, Node* dest) = 0; - - virtual MBool hasChildNodes() const = 0; - }; - - // - // Abstract class containing the Interface for a NodeList. See NodeDefinition - // below for the actual implementation of a WC3 NodeList as it applies to the - // getChildNodes Node function. Also see NodeListDefinition for the - // implementation of a NodeList as it applies to such functions as - // getElementByTagName. - // - class NodeList - { - public: - virtual Node* item(Int32 index) = 0; - virtual Int32 getLength() = 0; - protected: - Int32 length; - }; - - // - //Definition of the implementation of a NodeList. This class maintains a - //linked list of pointers to Nodes. "Friends" of the class can add and remove - //pointers to Nodes as needed. - // *** NOTE: Is there any need for someone to "remove" a node from the - // list? - // - class NodeListDefinition : public NodeList - { - friend NamedNodeMap; //-- LF - public: - NodeListDefinition(); - ~NodeListDefinition(); - - void append(Node& newNode); - void append(Node* newNode); - - //Inherited from NodeList - Node* item(Int32 index); - Int32 getLength(); - - protected: - struct ListItem { - ListItem* next; - ListItem* prev; - Node* node; - }; - - ListItem* firstItem; - ListItem* lastItem; - }; - - // - //Definition of a NamedNodeMap. For the time being it builds off the - //NodeListDefinition class. This will probably change when NamedNodeMap needs - //to move to a more efficient search algorithm for attributes. - // - class NamedNodeMap : public NodeListDefinition - { - public: - NamedNodeMap(); - ~NamedNodeMap(); - - Node* getNamedItem(const DOMString& name); - Node* setNamedItem(Node* arg); - Node* removeNamedItem(const DOMString& name); - - private: - NodeListDefinition::ListItem* findListItemByName(const DOMString& name); - }; - - // - // Definition and Implementation of Node and NodeList functionality. This is - // the central class, from which all other DOM classes (objects) are derrived. - // Users of this DOM should work strictly with the Node interface and NodeList - // interface (see above for those definitions) - // - class NodeDefinition : public Node, public NodeList - { - public: - NodeDefinition(NodeType type, const DOMString& name, - const DOMString& value, Document* owner); - virtual ~NodeDefinition(); //Destructor, delete all children of node - - //Read functions - const DOMString& getNodeName() const; - virtual const DOMString& getNodeValue() const; - virtual const DOMString& getNodeValue(); - unsigned short getNodeType() const; - Node* getParentNode() const; - NodeList* getChildNodes(); - Node* getFirstChild() const; - Node* getLastChild() const; - Node* getPreviousSibling() const; - Node* getNextSibling() const; - NamedNodeMap* getAttributes(); - Document* getOwnerDocument() const; - - //Write functions - virtual void setNodeValue(const DOMString& nodeValue); - - //Child node manipulation functions - virtual Node* insertBefore(Node* newChild, Node* refChild); - virtual Node* replaceChild(Node* newChild, Node* oldChild); - virtual Node* removeChild(Node* oldChild); - virtual Node* appendChild(Node* newChild); - Node* cloneNode(MBool deep, Node* dest); - - MBool hasChildNodes() const; - - //Inherrited from NodeList - Node* item(Int32 index); - Int32 getLength(); - - protected: - //Name, value, and attributes for this node. Available to derrived - //classes, since those derrived classes have a better idea how to use them, - //than the generic node does. - DOMString nodeName; - DOMString nodeValue; - NamedNodeMap attributes; - - void DeleteChildren(); - - Node* implInsertBefore(NodeDefinition* newChild, NodeDefinition* refChild); - private: - //Type of node this is - NodeType nodeType; - - //Data members for linking this Node to its parent and siblings - NodeDefinition* parentNode; - NodeDefinition* previousSibling; - NodeDefinition* nextSibling; - - //Pointer to the node's document - Document* ownerDocument; - - //Data members for maintaining a list of child nodes - NodeDefinition* firstChild; - NodeDefinition* lastChild; - - }; - - // - //Definition and Implementation of a Document Fragment. All functionality is - //inherrited directly from NodeDefinition. We just need to make sure the Type - //of the node set to Node::DOCUMENT_FRAGMENT_NODE. - // - class DocumentFragment : public NodeDefinition - { - public: - DocumentFragment(const DOMString& name, const DOMString& value, Document* owner); - - //Override insertBefore to limit Elements to having only certain nodes as - //children - Node* insertBefore(Node* newChild, Node* refChild); - }; - - // - //Definition and Implementation of a Document. - // - class Document : public NodeDefinition - { - public: - Document(DocumentType* theDoctype = NULL); - - Element* getDocumentElement(); - DocumentType* getDoctype(); - const DOMImplementation& getImplementation(); - - //Factory functions for various node types - DocumentFragment* createDocumentFragment(); - Element* createElement(const DOMString& tagName); - Attr* createAttribute(const DOMString& name); - Text* createTextNode(const DOMString& theData); - Comment* createComment(const DOMString& theData); - CDATASection* createCDATASection(const DOMString& theData); - ProcessingInstruction* createProcessingInstruction(const DOMString& target, - const DOMString& data); - EntityReference* createEntityReference(const DOMString& name); - - //Override functions to enforce the One Element rule for documents, as well - //as limit documents to certain types of nodes. - Node* insertBefore(Node* newChild, Node* refChild); - Node* replaceChild(Node* newChild, Node* oldChild); - Node* removeChild(Node* oldChild); - - private: - Element* documentElement; - DocumentType* doctype; - DOMImplementation implementation; - }; - - // - //Definition and Implementation of an Element - // - class Element : public NodeDefinition - { - public: - Element(const DOMString& tagName, Document* owner); - - //Override insertBefore to limit Elements to having only certain nodes as - //children - Node* insertBefore(Node* newChild, Node* refChild); - - const DOMString& getTagName(); - const DOMString& getAttribute(const DOMString& name); - void setAttribute(const DOMString& name, const DOMString& value); - void removeAttribute(const DOMString& name); - Attr* getAttributeNode(const DOMString& name); - Attr* setAttributeNode(Attr* newAttr); - Attr* removeAttributeNode(Attr* oldAttr); - NodeList* getElementsByTagName(const DOMString& name); - void normalize(); - }; - - // - //Definition and Implementation of a Attr - // NOTE: For the time bing use just the default functionality found in the - // NodeDefinition class - // - class Attr : public NodeDefinition - { - public: - Attr(const DOMString& name, Document* owner); - - const DOMString& getName() const; - MBool getSpecified() const; - const DOMString& getValue(); - void setValue(const DOMString& newValue); - - //Override the set and get member functions for a node's value to create a - //new TEXT node when set, and to interpret its children when read. - void setNodeValue(const DOMString& nodeValue); - const DOMString& getNodeValue(); - - //Override insertBefore to limit Attr to having only certain nodes as - //children - Node* insertBefore(Node* newChild, Node* refChild); - - private: - MBool specified; - }; - - // - //Definition and Implementation of CharacterData. This class mearly provides - //the interface and some default implementation. It is not intended to be - //instantiated by users of the DOM - // - class CharacterData : public NodeDefinition - { - public: - const DOMString& getData() const; - void setData(const DOMString& source); - Int32 getLength() const; - - DOMString& substringData(Int32 offset, Int32 count, DOMString& dest); - void appendData(const DOMString& arg); - void insertData(Int32 offset, const DOMString& arg); - void deleteData(Int32 offset, Int32 count); - void replaceData(Int32 offset, Int32 count, const DOMString& arg); - - protected: - CharacterData(NodeType type, const DOMString& name, - const DOMString& value, Document* owner); - }; - - // - //Definition and Implementation of a Text node. The bulk of the functionality - //comes from CharacterData and NodeDefinition. - // - class Text : public CharacterData - { - public: - Text(const DOMString& theData, Document* owner); - - Text* splitText(Int32 offset); - - //Override "child manipulation" function since Text Nodes can not have - //any children. - Node* insertBefore(Node* newChild, Node* refChild); - Node* replaceChild(Node* newChild, Node* oldChild); - Node* removeChild(Node* oldChild); - Node* appendChild(Node* newChild); - - protected: - Text(NodeType type, const DOMString& name, const DOMString& value, - Document* owner); - }; - - // - //Definition and Implementation of a Comment node. All of the functionality is - //inherrited from CharacterData and NodeDefinition. - // - class Comment : public CharacterData - { - public: - Comment(const DOMString& theData, Document* owner); - - //Override "child manipulation" function since Comment Nodes can not have - //any children. - Node* insertBefore(Node* newChild, Node* refChild); - Node* replaceChild(Node* newChild, Node* oldChild); - Node* removeChild(Node* oldChild); - Node* appendChild(Node* newChild); - }; - - // - //Definition and Implementation of a CDATASection node. All of the - //functionality is inherrited from Text, CharacterData, and NodeDefinition - // - class CDATASection : public Text - { - public: - CDATASection(const DOMString& theData, Document* owner); - - //Override "child manipulation" function since CDATASection Nodes can not - //have any children. - Node* insertBefore(Node* newChild, Node* refChild); - Node* replaceChild(Node* newChild, Node* oldChild); - Node* removeChild(Node* oldChild); - Node* appendChild(Node* newChild); - }; - - // - //Definition and Implemention of a ProcessingInstruction node. Most - //functionality is inherrited from NodeDefinition. - // The Target of a processing instruction is stored in the nodeName datamember - // inherrited from NodeDefinition. - // The Data of a processing instruction is stored in the nodeValue datamember - // inherrited from NodeDefinition - // - class ProcessingInstruction : public NodeDefinition - { - public: - ProcessingInstruction(const DOMString& theTarget, const DOMString& theData, - Document* owner); - - const DOMString& getTarget() const; - const DOMString& getData() const; - - void setData(const DOMString& theData); - - //Override "child manipulation" function since ProcessingInstruction Nodes - //can not have any children. - Node* insertBefore(Node* newChild, Node* refChild); - Node* replaceChild(Node* newChild, Node* oldChild); - Node* removeChild(Node* oldChild); - Node* appendChild(Node* newChild); - }; - - // - //Definition and Implementation of a Notation. Most functionality is inherrited - //from NodeDefinition. - // - class Notation : public NodeDefinition - { - public: - Notation(const DOMString& name, const DOMString& pubID, - const DOMString& sysID); - - const DOMString& getPublicId() const; - const DOMString& getSystemId() const; - - //Override "child manipulation" function since Notation Nodes - //can not have any children. - Node* insertBefore(Node* newChild, Node* refChild); - Node* replaceChild(Node* newChild, Node* oldChild); - Node* removeChild(Node* oldChild); - Node* appendChild(Node* newChild); - - private: - DOMString publicId; - DOMString systemId; - }; - - // - //Definition and Implementation of an Entity - // - class Entity : public NodeDefinition - { - public: - Entity(const DOMString& name, const DOMString& pubID, - const DOMString& sysID, const DOMString& notName); - - const DOMString& getPublicId() const; - const DOMString& getSystemId() const; - const DOMString& getNotationName() const; - - //Override insertBefore to limit Entity to having only certain nodes as - //children - Node* insertBefore(Node* newChild, Node* refChild); - - private: - DOMString publicId; - DOMString systemId; - DOMString notationName; - }; - - // - //Definition and Implementation of an EntityReference - // - class EntityReference : public NodeDefinition - { - public: - EntityReference(const DOMString& name, Document* owner); - - //Override insertBefore to limit EntityReference to having only certain - //nodes as children - Node* insertBefore(Node* newChild, Node* refChild); - }; - - // - //Definition and Implementation of the DocumentType - // - class DocumentType : public NodeDefinition - { - public: - DocumentType(const DOMString& name, NamedNodeMap* theEntities, - NamedNodeMap* theNotations); - ~DocumentType(); - - NamedNodeMap* getEntities(); - NamedNodeMap* getNotations(); - - //Override "child manipulation" function since Notation Nodes - //can not have any children. - Node* insertBefore(Node* newChild, Node* refChild); - Node* replaceChild(Node* newChild, Node* oldChild); - Node* removeChild(Node* oldChild); - Node* appendChild(Node* newChild); - - private: - NamedNodeMap* entities; - NamedNodeMap* notations; - }; - - //NULL string for use by Element::getAttribute() for when the attribute - //spcified by "name" does not exist, and therefore shoud be "NULL". - const DOMString NULL_STRING; - - #endif -