EppCommand * EppCommand::fromXML( const DOMNode& root ) { unsigned int i; EppCommand * cmd = null; DOMNode* command; bool found = false; DOMNodeList* list = root.getChildNodes(); for( i = 0; i < list->getLength(); i++ ) { DOMNode* node = list->item(i); DOMString name = node->getLocalName(); if( name.isNull() ) { name = node->getNodeName(); } if( name.isNull() ) { continue; } if( name.equals("command") ) { command = node; found = true; break; } } if( found == false ) { return null; } list = command->getChildNodes(); for( i = 0; i < list->getLength(); i++ ) { DOMNode* node = list->item(i); DOMString name = node->getLocalName(); if( name.isNull() ) { name = node->getNodeName(); } if( name.isNull() ) { continue; } if( name.equals("login") ) { cmd = EppCommandLogin::fromXML(*node); } else if( name.equals("logout") ) { cmd = EppCommandLogout::fromXML(*node); } else if( name.equals("poll") ) { cmd = EppCommandPoll::fromXML(*node); } else if( name.equals("create") ) { cmd = EppCommandCreate::fromXML(*node); } else if( name.equals("delete") ) { cmd = EppCommandDelete::fromXML(*node); } else if( name.equals("info") ) { cmd = EppCommandInfo::fromXML(*node); } else if( name.equals("check") ) { cmd = EppCommandCheck::fromXML(*node); } else if( name.equals("renew") ) { cmd = EppCommandRenew::fromXML(*node); } else if( name.equals("transfer") ) { cmd = EppCommandTransfer::fromXML(*node); } else if( name.equals("update") ) { cmd = EppCommandUpdate::fromXML(*node); } /* * other commands */ if( cmd != null ) { break; } } if( cmd == null ) { return null; } for( i = 0; i < list->getLength(); i++ ) { DOMNode* node = list->item(i); DOMString name = node->getLocalName(); if( name.isNull() ) { name = node->getNodeName(); } if( name.isNull() ) { continue; } if( name.equals("creds") ) { if( cmd->creds == null ) { //cmd->creds = EppCreds::fromXML(node); } } else if( name.equals("extension") ) { DOMNodeList* clist = node->getChildNodes(); for( unsigned int j = 0; j < clist->getLength(); j++ ) { DOMNode* cnode = clist->item(j); DOMString prefix = cnode->getPrefix(); DOMString cname = cnode->getLocalName(); DOMString nsURI = cnode->getNamespaceURI(); if( cname.isNull() ) { cname = cnode->getNodeName(); } if( cname.isNull() ) { continue; } if( cname.equals("neulevel:extension") || ( (prefix.isNotNull()) && prefix.equals("neulevel") && (cname.isNotNull()) && cname.equals("extension") ) || cname.equals("ex01:extension") ) { EppUnspec * unspec = EppUnspec::fromXML(*cnode); if( unspec != null ) { cmd->addExtension(unspec); } } else if( cname.isNotNull() ) { EppExtension * ext = EppExtension::fromXML(*cnode); if( ext != null ) { cmd->addExtension(ext); } // else other extensions } else { // other extensions } } } else if( name.equals("clTRID") ) { cmd->clTRID = EppUtil::getText(*node); } } return cmd; }
const XMLCh* DOMNodeImpl::lookupNamespacePrefix(const XMLCh* const namespaceURI, bool useDefault, DOMElement *el) const { DOMNode *thisNode = castToNode(this); const XMLCh* ns = thisNode->getNamespaceURI(); // REVISIT: if no prefix is available is it null or empty string, or // could be both? const XMLCh* prefix = thisNode->getPrefix(); if (ns != 0 && XMLString::equals(ns,namespaceURI)) { if (useDefault || prefix != 0) { const XMLCh* foundNamespace = el->lookupNamespaceURI(prefix); if (foundNamespace != 0 && XMLString::equals(foundNamespace, namespaceURI)) { return prefix; } } } if (thisNode->hasAttributes()) { DOMNamedNodeMap *nodeMap = thisNode->getAttributes(); if(nodeMap != 0) { int length = nodeMap->getLength(); for (int i = 0;i < length;i++) { DOMNode *attr = nodeMap->item(i); const XMLCh* attrPrefix = attr->getPrefix(); const XMLCh* value = attr->getNodeValue(); ns = attr->getNamespaceURI(); if (ns != 0 && XMLString::equals(ns, XMLUni::fgXMLNSURIName)) { // DOM Level 2 nodes if ((useDefault && XMLString::equals(attr->getNodeName(), XMLUni::fgXMLNSString)) || (attrPrefix != 0 && XMLString::equals(attrPrefix, XMLUni::fgXMLNSString)) && XMLString::equals(value, namespaceURI)) { const XMLCh* localname= attr->getLocalName(); const XMLCh* foundNamespace = el->lookupNamespaceURI(localname); if (foundNamespace != 0 && XMLString::equals(foundNamespace, namespaceURI)) { return localname; } } } } } } DOMNode *ancestor = getElementAncestor(thisNode); if (ancestor != 0) { return castToNodeImpl(ancestor)->lookupNamespacePrefix(namespaceURI, useDefault, el); } return 0; }
void XercesUpdateFactory::setTypes(DOMNode *node, const DOMNode *from) { if(node->getNodeType() == DOMNode::ELEMENT_NODE) { const XMLCh *turi, *tname; XercesNodeImpl::typeUriAndName(from, turi, tname); XercesSequenceBuilder::setElementTypeInfo((DOMElement *)node, turi, tname); DOMNamedNodeMap *attrs = node->getAttributes(); DOMNamedNodeMap *attrsfrom = from->getAttributes(); for(unsigned int i = 0; i < attrs->getLength(); ++i) { DOMNode *a = attrs->item(i); DOMNode *afrom = attrsfrom->getNamedItemNS(a->getNamespaceURI(), Axis::getLocalName(a)); if(afrom) setTypes(a, afrom); } DOMNode *child = node->getFirstChild(); DOMNode *cfrom = from->getFirstChild(); while(child) { if(child->getNodeType() == DOMNode::ELEMENT_NODE) setTypes(child, cfrom); child = child->getNextSibling(); cfrom = cfrom->getNextSibling(); } } else if(node->getNodeType() == DOMNode::ATTRIBUTE_NODE) { const XMLCh *turi, *tname; XercesNodeImpl::typeUriAndName(from, turi, tname); XercesSequenceBuilder::setAttributeTypeInfo((DOMAttr *)node, turi, tname); } }
int DOMAttrMapImpl::findNamePoint(const XMLCh *namespaceURI, const XMLCh *localName) const { if (fNodes == 0) return -1; // This is a linear search through the same fNodes Vector. // The Vector is sorted on the DOM Level 1 nodename. // The DOM Level 2 NS keys are namespaceURI and Localname, // so we must linear search thru it. // In addition, to get this to work with fNodes without any namespace // (namespaceURI and localNames are both 0) we then use the nodeName // as a secondary key. int i, len = fNodes -> size(); for (i = 0; i < len; ++i) { DOMNode *node = fNodes -> elementAt(i); const XMLCh * nNamespaceURI = node->getNamespaceURI(); const XMLCh * nLocalName = node->getLocalName(); if (!XMLString::equals(nNamespaceURI, namespaceURI)) //URI not match continue; else { if (XMLString::equals(localName, nLocalName) || (nLocalName == 0 && XMLString::equals(localName, node->getNodeName()))) return i; } } return -1; //not found }
// remove the name using index // avoid calling findNamePoint again if the index is already known DOMNode * DOMAttrMapImpl::removeNamedItemAt(XMLSize_t index) { DOMNode* removed = DOMNamedNodeMapImpl::removeNamedItemAt(index); // Replace it if it had a default value // (DOM spec level 1 - Element Interface) if (hasDefaults() && (removed != 0)) { DOMAttrMapImpl* defAttrs = ((DOMElementImpl*)fOwnerNode)->getDefaultAttributes(); const XMLCh* localName = removed->getLocalName(); DOMAttr* attr = 0; if (localName) attr = (DOMAttr*)(defAttrs->getNamedItemNS(removed->getNamespaceURI(), localName)); else attr = (DOMAttr*)(defAttrs->getNamedItem(((DOMAttr*)removed)->getName())); if (attr != 0) { DOMAttr* newAttr = (DOMAttr*)attr->cloneNode(true); setNamedItem(newAttr); } } return removed; }
bool DOMNodeImpl::isDefaultNamespace(const XMLCh* namespaceURI) const{ DOMNode *thisNode = castToNode(this); short type = thisNode->getNodeType(); switch (type) { case DOMNode::ELEMENT_NODE: { const XMLCh *prefix = thisNode->getPrefix(); // REVISIT: is it possible that prefix is empty string? if (prefix == 0 || !*prefix) { return XMLString::equals(namespaceURI, thisNode->getNamespaceURI()); } if (thisNode->hasAttributes()) { DOMElement *elem = (DOMElement *)thisNode; DOMNode *attr = elem->getAttributeNodeNS(XMLUni::fgXMLNSURIName, XMLUni::fgXMLNSString); if (attr != 0) { const XMLCh *value = attr->getNodeValue(); return XMLString::equals(namespaceURI, value); } } DOMNode *ancestor = getElementAncestor(thisNode); if (ancestor != 0) { return ancestor->isDefaultNamespace(namespaceURI); } return false; } case DOMNode::DOCUMENT_NODE:{ return ((DOMDocument*)thisNode)->getDocumentElement()->isDefaultNamespace(namespaceURI); } case DOMNode::ENTITY_NODE : case DOMNode::NOTATION_NODE: case DOMNode::DOCUMENT_FRAGMENT_NODE: case DOMNode::DOCUMENT_TYPE_NODE: // type is unknown return false; case DOMNode::ATTRIBUTE_NODE:{ if (fOwnerNode->getNodeType() == DOMNode::ELEMENT_NODE) { return fOwnerNode->isDefaultNamespace(namespaceURI); } return false; } default:{ DOMNode *ancestor = getElementAncestor(thisNode); if (ancestor != 0) { return ancestor->isDefaultNamespace(namespaceURI); } return false; } } }
bool DOMNodeImpl::isEqualNode(const DOMNode* arg) const { if (!arg) return false; if (isSameNode(arg)) { return true; } DOMNode* thisNode = castToNode(this); if (arg->getNodeType() != thisNode->getNodeType()) { return false; } // the compareString will check null string as well if (!XMLString::equals(thisNode->getNodeName(), arg->getNodeName())) { return false; } if (!XMLString::equals(thisNode->getLocalName(),arg->getLocalName())) { return false; } if (!XMLString::equals(thisNode->getNamespaceURI(), arg->getNamespaceURI())) { return false; } if (!XMLString::equals(thisNode->getPrefix(), arg->getPrefix())) { return false; } if (!XMLString::equals(thisNode->getNodeValue(), arg->getNodeValue())) { return false; } if (!XMLString::equals(thisNode->getBaseURI(), arg->getBaseURI())) { return false; } return true; }
// remove the name using index // avoid calling findNamePoint again if the index is already known DOMNode * DOMAttrMapImpl::removeNamedItemAt(XMLSize_t index) { if (this->readOnly()) throw DOMException( DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNamedNodeMapMemoryManager); DOMNode *removed = item(index); if(!removed) throw DOMException(DOMException::NOT_FOUND_ERR, 0, GetDOMNamedNodeMapMemoryManager); fNodes->removeElementAt(index); castToNodeImpl(removed)->fOwnerNode = fOwnerNode->getOwnerDocument(); castToNodeImpl(removed)->isOwned(false); // Replace it if it had a default value // (DOM spec level 1 - Element Interface) if (hasDefaults() && (removed != 0)) { DOMAttrMapImpl* defAttrs = ((DOMElementImpl*)fOwnerNode)->getDefaultAttributes(); const XMLCh* localName = removed->getLocalName(); DOMAttr* attr = 0; if (localName) attr = (DOMAttr*)(defAttrs->getNamedItemNS(removed->getNamespaceURI(), localName)); else attr = (DOMAttr*)(defAttrs->getNamedItem(((DOMAttr*)removed)->getName())); if (attr != 0) { DOMAttr* newAttr = (DOMAttr*)attr->cloneNode(true); setNamedItem(newAttr); } } return removed; }
// Finds and returns the next sibling element node with the give name. DOMElement* XUtil::getNextSiblingElementNS(const DOMNode* const node , const XMLCh** const elemNames , const XMLCh* const uriStr , unsigned int length) { // search for node DOMNode* sibling = node->getNextSibling(); while (sibling != 0) { if (sibling->getNodeType() == DOMNode::ELEMENT_NODE) { for (unsigned int i = 0; i < length; i++) { if (XMLString::equals(sibling->getNamespaceURI(), uriStr) && XMLString::equals(sibling->getLocalName(), elemNames[i])) return (DOMElement*)sibling; } } sibling = sibling->getNextSibling(); } // not found return 0; }
// Finds and returns the first child node with the given name. DOMElement* XUtil::getFirstChildElementNS(const DOMNode* const parent , const XMLCh** const elemNames , const XMLCh* const uriStr , unsigned int length) { // search for node DOMNode* child = parent->getFirstChild(); while (child != 0) { if (child->getNodeType() == DOMNode::ELEMENT_NODE) { for (unsigned int i = 0; i < length; i++) { if (XMLString::equals(child->getNamespaceURI(), uriStr) && XMLString::equals(child->getLocalName(), elemNames[i])) return (DOMElement*)child; } } child = child->getNextSibling(); } // not found return 0; }
// --------------------------------------------------------------------------- // GeneralAttributeCheck: Validation methods // --------------------------------------------------------------------------- void GeneralAttributeCheck::checkAttributes(const DOMElement* const elem, const unsigned short elemContext, TraverseSchema* const schema, const bool isTopLevel, ValueVectorOf<DOMNode*>* const nonXSAttList) { if (nonXSAttList) nonXSAttList->removeAllElements(); if (elem == 0 || !fAttMap || elemContext>=E_Count) return; const XMLCh* elemName = elem->getLocalName(); if (!XMLString::equals(SchemaSymbols::fgURI_SCHEMAFORSCHEMA, elem->getNamespaceURI())) { schema->reportSchemaError ( elem , XMLUni::fgXMLErrDomain , XMLErrs::ELTSchemaNS , elemName ); } const XMLCh* contextStr = (isTopLevel) ? fgGlobal : fgLocal; DOMNamedNodeMap* eltAttrs = elem->getAttributes(); int attrCount = eltAttrs->getLength(); XMLByte attList[A_Count]; memset(attList, 0, sizeof(attList)); for (int i = 0; i < attrCount; i++) { DOMNode* attribute = eltAttrs->item(i); const XMLCh* attName = attribute->getNodeName(); // skip namespace declarations if (XMLString::equals(attName, XMLUni::fgXMLNSString) || XMLString::startsWith(attName, XMLUni::fgXMLNSColonString)) continue; // Bypass attributes that start with xml // add this to the list of "non-schema" attributes if ((*attName == chLatin_X || *attName == chLatin_x) && (*(attName+1) == chLatin_M || *(attName+1) == chLatin_m) && (*(attName+2) == chLatin_L || *(attName+2) == chLatin_l)) { if (nonXSAttList) nonXSAttList->addElement(attribute); continue; } // for attributes with namespace prefix const XMLCh* attrURI = attribute->getNamespaceURI(); if (attrURI != 0 && *attrURI) { // attributes with schema namespace are not allowed // and not allowed on "documentation" and "appInfo" if (XMLString::equals(attrURI, SchemaSymbols::fgURI_SCHEMAFORSCHEMA) || XMLString::equals(elemName, SchemaSymbols::fgELT_APPINFO) || XMLString::equals(elemName, SchemaSymbols::fgELT_DOCUMENTATION)) { schema->reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::AttributeDisallowed, attName, contextStr, elemName); } else if (nonXSAttList) { nonXSAttList->addElement(attribute); } continue; } int attNameId = A_Invalid; attName = attribute->getLocalName(); bool bContinue=false; // workaround for Borland bug with 'continue' in 'catch' try { attNameId= fAttMap->get(attName, fMemoryManager); } catch(const OutOfMemoryException&) { throw; } catch(...) { schema->reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::AttributeDisallowed, attName, contextStr, elemName); bContinue=true; } if(bContinue) continue; if (fgElemAttTable[elemContext][attNameId] & Att_Mask) { attList[attNameId] = 1; validate ( elem , attName , attribute->getNodeValue() , fgElemAttTable[elemContext][attNameId] & DV_Mask , schema ); } else { schema->reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::AttributeDisallowed, attName, contextStr, elemName); } } // ------------------------------------------------------------------ // Check for required attributes // ------------------------------------------------------------------ for (unsigned int j=0; j < A_Count; j++) { if ((fgElemAttTable[elemContext][j] & Att_Required) && attList[j] == 0) { schema->reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::AttributeRequired, fAttNames[j], contextStr, elemName); } } }
const XMLCh* DOMNodeImpl::lookupNamespaceURI(const XMLCh* specifiedPrefix) const { DOMNode *thisNode = castToNode(this); short type = thisNode->getNodeType(); switch (type) { case DOMNode::ELEMENT_NODE : { const XMLCh* ns = thisNode->getNamespaceURI(); const XMLCh* prefix = thisNode->getPrefix(); if (ns != 0) { // REVISIT: is it possible that prefix is empty string? if (specifiedPrefix == 0 && prefix == specifiedPrefix) { // looking for default namespace return ns; } else if (prefix != 0 && XMLString::equals(prefix, specifiedPrefix)) { // non default namespace return ns; } } if (thisNode->hasAttributes()) { DOMNamedNodeMap *nodeMap = thisNode->getAttributes(); if(nodeMap != 0) { int length = nodeMap->getLength(); for (int i = 0;i < length;i++) { DOMNode *attr = nodeMap->item(i); const XMLCh *attrPrefix = attr->getPrefix(); const XMLCh *value = attr->getNodeValue(); ns = attr->getNamespaceURI(); if (ns != 0 && XMLString::equals(ns, XMLUni::fgXMLNSURIName)) { // at this point we are dealing with DOM Level 2 nodes only if (specifiedPrefix == 0 && XMLString::equals(attr->getNodeName(), XMLUni::fgXMLNSString)) { // default namespace return value; } else if (attrPrefix != 0 && XMLString::equals(attrPrefix, XMLUni::fgXMLNSString) && XMLString::equals(attr->getLocalName(), specifiedPrefix)) { // non default namespace return value; } } } } } DOMNode *ancestor = getElementAncestor(thisNode); if (ancestor != 0) { return ancestor->lookupNamespaceURI(specifiedPrefix); } return 0; } case DOMNode::DOCUMENT_NODE : { return((DOMDocument*)thisNode)->getDocumentElement()->lookupNamespaceURI(specifiedPrefix); } case DOMNode::ENTITY_NODE : case DOMNode::NOTATION_NODE: case DOMNode::DOCUMENT_FRAGMENT_NODE: case DOMNode::DOCUMENT_TYPE_NODE: // type is unknown return 0; case DOMNode::ATTRIBUTE_NODE:{ if (fOwnerNode->getNodeType() == DOMNode::ELEMENT_NODE) { return fOwnerNode->lookupNamespaceURI(specifiedPrefix); } return 0; } default:{ DOMNode *ancestor = getElementAncestor(castToNode(this)); if (ancestor != 0) { return ancestor->lookupNamespaceURI(specifiedPrefix); } return 0; } } }
// --------------------------------------------------------------------------- // This method assumes that currentNode is an xinclude element and parses // it accordingly, acting on what it finds. // --------------------------------------------------------------------------- bool XIncludeUtils::doDOMNodeXInclude(DOMNode *xincludeNode, DOMDocument *parsedDocument, XMLEntityHandler* entityResolver){ bool modifiedNode = false; /* the relevant attributes to look for */ const XMLCh *href = NULL; const XMLCh *parse = NULL; const XMLCh *xpointer = NULL; const XMLCh *encoding = NULL; const XMLCh *accept = NULL; const XMLCh *acceptlanguage = NULL; DOMNode *includeParent = xincludeNode->getParentNode(); if(xincludeNode->hasAttributes()) { /* get all the attributes of the node */ DOMNamedNodeMap *pAttributes = xincludeNode->getAttributes(); XMLSize_t nSize = pAttributes->getLength(); for(XMLSize_t i=0;i<nSize;++i) { DOMAttr *pAttributeNode = (DOMAttr*) pAttributes->item(i); const XMLCh *attrName = pAttributeNode->getName(); /* check each attribute against the potential useful names */ if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeHREFAttrName)){ href = pAttributeNode->getValue(); } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeParseAttrName)){ parse = pAttributeNode->getValue(); } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeXPointerAttrName)){ xpointer = pAttributeNode->getValue(); } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeEncodingAttrName)){ encoding = pAttributeNode->getValue(); } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeAcceptAttrName)){ accept = pAttributeNode->getValue(); } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeAcceptLanguageAttrName)){ acceptlanguage = pAttributeNode->getValue(); } else { /* if any other attribute is in the xi namespace, it's an error */ const XMLCh *attrNamespaceURI = pAttributeNode->getNamespaceURI(); if (attrNamespaceURI && XMLString::equals(attrNamespaceURI, XIncludeUtils::fgXIIIncludeNamespaceURI)){ } else { /* ignore - any other attribute is allowed according to spec, and must be ignored */ } } } } // 3.1 xi:include Element // The children property of the xi:include element may include a single xi:fallback element; // the appearance of more than one xi:fallback element, an xi:include element, // or any other element from the XInclude namespace is a fatal error. DOMNode *child; DOMElement *fallback = NULL; for (child = xincludeNode->getFirstChild(); child != 0; child=child->getNextSibling()){ if(child->getNodeType()!=DOMNode::ELEMENT_NODE) continue; if ( isXIFallbackDOMNode(child) ){ if (fallback != NULL){ /* fatal error - there are more than one fallback children */ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeMultipleFallbackElems, parsedDocument->getDocumentURI(), parsedDocument->getDocumentURI()); return false; } fallback = (DOMElement*)child; } else if(isXIIncludeDOMNode(child) || XMLString::equals(child->getNamespaceURI(), XIncludeUtils::fgXIIIncludeNamespaceURI)) { /* fatal error - an xi element different from xi:fallback is a child of xi:include */ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeDisallowedChild, child->getNodeName(), parsedDocument->getDocumentURI()); return false; } } if (href == NULL){ /* this is an unrecoverable error until we have xpointer support - if there is an xpointer, the current document is assumed however, there is no xpointer support yet */ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeNoHref, NULL, parsedDocument->getDocumentURI()); return false; } /* set up the accept and accept-language values */ if (accept != NULL){ } if (parse == NULL){ /* use the default, as specified */ parse = XIncludeUtils::fgXIIncludeParseAttrXMLValue; } if (xpointer != NULL){ /* not supported yet */ /* Note that finding an xpointer attr along with parse="text" is a Fatal Error * - http://www.w3.org/TR/xinclude/#include-location */ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeXPointerNotSupported, NULL, href); return false; } /* set up the href according to what has gone before */ XIncludeLocation hrefLoc(href); XIncludeLocation relativeLocation(href); const XMLCh *includeBase = xincludeNode->getBaseURI(); if (includeBase != NULL){ hrefLoc.prependPath(includeBase); } if (getBaseAttrValue(xincludeNode) != NULL){ relativeLocation.prependPath(getBaseAttrValue(xincludeNode)); } /* Take the relevant action - we need to retrieve the target as a whole before we can know if it was successful or not, therefore the do* methods do not modify the parsedDocument. Swapping the results in is left to the caller (i.e. here) */ DOMText *includedText = NULL; DOMDocument *includedDoc = NULL; if (XMLString::equals(parse, XIncludeUtils::fgXIIncludeParseAttrXMLValue)){ /* including a XML element */ includedDoc = doXIncludeXMLFileDOM(hrefLoc.getLocation(), relativeLocation.getLocation(), xincludeNode, parsedDocument, entityResolver); } else if (XMLString::equals(parse, XIncludeUtils::fgXIIncludeParseAttrTextValue)){ /* including a text value */ includedText = doXIncludeTEXTFileDOM(hrefLoc.getLocation(), relativeLocation.getLocation(), encoding, xincludeNode, parsedDocument, entityResolver); } else { /* invalid parse attribute value - fatal error according to the specification */ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeInvalidParseVal, parse, parsedDocument->getDocumentURI()); return false; } RefVectorOf<DOMNode> delayedProcessing(12,false); if (includedDoc == NULL && includedText == NULL){ /* there was an error - this is now a resource error let's see if there is a fallback */ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeIncludeFailedResourceError, hrefLoc.getLocation(), parsedDocument->getDocumentURI()); if (includeParent == NULL){ includeParent = parsedDocument; } // we could be getting errors trying to insert elements at the root of the document, so we should use replaceChild; // in order to handle multiple nodes, add them to a document fragment and use that to replace the original node if (fallback){ /* baseURI fixups - see http://www.w3.org/TR/xinclude/#base for details. */ XMLUri parentURI(includeParent->getBaseURI()); XMLUri includedURI(fallback->getBaseURI()); if (fallback->hasChildNodes()){ DOMDocumentFragment* frag = parsedDocument->createDocumentFragment(); DOMNode *child = fallback->getFirstChild(); /* add the content of the fallback element, and remove the fallback elem itself */ for ( ; child != NULL ; child=child->getNextSibling()){ if (child->getNodeType() == DOMNode::DOCUMENT_TYPE_NODE){ continue; } DOMNode *newNode = parsedDocument->importNode(child, true); /* if the paths differ we need to add a base attribute */ if (newNode->getNodeType()==DOMNode::ELEMENT_NODE && !XMLString::equals(parentURI.getPath(), includedURI.getPath())){ if (getBaseAttrValue(newNode) == NULL){ /* need to calculate the proper path difference to get the relativePath */ ((DOMElement*)newNode)->setAttribute(fgXIBaseAttrName, getBaseAttrValue(fallback->getParentNode())); } else { /* the included node has base of its own which takes precedence */ XIncludeLocation xil(getBaseAttrValue(newNode)); if (getBaseAttrValue(fallback->getParentNode()) != NULL){ /* prepend any specific base modification of the xinclude node */ xil.prependPath(getBaseAttrValue(fallback->getParentNode())); } ((DOMElement*)newNode)->setAttribute(fgXIBaseAttrName, xil.getLocation()); } } DOMNode *newChild = frag->appendChild(newNode); // don't process the node now, wait until it is placed in the final position delayedProcessing.addElement(newChild); //parseDOMNodeDoingXInclude(newChild, parsedDocument, entityResolver); } includeParent->replaceChild(frag, xincludeNode); frag->release(); for(XMLSize_t i=0;i<delayedProcessing.size();i++) { DOMNode* childNode=delayedProcessing.elementAt(i); parseDOMNodeDoingXInclude(childNode, parsedDocument, entityResolver); } modifiedNode = true; } else { /* empty fallback element - simply remove it! */ includeParent->removeChild(xincludeNode); modifiedNode = true; } } else { XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeIncludeFailedNoFallback, parsedDocument->getDocumentURI(), parsedDocument->getDocumentURI()); return false; } } else { if (includedDoc){ /* record the successful include while we process the children */ addDocumentURIToCurrentInclusionHistoryStack(hrefLoc.getLocation()); DOMDocumentFragment* frag = parsedDocument->createDocumentFragment(); /* need to import the document prolog here */ DOMNode *child = includedDoc->getFirstChild(); for (; child != NULL; child = child->getNextSibling()) { if (child->getNodeType() == DOMNode::DOCUMENT_TYPE_NODE) continue; // check for NOTATION or ENTITY clash if(child->getNodeType()==DOMNode::ELEMENT_NODE && includedDoc->getDoctype()!=NULL) { DOMNamedNodeMap *pAttributes = child->getAttributes(); XMLSize_t nSize = pAttributes->getLength(); for(XMLSize_t i=0;i<nSize;++i) { DOMAttr *pAttributeNode = (DOMAttr*) pAttributes->item(i); const DOMTypeInfo * typeInfo=pAttributeNode->getSchemaTypeInfo(); if(typeInfo && XMLString::equals(typeInfo->getTypeNamespace(), XMLUni::fgInfosetURIName)) { if(XMLString::equals(typeInfo->getTypeName(), XMLUni::fgNotationString)) { const XMLCh* notationName=pAttributeNode->getNodeValue(); DOMNotation* notat=(DOMNotation*)includedDoc->getDoctype()->getNotations()->getNamedItem(notationName); // ensure we have a DTD if(parsedDocument->getDoctype()==NULL) parsedDocument->insertBefore(parsedDocument->createDocumentType(parsedDocument->getDocumentElement()->getNodeName(), NULL,NULL), parsedDocument->getFirstChild()); DOMNotation* myNotation=(DOMNotation*)parsedDocument->getDoctype()->getNotations()->getNamedItem(notationName); if(myNotation==NULL) { // it's missing, add it parsedDocument->getDoctype()->getNotations()->setNamedItem(parsedDocument->importNode(notat, true)); } else if(XMLString::equals(myNotation->getPublicId(), notat->getPublicId()) && XMLString::equals(myNotation->getSystemId(), notat->getSystemId()) && XMLString::equals(myNotation->getBaseURI(), notat->getBaseURI())) { // it's duplicate, ignore it } else { // it's a conflict, report it XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeConflictingNotation, notationName, parsedDocument->getDocumentURI()); } } else if(XMLString::equals(typeInfo->getTypeName(), XMLUni::fgEntityString)) { const XMLCh* entityName=pAttributeNode->getNodeValue(); DOMEntity* ent=(DOMEntity*)includedDoc->getDoctype()->getEntities()->getNamedItem(entityName); // ensure we have a DTD if(parsedDocument->getDoctype()==NULL) parsedDocument->insertBefore(parsedDocument->createDocumentType(parsedDocument->getDocumentElement()->getNodeName(), NULL,NULL), parsedDocument->getFirstChild()); DOMEntity* myEnt=(DOMEntity*)parsedDocument->getDoctype()->getEntities()->getNamedItem(entityName); if(myEnt==NULL) { // it's missing, add it parsedDocument->getDoctype()->getEntities()->setNamedItem(parsedDocument->importNode(ent, true)); } else if(XMLString::equals(myEnt->getPublicId(), ent->getPublicId()) && XMLString::equals(myEnt->getSystemId(), ent->getSystemId()) && XMLString::equals(myEnt->getBaseURI(), ent->getBaseURI())) { // it's duplicate, ignore it } else { // it's a conflict, report it XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeConflictingEntity, entityName, parsedDocument->getDocumentURI()); } } } } } DOMNode *newNode = parsedDocument->importNode(child, true); DOMNode *newChild = frag->appendChild(newNode); // don't process the node now, wait until it is placed in the final position delayedProcessing.addElement(newChild); //parseDOMNodeDoingXInclude(newChild, parsedDocument, entityResolver); } includeParent->replaceChild(frag, xincludeNode); frag->release(); for(XMLSize_t i=0;i<delayedProcessing.size();i++) { DOMNode* childNode=delayedProcessing.elementAt(i); parseDOMNodeDoingXInclude(childNode, parsedDocument, entityResolver); } popFromCurrentInclusionHistoryStack(NULL); modifiedNode = true; } else if (includedText){ includeParent->replaceChild(includedText, xincludeNode); modifiedNode = true; } } if (includedDoc) includedDoc->release(); return modifiedNode; }
const DOMNode *NamespaceAxis::nextNode(DynamicContext *context) { const DOMNode *result = 0; while(result == 0) { switch(state_) { case CHECK_ELEMENT: { const XMLCh* uri = node_->getNamespaceURI(); const XMLCh* prefix = node_->getPrefix(); if(done_.insert(prefix).second && uri && *uri) { result = createNamespaceNode(prefix, uri, originalNode_); } state_ = CHECK_ATTR; break; } case CHECK_ATTR: { if(nodeMap_ != 0 && i_ < nodeMap_->getLength()) { DOMNode *tmpAttr = nodeMap_->item(i_); ++i_; const XMLCh* attrName = tmpAttr->getNodeName(); // Check to see if this attribute starts with xmlns if(!XMLString::startsWith(attrName, XMLUni::fgXMLNSString)) { const XMLCh* uri = tmpAttr->getNamespaceURI(); const XMLCh* prefix = tmpAttr->getPrefix(); if(uri && *uri && done_.insert(prefix).second) { result = createNamespaceNode(prefix, uri, originalNode_); } } else { // Get uri const XMLCh* uri = tmpAttr->getNodeValue(); // Figure out prefix const XMLCh* prefix = 0; if(XMLString::stringLen(attrName) != 5) { // A prefix was given // If the name doesn't start with xmlns: (and its not xmlns) then skip it // XXX: Is this necessary/allowed? if(attrName[5] != chColon) { continue; } prefix = attrName + 6; } if(done_.insert(prefix).second && uri && *uri) { result = createNamespaceNode(prefix, uri, originalNode_); } } } else { node_ = XPath2NSUtils::getParent(node_); if(node_ == 0 || node_->getNodeType() != DOMNode::ELEMENT_NODE) { state_ = DO_XML; } else { nodeMap_ = node_->getAttributes(); i_ = 0; state_ = CHECK_ELEMENT; } } break; } case DO_XML: { result = createNamespaceNode(XMLUni::fgXMLString, XMLUni::fgXMLURIName, originalNode_); state_ = DONE; break; } case DONE: return 0; } } return result; }