moved from source/dom

This commit is contained in:
kvisco%ziplink.net 2000-05-18 08:31:46 +00:00
parent 3e13714049
commit 392890ab2c
20 changed files with 2717 additions and 0 deletions

View File

@ -0,0 +1,143 @@
/*
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* The program provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* The Copyright owner will not be liable for any damages suffered by
* you as a result of using the Program. In no event will the Copyright
* owner be liable for any special, indirect or consequential damages or
* lost profits even if the Copyright owner has been advised of the
* possibility of their occurrence.
*
* Please see release.txt distributed with this file for more information.
*
*/
// Tom Kneeland (3/29/99)
//
// Implementation of the Document Object Model Level 1 Core
// Implementation of the Attr class
//
// Modification History:
// Who When What
// TK 03/29/99 Created
// LF 08/06/1999 fixed typo: defalut to default
//
#include "dom.h"
//
//Construct an Attribute object using the specified name and document owner
//
Attr::Attr(const DOMString& name, Document* owner):
NodeDefinition(Node::ATTRIBUTE_NODE, name, NULL_STRING, owner)
{
specified = MB_FALSE;
}
//
//Retrieve the name of the attribute from the nodeName data member
//
const DOMString& Attr::getName() const
{
return nodeName;
}
//
//Retrieve the specified flag
//
MBool Attr::getSpecified() const
{
return specified;
}
//
//Retrieve the value of the attribute. This is a comma-deliminated string
//representation of the Attribute's children.
//
const DOMString& Attr::getValue()
{
Int32 valueLoop;
nodeValue = NULL_STRING;
NodeList* childList = getChildNodes();
Int32 numChildren = childList->getLength();
for (valueLoop=0;valueLoop<numChildren;valueLoop++)
{
if (childList->item(valueLoop)->getNodeType() != Node::ENTITY_REFERENCE_NODE)
{
nodeValue.append(childList->item(valueLoop)->getNodeValue());
if (valueLoop < (numChildren-1))
nodeValue.append(",");
}
}
return nodeValue;
}
//
//Create a new Text node and add it to the Attribute's list of children. Also
//set the Specified flag to true.
//
void Attr::setValue(const DOMString& newValue)
{
NodeDefinition::DeleteChildren();
appendChild(getOwnerDocument()->createTextNode(newValue));
specified = MB_TRUE;
}
//
//Override the set node value member function to create a new TEXT node with
//the DOMString and to add it as the Attribute's child.
// NOTE: Not currently impemented, just execute the default setNodeValue
//
void Attr::setNodeValue(const DOMString& nodeValue)
{
setValue(nodeValue);
}
//
//Return a DOMString represening the value of this node. If the value is an
//Entity Reference then return the value of the reference. Otherwise, it is a
//simple conversion of the text value.
// NOTE: Not currently implemented, just execute the default getNodeValue
//
const DOMString& Attr::getNodeValue()
{
return getValue();
}
//
//First check to see if the new node is an allowable child for an Attr. If it
//is, call NodeDefinition's implementation of Insert Before. If not, return
//null as an error.
//
Node* Attr::insertBefore(Node* newChild, Node* refChild)
{
Node* returnVal = NULL;
switch (newChild->getNodeType())
{
case Node::TEXT_NODE :
case Node::ENTITY_REFERENCE_NODE:
returnVal = NodeDefinition::insertBefore(newChild, refChild);
if (returnVal)
specified = MB_TRUE;
break;
default:
returnVal = NULL;
}
return returnVal;
}

View File

@ -0,0 +1,64 @@
/*
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* The program provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* The Copyright owner will not be liable for any damages suffered by
* you as a result of using the Program. In no event will the Copyright
* owner be liable for any special, indirect or consequential damages or
* lost profits even if the Copyright owner has been advised of the
* possibility of their occurrence.
*
* Please see release.txt distributed with this file for more information.
*
*/
// Tom Kneeland (3/29/99)
//
// Implementation of the Document Object Model Level 1 Core
// Implementation of the CDATASection class
//
// Modification History:
// Who When What
// TK 03/29/99 Created
//
#include "dom.h"
//
//Construct a text object with the specified document owner and data
//
CDATASection::CDATASection(const DOMString& theData, Document* owner) :
Text(Node::CDATA_SECTION_NODE, "#cdata-section", theData, owner)
{
}
//
//CDATASection nodes can not have any children, so just return null from all child
//manipulation functions.
//
Node* CDATASection::insertBefore(Node* newChild, Node* refChild)
{
return NULL;
}
Node* CDATASection::replaceChild(Node* newChild, Node* oldChild)
{
return NULL;
}
Node* CDATASection::removeChild(Node* oldChild)
{
return NULL;
}
Node* CDATASection::appendChild(Node* newChild)
{
return NULL;
}

View File

@ -0,0 +1,113 @@
/*
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* The program provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* The Copyright owner will not be liable for any damages suffered by
* you as a result of using the Program. In no event will the Copyright
* owner be liable for any special, indirect or consequential damages or
* lost profits even if the Copyright owner has been advised of the
* possibility of their occurrence.
*
* Please see release.txt distributed with this file for more information.
*
*/
// Tom Kneeland (3/29/99)
//
// Implementation of the Document Object Model Level 1 Core
// Implementation of the CharacterData class
//
// Modification History:
// Who When What
// TK 03/29/99 Created
//
#include "dom.h"
//
//Protected constructor. Just pass parameters onto NodeDefinition.
//
CharacterData::CharacterData(NodeType type, const DOMString& name,
const DOMString& value, Document* owner) :
NodeDefinition(type, name, value, owner)
{
}
//
//Return a constant reference to the data stored by this object.
//
const DOMString& CharacterData::getData() const
{
return nodeValue;
}
//
//Set the data stored by this object to the string represented by "source".
//
void CharacterData::setData(const DOMString& source)
{
nodeValue = source;
}
//
//Returns the length of the data object.
//
Int32 CharacterData::getLength() const
{
return nodeValue.length();
}
//
//Retreive the substring starting at offset anc ending count number of
//characters away.
// NOTE: An empty string will be returned in the event of an error.
//
DOMString& CharacterData::substringData(Int32 offset, Int32 count, DOMString& dest)
{
if ((offset >= 0) && (offset < nodeValue.length()) && (count > 0))
return nodeValue.subString(offset, offset+count, dest);
else
{
dest.clear();
return dest;
}
}
void CharacterData::appendData(const DOMString& arg)
{
nodeValue.append(arg);
}
void CharacterData::insertData(Int32 offset, const DOMString& arg)
{
if ((offset >= 0) && (offset < nodeValue.length()))
nodeValue.insert(offset, arg);
}
void CharacterData::deleteData(Int32 offset, Int32 count)
{
if ((offset >= 0) && (offset < nodeValue.length()) && (count > 0))
nodeValue.deleteChars(offset, count);
}
void CharacterData::replaceData(Int32 offset, Int32 count, const DOMString& arg)
{
DOMString tempString;
if ((offset >= 0) && (offset < nodeValue.length()) && (count > 0))
{
if (count < arg.length())
{
tempString = arg.subString(0, count, tempString);
nodeValue.replace(offset, tempString);
}
else
nodeValue.replace(offset, arg);
}
}

View File

@ -0,0 +1,64 @@
/*
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* The program provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* The Copyright owner will not be liable for any damages suffered by
* you as a result of using the Program. In no event will the Copyright
* owner be liable for any special, indirect or consequential damages or
* lost profits even if the Copyright owner has been advised of the
* possibility of their occurrence.
*
* Please see release.txt distributed with this file for more information.
*
*/
// Tom Kneeland (3/29/99)
//
// Implementation of the Document Object Model Level 1 Core
// Implementation of the Comment class
//
// Modification History:
// Who When What
// TK 03/29/99 Created
//
#include "dom.h"
//
//Construct a text object with the specified document owner and data
//
Comment::Comment(const DOMString& theData, Document* owner) :
CharacterData(Node::COMMENT_NODE, "#comment", theData, owner)
{
}
//
//Comment nodes can not have any children, so just return null from all child
//manipulation functions.
//
Node* Comment::insertBefore(Node* newChild, Node* refChild)
{
return NULL;
}
Node* Comment::replaceChild(Node* newChild, Node* oldChild)
{
return NULL;
}
Node* Comment::removeChild(Node* oldChild)
{
return NULL;
}
Node* Comment::appendChild(Node* newChild)
{
return NULL;
}

View File

@ -0,0 +1,56 @@
/*
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* The program provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* The Copyright owner will not be liable for any damages suffered by
* you as a result of using the Program. In no event will the Copyright
* owner be liable for any special, indirect or consequential damages or
* lost profits even if the Copyright owner has been advised of the
* possibility of their occurrence.
*
* Please see release.txt distributed with this file for more information.
*
*/
// Tom Kneeland (3/29/99)
//
// Implementation of the Document Object Model Level 1 Core
// Implementation of the DOMImplementation class
//
// Modification History:
// Who When What
// TK 03/29/99 Created
//
#include "dom.h"
DOMImplementation::DOMImplementation()
{
implFeature = "XML";
implVersion = "1.0";
}
DOMImplementation::~DOMImplementation()
{
}
//
//Perform a case insensitive comparison between "feature" and the
//functionality of this DOM implementation/version.
//
MBool DOMImplementation::hasFeature(DOMString feature,
const DOMString& version) const
{
feature.toUpperCase();
if (feature.isEqual(implFeature) && version.isEqual(implVersion))
return MB_TRUE;
else
return MB_FALSE;
}

View File

@ -0,0 +1,258 @@
/*
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* The program provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* The Copyright owner will not be liable for any damages suffered by
* you as a result of using the Program. In no event will the Copyright
* owner be liable for any special, indirect or consequential damages or
* lost profits even if the Copyright owner has been advised of the
* possibility of their occurrence.
*
* Please see release.txt distributed with this file for more information.
*
*/
// Tom Kneeland (3/29/99)
//
// Implementation of the Document Object Model Level 1 Core
// Implementation of the Document class
//
// Modification History:
// Who When What
// TK 03/29/99 Created
// LF 08/06/1999 Removed Default argument initializer from
// Document() constructor
// LF 08/06/1999 fixed typo: defalut to default
//
#include "dom.h"
//
//Construct a Document. Currently no parameters are required, but the the
//node constructor is called to identify the node type.
//
Document::Document(DocumentType* theDoctype) :
NodeDefinition(Node::DOCUMENT_NODE, "#document", NULL_STRING, NULL)
{
documentElement = NULL;
doctype = theDoctype;
}
//
//Return the one and only element for this document
//
Element* Document::getDocumentElement()
{
return documentElement;
}
//
//Return the document type of this document object
//
DocumentType* Document::getDoctype()
{
return doctype;
}
//
//Return a constant reference to the DOM's Implementation
//
const DOMImplementation& Document::getImplementation()
{
return implementation;
}
//
//Ensure that no Element node is inserted if the document already has an
//associated Element child.
//
Node* Document::insertBefore(Node* newChild, Node* refChild)
{
Node* returnVal = NULL;
NodeDefinition* pCurrentNode = NULL;
NodeDefinition* pNextNode = NULL;
//Convert to a NodeDefinition Pointer
NodeDefinition* pNewChild = (NodeDefinition*)newChild;
NodeDefinition* pRefChild = (NodeDefinition*)refChild;
//Check to see if the reference node is a child of this node
if ((refChild != NULL) && (pRefChild->getParentNode() != this))
return NULL;
switch (pNewChild->getNodeType())
{
case Node::DOCUMENT_FRAGMENT_NODE :
pCurrentNode = (NodeDefinition*)pNewChild->getFirstChild();
while (pCurrentNode)
{
pNextNode = (NodeDefinition*)pCurrentNode->getNextSibling();
//Make sure that if the current node is an Element, the document
//doesn't already have one.
if ((pCurrentNode->getNodeType() != Node::ELEMENT_NODE) ||
((pCurrentNode->getNodeType() == Node::ELEMENT_NODE) &&
(documentElement == NULL)))
{
pCurrentNode = (NodeDefinition*)pNewChild->removeChild(pCurrentNode);
implInsertBefore(pCurrentNode, pRefChild);
if (pCurrentNode->getNodeType() == Node::ELEMENT_NODE)
documentElement = (Element*)pCurrentNode;
}
pCurrentNode = pNextNode;
}
returnVal = newChild;
break;
case Node::PROCESSING_INSTRUCTION_NODE :
case Node::COMMENT_NODE :
case Node::DOCUMENT_TYPE_NODE :
returnVal = implInsertBefore(pNewChild, pRefChild);
break;
case Node::ELEMENT_NODE :
if (!documentElement)
{
documentElement = (Element*)pNewChild;
returnVal = implInsertBefore(pNewChild, pRefChild);
}
else
returnVal = NULL;
break;
default:
returnVal = NULL;
}
return returnVal;
}
//
//Ensure that if the newChild is an Element and the Document already has an
//element, then oldChild should be specifying the existing element. If not
//then the replacement can not take place.
//
Node* Document::replaceChild(Node* newChild, Node* oldChild)
{
Node* replacedChild = NULL;
if (newChild->getNodeType() != Node::ELEMENT_NODE)
{
//The new child is not an Element, so perform replacement
replacedChild = NodeDefinition::replaceChild(newChild, oldChild);
//If old node was an Element, then the document's element has been
//replaced with a non-element node. Therefore clear the documentElement
//pointer
if (replacedChild && (oldChild->getNodeType() == Node::ELEMENT_NODE))
documentElement = NULL;
return replacedChild;
}
else
{
//A node is being replaced with an Element. If the document does not
//have an elemet yet, then just allow the replacemetn to take place.
if (!documentElement)
replacedChild = NodeDefinition::replaceChild(newChild, oldChild);
else if (oldChild->getNodeType() == Node::ELEMENT_NODE)
replacedChild = NodeDefinition::replaceChild(newChild, oldChild);
if (replacedChild)
documentElement = (Element*)newChild;
return replacedChild;
}
}
//
//Update the documentElement pointer if the associated Element node is being
//removed.
//
Node* Document::removeChild(Node* oldChild)
{
Node* removedChild = NULL;
removedChild = NodeDefinition::removeChild(oldChild);
if (removedChild && (removedChild->getNodeType() == Node::ELEMENT_NODE))
documentElement = NULL;
return removedChild;
}
//
//Construct an empty document fragment.
// NOTE: The caller is responsible for cleaning up this fragment's memory
// when it is no longer needed.
//
DocumentFragment* Document::createDocumentFragment()
{
return new DocumentFragment("#document-fragment", NULL_STRING, this);
}
//
//Construct an element with the specified tag name.
// NOTE: The caller is responsible for cleaning up the element's menory
//
Element* Document::createElement(const DOMString& tagName)
{
return new Element(tagName, this);
}
//
//Construct an attribute with the specified name
//
Attr* Document::createAttribute(const DOMString& name)
{
return new Attr(name, this);
}
//
//Construct a text node with the given data
//
Text* Document::createTextNode(const DOMString& theData)
{
return new Text(theData, this);
}
//
//Construct a comment node with the given data
//
Comment* Document::createComment(const DOMString& theData)
{
return new Comment(theData, this);
}
//
//Construct a CDATASection node with the given data
//
CDATASection* Document::createCDATASection(const DOMString& theData)
{
return new CDATASection(theData, this);
}
//
//Construct a ProcessingInstruction node with the given targe and data.
//
ProcessingInstruction*
Document::createProcessingInstruction(const DOMString& target,
const DOMString& data)
{
return new ProcessingInstruction(target, data, this);
}
//
//Construct an EntityReference with the given name
//
EntityReference* Document::createEntityReference(const DOMString& name)
{
return new EntityReference(name, this);
}

View File

@ -0,0 +1,68 @@
/*
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* The program provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* The Copyright owner will not be liable for any damages suffered by
* you as a result of using the Program. In no event will the Copyright
* owner be liable for any special, indirect or consequential damages or
* lost profits even if the Copyright owner has been advised of the
* possibility of their occurrence.
*
* Please see release.txt distributed with this file for more information.
*
*/
// Tom Kneeland (3/29/99)
//
// Implementation of the Document Object Model Level 1 Core
// Implementation of the DocumentFragment class
//
// Modification History:
// Who When What
// TK 03/29/99 Created
// LF 08/06/1999 fixed typo: defalut to default
//
#include "dom.h"
//
//Construct a DocumentFragment with the specified name and value. Call the
//constructor for NodeDefinition and specify the DocumentFragment Type.
//
DocumentFragment::DocumentFragment(const DOMString& name,
const DOMString& value, Document* owner) :
NodeDefinition(Node::DOCUMENT_FRAGMENT_NODE, name, value, owner)
{
}
//
//First check to see if the new node is an allowable child for a
//DocumentFragment. If it is, call NodeDefinition's implementation of Insert
//Before. If not, return null as an error.
//
Node* DocumentFragment::insertBefore(Node* newChild, Node* refChild)
{
Node* returnVal = NULL;
switch (newChild->getNodeType())
{
case Node::ELEMENT_NODE :
case Node::PROCESSING_INSTRUCTION_NODE :
case Node::COMMENT_NODE :
case Node::TEXT_NODE :
case Node::CDATA_SECTION_NODE :
case Node::ENTITY_REFERENCE_NODE:
returnVal = NodeDefinition::insertBefore(newChild, refChild);
break;
default:
returnVal = NULL;
}
return returnVal;
}

View File

@ -0,0 +1,96 @@
/*
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* The program provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* The Copyright owner will not be liable for any damages suffered by
* you as a result of using the Program. In no event will the Copyright
* owner be liable for any special, indirect or consequential damages or
* lost profits even if the Copyright owner has been advised of the
* possibility of their occurrence.
*
* Please see release.txt distributed with this file for more information.
*
*/
// Tom Kneeland (3/29/99)
//
// Implementation of the Document Object Model Level 1 Core
// Implementation of the DocumentType class
//
// Modification History:
// Who When What
// TK 03/29/99 Created
//
#include "dom.h"
//
//Construct a text object with the specified document owner and data
//
DocumentType::DocumentType(const DOMString& name, NamedNodeMap* theEntities,
NamedNodeMap* theNotations) :
NodeDefinition(Node::DOCUMENT_TYPE_NODE, name, NULL_STRING, NULL)
{
entities = theEntities;
notations = theNotations;
}
//
//When destroying the DocumentType, the entities and notations must be
//destroyed too.
//
DocumentType::~DocumentType()
{
if (entities)
delete entities;
if (notations)
delete notations;
}
//
//Return a pointer to the entities contained in this Document Type
//
NamedNodeMap* DocumentType::getEntities()
{
return entities;
}
//
//Return a pointer to the notations contained in this Document Type
//
NamedNodeMap* DocumentType::getNotations()
{
return notations;
}
//
//Comment nodes can not have any children, so just return null from all child
//manipulation functions.
//
Node* DocumentType::insertBefore(Node* newChild, Node* refChild)
{
return NULL;
}
Node* DocumentType::replaceChild(Node* newChild, Node* oldChild)
{
return NULL;
}
Node* DocumentType::removeChild(Node* oldChild)
{
return NULL;
}
Node* DocumentType::appendChild(Node* newChild)
{
return NULL;
}

View File

@ -0,0 +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()
{
}

View File

@ -0,0 +1,95 @@
/*
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* The program provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* The Copyright owner will not be liable for any damages suffered by
* you as a result of using the Program. In no event will the Copyright
* owner be liable for any special, indirect or consequential damages or
* lost profits even if the Copyright owner has been advised of the
* possibility of their occurrence.
*
* Please see release.txt distributed with this file for more information.
*
*/
// Tom Kneeland (3/29/99)
//
// Implementation of the Document Object Model Level 1 Core
// Implementation of the Entity class
//
// Modification History:
// Who When What
// TK 03/29/99 Created
// LF 08/06/1999 fixed typo: defalut to default
//
#include "dom.h"
//
//Construct a text object with the specified document owner and data
//
Entity::Entity(const DOMString& name, const DOMString& pubID,
const DOMString& sysID, const DOMString& notName) :
NodeDefinition(Node::ENTITY_NODE, name, NULL_STRING, NULL)
{
publicId = pubID;
systemId = sysID;
notationName = notName;
}
//
//Return the Public ID of the Entity
//
const DOMString& Entity::getPublicId() const
{
return publicId;
}
//
//Return the System ID of the Entity
//
const DOMString& Entity::getSystemId() const
{
return systemId;
}
//
//Return the Notation Name of the Entity
//
const DOMString& Entity::getNotationName() const
{
return notationName;
}
//
//First check to see if the new node is an allowable child for an Entity. If
//it is, call NodeDefinition's implementation of Insert Before. If not, return
//null as an error.
//
Node* Entity::insertBefore(Node* newChild, Node* refChild)
{
Node* returnVal = NULL;
switch (newChild->getNodeType())
{
case Node::ELEMENT_NODE:
case Node::PROCESSING_INSTRUCTION_NODE:
case Node::COMMENT_NODE:
case Node::TEXT_NODE :
case Node::CDATA_SECTION_NODE:
case Node::ENTITY_REFERENCE_NODE:
returnVal = NodeDefinition::insertBefore(newChild, refChild);
break;
default:
returnVal = NULL;
}
return returnVal;
}

View File

@ -0,0 +1,66 @@
/*
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* The program provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* The Copyright owner will not be liable for any damages suffered by
* you as a result of using the Program. In no event will the Copyright
* owner be liable for any special, indirect or consequential damages or
* lost profits even if the Copyright owner has been advised of the
* possibility of their occurrence.
*
* Please see release.txt distributed with this file for more information.
*
*/
// Tom Kneeland (3/29/99)
//
// Implementation of the Document Object Model Level 1 Core
// Implementation of the EntityReference class
//
// Modification History:
// Who When What
// TK 03/29/99 Created
// LF 08/06/1999 fixed typo: defalut to default
//
#include "dom.h"
//
//Construct a text object with the specified document owner and data
//
EntityReference::EntityReference(const DOMString& name, Document* owner) :
NodeDefinition(Node::ENTITY_REFERENCE_NODE, name, NULL_STRING, owner)
{
}
//
//First check to see if the new node is an allowable child for an
//EntityReference. If it is, call NodeDefinition's implementation of Insert
//Before. If not, return null as an error.
//
Node* EntityReference::insertBefore(Node* newChild, Node* refChild)
{
Node* returnVal = NULL;
switch (newChild->getNodeType())
{
case Node::ELEMENT_NODE:
case Node::PROCESSING_INSTRUCTION_NODE:
case Node::COMMENT_NODE:
case Node::TEXT_NODE :
case Node::CDATA_SECTION_NODE:
case Node::ENTITY_REFERENCE_NODE:
returnVal = NodeDefinition::insertBefore(newChild, refChild);
break;
default:
returnVal = NULL;
}
return returnVal;
}

View File

@ -0,0 +1,81 @@
#ifndef PROJ_PATH
BASE_PATH = ../../base
DOM_PATH = .
#endif
INCLUDE_PATHS = -I$(BASE_PATH) -I. -I-
CC := $(CC) -g $(INCLUDE_PATHS)
DOM_OBJS = NodeDefinition.o \
Document.o \
DocumentFragment.o \
NamedNodeMap.o \
NodeListDefinition.o \
Element.o \
Attr.o \
CharacterData.o \
Text.o \
Comment.o \
CDATASection.o \
ProcessingInstruction.o \
Notation.o \
Entity.o \
EntityReference.o \
DocumentType.o \
DOMImplementation.o
target: $(DOM_OBJS)
NodeDefinition.o: NodeDefinition.cpp dom.h
$(CC) -c NodeDefinition.cpp
Document.o: Document.cpp dom.h
$(CC) -c Document.cpp
DocumentFragment.o: DocumentFragment.cpp dom.h
$(CC) -c DocumentFragment.cpp
NamedNodeMap.o: NamedNodeMap.cpp dom.h
$(CC) -c NamedNodeMap.cpp
NodeListDefinition.o: NodeListDefinition.cpp dom.h
$(CC) -c NodeListDefinition.cpp
Element.o: Element.cpp dom.h
$(CC) -c Element.cpp
Attr.o: Attr.cpp dom.h
$(CC) -c Attr.cpp
CharacterData.o: CharacterData.cpp dom.h
$(CC) -c CharacterData.cpp
Text.o: Text.cpp dom.h
$(CC) -c Text.cpp
Comment.o: Comment.cpp dom.h
$(CC) -c Comment.cpp
CDATASection.o: CDATASection.cpp dom.h
$(CC) -c CDATASection.cpp
ProcessingInstruction.o: ProcessingInstruction.cpp dom.h
$(CC) -c ProcessingInstruction.cpp
Notation.o: Notation.cpp dom.h
$(CC) -c Notation.cpp
Entity.o: Entity.cpp dom.h
$(CC) -c Entity.cpp
EntityReference.o: EntityReference.cpp dom.h
$(CC) -c EntityReference.cpp
DocumentType.o: DocumentType.cpp dom.h
$(CC) -c DocumentType.cpp
DOMImplementation.o: DOMImplementation.cpp dom.h
$(CC) -c DOMImplementation.cpp

View File

@ -0,0 +1,111 @@
/*
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* The program provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* The Copyright owner will not be liable for any damages suffered by
* you as a result of using the Program. In no event will the Copyright
* owner be liable for any special, indirect or consequential damages or
* lost profits even if the Copyright owner has been advised of the
* possibility of their occurrence.
*
* Please see release.txt distributed with this file for more information.
*
*/
// Tom Kneeland (3/29/99)
//
// Implementation of the Document Object Model Level 1 Core
// Implementation of the NamedNodeMap class
//
// Modification History:
// Who When What
// TK 03/29/99 Created
//
#include "dom.h"
NamedNodeMap::NamedNodeMap()
{
}
NamedNodeMap::~NamedNodeMap()
{
}
Node* NamedNodeMap::getNamedItem(const DOMString& name)
{
ListItem* pSearchItem = findListItemByName(name);
if (pSearchItem)
return pSearchItem->node;
else
return NULL;
}
Node* NamedNodeMap::setNamedItem(Node* arg)
{
//Since the DOM does not specify any ording for the NamedNodeMap, just
//try and remove the new node (arg). If successful, return a pointer to
//the removed item. Reguardless of wheter the node already existed or not,
//insert the new node at the end of the list.
Node* pReplacedNode = removeNamedItem(arg->getNodeName());
NodeListDefinition::append(arg);
return pReplacedNode;
}
Node* NamedNodeMap::removeNamedItem(const DOMString& name)
{
NodeListDefinition::ListItem* pSearchItem;
Node* returnNode;
pSearchItem = findListItemByName(name);
if (pSearchItem)
{
if (pSearchItem != firstItem)
pSearchItem->prev->next = pSearchItem->next;
else
firstItem = pSearchItem->next;
if (pSearchItem != lastItem)
pSearchItem->next->prev = pSearchItem->prev;
else
lastItem = pSearchItem->prev;
pSearchItem->next = NULL;
pSearchItem->prev = NULL;
length--;
returnNode = pSearchItem->node;
delete pSearchItem;
return returnNode;
}
return NULL;
}
NodeListDefinition::ListItem*
NamedNodeMap::findListItemByName(const DOMString& name)
{
NodeListDefinition::ListItem* pSearchItem = firstItem;
while (pSearchItem)
{
if (name.isEqual(pSearchItem->node->getNodeName()))
return pSearchItem;
pSearchItem = pSearchItem->next;
}
return NULL;
}

View File

@ -0,0 +1,356 @@
/*
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* The program provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* The Copyright owner will not be liable for any damages suffered by
* you as a result of using the Program. In no event will the Copyright
* owner be liable for any special, indirect or consequential damages or
* lost profits even if the Copyright owner has been advised of the
* possibility of their occurrence.
*
* Please see release.txt distributed with this file for more information.
*
*/
// Tom Kneeland (3/29/99)
//
// Implementation of the Document Object Model Level 1 Core
// Implementation of the NodeDefinition Class
//
// Modification History:
// Who When What
// TK 03/29/99 Created
//
#include "dom.h"
NodeDefinition::NodeDefinition(NodeType type, const DOMString& name,
const DOMString& value, Document* owner)
{
nodeName = name;
nodeValue = value;
nodeType = type;
parentNode = NULL;
previousSibling = NULL;
nextSibling = NULL;;
firstChild = NULL;
lastChild = NULL;
ownerDocument = owner;
length = 0;
}
//
// This node is being destroyed, so loop through and destroy all the children.
// Also, destroy all attributes stored in the attributes NamedNodeMap.
//
NodeDefinition::~NodeDefinition()
{
Int32 numAttributes = attributes.getLength();
Int32 killAttrLoop;
DeleteChildren();
for (killAttrLoop=0;killAttrLoop<numAttributes;killAttrLoop++)
delete attributes.removeNamedItem(attributes.item(0)->getNodeName());
}
//
//Remove and delete all children of this node
//
void NodeDefinition::DeleteChildren()
{
NodeDefinition* pCurrent = firstChild;
NodeDefinition* pDestroyer;
while (pCurrent)
{
pDestroyer = pCurrent;
pCurrent = pCurrent->nextSibling;
delete pDestroyer;
}
length = 0;
firstChild = NULL;
lastChild = NULL;
}
const DOMString& NodeDefinition::getNodeName() const
{
return nodeName;
}
const DOMString& NodeDefinition::getNodeValue() const
{
return nodeValue;
}
const DOMString& NodeDefinition::getNodeValue()
{
return nodeValue;
}
unsigned short NodeDefinition::getNodeType() const
{
return nodeType;
}
Node* NodeDefinition::getParentNode() const
{
return parentNode;
}
NodeList* NodeDefinition::getChildNodes()
{
return this;
}
Node* NodeDefinition::getFirstChild() const
{
return firstChild;
}
Node* NodeDefinition::getLastChild() const
{
return lastChild;
}
Node* NodeDefinition::getPreviousSibling() const
{
return previousSibling;
}
Node* NodeDefinition::getNextSibling() const
{
return nextSibling;
}
NamedNodeMap* NodeDefinition::getAttributes()
{
return &attributes;
}
Document* NodeDefinition::getOwnerDocument() const
{
return ownerDocument;
}
Node* NodeDefinition::item(Int32 index)
{
Int32 selectLoop;
NodeDefinition* pSelectNode = firstChild;
if (index < length)
{
for (selectLoop=0;selectLoop<index;selectLoop++)
pSelectNode = pSelectNode->nextSibling;
return pSelectNode;
}
return NULL;
}
Int32 NodeDefinition::getLength()
{
return length;
}
void NodeDefinition::setNodeValue(const DOMString& newNodeValue)
{
nodeValue = newNodeValue;
}
//
//Insert the "newChild" node before the "refChild" node. Return a pointer to
//the inserted child. If the node to insert is a document fragment, then
//insert each child of the document fragment, and return the document fragment
//which should be empty if all the inserts suceeded.
//This function's responsibility is to check for and handle document fragments
//vs. plain nodes.
// *** NOTE: Need to check the document types before inserting.
//
// The decision to return the possibly empty document fragment
// was an implementation choice. The spec did not dictate what
// whould occur.
//
Node* NodeDefinition::insertBefore(Node* newChild,
Node* refChild)
{
NodeDefinition* pCurrentNode = NULL;
NodeDefinition* pNextNode = NULL;
//Convert to a NodeDefinition Pointer
NodeDefinition* pNewChild = (NodeDefinition*)newChild;
NodeDefinition* pRefChild = (NodeDefinition*)refChild;
//Check to see if the reference node is a child of this node
if ((refChild != NULL) && (pRefChild->parentNode != this))
return NULL;
if (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;
}

View File

@ -0,0 +1,117 @@
/*
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* The program provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* The Copyright owner will not be liable for any damages suffered by
* you as a result of using the Program. In no event will the Copyright
* owner be liable for any special, indirect or consequential damages or
* lost profits even if the Copyright owner has been advised of the
* possibility of their occurrence.
*
* Please see release.txt distributed with this file for more information.
*
*/
// Tom Kneeland (3/29/99)
//
// Implementation of the Document Object Model Level 1 Core
// Implementation of the NodeListDefinition class
//
// Modification History:
// Who When What
// TK 03/29/99 Created
//
#include "dom.h"
//
//Create an empty node list.
//
NodeListDefinition::NodeListDefinition()
{
firstItem = NULL;
lastItem = NULL;
length = 0;
}
//
//Free up the memory used by the List of Items. Don't delete the actual nodes
//though.
//
NodeListDefinition::~NodeListDefinition()
{
ListItem* pDeleteItem;
ListItem* pListTraversal = firstItem;
while (pListTraversal)
{
pDeleteItem = pListTraversal;
pListTraversal = pListTraversal->next;
delete pDeleteItem;
}
}
//
//Create a new ListItem, point it to the newNode, and append it to the current
//list of nodes.
//
void NodeListDefinition::append(Node* newNode)
{
append(*newNode);
}
void NodeListDefinition::append(Node& newNode)
{
ListItem* newListItem = new ListItem;
// Setup the new list item
newListItem->node = &newNode;
newListItem->prev = lastItem;
newListItem->next = NULL;
//Append the list item
if (lastItem)
lastItem->next = newListItem;
lastItem = newListItem;
//Adjust firstItem if this new item is being added to an empty list
if (!firstItem)
firstItem = lastItem;
//Need to increment the length of the list. Inherited from NodeList
length++;
}
//
// Return the Node contained in the item specified
//
Node* NodeListDefinition::item(Int32 index)
{
Int32 selectLoop;
ListItem* pListItem = firstItem;
if (index < length)
{
for (selectLoop=0;selectLoop<index;selectLoop++)
pListItem = pListItem->next;
return pListItem->node;
}
return NULL;
}
//
// Return the number of items in the list
//
Int32 NodeListDefinition::getLength()
{
return length;
}

View File

@ -0,0 +1,81 @@
/*
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* The program provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* The Copyright owner will not be liable for any damages suffered by
* you as a result of using the Program. In no event will the Copyright
* owner be liable for any special, indirect or consequential damages or
* lost profits even if the Copyright owner has been advised of the
* possibility of their occurrence.
*
* Please see release.txt distributed with this file for more information.
*
*/
// Tom Kneeland (3/29/99)
//
// Implementation of the Document Object Model Level 1 Core
// Implementation of the Notation class
//
// Modification History:
// Who When What
// TK 03/29/99 Created
//
#include "dom.h"
//
//Construct a text object with the specified document owner and data
//
Notation::Notation(const DOMString& name, const DOMString& pubID,
const DOMString& sysID) :
NodeDefinition(Node::NOTATION_NODE, name, NULL_STRING, NULL)
{
publicId = pubID;
systemId = sysID;
}
//
//Return the Public ID of the Notation
//
const DOMString& Notation::getPublicId() const
{
return publicId;
}
//Return the System ID of the Notation
const DOMString& Notation::getSystemId() const
{
return systemId;
}
//
//Notation nodes can not have any children, so just return null from all child
//manipulation functions.
//
Node* Notation::insertBefore(Node* newChild, Node* refChild)
{
return NULL;
}
Node* Notation::replaceChild(Node* newChild, Node* oldChild)
{
return NULL;
}
Node* Notation::removeChild(Node* oldChild)
{
return NULL;
}
Node* Notation::appendChild(Node* newChild)
{
return NULL;
}

View File

@ -0,0 +1,93 @@
/*
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* The program provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* The Copyright owner will not be liable for any damages suffered by
* you as a result of using the Program. In no event will the Copyright
* owner be liable for any special, indirect or consequential damages or
* lost profits even if the Copyright owner has been advised of the
* possibility of their occurrence.
*
* Please see release.txt distributed with this file for more information.
*
*/
// Tom Kneeland (3/29/99)
//
// Implementation of the Document Object Model Level 1 Core
// Implementation of the ProcessingInstruction class
//
// Modification History:
// Who When What
// TK 03/29/99 Created
//
#include "dom.h"
//
//Construct a text object with the specified document owner and data
//
ProcessingInstruction::ProcessingInstruction(const DOMString& theTarget,
const DOMString& theData,
Document* owner) :
NodeDefinition(Node::PROCESSING_INSTRUCTION_NODE,
theTarget, theData, owner)
{
}
//
//Return the Target of the processing instruction. This is simply the
//nodeName.
//
const DOMString& ProcessingInstruction::getTarget() const
{
return nodeName;
}
//
//Return the Data of the processing instruction. This is simply the value
//of the node, "nodeValue"
//
const DOMString& ProcessingInstruction::getData() const
{
return nodeValue;
}
//
//Set the Data element of the processing instruction.
void ProcessingInstruction::setData(const DOMString& theData)
{
nodeValue = theData;
}
//
//ProcessingInstruction nodes can not have any children, so just return null
//from all child manipulation functions.
//
Node* ProcessingInstruction::insertBefore(Node* newChild, Node* refChild)
{
return NULL;
}
Node* ProcessingInstruction::replaceChild(Node* newChild, Node* oldChild)
{
return NULL;
}
Node* ProcessingInstruction::removeChild(Node* oldChild)
{
return NULL;
}
Node* ProcessingInstruction::appendChild(Node* newChild)
{
return NULL;
}

View File

@ -0,0 +1,93 @@
/*
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* The program provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* The Copyright owner will not be liable for any damages suffered by
* you as a result of using the Program. In no event will the Copyright
* owner be liable for any special, indirect or consequential damages or
* lost profits even if the Copyright owner has been advised of the
* possibility of their occurrence.
*
* Please see release.txt distributed with this file for more information.
*
*/
// Tom Kneeland (3/29/99)
//
// Implementation of the Document Object Model Level 1 Core
// Implementation of the Text class
//
// Modification History:
// Who When What
// TK 03/29/99 Created
//
#include "dom.h"
//
//Construct a text object with the specified document owner and data
//
Text::Text(const DOMString& theData, Document* owner) :
CharacterData(Node::TEXT_NODE, "#text", theData, owner)
{
}
//
//Protected constructor for children of the Text Class. Currently only
//CDATASection needs to use this function.
Text::Text(NodeType type, const DOMString& name, const DOMString& value,
Document* owner) :
CharacterData(type, name, value, owner)
{
}
//
//Split the text node at Offset into two siblings. Return a pointer to the new
//sibling.
//
Text* Text::splitText(Int32 offset)
{
Text* newTextSibling = NULL;
DOMString newData;
if ((offset >= 0) && (offset < nodeValue.length()))
{
newTextSibling = getOwnerDocument()->createTextNode(nodeValue.subString(offset, newData));
getParentNode()->insertBefore(newTextSibling, getNextSibling());
nodeValue.deleteChars(offset, nodeValue.length() - offset);
}
return newTextSibling;
}
//
//Text nodes can not have any children, so just return null from all child
//manipulation functions.
//
Node* Text::insertBefore(Node* newChild, Node* refChild)
{
return NULL;
}
Node* Text::replaceChild(Node* newChild, Node* oldChild)
{
return NULL;
}
Node* Text::removeChild(Node* oldChild)
{
return NULL;
}
Node* Text::appendChild(Node* newChild)
{
return NULL;
}

View File

@ -0,0 +1,574 @@
/*
* (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
//
// XXX HACK (Pvdb) This should be removed once the dom directories have been reorganized
#ifdef MOZILLA
#include "mozilladom.h"
#else
#ifndef MITRE_DOM
#define MITRE_DOM
#ifdef __BORLANDC__
#include <stdlib.h>
#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
#endif //MOZILLA

View File

@ -0,0 +1,26 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (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/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
DEPTH=..\..\..\..\..
DIRS=mozImpl
include <$(DEPTH)\config\rules.mak>