void *PointSet::read(DOMNode *node) { unsigned int i; // variable to counter DOMNodeList *children; // variable to hold the node children DOMNamedNodeMap *attributes; // variable to hold the node attributes attributes = node->getAttributes(); for (i = 0; i < attributes->getLength(); i++) { if (!strcmp(XMLString::transcode(attributes->item(i)->getNodeName()) , "DEF")) { setLink(XMLString::transcode(attributes->item(i)->getNodeValue()),this); }// else //if (!strcmp(XMLString::transcode(attributes->item(i)->getNodeName()) , "USE")) { // return(getLink(XMLString::transcode(attributes->item(i)->getNodeValue()))); //} } children = node->getChildNodes(); if (children != NULL) { for (i = 0; i < children->getLength (); i++) { if (!strcmp (XMLString::transcode(children->item(i)->getNodeName()),"Coordinate")) { coordinate = Coordinate::get(children->item(i)); coordinateNumber = coordinate->getNumberOfElements(); } else if (!strcmp (XMLString::transcode(children->item(i)->getNodeName()),"Color")) { color = Color::get(children->item(i)); colorNumber = color->getNumberOfElements(); } } } #ifdef DEBUG float sizes[2]; float step; glGetFloatv(GL_POINT_SIZE_RANGE,sizes); glGetFloatv(GL_POINT_SIZE_GRANULARITY,&step); cout << "Max and Min point size " << sizes[0] << " , " << sizes[1] << " Granularity " << step << endl; #endif if(colorNumber) { if(colorNumber==3) { cout << "Three colors selected" << endl; } else if(colorNumber!=coordinateNumber) { cerr << "Color and coordinate not matching" << endl; } } #ifdef DEBUG cout << "Coordinate Number " << coordinateNumber << endl; cout << "Color Number " << colorNumber << endl; #endif return(NULL); }
Inline *Inline::get(DOMNode *node) { unsigned int i; // variable to counter DOMNamedNodeMap *attributes; // variable to hold the node attributes char DEF2[256]; // temporary variable to hold the DEF name strcpy(DEF2,""); // reseting the variable Inline *inline2 = NULL; // temporary variable attributes = node->getAttributes(); for (i = 0; i < attributes->getLength(); i++) { if (!strcmp(XMLString::transcode(attributes->item(i)->getNodeName()) , "DEF")) { strcpy(DEF2,XMLString::transcode (attributes->item(i)->getNodeValue())); break; } else if (!strcmp(XMLString::transcode(attributes->item(i)->getNodeName()) , "USE")) { inline2 = (Inline *)getLink(XMLString::transcode(attributes->item(i)->getNodeValue())); if( inline2->ami("Inline") ) { cout << "USE of a different DEF type" << endl; } return(inline2); } } // verificar se o USE ta retornando NULL inline2 = new Inline(); if(inline2==NULL) { cerr << "Error on getting Group" << endl; } if(strcmp(DEF2,"")) { #ifdef DEBUG3 cout << "DEF : " << DEF2 << endl; #endif strcpy(inline2->DEF,DEF2); setLink(inline2->DEF,inline2); } inline2->read(node); return inline2; }
//============================================================================= // METHOD: SPELLxmlConfigReaderXC::convertToNode //============================================================================= SPELLxmlNode* SPELLxmlConfigReaderXC::convertToNode( DOMElement* element ) { // Create an abstract node with this name SPELLxmlNode* node = new SPELLxmlNode( XMLString::transcode(element->getNodeName()) ); // Get any possible attributes DOMNamedNodeMap* attrs = element->getAttributes(); XMLSize_t numAttrs = attrs->getLength(); for( XMLSize_t idx = 0; idx < numAttrs; idx++) { // Get the attribute node DOMNode* attrNode = attrs->item(idx); // Get name and value const XMLCh* aname = attrNode->getNodeName(); const XMLCh* avalue = attrNode->getNodeValue(); // Convert name and value to strings std::string name = "<?>"; if (aname != NULL) { name = XMLString::transcode(aname); } std::string value = "<?>"; if (avalue != NULL) { value = XMLString::transcode(avalue); } node->addAttribute( name, value ); } // Get any possible children DOMNodeList* children = element->getChildNodes(); XMLSize_t numChildren = children->getLength(); for( XMLSize_t idx = 0; idx < numChildren; idx++) { // Get the children node DOMNode* childNode = children->item(idx); // Process only ELEMENTs and TEXTs if (childNode->getNodeType() && // true is not NULL childNode->getNodeType() == DOMNode::ELEMENT_NODE) // is element { // For elements, recursively add children SPELLxmlNode* child = convertToNode( dynamic_cast<xercesc::DOMElement*>(childNode) ); node->addChild(child); } else if (childNode->getNodeType() == DOMNode::TEXT_NODE) { // For text values, add the value. This code will just ignore // carriage-return values const XMLCh* nvalue = childNode->getNodeValue(); if (nvalue != NULL) { std::string thevalue = XMLString::transcode(nvalue); SPELLutils::trim(thevalue, " \n\r\t"); node->setValue( thevalue ); } } } return node; }
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); } }
std::string getAttributeByName (DOMNode* node, std::string attrName) { cdebug << "getAttr " << attrName << std::endl; assert (node->getNodeType () == DOMNode::ELEMENT_NODE); std::string value = ""; if (node->hasAttributes()) { DOMNamedNodeMap *pAttributes = node->getAttributes (); for (unsigned int i = 0; i < pAttributes->getLength (); i++) { DOMAttr* pAttributeNode = (DOMAttr*) pAttributes->item(i); char* name = XMLString::transcode(pAttributeNode->getName()); if (name == attrName) { char* tmpValue = XMLString::transcode(pAttributeNode->getValue()); value = tmpValue; XMLString::release(&tmpValue); } XMLString::release(&name); } } else { cdebug << "Error in file to parse" << std::endl; throw ("Error in file to parse attributes"); } cdebug << value << std::endl; return value; } /* std::string getAttributeByName (DOMNode* node, std::string attrName) */
void DOMtoXMLElement(DOMNode* dom, XMLElement& xml) { xml.setName(StrX(dom->getNodeName())); unsigned int i; string text; DOMNodeList* children = dom->getChildNodes(); for (i=0;children && i<children->getLength();i++) { DOMNode* child = children->item(i); switch (child->getNodeType()) { case DOMNode::TEXT_NODE: text+=StrX(child->getNodeValue()); break; case DOMNode::ELEMENT_NODE: { XMLElement childElement; DOMtoXMLElement(child, childElement); xml.addChild(childElement); } break; default: continue; } } xml.setText(text); DOMNamedNodeMap* attrs = dom->getAttributes(); if (attrs == 0) return; for (i=0;i<attrs->getLength();i++) { DOMNode* attr = attrs->item(i); xml.setAttribute(StrX(attr->getNodeName()), StrX(attr->getNodeValue())); } }
// ---------------------------------------------------------------------------- // Base Attributes Builder // ---------------------------------------------------------------------------- void AttributesBuilder::getAttributes() { if ( node_->hasAttributes() ) { DOMNamedNodeMap* theAttributes = node_->getAttributes(); int numAttributes = theAttributes->getLength(); for (int n=0; n < numAttributes; ++n) { DOMNode* attrib = theAttributes->item(n); const XMLCh* xmlch_Name = attrib->getNodeName(); char* attrName = XMLString::transcode(xmlch_Name); const XMLCh* xmlch_Value = attrib->getNodeValue(); char* attrValue = XMLString::transcode(xmlch_Value); try { //attrib_->update(pname.get(), pval.get()); attrib_->update(attrName, attrValue); } catch (std::runtime_error &ex) { std::cerr << ex.what() << std::endl << builderType_ << __FUNCTION__ << "(): " << "In space \"" << attrib_->getValAsStr("name") << "\", unrecognized attribute \"" << attrName << "=" << attrValue << "\". Ignoring it." << std::endl; }; XMLString::release( &attrName ); XMLString::release( &attrValue ); } } }
bool XMLExtServiceHelper::parseExtServicesReq( DOMNode* cur, DOMNode* out, DOMDocument* reply, bool indent, const HttpHeader& inHeaders ) { // Attributes DOMNamedNodeMap* attributes = cur->getAttributes(); // Language of the request. LangTypes::language_t lang = LangTypes::english; // Semi-optional crc MC2String crc; for( int i = 0, n = attributes->getLength(); i < n; ++i ) { DOMNode* attrib = attributes->item( i ); if ( XMLString::equals( attrib->getNodeName(), "language" ) ) { lang = m_xmlParserThread->getStringAsLanguage( XMLUtility::getChildTextStr( *attrib ).c_str() ); } else if ( XMLString::equals( attrib->getNodeName(), "crc" ) ) { crc = XMLUtility::getChildTextStr( *attrib ); } } // Make the answer. appendExternalSearchDesc( out, reply, cur, crc, lang, 1, indent ); return true; }
EppCommandInfoLaunchRegistration* EppCommandInfoLaunchRegistration::fromXML( const DOMNode& root ) { EppCommandInfoLaunchRegistration* cmd = new EppCommandInfoLaunchRegistration(); if( cmd == null ) { return null; } DOMNodeList* list = root.getChildNodes(); DOMNamedNodeMap* attrs = root.getAttributes(); for( unsigned int 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.length() > 7) && name.substringData(0, 7).equals("launch:") ) { name = name.substringData(7, name.length() - 7); } if( name.equals("phase") ) { EppLaunchPhase *_pptr = EppLaunchPhase::fromXML(*node); if( null != _pptr ) { cmd->_phase = *_pptr; delete _pptr; } _pptr = null; } else if ( name.equals("applicationID") ) { cmd->_appId = EppUtil::getText(*node); } } for( unsigned int i = 0;i<attrs->getLength();i++ ) { DOMNode* attr = attrs->item(i); if( XS(attr->getNodeName()).equals("includeMark") ) { DOMString _v = attr->getNodeValue(); if( _v.length() > 0 ) { if( _v.equals("true") ) { cmd->includeMark(true); } } break; } } return cmd; }
Anchor *Anchor::get(DOMNode *node) { unsigned int i; // variable to counter DOMNamedNodeMap *attributes; // variable to hold the node attributes Anchor *anchor; attributes = node->getAttributes(); for (i = 0; i < attributes->getLength(); i++) { if (!strcmp(XMLString::transcode(attributes->item(i)->getNodeName()) , "USE")) { return((Anchor *)getLink(XMLString::transcode(attributes->item(i)->getNodeValue()))); } } anchor = new Anchor(); anchor->read(node); return anchor; }
// // domCheckSum - Compute the check sum for a DOM node. // Works recursively - initially called with a document node. // void ThreadParser::domCheckSum(const DOMNode *node) { const XMLCh *s; DOMNode *child; DOMNamedNodeMap *attributes; switch (node->getNodeType() ) { case DOMNode::ELEMENT_NODE: { s = node->getNodeName(); // the element name attributes = node->getAttributes(); // Element's attributes int numAttributes = attributes->getLength(); int i; for (i=0; i<numAttributes; i++) domCheckSum(attributes->item(i)); addToCheckSum(s); // Content and Children for (child=node->getFirstChild(); child!=0; child=child->getNextSibling()) domCheckSum(child); break; } case DOMNode::ATTRIBUTE_NODE: { s = node->getNodeName(); // The attribute name addToCheckSum(s); s = node->getNodeValue(); // The attribute value if (s != 0) addToCheckSum(s); break; } case DOMNode::TEXT_NODE: case DOMNode::CDATA_SECTION_NODE: { s = node->getNodeValue(); addToCheckSum(s); break; } case DOMNode::ENTITY_REFERENCE_NODE: case DOMNode::DOCUMENT_NODE: { // For entity references and the document, nothing is dirctly // added to the checksum, but we do want to process the chidren nodes. // for (child=node->getFirstChild(); child!=0; child=child->getNextSibling()) domCheckSum(child); break; } } }
bool XmlParser::nodesMatch(DOMElement *mergeEl, DOMElement *patchEl) { DualString mergeTagName(mergeEl->getTagName()); DualString patchTagName(patchEl->getTagName()); if (verbose) { cerr << "Comparing Tag \'" << mergeTagName.asCString() << "\' to \'" << patchTagName.asCString(); } if (!XMLString::equals(mergeTagName.asXMLString(), patchTagName.asXMLString())) { if (verbose) { cerr << "\' - false\n"; } return false; } if (verbose) { cerr << "\' - equal\n"; } DOMNamedNodeMap *patchAttributes = patchEl->getAttributes(); unsigned attributeCount = patchAttributes->getLength(); for (unsigned attrIndex = 0; attrIndex < attributeCount; attrIndex++) { DOMNode *attribute = patchAttributes->item(attrIndex); DualString attributeName(attribute->getNodeName()); if (XMLString::equals(attributeName.asXMLString(), attr_merge_actions.asXMLString())) { if (verbose) { cerr << "Skipping attribute \'" << attributeName.asCString() << "\'\n"; } continue; } if (verbose) { cerr << "Checking for attribute \'" << attributeName.asCString(); } if (!mergeEl->hasAttribute(attributeName.asXMLString())) { if (verbose) { cerr << "\' - Not present\n"; } return false; } if (verbose) { cerr << "\' - Present"; } DualString patchAttributeValue(attribute->getNodeValue()); DualString mergeAttributeValue(mergeEl->getAttribute(attributeName.asXMLString())); if (!XMLString::equals(patchAttributeValue.asXMLString(), mergeAttributeValue.asXMLString())) { if (verbose) { cerr << "\' - Not equal\n"; } return false; } if (verbose) { cerr << "\' - Equal (" << patchAttributeValue.asCString() << ")\n"; } } return true; }
bool DataSource::parserDataSource(XSchema* pschema,xercesc::DOMElement* element) { this->parentschema=pschema; if(element) { DOMNamedNodeMap *attributes; DOMNodeList *children =element->getChildNodes(); DOMNode *tmpnode; std::string tmpstr=XMLString::transcode(element->getNodeName()); if(tmpstr!="DataSource") { return false; } attributes=element->getAttributes(); if(attributes) { for(int j=0;j<attributes->getLength();j++) { tmpnode=attributes->item(j); tmpstr=XMLString::transcode(tmpnode->getNodeName()); if(tmpstr == "type") { this->type_ = (DataSource::CUBETYPE) atoi(XMLString::transcode(tmpnode->getNodeValue())); } else if(tmpstr=="url") { this->_URL=XMLString::transcode(tmpnode->getNodeValue()); } else if(tmpstr=="passWord") { this->_psword=XMLString::transcode(tmpnode->getNodeValue()); } else if(tmpstr=="userName") { this->_UserName =XMLString::transcode(tmpnode->getNodeValue()); } } } else { return false; } } else { return false; } return true; }
PointSet *PointSet::get(DOMNode *node) { unsigned int i; // variable to counter DOMNamedNodeMap *attributes; // variable to hold the node attributes PointSet *pointSet; attributes = node->getAttributes(); for (i = 0; i < attributes->getLength(); i++) { if (!strcmp(XMLString::transcode(attributes->item(i)->getNodeName()) , "USE")) { return((PointSet *)getLink(XMLString::transcode(attributes->item(i)->getNodeValue()))); } } pointSet = new PointSet(); pointSet->read(node); return pointSet; }
NurbsCurve *NurbsCurve::get(DOMNode *node) { NurbsCurve *nurbsCurve; unsigned int i; // variable to counter DOMNamedNodeMap *attributes; // variable to hold the node attributes attributes = node->getAttributes(); for (i = 0; i < attributes->getLength(); i++) { if (!strcmp(XMLString::transcode(attributes->item(i)->getNodeName()) , "USE")) { return((NurbsCurve *)getLink(XMLString::transcode(attributes->item(i)->getNodeValue()))); } } nurbsCurve = new NurbsCurve(); nurbsCurve->read(node); return nurbsCurve; }
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; }
XMLNode *JobXML::deepCopyElement( XMLNode **copy, const XMLNode *original ) { // add the element to the copy char *nodeName = XMLString::transcode( original->getNodeName() ); XMLNode *newElement = AddElement( (*copy), nodeName ); XMLString::release( &nodeName ); // add its attributes if ( original->hasAttributes() ) { DOMNamedNodeMap *attributes = original->getAttributes(); for( unsigned int i=0; i<attributes->getLength(); i++ ) { DOMAttr *attr = (DOMAttr*)attributes->item( i ); char *key = XMLString::transcode( attr->getName() ); char *val = XMLString::transcode( attr->getValue() ); SetAttribute( newElement, key, val ); XMLString::release( &key ); XMLString::release( &val ); } } // recursively copy all child elements int childElementCount=0; XMLNode *itr = original->getFirstChild(); for ( ; itr != NULL; itr = itr->getNextSibling() ) { if ( itr->getNodeType() == XMLNode::ELEMENT_NODE ) { deepCopyElement( &newElement, itr ); childElementCount++; } } // if no child elements, copy this element's text content and we are done if ( childElementCount == 0 ) { char *content = XMLString::transcode( original->getTextContent() ); SetContent( newElement, content ); XMLString::release( &content ); } return newElement; }
// --------------------------------------------------------------------------- // // Recursively Count up the total number of child Elements under the specified Node. // Process attributes of the node, if any. // // --------------------------------------------------------------------------- static int countChildElements(DOMNode *n, bool printOutEncounteredEles) { DOMNode *child; int count = 0; if (n) { if (n->getNodeType() == DOMNode::ELEMENT_NODE) { if(printOutEncounteredEles) { char *name = XMLString::transcode(n->getNodeName()); cout <<"----------------------------------------------------------"<<endl; cout <<"Encountered Element : "<< name << endl; XMLString::release(&name); if(n->hasAttributes()) { // get all the attributes of the node DOMNamedNodeMap *pAttributes = n->getAttributes(); int nSize = pAttributes->getLength(); cout <<"\tAttributes" << endl; cout <<"\t----------" << endl; for(int i=0; i<nSize; ++i) { DOMAttr *pAttributeNode = (DOMAttr*) pAttributes->item(i); // get attribute name char *name = XMLString::transcode(pAttributeNode->getName()); cout << "\t" << name << "="; XMLString::release(&name); // get attribute type name = XMLString::transcode(pAttributeNode->getValue()); cout << name << endl; XMLString::release(&name); } } } ++count; } for (child = n->getFirstChild(); child != 0; child=child->getNextSibling()) count += countChildElements(child, printOutEncounteredEles); } return count; }
void SYSTEM::CConfigItem::RemoveAllAttributes() { if(((DOMElement*)itemElement)->hasAttributes()) { DOMNamedNodeMap *pAttributes = ((DOMElement*)itemElement)->getAttributes(); XMLSize_t count = pAttributes->getLength(); DOMAttr* pNode = NULL; for (XMLSize_t i = 0 ; i < count ; ++i) { pNode = (DOMAttr*)pAttributes->item(0); if( m_curValue != NULL ) XMLString::release(&m_curValue); if(!pNode) //属性名称不存在 m_curValue = NULL; else m_curValue = XMLString::transcode(pNode->getName());/*DOMAttr **/ ((DOMElement*)itemElement)->removeAttribute(pNode->getName()); } } }
// --------------------------------------------------------------------------- // utility func to extract a DOMNodes Base attr value if present // --------------------------------------------------------------------------- static const XMLCh * getBaseAttrValue(DOMNode *node){ if (node->getNodeType() == DOMNode::ELEMENT_NODE){ DOMElement *elem = (DOMElement *)node; if(elem->hasAttributes()) { /* get all the attributes of the node */ DOMNamedNodeMap *pAttributes = elem->getAttributes(); XMLSize_t nSize = pAttributes->getLength(); for(XMLSize_t i=0;i<nSize;++i) { DOMAttr *pAttributeNode = (DOMAttr*) pAttributes->item(i); /* get attribute name */ if (XMLString::equals(pAttributeNode->getName(), XIncludeUtils::fgXIBaseAttrName)){ /*if (namespace == XMLUni::fgXMLString){ }*/ return pAttributeNode->getValue(); } } } } return NULL; }
void DWXML::printElement(xercesc::DOMElement *element) { int k; DOMNamedNodeMap *attributes; DOMNodeList *children =element->getChildNodes(); DOMNode *tmpnode; std::cout<<"< "<<XMLString::transcode(element->getNodeName()); attributes=element->getAttributes(); int r= children->getLength(); if(attributes) { for(int j=0;j<attributes->getLength();j++) { tmpnode=attributes->item(j); std::cout<<" "<<XMLString::transcode(tmpnode->getNodeName()); std::cout<<"="; std::cout<<" "<<XMLString::transcode(tmpnode->getNodeValue()); } } std::cout<<" >"; if(element->hasChildNodes()) { std::cout<<std::endl; std::cout<<"children.length:"<<r<<std::endl; for( k=0;k<children->getLength();k++) { std::cout<<k<<"="<<"type: "<<children->item(k)->getNodeType()<<std::endl;; if(children->item(k)->getNodeType()==1) { printElement((DOMElement *)children->item(k)); } else if(children->item(k)->getNodeType()== 3) { cout<<" "<<XMLString::transcode(children->item(k)->getNodeValue()); } } } }
Triggerconf::STRING_LIST Triggerconf::getConfigAttributeNames (string module, string submodule, string configname) { STRING_LIST ret; if (! existsConfigElement (module, submodule, configname)) return ret; DOMNode* node = selectConfigElement (module, submodule, configname); if (node == NULL || node->getNodeType () != DOMNode::ELEMENT_NODE) return ret; DOMElement* elem = (DOMElement*) node; DOMNamedNodeMap* attributes = elem->getAttributes (); for (unsigned int i=0; i<attributes->getLength (); i++) { DOMNode* attr = attributes->item (i); const XMLCh* xname = attr->getNodeName (); char* cname = XMLString::transcode (xname); ret.push_back (cname); XMLString::release (&cname); } return ret; }
EppLaunchPhase* EppLaunchPhase::fromXML( const DOMNode& root ) { DOMNamedNodeMap* attrs = root.getAttributes(); EppLaunchPhase *_ret = new EppLaunchPhase(); if( null == _ret ) return null; { DOMNode* node = (DOMNode*)&root; DOMString name = node->getLocalName(); if( name.isNull() ) { name = node->getNodeName(); } if( name.isNotNull() ) { if( name.substringData(0, 7).equals("launch:") ) { name = name.substringData(7, name.length() - 7); } if( name.equals("phase") ) { _ret->_phase = EppUtil::getText(*node); } } } for( unsigned int i = 0; i<attrs->getLength(); i++ ) { DOMNode* attr = attrs->item(i); DOMString _v = attr->getNodeValue(); if( XS(attr->getNodeName()).equals("name") ) { _ret->_sub_phase = attr->getNodeValue(); break; } } return _ret; }
// --------------------------------------------------------------------------- // 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); } } }
void *NurbsCurve::read(DOMNode *node) { unsigned int i; //* variable to counter DOMNamedNodeMap *attributes; //* variable to hold the node attributes char *ctemp; //* temporary variable attributes = node->getAttributes(); for (i = 0; i < attributes->getLength(); i++) { if (!strcmp(XMLString::transcode(attributes->item(i)->getNodeName()) , "DEF")) { strcpy(this->DEF,XMLString::transcode (attributes->item(i)->getNodeValue())); setLink(XMLString::transcode(attributes->item(i)->getNodeValue()),this); } else if (!strcmp(XMLString::transcode(attributes->item(i)->getNodeName()) , "USE")) { return(getLink(XMLString::transcode(attributes->item(i)->getNodeValue()))); } } for (i = 0; i < attributes->getLength(); i++) { if ( !strcmp(XMLString::transcode (attributes->item(i)->getNodeName()) , "tessellation")) { } else if ( !strcmp(XMLString::transcode (attributes->item(i)->getNodeName()) , "containerField")) { } else if ( !strcmp(XMLString::transcode (attributes->item(i)->getNodeName()) , "order")) { } else if ( !strcmp(XMLString::transcode (attributes->item(i)->getNodeName()) , "controlPoint")) { numberOfPoints=0; ctemp = strtok(XMLString::transcode (attributes->item(i)->getNodeValue())," "); while (ctemp != NULL) { points[numberOfPoints][0] = atof(ctemp); ctemp = strtok(NULL," "); points[numberOfPoints][1] = atof(ctemp); ctemp = strtok(NULL," "); points[numberOfPoints++][2] = atof(ctemp); ctemp = strtok(NULL," "); #ifdef DEBUG cout << "Points : " << points[numberOfPoints-1][0] << " , " << points[numberOfPoints-1][1] << " , " << points[numberOfPoints-1][2] << endl; #endif } } } #ifdef DEBUG cout << "Number of Points : " << numberOfPoints << endl; #endif controlPoint = new float[3*numberOfPoints]; unsigned int f; for(f=0;f<routeStruct::routeCount;f++) { if (!strcmp (x3d::my_x3d->routeTable[f]->toNode,DEF)) { if(!strcmp(x3d::my_x3d->routeTable[f]->toField,"set_controlPoint")) { if((*x3d::my_x3d->routeTable[f]->field2)==NULL) { (*x3d::my_x3d->routeTable[f]->field2) = new float[3*numberOfPoints]; } delete controlPoint; controlPoint = (float *)(*x3d::my_x3d->routeTable[f]->field2); } } } return(NULL); }
void XmlTag::construct(XmlTag * parent, DOMNode * n, bool logging) { this->parent = parent; this->name = "unknown"; if (parent == NULL) { if (logging) { pLogEngine l (LogEngine::create (LOG_DEVELOPER, "XmlTag")); this->log = l; } } else { if (logging) this->log = parent->log; } if (n == NULL) { if (logging) log->__format(LOG_ERROR, "Empty tag (%s)!", getFullName().c_str()); return; } if (n->getNodeType() != DOMNode::ELEMENT_NODE) { if (logging) log->__format(LOG_ERROR, "This (%s) is not a tag!", getFullName().c_str()); } assignXmlString (name, n->getNodeName()); //fill tag attributes map if (!n->hasAttributes()) { if (logging) log->__format(LOG_WARNING, "No attributes in this tag (%s)!", getFullName().c_str() ); } else { std::string attributeName = ""; std::string attributeData = ""; DOMNamedNodeMap *attList = n->getAttributes (); int size = attList->getLength (); for (int i = 0; i < size; ++i) { DOMAttr *attNode = (DOMAttr *) attList->item (i); assignXmlString (attributeName, attNode->getName ()); assignXmlString (attributeData, attNode->getValue ()); if ( (attributeName != "") && (attributeData != "") ) { attributes[attributeName] = attributeData; attributesRead[attributeName] = false; } } } //fill child tags map if (n->hasChildNodes()) { std::string childTagName; for (n = n->getFirstChild (); n != 0; n = n->getNextSibling ()) { if (n) if (n->getNodeType() == DOMNode::ELEMENT_NODE) { assignXmlString (childTagName, n->getNodeName()); //XmlTag * tmpTag = new XmlTag(this, n, logging); XmlTag * tmpTag = new XmlTag(this, n); tags.push_back(tmpTag); } } } }
bool XCube::parserCube(XSchema* pschema,xercesc::DOMElement* element) { this->_parentschema=pschema; if(element) { DOMNamedNodeMap *attributes; DOMNodeList *children =element->getChildNodes(); DOMNode *tmpnode; std::string tmpstr=XMLString::transcode(element->getNodeName()); if(tmpstr!="Cube") { return false; } attributes=element->getAttributes(); if(attributes) { for(int j=0;j<attributes->getLength();j++) { tmpnode=attributes->item(j); tmpstr=XMLString::transcode(tmpnode->getNodeName()); if(tmpstr=="name") { this->_name=XMLString::transcode(tmpnode->getNodeValue()); } else if(tmpstr=="tableName") { this->_fact=XMLString::transcode(tmpnode->getNodeValue()); } } } else { return false; } if(element->hasChildNodes()) { for(int k=0;k<children->getLength();k++) { if(children->item(k)->getNodeType()==1) { DOMElement* tmpelement=(DOMElement*)children->item(k); tmpstr=XMLString::transcode(tmpelement->getNodeName()); if(tmpstr=="Dimension") { Dimension *dimension=new Dimension; if(dimension->parserDimension(this,tmpelement)) { this->_dimensions.push_back(dimension); } else { return false; } } else if(tmpstr=="DimensionUsage") { Dimension* dimension=NULL; attributes=tmpelement->getAttributes(); if(attributes) { for(int j=0;j<attributes->getLength();j++) { DOMNode *tmpnode=attributes->item(j); tmpstr=XMLString::transcode(tmpnode->getNodeName()); // std::string dname1=XMLString::transcode(tmpnode->getNodeValue()); if(tmpstr=="source") { std::string dname=XMLString::transcode(tmpnode->getNodeValue()); dimension=this->getSchema()->getShareDimension(dname); } } if(dimension) { Dimension *tmpdmen=new Dimension; *tmpdmen=*dimension; for(int j=0;j<attributes->getLength();j++) { DOMNode *tmpnode=attributes->item(j); tmpstr=XMLString::transcode(tmpnode->getNodeName()); if(tmpstr=="name") { std::string dname=XMLString::transcode(tmpnode->getNodeValue()); tmpdmen->setName(dname); } else if(tmpstr=="foreignKey") { std::string fkey=XMLString::transcode(tmpnode->getNodeValue()); tmpdmen->setForeignKey(fkey); } } tmpdmen->setCubeDimension(this); this->_dimensions.push_back(tmpdmen); } } } else if(tmpstr=="Measure") { Measure *measure=new Measure; if(measure->parserMeasure(this,tmpelement)) { this->_measures.push_back(measure); } else { return false; } } else if(tmpstr=="CalculatedMember") { calcMember *calmember=new calcMember; if(calmember->parserCalMember(this,tmpelement)) { this->_calcmembers.push_back(calmember); } else { return false; } } } } } else { return false; } } else { return false; } return true; }
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; }
bool XMLExtServiceHelper::parseAndReplyToExtSearchReq( DOMNode* cur, DOMNode* out, DOMDocument* reply, bool indent, const HttpHeader& inHeaders ) throw ( XMLServerErrorMsg ) { // Be careful! This method throws, which means stuff has to be cleaned // up. // <ext_search_request language="english" // search_item_starting_index="1" // search_item_ending_index="10" // service_id = "2" // transaction_id = "xoxox"> // <field_val id="1">3</field_val> // <field_val id="7">svend</field_val> // <field_val id="6">tromsö</field_val> // </ext_search_request> // Get the attribs DOMNamedNodeMap* attributes = cur->getAttributes(); // Needed stuff ExternalSearchRequestData::stringMap_t fields; LangType lang; uint32 extService = 0; // Default to MC2. Add paramter to request if needed only. XMLCommonEntities::coordinateType positionSystem = XMLCommonEntities::MC2; int search_item_starting_index = 0; int search_item_ending_index = 25; for( int i = 0, n = attributes->getLength(); i < n; ++i ) { DOMNode* attrib = attributes->item( i ); if ( XMLString::equals( attrib->getNodeName(), "language" ) ) { lang = m_xmlParserThread->getStringAsLanguage( XMLUtility::getChildTextStr( *attrib ).c_str() ); } else if ( XMLString::equals( attrib->getNodeName(), "search_item_starting_index" ) ) { search_item_starting_index = getLongOrThrow( attrib ); } else if ( XMLString::equals( attrib->getNodeName(), "search_item_ending_index" ) ) { search_item_ending_index = getLongOrThrow( attrib ); } else if ( XMLString::equals( attrib->getNodeName(), "service_id" ) ) { extService = getLongOrThrow( attrib ); } } // Good. Now take the other stuff. for ( DOMNode* child = cur->getFirstChild(); child != NULL; child = child->getNextSibling() ) { switch ( child->getNodeType() ) { case DOMNode::ELEMENT_NODE: if ( XMLString::equals( child->getNodeName(), "field_val" ) ) { pair<int, MC2String> cur_field; cur_field.first = getRequiredLongOrThrow( child, "id" ); cur_field.second = XMLUtility::getChildTextStr( *child ); fields.insert( cur_field ); } else { throw XMLServerErrorMsg( "-1", MC2String("Unexpected node in " "external_search_request: ") + XMLUtility::transcodefrom( child->getNodeName() )); } break; case DOMNode::COMMENT_NODE : // Ignore comments break; case DOMNode::TEXT_NODE : // Ignore stray texts break; default: mc2log << warn << "[XMLExtServiceHelper::" << "parseAndReplyToExtSearchReq]: Odd node " << MC2CITE( child->getNodeName() ) << " especially the type " << child->getNodeType()<< endl; break; } } // Check the field values CompactSearchHitTypeVector headings = m_thread->getSearchHandler().getSearchHitTypes(lang, 0); for ( CompactSearchHitTypeVector::iterator it = headings.begin(); it != headings.end(); ++it ) { if ( it->m_serviceID == extService ) { ExternalSearchRequestData::stringMap_t::const_iterator findit; if( it->m_providerType == CompactSearchHitType::white_pages ) { // Check fields required for white pages findit = fields.find( ExternalSearchConsts::name_or_phone ); } else { // Check required fields yellow pages findit = fields.find( ExternalSearchConsts::company_or_search_word ); } if( findit != fields.end() ) { // country is required for both wp and yp findit = fields.find( ExternalSearchConsts::country ); if( findit != fields.end() ) { // Country provided. Check that it is valid // Try strtoul char* endPtr; uint32 val = strtoul( findit->second.c_str(), &endPtr, 0 ); if ( *endPtr != '\0' || ( val != MAX_UINT32 && val != static_cast<uint32>( ExternalSearchHelper::topRegionToCountryCode( it->m_topRegionID, lang ) ) ) ) { mc2dbg << "[XMLExtServiceHelper]: param " << findit->first << " = " << findit->second << " is bad" << endl; findit = fields.end(); } } } if ( findit == fields.end() ) { throw XMLServerErrorMsg( "-1", "Fields filled in the wrong way" ); } // Service found, break loop break; } } // Prepare for searching SearchRequestParameters params; params.setRequestedLang( lang ); int nbrWanted = search_item_ending_index - search_item_starting_index + 1; ExternalSearchRequestData reqData( params, extService, fields, search_item_starting_index, nbrWanted ); // Do the searching ExternalSearchRequest req ( m_thread->getNextRequestID(), reqData ); m_thread->putRequest( &req ); if ( req.getStatus() != StringTable::OK ) { throw XMLServerErrorMsg( req.getStatus() ); } XMLSearchUtility::appendSearchItemList( out, reply, 1, false, // indent off req, "", //currentLocation, search_item_starting_index, search_item_ending_index, false, true, // positionSearchItems, positionSystem, params ); return true; }