void Parameters::readFile(string str){ file = str; XMLPlatformUtils::Initialize(); XercesDOMParser parser; parser.setValidationScheme(XercesDOMParser::Val_Always); HandlerBase errHandler;// = (ErrorHandler*) new HandlerBase(); parser.setErrorHandler(&errHandler); parser.parse(str.c_str()); DOMDocument * doc = parser.getDocument(); DOMElement* elementRoot = doc->getDocumentElement(); // Extract floats DOMElement* floatRoot = (DOMElement *) elementRoot->getElementsByTagName(XMLString::transcode("real"))->item(0); DOMElement* child = floatRoot->getFirstElementChild(); do{ saveReal(XMLString::transcode(child->getNodeName()), atof(XMLString::transcode(child->getTextContent()))); child = child->getNextElementSibling(); }while(child != NULL); // Extract integers DOMElement* intRoot = (DOMElement *) elementRoot->getElementsByTagName(XMLString::transcode("integer"))->item(0); child = intRoot->getFirstElementChild(); do{ saveInteger( XMLString::transcode(child->getNodeName()), atoi(XMLString::transcode(child->getTextContent()))); child = child->getNextElementSibling(); }while(child != NULL); }
XMLSize_t DOMElementImpl::getChildElementCount() const { XMLSize_t count = 0; DOMElement* child = getFirstElementChild(); while (child != NULL) { ++count; child = child->getNextElementSibling(); } return count; }
XmlElementList XmlElement::getChildren() const { XmlElementList vec; DOMElement* curr = base->getFirstElementChild(); while(curr) { if(!(curr->getNodeType() == DOMNode::TEXT_NODE || curr->getNodeType() == DOMNode::COMMENT_NODE)) //skip text nodes and comments vec.push_back( XmlElement(curr, doc) ); curr = curr->getNextElementSibling(); } return vec; }
void XmlSchemaGenerator::findAllElements ( const DOMElement &element, size_t nIndent /*= 0*/) { wxString tagName = WrapXerces::toString ( element.getTagName() ); mElements[tagName].nodes.insert ( &element ); DOMElement *child = element.getFirstElementChild(); for ( ; child != NULL; child = child->getNextElementSibling() ) { findAllElements ( *child, nIndent ); } }
void XmlSchemaGenerator::generateData ( const DOMElement &element, size_t nIndent /*= 0*/) { wxString name = WrapXerces::toString ( element.getTagName() ); if ( mElements[name].name.empty() ) { // Only generate data once generateData ( name, nIndent ); } DOMElement *child = element.getFirstElementChild(); for ( ; child != NULL; child = child->getNextElementSibling() ) { generateData ( *child, nIndent ); } }
static DOMElement * SAMLFindChildByName(const DOMElement *elem, const char *name) { XMLT sigNodeName(name); DOMElement *childElem; for (childElem = elem->getFirstElementChild(); childElem != NULL; childElem = childElem->getNextElementSibling()) { if (XMLString::equals(childElem->getNodeName(), sigNodeName.getUnicodeStr())) { break; } } return childElem; }
void XmlSchemaGenerator::outputSchema ( const DOMElement &element ) { wxString tagName = WrapXerces::toString ( element.getTagName() ); ElmtData &data = mElements[tagName]; if ( data.schema.empty() ) { if ( mGrammarType == Grammar::SchemaGrammarType ) generateSchema ( data, 1 ); else generateDTD ( data, 1 ); mSchema << data.schema; } DOMElement *child = element.getFirstElementChild(); for ( ; child != NULL; child = child->getNextElementSibling() ) { outputSchema ( *child ); } }
XERCES_CPP_NAMESPACE_USE std::vector<DgFileTile> DgFileTile::getTiles(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* pDocument, const std::string& filename, unsigned int& height, unsigned int& width) { std::vector<DgFileTile> tiles; DOMElement* pRoot = pDocument->getDocumentElement(); if (pRoot == NULL || !XMLString::equals(pRoot->getNodeName(), X("isd"))) { return tiles; } DOMNodeList* pTilList = pRoot->getElementsByTagName(X("TIL")); if (pTilList == NULL || pTilList->getLength() != 1) { return tiles; } DOMNode* pTil = pTilList->item(0); if (pTil == NULL || pTil->getNodeType() != DOMNode::ELEMENT_NODE) { return tiles; } DOMElement* pTilElement = static_cast<DOMElement*>(pTil); DOMNodeList* pTilesList = pTilElement->getElementsByTagName(X("TILE")); if (pTilesList == NULL) { return tiles; } height = 0; width = 0; bool error = false; QFileInfo fileInfo(QString::fromStdString(filename)); QDir fileDir = fileInfo.dir(); for (unsigned int i = 0; i < pTilesList->getLength(); ++i) { DgFileTile curTile; DOMNode* pNode = pTilesList->item(i); if (pNode == NULL || pNode->getNodeType() != DOMNode::ELEMENT_NODE) { continue; } DOMElement* pElement = static_cast<DOMElement*>(pNode); DOMElement* pChildElement = pElement->getFirstElementChild(); while (pChildElement != NULL) { std::string textContent = A(pChildElement->getTextContent()); if (XMLString::equals(pChildElement->getNodeName(), X("FILENAME"))) { curTile.mTilFilename = fileDir.filePath(QString::fromStdString(textContent)).toStdString(); } if (XMLString::equals(pChildElement->getNodeName(), X("ULCOLOFFSET"))) { curTile.mStartCol = StringUtilities::fromXmlString<unsigned int>(textContent, &error); } if (XMLString::equals(pChildElement->getNodeName(), X("ULROWOFFSET"))) { curTile.mStartRow = StringUtilities::fromXmlString<unsigned int>(textContent, &error); } if (XMLString::equals(pChildElement->getNodeName(), X("LRCOLOFFSET"))) { curTile.mEndCol = StringUtilities::fromXmlString<unsigned int>(textContent, &error); } if (XMLString::equals(pChildElement->getNodeName(), X("LRROWOFFSET"))) { curTile.mEndRow = StringUtilities::fromXmlString<unsigned int>(textContent, &error); } pChildElement = pChildElement->getNextElementSibling(); } tiles.push_back(curTile); if (curTile.mEndCol > width) { width = curTile.mEndCol; } if (curTile.mEndRow > height) { height = curTile.mEndRow; } } return tiles; }
void XmlSchemaGenerator::generateData ( const wxString &elementName, size_t nIndent /*= 0*/) { ElmtData &data = mElements[elementName]; std::set<const DOMElement *>::iterator elmtItr; data.name = elementName; //Content std::map<wxString, ChildData> &childMap = data.children; std::map<wxString, ChildData>::iterator itr; std::set<wxString> previous; elmtItr = data.nodes.begin(); for ( ; elmtItr != data.nodes.end(); ++elmtItr ) { previous.clear(); std::map<wxString, size_t> countMap; DOMElement *child = ( **elmtItr ).getFirstElementChild(); for ( ; child != NULL; child = child->getNextElementSibling() ) { wxString name = WrapXerces::toString ( child->getTagName() ); childMap[name].prevSiblings.insert ( previous.begin(), previous.end() ); childMap[name].prevSiblings.erase ( name ); // Don't depend on oneself previous.insert ( name ); countMap[name] += 1; } std::map<wxString, size_t>::iterator countItr = countMap.begin(); for ( ; countItr != countMap.end(); ++countItr ) { if ( childMap[countItr->first].maxOccurs < countItr->second ) childMap[countItr->first].maxOccurs = countItr->second; } if ( childMap.size() == countMap.size() ) continue; for ( itr = childMap.begin(); itr != childMap.end(); ++itr ) { if ( countMap.find ( itr->first ) != countMap.end() ) continue; itr->second.minOccurs = 0; } } // Attribute std::map<wxString, const XMLCh *> &attrMap = data.attrMap; std::set<wxString> &optAttrs = data.optAttrs; std::map<wxString, const XMLCh *>::iterator attrItr; elmtItr = data.nodes.begin(); for ( ; elmtItr != data.nodes.end(); ++elmtItr ) { if ( ! ( **elmtItr ).hasAttributes() ) continue; wxString name; DOMAttr *attr; DOMNamedNodeMap *attrs = ( **elmtItr ).getAttributes(); size_t i = attrs->getLength(); while ( i-- > 0 ) { attr = ( DOMAttr* ) attrs->item ( i ); name = WrapXerces::toString ( attr->getName() ); if ( attr->getPrefix() != NULL ) { wxLogDebug ( _T("Ignore: %s"), name.c_str() ); continue; } if ( attr->getSpecified() ) attrMap[name]; // Initialize attribute map else attrMap[name] = attr->getValue(); } if ( attrMap.size() == optAttrs.size() ) continue; for ( attrItr = attrMap.begin(); attrItr != attrMap.end(); ++attrItr ) { if ( attrs->getNamedItem ( ( const XMLCh * ) WrapXerces::toString ( attrItr->first ).GetData() ) == NULL ) { optAttrs.insert ( attrItr->first ); } } } // Deal with sequence wxLogDebug ( _T("%s:"), elementName.c_str() ); data.useSequence = getSequence ( data.sequence, childMap ); // Now we have the data of the element if ( mGrammarType == Grammar::DTDGrammarType ) { generateDTD ( data, nIndent ); mSchema << data.schema; } else if ( !mInlineSimpleType ) { // Or wait until all data are available generateSchema ( data, nIndent ); mSchema << data.schema; } }
static bool SAMLCheckSubject(const DOMDocument *doc, SAMLTokenData &token) { const DOMElement *subject; char *name = g_strdup_printf("%sSubject", token.ns.c_str()); subject = SAMLFindChildByName(doc->getDocumentElement(), name); g_free(name); if (NULL == subject) { // Should not happen, since this is required element in the schema. Log("%s: Missing subject element!\n", __FUNCTION__); // ASSERT(0); return false; } const DOMElement *nameID; name = g_strdup_printf("%sNameID", token.ns.c_str()); nameID = SAMLFindChildByName(subject, name); g_free(name); if (NULL == nameID) { /* * The schema allows BaseID, NameID, or EncryptedID. The library code * for the SSO server only supports NameID. EncryptedID is really * complicated (and we don't have decryption keys, so let's not * support it for now. */ Log("%s: No NameID element for the subject.\n", __FUNCTION__); return false; } token.subjectName = SAMLStringWrapper(nameID->getTextContent()).c_str(); Debug("%s: subjectName: '%s'\n", __FUNCTION__, token.subjectName.c_str()); /* * TODO: Investigate: NameID elements can have a NameQualifier attribute. * This smells like a domain name, and we might want to include it with * subject name (<NameQualifier>\subjectName). */ /* * Find all the SubjectConfirmation nodes and see if at least one can be * verified. */ name = g_strdup_printf("%sSubjectConfirmation", token.ns.c_str()); XMLT scName(name); g_free(name); for (DOMElement *child = subject->getFirstElementChild(); child != NULL; child = child->getNextElementSibling()) { if (!XMLString::equals(child->getNodeName(), scName.getUnicodeStr())) { continue; } const XMLCh *method = child->getAttribute(MAKE_UNICODE_STRING("Method")); if ((NULL == method) || (0 == *method)) { // Should not happen, since this is a required attribute. ASSERT(0); Debug("%s: Missing confirmation method.\n", __FUNCTION__); continue; } if (!XMLString::equals( MAKE_UNICODE_STRING("urn:oasis:names:tc:SAML:2.0:cm:bearer"), method)) { Debug("%s: Non-bearer confirmation method in token", __FUNCTION__); continue; } const DOMElement *subjConfirmData; name = g_strdup_printf("%sSubjectConfirmationData", token.ns.c_str()); subjConfirmData = SAMLFindChildByName(child, name); g_free(name); if (NULL != subjConfirmData) { if (!SAMLCheckTimeAttr(subjConfirmData, "NotBefore", true) || !SAMLCheckTimeAttr(subjConfirmData, "NotOnOrAfter", false)) { Warning("%s: subjConfirmData time check failed\n", __FUNCTION__); continue; } const XMLCh *recipient; recipient = subjConfirmData->getAttribute( MAKE_UNICODE_STRING("Recipient")); /* * getAttribute() returns a 0-length string, not NULL, if it can't * find what it wants. */ if ((0 != XMLString::stringLen(recipient)) && !SAMLCheckAudience(recipient)) { Debug("%s: failed recipient check\n", __FUNCTION__); continue; } } return true; } Debug("%s: Could not verify using any SubjectConfirmation elements\n", __FUNCTION__); return false; }