The implementation of the Mozilla DOM wrapper classes. testMozDOM.cpp is an

example of how to use/test the classes and makedom is a sample make file for
building the test app and all classes.
This commit is contained in:
tomk%mitre.org 2000-02-02 18:44:48 +00:00
parent 47a8eab4e9
commit 5eeb6cafd2
20 changed files with 3424 additions and 0 deletions

View File

@ -0,0 +1,174 @@
/*
* (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 (01/13/2000)
//
// Wrapper class to convert Mozilla's Attr Interface to TransforMIIX's Attr
// Interface.
//
// NOTE: The objects being wrapped are not deleted. It is assumed that they
// will be deleted when the actual ("real") Mozilla Document is
// destroyed
//
// Modification History:
// Who When What
//
#include "mozilladom.h"
//
//Construct an Attribute wrapper object using the specified nsIDOMAttr object
//
Attr::Attr(nsIDOMAttr* attr, Document* owner) : Node(attr, owner)
{
nsAttr = attr;
}
//
//Destroy the delegate nsIDOMAttr object
//
Attr::~Attr()
{
}
//
//Return the nsAttr data member to the caller.
//
nsIDOMAttr* Attr::getNSAttr()
{
return nsAttr;
}
void Attr::setNSObj(nsIDOMAttr* attr)
{
Node::setNSObj(attr);
nsAttr = attr;
}
//
//Retrieve the name of the attribute storing it in a MozillaString wrapper
//class. The wrapper is retrieved from the Document so it can be hashed. At
//this time no one else will use this hased object since it has been
//specifically created for the caller of this function, but at lease its
//memory managment is handled automatically. In the future, a more efficient
//implementation can be created based on the characters stored in the string
//or something.
// NOTE: We don't need to worry about memory management here since the
// MozillaString object will delete its nsString object automatically
// ( nsIDOMAttr::GetName(nsString&) )
//
const DOMString& Attr::getName()
{
nsString* name = new nsString();
if (nsAttr->GetName(*name) == NS_OK)
return *(ownerDocument->createDOMString(name));
else
{
//name won't be used, so delete it.
delete name;
return NULL_STRING;
}
}
//
//Retrieve the specified flag. ( nsIDOMAttr::GetSpecified(PRBool*) )
//
MBool Attr::getSpecified() const
{
MBool specified;
nsAttr->GetSpecified(&specified);
return specified;
}
//
//Retrieve the value of the attribute. See getName above for hashing info
//
const DOMString& Attr::getValue()
{
nsString* value = new nsString();
if (nsAttr->GetValue(*value) == NS_OK)
return *(ownerDocument->createDOMString(value));
else
{
//value is not needed so delete it.
delete value;
return NULL_STRING;
}
}
//
//Foward call to nsIDOMAttr::SetValue.
//
void Attr::setValue(const DOMString& newValue)
{
nsAttr->SetValue(newValue.getConstNSString());
}
//
//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,55 @@
/*
* (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 (02/01/2000)
//
// Implementation of the wrapper class to convert the Mozilla
// nsIDOMCDATASection interface into a TransforMIIX CDATASection interface.
//
// Modification History:
// Who When What
//
#include "mozilladom.h"
//
//Construct a text object with the specified document owner and data
//
CDATASection::CDATASection(nsIDOMCDATASection* cdataSection, Document* owner) :
Text(cdataSection, owner)
{
nsCDATASection = cdataSection;
}
//
//Destructor. Do nothing
//
CDATASection::~CDATASection()
{
}
//
//Use this object to wrap a different Mozilla Object
//
void CDATASection::setNSObj(nsIDOMCDATASection* cdataSection)
{
Text::setNSObj(cdataSection);
nsCDATASection = cdataSection;
}

View File

@ -0,0 +1,130 @@
/*
* (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 (02/01/2000)
//
// Implementation of the wrapper class to convert the nsIDOMCharacterData into
// a TransforMIIX CharacterData interface.
//
// Modification History:
// Who When What
//
#include "mozilladom.h"
//
//Protected constructor. Just pass parameters onto Node.
//
CharacterData::CharacterData(nsIDOMCharacterData* charData, Document* owner) :
Node(charData, owner)
{
nsCharacterData = charData;
}
//
//Destructor. Just do nothing
//
CharacterData::~CharacterData()
{
}
//
//Store a new nsIDOMCharacterData object for wrapping
//
void CharacterData::setNSObj(nsIDOMCharacterData* charData)
{
Node::setNSObj(charData);
nsCharacterData = charData;
}
//
//Retrieve the data from the Mozilla object, and wrap it appropriately
//
const DOMString& CharacterData::getData() const
{
nsString* data = new nsString();
if (nsCharacterData->GetData(*data) == NS_OK)
return *(ownerDocument->createDOMString(data));
else
{
//name won't be used, so delete it.
delete data;
return NULL_STRING;
}
}
//
//Set the data stored by this object to the string represented by "source".
//
void CharacterData::setData(const DOMString& source)
{
nsCharacterData->SetData(source.getConstNSString());
}
//
//Retrieve the length from the Mozilla object and return it to the caller
//
Int32 CharacterData::getLength() const
{
UInt32 length = 0;
nsCharacterData->GetLength(&length);
return length;
}
//
//Refer to the Mozilla Object for its substring, and return the result in
//the provided Mozilla String wrapper.
// NOTE: An empty string will be returned in the event of an error.
//
DOMString& CharacterData::substringData(Int32 offset, Int32 count,
DOMString& dest)
{
if (nsCharacterData->SubstringData(offset, count, dest.getNSString()) == NS_OK)
return dest;
else
{
dest.clear();
return dest;
}
}
void CharacterData::appendData(const DOMString& arg)
{
nsCharacterData->AppendData(arg.getConstNSString());
}
void CharacterData::insertData(Int32 offset, const DOMString& arg)
{
nsCharacterData->InsertData(offset, arg.getConstNSString());
}
void CharacterData::deleteData(Int32 offset, Int32 count)
{
nsCharacterData->DeleteData(offset, count);
}
void CharacterData::replaceData(Int32 offset, Int32 count, const DOMString& arg)
{
nsCharacterData->ReplaceData(offset, count, arg.getConstNSString());
}

View File

@ -0,0 +1,55 @@
/*
* (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 (02/01/2000)
//
// Implementation of the wrapper class to convert the Mozilla nsIDOMComment
// interface into a TransforMIIX Comment interface.
//
// Modification History:
// Who When What
//
#include "mozilladom.h"
//
//Construct a text object with the specified document owner and data
//
Comment::Comment(nsIDOMComment* comment, Document* owner) :
CharacterData(comment, owner)
{
nsComment = comment;
}
//
//Destructor. Do Nothing
//
Comment::~Comment()
{
}
//
//Wrap a differnt Mozilla object with this object
//
void Comment::setNSObj(nsIDOMComment* comment)
{
CharacterData::setNSObj(comment);
nsComment = comment;
}

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 (02/02/2000)
//
// Implementation of the wrapper class to convert a Mozilla
// nsIDOMDOMImplementation into a TransforMIIX DOMImplementation interface.
//
// Modification History:
// Who When What
//
#include "mozilladom.h"
DOMImplementation::DOMImplementation(nsIDOMDOMImplementation* domImpl,
Document* owner)
{
nsDOMImpl = domImpl;
ownerDocument = owner;
}
DOMImplementation::~DOMImplementation()
{
}
//
//Query the mozilla object for the requested feature, and return the
//result to the caller.
//
MBool DOMImplementation::hasFeature(const DOMString& feature,
const DOMString& version) const
{
MBool bHasFeature = MB_FALSE;
nsDOMImpl->HasFeature(feature.getConstNSString(), version.getConstNSString(),
&bHasFeature);
return bHasFeature;
}

View File

@ -0,0 +1,756 @@
/*
* (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 (01/18/2000)
//
// Implementation of the Mozilla Wrapper class for the Document Object.
//
// Modification History:
// Who When What
//
#include "mozilladom.h"
#include "iostream.h"
//
//Construct a Document Wrapper object without specificy a nsIDOMDocument
//object.
//
/*Document::Document() : Node()
{
}*/
//
//Construct a Document Wrapper object with a nsIDOMDocument object
//
Document::Document(nsIDOMDocument* document) : Node(document, this)
{
nsDocument = document;
}
//
//Clean up the private data members
//
Document::~Document()
{
}
//
//Provide an nsIDOMDocument object for wrapping
//
void Document::setNSObj(nsIDOMDocument* document)
{
Node::setNSObj(document);
nsDocument = document;
}
//
//Call nsIDOMDocument::GetDocumentElement to retreive the element for this
//document. Then call the createElement factory method to retreive an element
//wrapper for this object.
//
Element* Document::getDocumentElement()
{
nsIDOMElement* theElement = NULL;
Element* elemWrapper = NULL;
nsresult retval = 5;
if (nsDocument == NULL)
return NULL;
//retval = nsDocument->GetDocumentElement(&theElement);
//if (retval == NS_OK)
if ((retval = nsDocument->GetDocumentElement(&theElement)) == NS_OK)
{
cout << "Document::getDocumentElement - Mozilla Call ok" << endl;
return createElement(theElement);
}
else
{
cout << "Document::getDocumentElement - Mozilla Call not ok(" << hex <<retval << ")" << endl;
return NULL;
}
}
//
//Retrieve the DocumentType from nsIDOMDocument::GetDocType. Return it wrapped
//in the docType data member.
//
DocumentType* Document::getDoctype()
{
nsIDOMDocumentType* theDocType = NULL;
if (nsDocument == NULL)
return NULL;
if (nsDocument->GetDoctype(&theDocType) == NS_OK)
return createDocumentType(theDocType);
else
return NULL;
}
//
//Return a constant reference to the DOM's Implementation
//
DOMImplementation* Document::getImplementation()
{
nsIDOMDOMImplementation* theImpl = NULL;
if (nsDocument == NULL)
return NULL;
if (nsDocument->GetImplementation(&theImpl) == NS_OK)
return createDOMImplementation(theImpl);
else
return NULL;
}
//
// DEFFER this functionality to the NODE parent class
//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;
}
*/
//
// DEFFER this functionality to the NODE implementation
//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;
}
}
*/
//
// DEFFER this functionality to the NODE Implementation
//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;
}
*/
//
//Call the nsIDOMDocument::CreateDocumentFragment function, then create or
//retrieve a wrapper class for it.
//
DocumentFragment* Document::createDocumentFragment()
{
nsIDOMDocumentFragment* fragment = NULL;
if (nsDocument == NULL)
return NULL;
if (nsDocument->CreateDocumentFragment(&fragment) == NS_OK)
return createDocumentFragment(fragment);
else
return NULL;
}
//
//Check the wrapperHashTable for a preexisting wrapper object. If it does not
// exists, create one and store it in the hash table. If it does exist, simply
// return it to the caller.
//
DocumentFragment*
Document::createDocumentFragment(nsIDOMDocumentFragment* fragment)
{
DocumentFragment* docFragWrapper =
(DocumentFragment*)wrapperHashTable.retrieve((Int32)fragment);
if (!docFragWrapper)
{
docFragWrapper = new DocumentFragment(fragment, this);
wrapperHashTable.add(docFragWrapper, (Int32)fragment);
}
return docFragWrapper;
}
//
//Call the nsIDOMDocument::CreateElement function, and retrieve or create
//a wrapper object for it.
//
Element* Document::createElement(const DOMString& tagName)
{
nsIDOMElement* element = NULL;
if (nsDocument->CreateElement(tagName.getConstNSString(), &element) == NS_OK)
return createElement(element);
else
return NULL;
}
//
//Check the wrapperHashTable for a precreated wrapper object. If one exists,
//return it to the caller. If it doens't exist, create one, store it in the
//hash, and return it to the caller.
//
Element* Document::createElement(nsIDOMElement* element)
{
Element* elemWrapper = (Element*)wrapperHashTable.retrieve((Int32)element);
if (!elemWrapper)
{
elemWrapper = new Element(element, this);
wrapperHashTable.add(elemWrapper, (Int32)element);
}
return elemWrapper;
}
//
//Call the nsIDOMDocument::CreateAttribute function, then create or retrieve a
//wrapper object for it.
//
Attr* Document::createAttribute(const DOMString& name)
{
nsIDOMAttr* attr = NULL;
if (nsDocument == NULL)
return NULL;
if (nsDocument->CreateAttribute(name.getConstNSString(), &attr) == NS_OK)
return createAttribute(attr);
else
return NULL;
}
//
//Check the wrapperHashTable for a precreated object. If one exists, return it,
//else, create one, store it in the table, and return it.
//
Attr* Document::createAttribute(nsIDOMAttr* attr)
{
Attr* attrWrapper = (Attr*)wrapperHashTable.retrieve((Int32)attr);
if (!attrWrapper)
{
attrWrapper = new Attr(attr, this);
wrapperHashTable.add(attrWrapper, (Int32)attr);
}
return attrWrapper;
}
//
//Call the nsIDOMDocument::CreateTextNode function, then create, or retrieve a
//wrapper object for it.
//
Text* Document::createTextNode(const DOMString& theData)
{
nsIDOMText* text = NULL;
if (nsDocument == NULL)
return NULL;
if (nsDocument->CreateTextNode(theData.getConstNSString(), &text) == NS_OK)
return createTextNode(text);
else
return NULL;
}
//
//Check the wrapperHashTable to see if a precreated object exists. If it does
//then return it. Else, create a new one, insert it into the hash table, and
//then return it.
//
Text* Document::createTextNode(nsIDOMText* text)
{
Text* textWrapper = (Text*)wrapperHashTable.retrieve((Int32)text);
if (!textWrapper)
{
textWrapper = new Text(text, this);
wrapperHashTable.add(textWrapper, (Int32)text);
}
return textWrapper;
}
//
//Call the nsIDOMDocument::CreateComment function, then create or retrieve a
//wrapper object to return to the caller.
//
Comment* Document::createComment(const DOMString& theData)
{
nsIDOMComment* comment = NULL;
if (nsDocument == NULL)
return NULL;
if (nsDocument->CreateComment(theData.getConstNSString(), &comment) == NS_OK)
return createComment(comment);
else
return NULL;
}
//
//Check the wrapperHashTable for a precreated object to return to the caller.
//If one does not exist, create it, store it in the hash, and return it to the
//caller.
Comment* Document::createComment(nsIDOMComment* comment)
{
Comment* commentWrapper =
(Comment*)wrapperHashTable.retrieve((Int32)comment);
if (!commentWrapper)
{
commentWrapper = new Comment(comment, this);
wrapperHashTable.add(commentWrapper, (Int32)comment);
}
return commentWrapper;
}
//
//Call the nsIDOMDocument::CreateCDATASection function, then create or retrieve
//a wrapper object to return to the caller.
//
CDATASection* Document::createCDATASection(const DOMString& theData)
{
nsIDOMCDATASection* cdata = NULL;
if (nsDocument == NULL)
return NULL;
if (nsDocument->CreateCDATASection(theData.getConstNSString(), &cdata) ==
NS_OK)
return createCDATASection(cdata);
else
return NULL;
}
//
//Check to see if a precreated object exists in the wrapperHashTable. If so
//simply return it to the caller. If not, creat one, store it in the hash, and
//return it to the caller.
//
CDATASection* Document::createCDATASection(nsIDOMCDATASection* cdata)
{
CDATASection* cdataWrapper =
(CDATASection*)wrapperHashTable.retrieve((Int32)cdata);
if (!cdataWrapper)
{
cdataWrapper = new CDATASection(cdata, this);
wrapperHashTable.add(cdataWrapper, (Int32)cdata);
}
return cdataWrapper;
}
//
//Call the nsIDOMDocument::CreateProcessingInstruction function, then find or
//create a wrapper class to return to the caller.
//
ProcessingInstruction*
Document::createProcessingInstruction(const DOMString& target,
const DOMString& data)
{
nsIDOMProcessingInstruction* pi = NULL;
if (nsDocument == NULL)
return NULL;
if (nsDocument->CreateProcessingInstruction(target.getConstNSString(),
data.getConstNSString(), &pi) == NS_OK)
return createProcessingInstruction(pi);
else
return NULL;
}
//
//Check the wrapperHashTable for a precreated object. If one exists, return
//it to the caller. If not, create one, store it in the hash table, and then
//return it to the caller.
//
ProcessingInstruction*
Document::createProcessingInstruction(nsIDOMProcessingInstruction* pi)
{
ProcessingInstruction* piWrapper =
(ProcessingInstruction*)wrapperHashTable.retrieve((Int32)pi);
if (!piWrapper)
{
piWrapper = new ProcessingInstruction(pi, this);
wrapperHashTable.add(piWrapper, (Int32)pi);
}
return piWrapper;
}
//
//Call the nsIDOMDocument::CreateEntityReference function, then obtain a wrapper
//class to return to the user.
//
EntityReference* Document::createEntityReference(const DOMString& name)
{
nsIDOMEntityReference* entityRef = NULL;
if (nsDocument == NULL)
return NULL;
if (nsDocument->CreateEntityReference(name.getConstNSString(),
&entityRef) == NS_OK)
return createEntityReference(entityRef);
else
return NULL;
}
//
//Check the wrapperHashTable for a wrapper class. If one exists, simply return
//it to the caller. Else, create one, place it in the hash, and return it to
//the caller.
//
EntityReference*
Document::createEntityReference(nsIDOMEntityReference* entityRef)
{
EntityReference* entityWrapper = (EntityReference*)
wrapperHashTable.retrieve((Int32)entityRef);
if (!entityWrapper)
{
entityWrapper = new EntityReference(entityRef, this);
wrapperHashTable.add(entityWrapper, (Int32)entityRef);
}
return entityWrapper;
}
//
//Check the wrapperHashTable for a wrapper class. If one exists, simply return
//it to the caller. Else create one, place it in the hash table, and then return
//it to the caller.
Entity* Document::createEntity(nsIDOMEntity* entity)
{
Entity* entityWrapper = (Entity*)wrapperHashTable.retrieve((Int32) entity);
if (!entity)
{
entityWrapper = new Entity(entity, this);
wrapperHashTable.add(entityWrapper, (Int32)entity);
}
return entityWrapper;
}
//
//Factory function for creating and hashing generic Node wrapper classes.
//Check the wrapperHashTable to see if a wrapper object already exists. If it
//does then return it. If one does not exist, then creat one, hash it, and
//return it to the caller.
//
Node* Document::createNode(nsIDOMNode* node)
{
Node* nodeWrapper = (Node*)wrapperHashTable.retrieve((Int32)node);
if (!nodeWrapper)
{
nodeWrapper = new Node(node, this);
wrapperHashTable.add(nodeWrapper, (Int32)node);
}
return nodeWrapper;
}
//
//Factory function for creating and hashing a DOMString object. Note that it
//is specifically for wrapping nsString objects with MozillaString objects.
//Once the object is created it is stored in the hash table.
//
DOMString* Document::createDOMString(nsString* str)
{
DOMString* strWrapper = (DOMString*)wrapperHashTable.retrieve((Int32)str);
if (!strWrapper)
{
strWrapper = new DOMString(str);
wrapperHashTable.add(strWrapper, (Int32)str);
}
return strWrapper;
}
//
//Factory function for creating and hashing a Notation object.
//
Notation* Document::createNotation(nsIDOMNotation* notation)
{
Notation* notationWrapper =
(Notation*)wrapperHashTable.retrieve((Int32) notation);
if (!notationWrapper)
{
notationWrapper = new Notation(notation, this);
wrapperHashTable.add(notationWrapper, (Int32)notation);
}
return notationWrapper;
}
//
//Factory function for creating and hashing DOM Implementation objects
//
DOMImplementation*
Document::createDOMImplementation(nsIDOMDOMImplementation* impl)
{
DOMImplementation* implWrapper =
(DOMImplementation*)wrapperHashTable.retrieve((Int32)impl);
if (!implWrapper)
{
implWrapper = new DOMImplementation(impl, this);
wrapperHashTable.add(implWrapper, (Int32)impl);
}
return implWrapper;
}
//
//Factory function for creating and hashing DOM DocumentType objects.
//
DocumentType* Document::createDocumentType(nsIDOMDocumentType* doctype)
{
DocumentType* doctypeWrapper =
(DocumentType*)wrapperHashTable.retrieve((Int32)doctype);
if (!doctypeWrapper)
{
doctypeWrapper = new DocumentType(doctype, this);
wrapperHashTable.add(doctypeWrapper, (Int32)doctype);
}
return doctypeWrapper;
}
//
//Factory function for creating and hashing NodeList objects
//
NodeList* Document::createNodeList(nsIDOMNodeList* list)
{
NodeList* listWrapper = (NodeList*)wrapperHashTable.retrieve((Int32)list);
if (!listWrapper)
{
listWrapper = new NodeList(list, this);
wrapperHashTable.add(listWrapper, (Int32)list);
}
return listWrapper;
}
//
//Factory function for creating and hashing NamedNodeMap objects
//
NamedNodeMap* Document::createNamedNodeMap(nsIDOMNamedNodeMap* map)
{
NamedNodeMap* mapWrapper =
(NamedNodeMap*)wrapperHashTable.retrieve((Int32)map);
if (!mapWrapper)
{
mapWrapper = new NamedNodeMap(map, this);
wrapperHashTable.add(mapWrapper, (Int32)map);
}
return mapWrapper;
}
//
//Remove the specified hashed object from wrapperHashTable and return it to the
//caller.
//
MITREObject* Document::removeWrapper(Int32 hashValue)
{
return wrapperHashTable.remove(hashValue);
}
//
//Add the specified wrapper to the hash table using the specified hash value
//
void Document::addWrapper(MITREObject* obj, Int32 hashValue)
{
wrapperHashTable.add(obj, hashValue);
}
//
//Determine what kind of node this is, and create the appropriate wrapper for it
//
Node* Document::createWrapper(nsIDOMNode* node)
{
unsigned short nodeType = 0;
node->GetNodeType(&nodeType);
switch (nodeType)
{
case nsIDOMNode::ELEMENT_NODE:
return createElement((nsIDOMElement*)node);
break;
case nsIDOMNode::ATTRIBUTE_NODE:
return createAttribute((nsIDOMAttr*)node);
break;
case nsIDOMNode::TEXT_NODE:
return createTextNode((nsIDOMText*)node);
break;
case nsIDOMNode::CDATA_SECTION_NODE:
return createCDATASection((nsIDOMCDATASection*)node);
break;
case nsIDOMNode::COMMENT_NODE:
return createComment((nsIDOMComment*)node);
break;
case nsIDOMNode::ENTITY_REFERENCE_NODE:
return createEntityReference((nsIDOMEntityReference*)node);
break;
case nsIDOMNode::ENTITY_NODE:
return createEntity((nsIDOMEntity*)node);
break;
case nsIDOMNode::PROCESSING_INSTRUCTION_NODE:
return createProcessingInstruction((nsIDOMProcessingInstruction*)node);
break;
case nsIDOMNode::DOCUMENT_TYPE_NODE:
return createDocumentType((nsIDOMDocumentType*)node);
break;
case nsIDOMNode::DOCUMENT_FRAGMENT_NODE:
return createDocumentFragment((nsIDOMDocumentFragment*)node);
break;
case nsIDOMNode::NOTATION_NODE:
return createNotation((nsIDOMNotation*)node);
break;
default:
return createNode(node);
}
}

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 (02/02/2000)
//
// Implementation of the wrapper class to convert a Mozilla
// nsIDOMDocumentFragmetn into a TransforMIIX DocumentFragmet interface.
//
// Modification History:
// Who When What
//
#include "mozilladom.h"
//
//Construct a DocumentFragment wrapper using the given Mozilla Object and owning
//document.
//
DocumentFragment::DocumentFragment(nsIDOMDocumentFragment* docFragment,
Document* owner) : Node(docFragment, owner)
{
nsDocumentFragment = docFragment;
}
//
//Destructor. Do nothing.
//
DocumentFragment::~DocumentFragment()
{
}
//
//Use this object to wrap another Mozilla object.
//
void DocumentFragment::setNSObj(nsIDOMDocumentFragment* docFragment)
{
Node::setNSObj(docFragment);
nsDocumentFragment = docFragment;
}

View File

@ -0,0 +1,97 @@
/*
* (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 (02/02/2000)
//
// Implementation of the wrapper class to convert an nsIDOMDocumentType into a
// TransforMIIX DocumentType interface.
//
// Modification History:
// Who When What
//
#include "mozilladom.h"
//
//Construct a text object with the specified document owner and data
//
DocumentType::DocumentType(nsIDOMDocumentType* documentType, Document* owner):
Node(documentType, owner)
{
nsDocumentType = documentType;
}
//
//Destructor. Do nothing
//
DocumentType::~DocumentType()
{
}
//
//Use this wrapper object to wrap a different Mozilla object
//
void DocumentType::setNSObj(nsIDOMDocumentType* documentType)
{
Node::setNSObj(documentType);
nsDocumentType = documentType;
}
//
//Retrieve the name from the Mozilla object and wrap acordingly.
//
const DOMString& DocumentType::getName() const
{
nsString* name = new nsString();
if (nsDocumentType->GetName(*name) == NS_OK)
return *(ownerDocument->createDOMString(name));
else
{
delete name;
return NULL_STRING;
}
}
//
//Retrieve the entites from the Mozilla object and wrap acordingly.
//
NamedNodeMap* DocumentType::getEntities()
{
nsIDOMNamedNodeMap* tmpEntities = NULL;
if (nsDocumentType->GetEntities(&tmpEntities) == NS_OK)
return ownerDocument->createNamedNodeMap(tmpEntities);
else
return NULL;
}
//
//Retrieve the notations from the Mozilla object and wrap acordingly
//
NamedNodeMap* DocumentType::getNotations()
{
nsIDOMNamedNodeMap* notations = NULL;
if (nsDocumentType->GetNotations(&notations) == NS_OK)
return ownerDocument->createNamedNodeMap(notations);
else
return NULL;
}

View File

@ -0,0 +1,230 @@
/*
* (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 (01/18/2000)
//
// Implementation of the Element wrapper class
//
// NOTE: Return values that are references to DOMStrings are all hashed
// and maintained in the owning document's wrapper hash table.
// They will not necessarly be used by more than one caller, but
// at least their memory management is taken care of. This can be done
// because all MozillaStrings clean up their nsString object upon
// deletion.
//
// Modification History:
// Who When What
//
#include "mozilladom.h"
#include "iostream.h"
//
//Construct a new element wrapper simply storing the nsIDOMElement object
//
Element::Element(nsIDOMElement* element, Document* owner) : Node(element, owner)
{
nsElement = element;
}
//
//Default destructor for Element wrappers
//
Element::~Element()
{
}
//
//Store a new subject object for this wrapper
//
void Element::setNSObj(nsIDOMElement* element)
{
Node::setNSObj(element);
nsElement = element;
}
//
//First check to see if the new node is an allowable child for an Element. If
//it is, call NodeDefinition's implementation of Insert Before. If not, return
//null as an error
//
/*Node* Element::insertBefore(Node* newChild, Node* refChild)
{
Node* returnVal = NULL;
switch (newChild->getNodeType())
{
case Node::ELEMENT_NODE :
case Node::TEXT_NODE :
case Node::COMMENT_NODE :
case Node::PROCESSING_INSTRUCTION_NODE :
case Node::CDATA_SECTION_NODE :
case Node::ENTITY_REFERENCE_NODE:
returnVal = NodeDefinition::insertBefore(newChild, refChild);
break;
default:
returnVal = NULL;
}
return returnVal;
}*/
//
//Call nsIDOMElement::GetTagName to retrieve the tag name for this element.
//If the call complests successfully get a new DOMString wrapper from the
//owner document.
//
const DOMString& Element::getTagName()
{
nsString* tagName = new nsString();
if (nsElement->GetTagName(*tagName) == NS_OK)
return *(ownerDocument->createDOMString(tagName));
else
{
//tagName is not needed so destroy it.
delete tagName;
return NULL_STRING;
}
}
//
//Call nsIDOMElement::GetAttribute to retrieve value for the specified
//attribute. Defer to the owner document to request a new DOMString
//wrapper.
const DOMString& Element::getAttribute(const DOMString& name)
{
nsString* attrValue = new nsString();
if (nsElement->GetAttribute(name.getConstNSString(), *attrValue) == NS_OK)
return *(ownerDocument->createDOMString(attrValue));
else
{
delete attrValue;
return NULL_STRING;
}
}
//
//Call nsIDOMElement::SetAttribute to create a new attribute.
//
void Element::setAttribute(const DOMString& name, const DOMString& value)
{
nsElement->SetAttribute(name.getConstNSString(), value.getConstNSString());
}
//
//We need to make this call a bit more complicated than usual because we want
//to make sure we remove the attribute wrapper from the document
//wrapperHashTable.
//
void Element::removeAttribute(const DOMString& name)
{
nsIDOMAttr* attr = NULL;
Attr* attrWrapper = NULL;
//Frist, get the nsIDOMAttr object from the nsIDOMElement object
nsElement->GetAttributeNode(name.getConstNSString(), &attr);
//Second, remove the attribute wrapper object from the hash table if it is
//there. It might not be if the attribute was created using
//Element::setAttribute. If it was removed, then delete it.
attrWrapper = (Attr*)ownerDocument->removeWrapper((Int32)attr);
if (attrWrapper)
delete attrWrapper;
//Lastly, have the Mozilla ojbect remove the attribute
nsElement->RemoveAttribute(name.getConstNSString());
}
//
//Call nsIDOMElement::GetAttributeNode. If successful, refer to the owner
//document for an attribute wrapper class.
//
Attr* Element::getAttributeNode(const DOMString& name)
{
nsIDOMAttr* attr = NULL;
if (nsElement->GetAttributeNode(name.getConstNSString(), &attr) == NS_OK)
return ownerDocument->createAttribute(attr);
else
return NULL;
}
//
//Call nsIDOMElement::SetAttributeNode passing it the nsIDOMAttr object wrapped
//by the newAttr parameter.
//
Attr* Element::setAttributeNode(Attr* newAttr)
{
nsIDOMAttr* returnAttr = NULL;
if (nsElement->SetAttributeNode(newAttr->getNSAttr(), &returnAttr) == NS_OK)
return ownerDocument->createAttribute(returnAttr);
else
return NULL;
}
//
//Call nsIDOMElement::RemoveAttributeNode, then refer to the owner document to
//remove it from the hash. The caller is then responsible for destroying the
//wrappr.
// NOTE: Do we need to worry about the memory used by the wrapped
// Mozilla object?
//
Attr* Element::removeAttributeNode(Attr* oldAttr)
{
nsIDOMAttr* removedAttr = NULL;
Attr* attrWrapper = NULL;
if (nsElement->RemoveAttributeNode(oldAttr->getNSAttr(), &removedAttr) == NS_OK)
{
attrWrapper = (Attr*)ownerDocument->removeWrapper((Int32)removedAttr);
if (!attrWrapper)
attrWrapper = new Attr(removedAttr, ownerDocument);
return attrWrapper;
}
else
return NULL;
}
//
//Call nsIDOMElement::GetElementsByTagName. If successful, defer to the owning
//documet to produce a wrapper for this object.
NodeList* Element::getElementsByTagName(const DOMString& name)
{
nsIDOMNodeList* list = NULL;
if (nsElement->GetElementsByTagName(name.getConstNSString(), &list) == NS_OK)
return ownerDocument->createNodeList(list);
else
return NULL;
}
//
//Simply call nsIDOMElement::Normalize()
//
void Element::normalize()
{
nsElement->Normalize();
}

View File

@ -0,0 +1,104 @@
/*
* (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 (02/02/2000)
//
// Implementation of the wrapper class to convert a Mozilla nsIDOMEntity into
// a TransforMIIX Entity interface.
//
// Modification History:
// Who When What
//
#include "mozilladom.h"
//
//Construct an entity wrapper
//
Entity::Entity(nsIDOMEntity* entity, Document* owner) : Node (entity, owner)
{
nsEntity = entity;
}
//
//Destructor. Do nothing
//
Entity::~Entity()
{
}
//
//Wrap a different mozilla object
//
void Entity::setNSObj(nsIDOMEntity* entity)
{
Node::setNSObj(entity);
nsEntity = entity;
}
//
//Retrieve the public id from the mozilla object, and then retrieve the
//appropriate wrapper from the document.
//
const DOMString& Entity::getPublicId() const
{
nsString* publicId = new nsString();
if (nsEntity->GetPublicId(*publicId) == NS_OK)
return *(ownerDocument->createDOMString(publicId));
else
{
delete publicId;
return NULL_STRING;
}
}
//
//Retrieve the system id from the Mozilla object, and then wrap it appropriately
//
const DOMString& Entity::getSystemId() const
{
nsString* systemId = new nsString();
if (nsEntity->GetSystemId(*systemId) == NS_OK)
return *(ownerDocument->createDOMString(systemId));
else
{
delete systemId;
return NULL_STRING;
}
}
//
//Retrieve the notation name from the Mozilla object, and then wrap it
//appropriately
//
const DOMString& Entity::getNotationName() const
{
nsString* notationName = new nsString();
if (nsEntity->GetNotationName(*notationName) == NS_OK)
return *(ownerDocument->createDOMString(notationName));
else
{
delete notationName;
return NULL_STRING;
}
}

View File

@ -0,0 +1,55 @@
/*
* (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 (02/01/2000)
//
// Implementation for the wrapper class to convert the Mozilla
// nsIDOMEntityReference interface into a TransforMIIX EntityReference
//
// Modification History:
// Who When What
//
#include "mozilladom.h"
//
//Construct a text object with the specified document owner and data
//
EntityReference::EntityReference(nsIDOMEntityReference* entityReference,
Document* owner) : Node(entityReference, owner)
{
nsEntityReference = entityReference;
}
//
//Destructor. Do Nothing
//
EntityReference::~EntityReference()
{
}
//
//Use this object to wrap a different Mozilla object
//
void EntityReference::setNSObj(nsIDOMEntityReference* entityReference)
{
Node::setNSObj(entityReference);
nsEntityReference = entityReference;
}

View File

@ -0,0 +1,119 @@
/*
* (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 (1/31/2000)
//
// Wrapper class to convert a Mozilla nsIDOMNamedNodeMap into a TransforMIIX
// NamedNodeMap object.
//
// Modification History:
// Who When What
//
#include "mozilladom.h"
//
//Construct the wrapper object
//
NamedNodeMap::NamedNodeMap(nsIDOMNamedNodeMap* namedNodeMap, Document* owner)
{
nsNamedNodeMap = namedNodeMap;
ownerDocument = owner;
}
//
//Destroy the wrapper object leaving the nsIDOMNamedNodeMap object intact.
//
NamedNodeMap::~NamedNodeMap()
{
}
//
// Search for the Node using the specified name. If found, refer to the owning
// document for a wrapper for the returned nsIDOMNode obejct
// (nsIDOMNamedNodeMap::GetNamedItem)
//
Node* NamedNodeMap::getNamedItem(const DOMString& name)
{
nsIDOMNode* node = NULL;
if (nsNamedNodeMap->GetNamedItem(name.getConstNSString(), &node) == NS_OK)
return ownerDocument->createWrapper(node);
else
return NULL;
}
//
// Store the nsIDOMNode object wrapped by arg in the nsIDOMNamedNodeMap. If
// successful refer to the owning document for a wrapper for the resultant
// nsIDOMNode. (In theory this should produce exactly the same wrapper class
// as arg).
// (nsIDOMNamedNodeMap::SetNamedItem)
//
Node* NamedNodeMap::setNamedItem(Node* arg)
{
nsIDOMNode* node = NULL;
if (nsNamedNodeMap->SetNamedItem(arg->getNSObj(), &node) == NS_OK)
return ownerDocument->createWrapper(node);
else
return NULL;
}
//
// Remove the named item from the nsIDOMNamedNodeMap. If successful, refer to
// the owner documetn for a wrapper object for the result.
// (nsIDOMNamedNodeMap::removeNamedItem)
//
Node* NamedNodeMap::removeNamedItem(const DOMString& name)
{
nsIDOMNode* node = NULL;
if (nsNamedNodeMap->RemoveNamedItem(name.getConstNSString(), &node) == NS_OK)
return ownerDocument->createWrapper(node);
else
return NULL;
}
//
// Retrieve the Node specified by index, then ask the owning document to provide
// a wrapper object for it. ( nsIDOMNamedNodeMap::Item )
//
Node* NamedNodeMap::item(UInt32 index)
{
nsIDOMNode* node = NULL;
if (nsNamedNodeMap->Item(index, &node) == NS_OK)
return ownerDocument->createWrapper(node);
else
return NULL;
}
//
// Get the number of Nodes stored in this list (nsIDOMNamedNodeMap::GetLength())
//
UInt32 NamedNodeMap::getLength()
{
UInt32 length = 0;
nsNamedNodeMap->GetLength(&length);
return length;
}

View File

@ -0,0 +1,386 @@
/*
* (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)
//
// Wrapper class to convert Mozilla's Node Interface to TransforMIIX's Node
// Interface.
//
// NOTE: The objects being wrapped are not deleted. It is assumed that they
// will be deleted when the actual ("real") Mozilla Document is
// destroyed
//
// Also note that this object's parent Document provides the necessary
// factory functions for creating wrapper classes; such as:
//
//
// Modification History:
// Who When What
//
#include "mozilladom.h"
/*Node::Node()
{
ownerDocument = new Document();
nsNode = NULL;
}*/
Node::Node(nsIDOMNode* node, Document* owner)
{
ownerDocument = owner;
nsNode = node;
}
Node::~Node()
{
}
void Node::setNSObj(nsIDOMNode* node)
{
//First we must remove this wrapper from the document hash table since we
//don't want to be associated with the existing nsIDOM* object anymore
ownerDocument->removeWrapper((Int32)nsNode);
//Now assume control of the new node
nsNode = node;
//Finally, place our selves back in the hash table, using the new object
//as the hash value
ownerDocument->addWrapper(this, (Int32)node);
}
nsIDOMNode* Node::getNSObj()
{
return nsNode;
}
//
//Call nsIDOMNode::GetNodeName, store the results in the nodeName DOMString,
//and return it to the caller.
//
const DOMString& Node::getNodeName()
{
if (nsNode == NULL)
return NULL_STRING;
nsNode->GetNodeName(nodeName.getNSString());
return nodeName;
}
//
//Call nsIDOMNode::GetNodeValue, store the results in nodeValue, and
//return it to the caller.
//
const DOMString& Node::getNodeValue()
{
if (nsNode == NULL)
return NULL_STRING;
nsNode->GetNodeValue(nodeValue.getNSString());
return nodeValue;
}
//
//Call nsIDOMNode::GetNodeType passing it a temporary unsigned short. Then
//pass the value stored in that variable to the caller.
//
unsigned short Node::getNodeType() const
{
unsigned short nodeType;
if (nsNode == NULL)
return 0;
nsNode->GetNodeType(&nodeType);
return nodeType;
}
//
//Call nsIDOMNode::GetParentNode(nsIDOMNode**) passing it a handle to a
//nsIDOMNode. Store the returned nsIDOMNode in the parentNode wrapper object
//and return its address to the caller.
//
Node* Node::getParentNode()
{
nsIDOMNode* tmpParent = NULL;
if (nsNode == NULL)
return NULL;
if (nsNode->GetParentNode(&tmpParent) == NS_OK)
return ownerDocument->createWrapper(tmpParent);
else
return NULL;
}
//
//Call nsIDOMNode::GetChildNodes(nsIDOMNodeList**) passing it a handle to a
//nsIDOMNodeList. Defer to the owner document to produce a wrapper for this
//object.
//
NodeList* Node::getChildNodes()
{
nsIDOMNodeList* tmpNodeList = NULL;
if (nsNode == NULL)
return NULL;
if (nsNode->GetChildNodes(&tmpNodeList) == NS_OK)
return ownerDocument->createNodeList(tmpNodeList);
else
return NULL;
}
//
//Call nsIDOMNode::GetFirstChild(nsIDOMNode**) passing it a handle to a
//nsIDOMNode. Defer to the owner document to produce a wrapper for this object.
//
Node* Node::getFirstChild()
{
nsIDOMNode* tmpFirstChild = NULL;
if (nsNode == NULL)
return NULL;
if (nsNode->GetFirstChild(&tmpFirstChild) == NS_OK)
return ownerDocument->createWrapper(tmpFirstChild);
else
return NULL;
}
//
//Call nsIDOMNode::GetLastChild(nsIDOMNode**) passing it a handle to a
//nsIDOMNode. Defer to the owner document to produce a wrapper for this object.
//
Node* Node::getLastChild()
{
nsIDOMNode* tmpLastChild = NULL;
if (nsNode == NULL)
return NULL;
if (nsNode->GetLastChild(&tmpLastChild) == NS_OK)
return ownerDocument->createWrapper(tmpLastChild);
else
return NULL;
}
//
//Call nsIDOMNode::GetPreviousSibling(nsIDOMNode**) passing it a handle to a
//nsIDOMNode. Defer to the owner document to produce a wrapper for this object.
//
Node* Node::getPreviousSibling()
{
nsIDOMNode* tmpPrevSib = NULL;
if (nsNode == NULL)
return NULL;
if (nsNode->GetPreviousSibling(&tmpPrevSib) == NS_OK)
return ownerDocument->createWrapper(tmpPrevSib);
else
return NULL;
}
//
//Call nsIDOMNode::GetNextSibling(nsIDOMNode**) passing it a handle to a
//nsIDOMNode. Defer to the owner document to produce a wrapper for this object.
//
Node* Node::getNextSibling()
{
nsIDOMNode* tmpNextSib = NULL;
if (nsNode == NULL)
return NULL;
if (nsNode->GetNextSibling(&tmpNextSib) == NS_OK)
return ownerDocument->createWrapper(tmpNextSib);
else
return NULL;
}
//
//Call nsIDOMNode::GetAttributes(nsIDOMNamedNodeMap**) passing it a handle to a
//nsIDOMNamedNodeMap. Defer to the owner document to produce a wrapper for this
//object.
//
NamedNodeMap* Node::getAttributes()
{
nsIDOMNamedNodeMap* tmpAttributes = NULL;
if (nsNode == NULL)
return NULL;
if (nsNode->GetAttributes(&tmpAttributes) == NS_OK)
return ownerDocument->createNamedNodeMap(tmpAttributes);
else
return NULL;
}
//
//Call nsIDOMNode::GetOwnerDocument(nsIDOMDocument**) passing it a handle to a
//nsIDOMDocument. ????
//
Document* Node::getOwnerDocument()
{
/*nsIDOMDocument* tmpOwnerDoc = NULL;
if (nsNode == NULL)
return NULL;
nsNode->GetOwnerDocument(&tmpOwnerDoc);
ownerDocument->setNSObj(tmpOwnerDoc); */
return ownerDocument;
}
//
//Call nsIDOMNode::SetNodeValue(nsString*) passing it the nsString wrapped by
//the provided DOMString.
//
void Node::setNodeValue(const DOMString& newNodeValue)
{
if (nsNode != NULL)
nsNode->SetNodeValue(newNodeValue.getConstNSString());
}
//
//Retreive the nsIDOMNode objects wrapped by newChild and refChild and pass
//them to nsIDOMNode::InsertBefore(...). If the return value from InsertBefore
//is valid, retrieve or create a wrapper class for it from the owner document.
//This ensures there newChild is properly hashed (it should have been when it
//was created.)
//
Node* Node::insertBefore(Node* newChild,
Node* refChild)
{
nsIDOMNode* returnValue = NULL;
if (nsNode == NULL)
return NULL;
if (nsNode->InsertBefore(newChild->getNSObj(), refChild->getNSObj(),
&returnValue) == NS_OK)
return ownerDocument->createWrapper(returnValue);
else
return NULL;
}
//
//Retreive the nsIDOMNode objects wrapped by newChild and oldChild and pass
//them to nsIDOMNode::ReplaceChild(...). If the replace call success, then
//we want to remove the old child's wrapper object from the hash and return
//it to the caller. This ensures that when the caller deletes the memory,
//no hash conflicts occure when the address is reused.
//
Node* Node::replaceChild(Node* newChild,
Node* oldChild)
{
nsIDOMNode* returnValue = NULL;
if (nsNode == NULL)
return NULL;
if (nsNode->ReplaceChild(newChild->getNSObj(), oldChild->getNSObj(),
&returnValue) == NS_OK)
{
//We want to remove the wrapper class from the hash table, and return
//it to the caller.
return (Node*)ownerDocument->removeWrapper((Int32)returnValue);
}
else
return NULL;
}
//
//Retreive the nsIDOMNode object wrapped by oldChild and pass it to
//nsIDOMNode::RemoveChild(...). If the return value from RemoveChild
//is valid, then we want to remove the wrapper class from from the hash.
//
Node* Node::removeChild(Node* oldChild)
{
nsIDOMNode* returnValue = NULL;
if (nsNode == NULL)
return NULL;
if (nsNode->RemoveChild(oldChild->getNSObj(), &returnValue) == NS_OK)
return (Node*)ownerDocument->removeWrapper((Int32)returnValue);
else
return NULL;
}
//
//Retreive the nsIDOMNode object wrapped by newChild and pass it to
//nsIDOMNode::AppendChild(...). If the return value from AppendChild
//is valid, then goto the owner document for a wrapper object for the return
//value.
//
Node* Node::appendChild(Node* newChild)
{
nsIDOMNode* returnValue = NULL;
if (nsNode == NULL)
return NULL;
if (nsNode->AppendChild(newChild->getNSObj(), &returnValue) == NS_OK)
return ownerDocument->createWrapper(returnValue);
else
return NULL;
}
//
//Call nsIDOMNode::Clone to clone the node wrapped by this object. Simply
//take the returned node, and wrap it in dest.
//
Node* Node::cloneNode(MBool deep, Node* dest)
{
nsIDOMNode* returnValue = NULL;
if (nsNode == NULL)
return NULL;
if (nsNode->CloneNode(deep, &returnValue) == NS_OK)
{
dest->setNSObj(returnValue);
return dest;
}
else
return NULL;
}
MBool Node::hasChildNodes() const
{
PRBool returnValue;
if (nsNode == NULL)
return MB_FALSE;
nsNode->HasChildNodes(&returnValue);
return returnValue;
}

View File

@ -0,0 +1,77 @@
/*
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* The program provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* The Copyright owner will not be liable for any damages suffered by
* you as a result of using the Program. In no event will the Copyright
* owner be liable for any special, indirect or consequential damages or
* lost profits even if the Copyright owner has been advised of the
* possibility of their occurrence.
*
* Please see release.txt distributed with this file for more information.
*
*/
// Tom Kneeland (01/13/2000)
//
// Wrapper class to convert Mozilla's NodeList Interface to TransforMIIX's
// NodeList Interface.
//
// NOTE: The objects being wrapped are not deleted. It is assumed that they
// will be deleted when the actual ("real") Mozilla Document is
// destroyed
//
// Modification History:
// Who When What
//
#include "mozilladom.h"
//
// Construct a NodeList wrapper class to wrap the provided nsIDOMNodeList object
//
NodeList::NodeList(nsIDOMNodeList* nodeList, Document* owner)
{
nsNodeList = nodeList;
ownerDocument = owner;
}
//
// Destroy the NodeList wrapper class. Leave the mozilla object behind though.
//
NodeList::~NodeList()
{
}
//
// Retrieve the Node specified by index, then ask the owning document to provide
// a wrapper object for it. ( nsIDOMNodeList::Item )
//
Node* NodeList::item(UInt32 index)
{
nsIDOMNode* node = NULL;
if (nsNodeList->Item(index, &node) == NS_OK)
return ownerDocument->createWrapper(node);
else
return NULL;
}
//
// Get the number of Nodes stored in this list (nsIDOMNodeList::GetLength())
//
UInt32 NodeList::getLength()
{
UInt32 length = 0;
nsNodeList->GetLength(&length);
return length;
}

View File

@ -0,0 +1,87 @@
/*
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* The program provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* The Copyright owner will not be liable for any damages suffered by
* you as a result of using the Program. In no event will the Copyright
* owner be liable for any special, indirect or consequential damages or
* lost profits even if the Copyright owner has been advised of the
* possibility of their occurrence.
*
* Please see release.txt distributed with this file for more information.
*
*/
// Tom Kneeland (02/02/2000)
//
// Implementation of the wrapper class to convert a Mozilla nsIDOMNotation into
// a TransforMIIX Notation interface.
//
// Modification History:
// Who When What
//
#include "mozilladom.h"
//
//Construct a wrapper object using the provided mozilla object and document
//owner.
//
Notation::Notation(nsIDOMNotation* notation, Document* document) :
Node(notation, document)
{
nsNotation = notation;
}
//
//Destructor. Do Nothing
//
Notation::~Notation()
{
}
//
//Use this object to wrap another mozilla object
//
void Notation::setNSObj(nsIDOMNotation* notation)
{
Node::setNSObj(notation);
nsNotation = notation;
}
//
//Return the Public ID of the Notation
//
const DOMString& Notation::getPublicId() const
{
nsString* publicId = new nsString();
if (nsNotation->GetPublicId(*publicId) == NS_OK)
return *(ownerDocument->createDOMString(publicId));
else
{
delete publicId;
return NULL_STRING;
}
}
//Return the System ID of the Notation
const DOMString& Notation::getSystemId() const
{
nsString* systemId = new nsString();
if (nsNotation->GetSystemId(*systemId) == NS_OK)
return *(ownerDocument->createDOMString(systemId));
else
{
delete systemId;
return NULL_STRING;
}
}

View File

@ -0,0 +1,99 @@
/*
* (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 (02/02/2000)
//
// Implementation of the wrapper class to convert a
// Mozilla nsIDOMProcessingInstruction into a TransforMIIX ProcessingInstruction
// interface.
//
// Modification History:
// Who When What
//
#include "mozilladom.h"
//
//Construct a wrapper class for the given object and document
//
ProcessingInstruction::ProcessingInstruction(
nsIDOMProcessingInstruction* procInstr,
Document* owner) :
Node (procInstr, owner)
{
nsProcessingInstruction = procInstr;
}
//
//Destructor. Do nothing
//
ProcessingInstruction::~ProcessingInstruction()
{
}
//
//Wrap the new object in this wrapper
//
void ProcessingInstruction::setNSObj(nsIDOMProcessingInstruction* procInstr)
{
Node::setNSObj(procInstr);
nsProcessingInstruction = procInstr;
}
//
//Retrieve the Target from the Mozilla object, then wrap appropriately in
//a MozillaString wrapper.
//
const DOMString& ProcessingInstruction::getTarget() const
{
nsString* target = new nsString();
if (nsProcessingInstruction->GetTarget(*target) == NS_OK)
return *(ownerDocument->createDOMString(target));
else
{
delete target;
return NULL_STRING;
}
}
//
//Retrieve the data from the Mozilla object, then wrap appropriately in a
//MozillaString wrapper.
//
const DOMString& ProcessingInstruction::getData() const
{
nsString* data = new nsString();
if (nsProcessingInstruction->GetData(*data) == NS_OK)
return *(ownerDocument->createDOMString(data));
else
{
delete data;
return NULL_STRING;
}
}
//
//Pass the nsString wapped by theData to the Mozilla object.
void ProcessingInstruction::setData(const DOMString& theData)
{
nsProcessingInstruction->SetData(theData.getConstNSString());
}

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 (02/01/2000)
//
// Wrapper class to convert the Mozilla nsIDOMText interface into a TransforMIIX
// Text interface
//
// Modification History:
// Who When What
//
#include "mozilladom.h"
//
//Construct a text object with the specified document owner and data
//
Text::Text(nsIDOMText* text, Document* owner) : CharacterData(text, owner)
{
nsText = text;
}
//
//Destructor. Do nothing
//
Text::~Text()
{
}
//
//Wrap a different nsIDOMText object with this wrapper
//
void Text::setNSObj(nsIDOMText* text)
{
CharacterData::setNSObj(text);
nsText = text;
}
//
//Request the Mozilla object to split, and wrap the result in the appropriate
//wrapper object.
//
Text* Text::splitText(Int32 offset)
{
nsIDOMText* split = NULL;
if (nsText->SplitText(offset, &split) == NS_OK)
return ownerDocument->createTextNode(split);
else
return NULL;
}

View File

@ -0,0 +1,68 @@
target: TestMozDOM
TestMozDOM: MozillaDOMImplementation.o MozillaNotation.o MozillaDocumentFragment.o MozillaDocumentType.o MozillaProcessingInstruction.o MozillaEntity.o MozillaEntityReference.o MozillaCDATASection.o MozillaComment.o MozillaText.o MozillaCharacterData.o MozillaNamedNodeMap.o MozillaNodeList.o MozillaElement.o MozillaAttr.o MozillaDocument.o MozillaNode.o testMozDOM.o
g++ -Xlinker ../../../../../../xpcom/build/libxpcom.so ../../../../../../layout/build/libraptorhtml.so ../../../base/String.o ../../../base/MITREObjectWrapper.o ../../../base/MozillaString.o ../../../base/HashTable.o MozillaNode.o MozillaDocument.o MozillaElement.o MozillaAttr.o MozillaNodeList.o MozillaNamedNodeMap.o MozillaCharacterData.o MozillaText.o MozillaComment.o MozillaCDATASection.o MozillaEntityReference.o MozillaEntity.o MozillaProcessingInstruction.o MozillaDocumentType.o MozillaDocumentFragment.o MozillaDOMImplementation.o MozillaNotation.o testMozDOM.o -o testdom
testMozDOM.o: testMozDOM.cpp mozilladom.h
g++ -c -I../../../../../../dist/include -I../../../../../../layout/xml/document/src -I../../../../../../layout/html/document/src -I../../../../../../layout/base/src -I../../../base testMozDOM.cpp
MozillaDOMImplementation.o: MozillaDOMImplementation.cpp mozilladom.h
g++ -c -I../../../../../../dist/include -I../../../base MozillaDOMImplementation.cpp
MozillaDocumentFragment.o: MozillaDocumentFragment.cpp mozilladom.h
g++ -c -I../../../../../../dist/include -I../../../base MozillaDocumentFragment.cpp
MozillaNotation.o: MozillaNotation.cpp mozilladom.h
g++ -c -I../../../../../../dist/include -I../../../base MozillaNotation.cpp
MozillaDocumentType.o: MozillaDocumentType.cpp mozilladom.h
g++ -c -I../../../../../../dist/include -I../../../base MozillaDocumentType.cpp
MozillaProcessingInstruction.o: MozillaProcessingInstruction.cpp mozilladom.h
g++ -c -I../../../../../../dist/include -I../../../base MozillaProcessingInstruction.cpp
MozillaEntity.o : MozillaEntity.cpp mozilladom.h
g++ -c -I../../../../../../dist/include -I../../../base MozillaEntity.cpp
MozillaEntityReference.o: MozillaEntityReference.cpp mozilladom.h
g++ -c -I../../../../../../dist/include -I../../../base MozillaEntityReference.cpp
MozillaCDATASection.o: MozillaCDATASection.cpp mozilladom.h
g++ -c -I../../../../../../dist/include -I../../../base MozillaCDATASection.cpp
MozillaComment.o: MozillaComment.cpp mozilladom.h
g++ -c -I../../../../../../dist/include -I../../../base MozillaComment.cpp
MozillaText.o: MozillaText.cpp mozilladom.h
g++ -c -I../../../../../../dist/include -I../../../base MozillaText.cpp
MozillaCharacterData.o: MozillaCharacterData.cpp mozilladom.h
g++ -c -I../../../../../../dist/include -I../../../base MozillaCharacterData.cpp
MozillaNamedNodeMap.o: MozillaNamedNodeMap.cpp mozilladom.h
g++ -c -I../../../../../../dist/include -I../../../base MozillaNamedNodeMap.cpp
MozillaNodeList.o: MozillaNodeList.cpp mozilladom.h
g++ -c -I../../../../../../dist/include -I../../../base MozillaNodeList.cpp
MozillaElement.o: MozillaElement.cpp mozilladom.h
g++ -c -I../../../../../../dist/include -I../../../base MozillaElement.cpp
MozillaDocument.o: MozillaDocument.cpp mozilladom.h
g++ -c -I../../../../../../dist/include -I../../../base MozillaDocument.cpp
MozillaNode.o: MozillaNode.cpp mozilladom.h
g++ -c -I../../../../../../dist/include -I../../../base MozillaNode.cpp
MozillaAttr.o: MozillaAttr.cpp mozilladom.h
g++ -c -I../../../../../../dist/include -I../../../base MozillaAttr.cpp

View File

@ -0,0 +1,652 @@
/*
* (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 (01/13/2000)
//
// Implementation of the Mozilla Wrapper classes for the Mozilla DOM to
// TransforMIIX DOM interface conversion. Note that these wrapper classes are
// only interchangable with the TransforMIIX DOM at compile time. They are
// merely a copy of the TransforMIIX interface/class structure wich then
// deffer their processing to a Mozilla object. Complete interchangability
// would require the use of multiple inherritance using virtual base classes
// and RTTI which is not supported in Mozilla's cross platform domain.
//
// NOTE: The objects being wrapped are not deleted. It is assumed that they
// will be deleted when the actual ("real") Mozilla Document is
// destroyed
//
// Also note that the Document wrapper class maintains a hash table of
// wrapper object. The objects are hashed based on the address of the
// mozilla object they are wrapping. When ever a new wrapper object is
// created, the Hash Table should first be check to see if one already
// exists.
//
// Modification History:
// Who When What
//
#ifndef MOZILLA_MITRE_DOM
#define MOZILLA_MITRE_DOM
#ifdef __BORLANDC__
#include <stdlib.h>
#endif
#include "MozillaString.h"
#include "baseutils.h"
#include "HashTable.h"
//A bunch of Mozilla DOM headers
#include "nsIDOMNode.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOMProcessingInstruction.h"
#include "nsIDOMAttr.h"
#include "nsIDOMCDATASection.h"
#include "nsIDOMText.h"
#include "nsIDOMDOMImplementation.h"
#include "nsIDOMDocumentType.h"
#include "nsIDOMEntityReference.h"
#include "nsIDOMDocumentFragment.h"
#include "nsIDOMComment.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMNotation.h"
#include "nsIDOMEntity.h"
#include "nsIDOMNamedNodeMap.h"
#include "nsIDOMCharacterData.h"
#ifndef NULL
typedef 0 NULL;
#endif
typedef MozillaString 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 Entity;
class DocumentType;
class Notation;
//
//Wrapper class for nsIDOMDOMImplementation. Convert to TransforMIIX
//DOMImplementation interface.
//
class DOMImplementation : public MITREObject
{
public:
DOMImplementation(nsIDOMDOMImplementation* domImpl, Document* owner);
~DOMImplementation();
void setNSObj(nsIDOMDOMImplementation* domImpl);
virtual MBool hasFeature(const DOMString& feature, const DOMString& version) const;
private:
nsIDOMDOMImplementation* nsDOMImpl;
Document* ownerDocument;
};
//
// Definition and Implementation of the Node Wrapper class. It provides the
// generic Node interface, forwarding all functionality to its Mozilla
// counterpart.
//
class Node : public MITREObject
{
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
};
//Node();
Node(nsIDOMNode* node, Document* owner);
virtual ~Node();
virtual void setNSObj(nsIDOMNode* node);
nsIDOMNode* getNSObj();
//Read functions
virtual const DOMString& getNodeName();
virtual const DOMString& getNodeValue();
virtual unsigned short getNodeType() const;
virtual Node* getParentNode();
virtual NodeList* getChildNodes();
virtual Node* getFirstChild();
virtual Node* getLastChild();
virtual Node* getPreviousSibling();
virtual Node* getNextSibling();
virtual NamedNodeMap* getAttributes();
virtual Document* getOwnerDocument();
//Write functions
virtual void setNodeValue(const DOMString& nodeValue);
//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);
virtual Node* cloneNode(MBool deep, Node* dest);
virtual MBool hasChildNodes() const;
protected:
//We want to maintain a pointer back to the owner document for Hash/
//memory management.
Document* ownerDocument;
private:
nsIDOMNode* nsNode;
//Maintain a few DOMString objects to ensure proper handling of references
DOMString nodeName;
DOMString nodeValue;
};
//
//Wrapper class for nsIDOMNodeList. Convert to TransforMIIX
//NodeList interface.
//
class NodeList : public MITREObject
{
public:
NodeList(nsIDOMNodeList* nodeList, Document* owner);
~NodeList();
Node* item(UInt32 index);
UInt32 getLength();
protected:
nsIDOMNodeList* nsNodeList;
Document* ownerDocument;
};
//
//Wrapper class for nsIDOMNamedNodeMap. Convert to TransforMIIX
//NameNodeMap interface.
//
class NamedNodeMap : public MITREObject
{
public:
NamedNodeMap(nsIDOMNamedNodeMap* namedNodeMap, Document* owner);
~NamedNodeMap();
Node* getNamedItem(const DOMString& name);
Node* setNamedItem(Node* arg);
Node* removeNamedItem(const DOMString& name);
Node* item(UInt32 index);
UInt32 getLength();
private:
nsIDOMNamedNodeMap* nsNamedNodeMap;
Document* ownerDocument;
};
//
//Wrapper class for nsIDOMDocumentFragment. Convert to TransforMIIX
//DocumentFragment interface.
//
class DocumentFragment : public Node
{
public:
DocumentFragment(nsIDOMDocumentFragment* docFragment, Document* owner);
~DocumentFragment();
void setNSObj(nsIDOMDocumentFragment* docFragment);
//TK - Just deffer to the Node Implementation since it already has a pointer
// to the proper "polymorphed" object.
//Override insertBefore to limit Elements to having only certain nodes as
//children
//Node* insertBefore(Node* newChild, Node* refChild);
private:
nsIDOMDocumentFragment* nsDocumentFragment;
};
//
//Wrapper class for nsIDOMDocument. Convert to TransforMIIX
//Document interface.
//
class Document : public Node
{
public:
//Document();
Document(nsIDOMDocument* document);
~Document();
virtual void setNSObj(nsIDOMDocument* node);
Element* getDocumentElement();
DocumentType* getDoctype();
DOMImplementation* getImplementation();
//Provide a means to remove items from the wrapperHashTable
MITREObject* removeWrapper(Int32 hashValue);
//Provide a means to place a specific wrapper in the hash table
//This is needed to support the concept of "cloning" a node where
//a precreated destination wrapper is provided as a destination.
//We need to be able to remove the provided wrapper (above) so a new
//object can be associated with it, then placed back in the hash
void addWrapper(MITREObject* obj, Int32 hashValue);
//Factory functions for various node types. These functions
//are responsible for storing the wrapper classes they create in
//the document's wrapperHashTable.
//Note the addition of the factory functions to "wrap"
//nsIDOM* objects.
DocumentFragment* createDocumentFragment();
DocumentFragment* createDocumentFragment(nsIDOMDocumentFragment* fragment);
Element* createElement(const DOMString& tagName);
Element* createElement(nsIDOMElement* element);
Attr* createAttribute(const DOMString& name);
Attr* createAttribute(nsIDOMAttr* attr);
Text* createTextNode(const DOMString& theData);
Text* createTextNode(nsIDOMText* text);
Comment* createComment(const DOMString& theData);
Comment* createComment(nsIDOMComment* comment);
CDATASection* createCDATASection(const DOMString& theData);
CDATASection* createCDATASection(nsIDOMCDATASection* cdata);
ProcessingInstruction* createProcessingInstruction(const DOMString& target,
const DOMString& data);
ProcessingInstruction* createProcessingInstruction(
nsIDOMProcessingInstruction* pi);
EntityReference* createEntityReference(const DOMString& name);
EntityReference* createEntityReference(nsIDOMEntityReference* entiyRef);
Entity* createEntity(nsIDOMEntity* entity);
Node* createNode(nsIDOMNode* node);
DOMString* createDOMString(nsString* str);
Notation* createNotation(nsIDOMNotation* notation);
DOMImplementation* createDOMImplementation(nsIDOMDOMImplementation* impl);
DocumentType* createDocumentType(nsIDOMDocumentType* doctype);
NodeList* createNodeList(nsIDOMNodeList* list);
NamedNodeMap* createNamedNodeMap(nsIDOMNamedNodeMap* map);
//Determine what kind of node this is, and create the appropriate wrapper
//for it.
Node* createWrapper(nsIDOMNode* node);
//TK - Just deffer to the Node implementation
//
//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:
nsIDOMDocument* nsDocument;
//Hash tables to maintain wrapper objects.
//NOTE: Should we maintain separate hash table for NamedNodeMaps and
// NodeLists?
HashTable wrapperHashTable;
};
//
//Wrapper class for nsIDOMElement. Convert to TransforMIIX
//Element interface.
//
class Element : public Node
{
public:
//Element();
Element(nsIDOMElement* element, Document* owner);
~Element();
virtual void setNSObj(nsIDOMElement* element);
//TK - Just deffer to the Node Implementation
//
//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();
private:
nsIDOMElement* nsElement;
};
//
//Wrapper class for nsIDOMAttr. Convert to TransforMIIX
//Attr interface.
//
class Attr : public Node
{
public:
Attr(nsIDOMAttr* attr, Document* owner);
~Attr();
nsIDOMAttr* getNSAttr();
virtual void setNSObj(nsIDOMAttr* attr);
const DOMString& getName();
MBool getSpecified() const;
const DOMString& getValue();
void setValue(const DOMString& newValue);
//TK - Simply deffer to Node Implementation
//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:
//
//I don't think we need these since the MozillaString objects will
//delete their nsString objects when they are destroyed.
//
//We don't want to make any assumptions about the implementation of
//the NS attribute object, so keep these around to store the name and
//value of the attribute when requested by the user.
//We don't want to make any assumptions about the implementation of
//DOMString attrName;
//DOMString attrValue;
nsIDOMAttr* nsAttr;
};
//
//Wrapper class for nsIDOMCharacterData. Convert to TransforMIIX
//CharacterData interface.
//
class CharacterData : public Node
{
public:
virtual ~CharacterData();
virtual void setNSObj(nsIDOMCharacterData* charData);
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(nsIDOMCharacterData* charData, Document* owner);
private:
nsIDOMCharacterData* nsCharacterData;
};
//
//Wrapper class for nsIDOMText. Convert to TransforMIIX
//Text interface.
//
class Text : public CharacterData
{
public:
Text(nsIDOMText* text, Document* owner);
~Text();
virtual void setNSObj(nsIDOMText* text);
Text* splitText(Int32 offset);
//TK - simply deffer to Node implementation
//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);
private:
nsIDOMText* nsText;
};
//
//Wrapper class for nsIDOMComment. Convert to TransforMIIX
//Comment interface.
//
class Comment : public CharacterData
{
public:
Comment(nsIDOMComment* comment, Document* owner);
~Comment();
virtual void setNSObj(nsIDOMComment* comment);
//TK - Simply defer to Node Implementation
//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);
private:
nsIDOMComment* nsComment;
};
//
//Wrapper class for nsIDOMCDATASection. Convert to TransforMIIX
//CDATASection interface.
//
class CDATASection : public Text
{
public:
CDATASection(nsIDOMCDATASection* cdataSection, Document* owner);
~CDATASection();
virtual void setNSObj(nsIDOMCDATASection* cdataSection);
//TK - Simply defer to Node Implementation
//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);
private:
nsIDOMCDATASection* nsCDATASection;
};
//
//Wrapper class for nsIDOMProcessingInstruction. Convert to TransforMIIX
//ProcessingInstruction interface.
//
class ProcessingInstruction : public Node
{
public:
ProcessingInstruction(nsIDOMProcessingInstruction* procInstr,
Document* owner);
~ProcessingInstruction();
virtual void setNSObj(nsIDOMProcessingInstruction* procInstr);
const DOMString& getTarget() const;
const DOMString& getData() const;
void setData(const DOMString& theData);
//TK - Defer to Node Implementation
//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);
private:
nsIDOMProcessingInstruction* nsProcessingInstruction;
};
//
//Wrapper class for nsIDOMNotation. Convert to TransforMIIX
//Notation interface.
//
class Notation : public Node
{
public:
Notation(nsIDOMNotation* notation, Document* owner);
~Notation();
virtual void setNSObj(nsIDOMNotation* notation);
const DOMString& getPublicId() const;
const DOMString& getSystemId() const;
//TK - Simply Defer to Node Implemntation
//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:
nsIDOMNotation* nsNotation;
};
//
//Wrapper class for nsIDOMEntity. Convert to TransforMIIX
//Entity interface.
//
class Entity : public Node
{
public:
Entity(nsIDOMEntity* entity, Document* owner);
~Entity();
virtual void setNSObj(nsIDOMEntity* entity);
const DOMString& getPublicId() const;
const DOMString& getSystemId() const;
const DOMString& getNotationName() const;
//TK - Defer to Node Implementation
//Override insertBefore to limit Entity to having only certain nodes as
//children
//Node* insertBefore(Node* newChild, Node* refChild);
private:
nsIDOMEntity* nsEntity;
};
//
//Wrapper class for nsIDOMEntityReference. Convert to TransforMIIX
//EntityReference interface.
//
class EntityReference : public Node
{
public:
EntityReference(nsIDOMEntityReference* entityReference, Document* owner);
~EntityReference();
virtual void setNSObj(nsIDOMEntityReference* entityReference);
//TK - Simply defer to Node Implementation
//Override insertBefore to limit EntityReference to having only certain
//nodes as children
//Node* insertBefore(Node* newChild, Node* refChild);
private:
nsIDOMEntityReference* nsEntityReference;
};
//
//Wrapper class for nsIDOMDocumentType. Convert to TransforMIIX
//Document interface.
//
class DocumentType : public Node
{
public:
DocumentType();
DocumentType(nsIDOMDocumentType* documentType, Document* owner);
~DocumentType();
void setNSObj(nsIDOMDocumentType* documentType);
const DOMString& getName() const;
NamedNodeMap* getEntities();
NamedNodeMap* getNotations();
//TK - Simply deffer to Node Implementation
//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:
nsIDOMDocumentType* nsDocumentType;
};
//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

View File

@ -0,0 +1,100 @@
//Simple test program for the Mozilla DOM wrapper classes
#include "mozilladom.h"
#include "nsXMLDocument.h"
#include "iostream.h"
void main()
{
/*
Test code for Pure Mozilla Objects
nsXMLDocument* nsxmlDocument = new nsXMLDocument();
nsIDOMElement* nsElem1 = NULL;
nsIDOMNode* returnElem = NULL;
nsIDOMElement* docElem = NULL;
MozillaString tag;
nsxmlDocument->CreateElement("TestFirstElement", &nsElem1);
nsxmlDocument->AppendChild(nsElem1, &returnElem);
if (!returnElem)
cout << "The AppendChild did not work" << endl;
nsElem1->GetTagName(tag.getNSString());
cout << tag << endl; */
nsXMLDocument* nsxmlDocument = new nsXMLDocument();
Document* document = new Document(nsxmlDocument);
Element* elem1;
Element* subelem1;
Element* subelem2;
Attr* attr2;
Attr* tmpAttr;
NodeList* subElems = NULL;
Element* tmpElem = NULL;
NamedNodeMap* attrs = NULL;
Node* tmpNode;
elem1 = document->createElement("FirstElement");
cout << "elem1 tag name=" << elem1->getTagName() << endl;
elem1->setAttribute("Attr1", "Attr1Value");
cout << "elem1 attr1=" << elem1->getAttribute("Attr1") << endl;
attr2 = document->createAttribute("Attr2");
attr2->setValue("attr2 value");
cout << "attr2 name=" << attr2->getName() << endl;
cout << "attr2 value=" << attr2->getValue() << endl;
elem1->setAttributeNode(attr2);
cout << "elem1 attr2=" << elem1->getAttribute("Attr2") << endl;
tmpAttr = elem1->getAttributeNode("Attr2");
cout << "tmpAttr name=" << tmpAttr->getName() << endl;
cout << "tmpAttr value=" << tmpAttr->getValue() << endl;
//tmpAttr = elem1->getAttributeNode("Attr1");
//elem1->removeAttributeNode(tmpAttr);
//cout << "elem1 attr1 (after removal)=" << elem1->getAttribute("Attr1") << endl;
//elem1->removeAttribute("Attr2");
//cout << "elem1 attr2 (after removal)=" << elem1->getAttribute("Attr2") << endl;
//tmpAttr = elem1->getAttributeNode("Attr2");
//cout << "tmpAttr name (after removal)=" << tmpAttr->getName() << endl;
//cout << "tmpAttr value (after removal)=" << tmpAttr->getValue() << endl;
cout << endl << "--- Check out the Node List Stuff ---" << endl;
subelem1 = document->createElement("Sub Elem0");
subelem2 = document->createElement("Sub Elem1");
elem1->appendChild(subelem1);
elem1->appendChild(subelem2);
subElems = elem1->getChildNodes();
cout << "subElems length=" << subElems->getLength() << endl;
tmpElem = (Element*)subElems->item(0);
cout << "tmpElem name=" << tmpElem->getTagName() << endl;
cout << endl << "--- Check out the Named Node Map Stuff ---" << endl;
attrs = elem1->getAttributes();
cout << "attrs length=" << attrs->getLength() << endl;
tmpAttr = (Attr*)attrs->item(1);
cout << tmpAttr->getName() << "=" << tmpAttr->getValue() << endl;
delete nsxmlDocument;
delete document;
}