void Aluno::buildFromXml (DOMNode *node) { DOMElement *element = dynamic_cast<DOMElement*>(node); //recuperar dados do xml XMLCh* tag_cpf = XMLString::transcode("cpf"); //strings do xml usam o tipo XMLCh XMLCh* tag_nome = XMLString::transcode("nome"); XMLCh* tag_universidade = XMLString::transcode("universidade"); XMLCh* tag_curso = XMLString::transcode("curso"); //armazenar dados no objeto DOMNodeList *l_children = node->getChildNodes(); for (XMLSize_t i = 0; i < l_children->getLength(); ++i) { DOMNode *n = l_children->item(i); const XMLCh *tag = n->getNodeName(); if (XMLString::equals(tag, tag_cpf)) { this->cpf = XMLString::transcode(n->getTextContent()); } else if (XMLString::equals(tag, tag_nome)) { this->nome = XMLString::transcode(n->getTextContent()); } else if (XMLString::equals(tag, tag_universidade)) { this->universidade = XMLString::transcode(n->getTextContent()); } else if (XMLString::equals(tag, tag_curso)) { this->curso = XMLString::transcode(n->getTextContent()); } } //strings xml precisam passar por um release apos uso XMLString::release(&tag_cpf); XMLString::release(&tag_nome); XMLString::release(&tag_universidade); XMLString::release(&tag_curso); }
void Materia::buildFromXml (DOMNode *node) { XMLCh* tag_codigo = XMLString::transcode("codigo"); XMLCh* tag_nome = XMLString::transcode("nome"); XMLCh* tag_creditos = XMLString::transcode("creditos"); XMLCh* tag_conceito = XMLString::transcode("conceito"); XMLCh* tag_situacao = XMLString::transcode("situacao"); DOMNodeList *l_children = node->getChildNodes(); for (XMLSize_t i = 0; i < l_children->getLength(); ++i) { DOMNode *n = l_children->item(i); const XMLCh *tag = n->getNodeName(); if (XMLString::equals(tag, tag_codigo)) { this->codigo = XMLString::transcode(n->getTextContent()); } else if (XMLString::equals(tag, tag_nome)) { this->nome = XMLString::transcode(n->getTextContent()); } else if (XMLString::equals(tag, tag_creditos)) { this->creditos = stoi(XMLString::transcode(n->getTextContent())); } else if (XMLString::equals(tag, tag_conceito)) { this->conceito = stod(XMLString::transcode(n->getTextContent())); } else if (XMLString::equals(tag, tag_situacao)) { this->situacao = XMLString::transcode(n->getTextContent()); } } XMLString::release(&tag_codigo); XMLString::release(&tag_nome); XMLString::release(&tag_creditos); XMLString::release(&tag_conceito); XMLString::release(&tag_situacao); }
static TUIObjectInstance extractTUIObjectInstance(DOMDocument * domDocument, DOMTreeWalker * domTreeWalker) { TUIObjectInstance tuiObjectInstance; DOMNode * node = domTreeWalker->getCurrentNode(); DOMNamedNodeMap * nodeMap = node->getAttributes(); DOMNode * nameAttribute = nodeMap->getNamedItem(XMLString::transcode("name")); if (nameAttribute) { tuiObjectInstance.setName(XMLString::transcode(nameAttribute->getNodeValue())); } DOMNode * tuiTypeNameAttribute = nodeMap->getNamedItem(XMLString::transcode("typename")); if (tuiTypeNameAttribute) { tuiObjectInstance.setTypeName(XMLString::transcode(tuiTypeNameAttribute->getNodeValue())); } while (node) { if (XMLString::compareString(XMLString::transcode(node->getNodeName()), "Description") == 0) { XMLCh * textContent = XMLString::replicate(node->getTextContent()); XMLString::trim(textContent); tuiObjectInstance.setDescription(XMLString::transcode(textContent)); XMLString::release(&textContent); } node = domTreeWalker->nextNode(); } return tuiObjectInstance; }
static TUIObjectType extractTUIObjectType(DOMDocument * domDocument, DOMTreeWalker * domTreeWalker) { TUIObjectType tuiObjectType; DOMNode * node = domTreeWalker->getCurrentNode(); DOMNamedNodeMap * nodeMap = node->getAttributes(); DOMNode * nameAttribute = nodeMap->getNamedItem(XMLString::transcode("name")); if (nameAttribute) { tuiObjectType.setName(XMLString::transcode(nameAttribute->getNodeValue())); } while (node) { if (XMLString::compareString(XMLString::transcode(node->getNodeName()), "PortTypeSequence") == 0) { XMLNodeFilter * nodeFilter = new XMLNodeFilter(); DOMTreeWalker * d = domDocument->createTreeWalker(node, DOMNodeFilter::SHOW_ALL, nodeFilter, true); tuiObjectType.setPortMap(extractPortMap(domDocument, d)); d->release(); delete nodeFilter; } else if (XMLString::compareString(XMLString::transcode(node->getNodeName()), "Description") == 0) { XMLCh * textContent = XMLString::replicate(node->getTextContent()); XMLString::trim(textContent); tuiObjectType.setDescription(XMLString::transcode(textContent)); XMLString::release(&textContent); } node = domTreeWalker->nextNode(); } return tuiObjectType; }
// // get_element_value // void Utils:: get_element_value (const xercesc::DOMElement * e, const std::string & element, std::string & value) { using namespace xercesc; // There should be only 1 <name> tag in the list. DOMNodeList * list = e->getElementsByTagName (GAME::Xml::String (element)); size_t len = list->getLength (); assert (len <= 1); if (len == 0) { value = ""; } else if (len == 1) { // Get text content of the one and only node in listing. DOMNode * node = list->item (0); GAME::Xml::String content (node->getTextContent (), false); // Save the value in C string format. value = content.to_string (); } }
static MSPInstance extractMSPInstance(DOMDocument * domDocument, DOMTreeWalker * domTreeWalker) { MSPInstance mspInstance; map<string, ParameterGroup> parameterGroupMap; DOMNode * node = domTreeWalker->getCurrentNode(); DOMNamedNodeMap * nodeMap = node->getAttributes(); DOMNode * nameAttribute = nodeMap->getNamedItem(XMLString::transcode("name")); if (nameAttribute) { mspInstance.setName(XMLString::transcode(nameAttribute->getNodeValue())); } DOMNode * typeNameAttribute = nodeMap->getNamedItem(XMLString::transcode("typename")); if (typeNameAttribute) { //TFDEBUG(XMLString::transcode(typeNameAttribute->getNodeValue())); mspInstance.setTypeName(XMLString::transcode(typeNameAttribute->getNodeValue())); } while (node) { if (XMLString::compareString(XMLString::transcode(node->getNodeName()), "ParameterGroup") == 0) { DOMNamedNodeMap * nodeMap = node->getAttributes(); string name; DOMNode * nameAttribute = nodeMap->getNamedItem(XMLString::transcode("name")); if (nameAttribute) { name = XMLString::transcode(nameAttribute->getNodeValue()); } XMLNodeFilter * nodeFilter = new XMLNodeFilter(); DOMTreeWalker * d = domDocument->createTreeWalker(node, DOMNodeFilter::SHOW_ALL, nodeFilter, true); ParameterGroup pg = extractParameterGroup(domDocument, d); pg.setName(name); parameterGroupMap[name] = pg; d->release(); delete nodeFilter; } else if (XMLString::compareString(XMLString::transcode(node->getNodeName()), "Description") == 0) { XMLCh * textContent = XMLString::replicate(node->getTextContent()); XMLString::trim(textContent); mspInstance.setDescription(XMLString::transcode(textContent)); XMLString::release(&textContent); } node = domTreeWalker->nextNode(); } ParameterGroup parameterGroup; parameterGroup.setName("root"); parameterGroup.setParameterGroupMap(parameterGroupMap); mspInstance.setParameterGroup(parameterGroup); return mspInstance; }
string Triggerconf::getConfigValue (string module, string submodule, string configname) { if (existsConfigElement (module, submodule, configname) == false) { setError ("invalid config element"); return ""; } DOMNode* node = selectConfigElement (module, submodule, configname); if (node == NULL) return ""; const XMLCh* xval = node->getTextContent (); char* charstring = XMLString::transcode (xval); string ret = charstring; XMLString::release (&charstring); resetError (); return ret; }
static DeviceType extractDeviceType(DOMDocument * domDocument, DOMTreeWalker * domTreeWalker) { DeviceType deviceType; DOMNode * node = domTreeWalker->getCurrentNode(); while (node) { if (XMLString::compareString(XMLString::transcode(node->getNodeName()), "PortTypeSequence") == 0) { XMLNodeFilter * nodeFilter = new XMLNodeFilter(); DOMTreeWalker * d = domDocument->createTreeWalker(node, DOMNodeFilter::SHOW_ALL, nodeFilter, true); deviceType.setPortMap(extractPortMap(domDocument, d)); d->release(); delete nodeFilter; } else if (XMLString::compareString(XMLString::transcode(node->getNodeName()), "Description") == 0) { XMLCh * textContent = XMLString::replicate(node->getTextContent()); XMLString::trim(textContent); deviceType.setDescription(XMLString::transcode(textContent)); XMLString::release(&textContent); } node = domTreeWalker->nextNode(); } return deviceType; }
// Returns the value of the "name" child of an "animal" element. const XMLCh* getAnimalName(const DOMElement* animal) { static XercesString name = fromNative("name"); // Iterate though animal's children DOMNodeList* children = animal->getChildNodes( ); for ( size_t i = 0, len = children->getLength( ); i < len; ++i ) { DOMNode* child = children->item(i); if ( child->getNodeType( ) == DOMNode::ELEMENT_NODE && static_cast<DOMElement*>(child)->getTagName( ) == name ) { // We've found the "name" element. return child->getTextContent( ); } } return 0; }
bool CustomLayerImp::fromXml(DOMNode* pDocument, unsigned int version) { if (!LayerImp::fromXml(pDocument, version)) { return false; } DOMElement* pElem = static_cast<DOMElement*>(pDocument); setAcceptsMouseEvents(StringUtilities::fromXmlString<bool>(A(pElem->getAttribute(X("mouseEventsSupported"))))); for (DOMNode* pChld = pElem->getFirstChild(); pChld != NULL; pChld = pChld->getNextSibling()) { if (XMLString::equals(pChld->getNodeName(), X("mouseCursor"))) { string cursorStr = string(A(pChld->getTextContent())); if (cursorStr.empty() == false) { QByteArray cursorArray(QByteArray::fromBase64(QByteArray::fromRawData( cursorStr.c_str(), cursorStr.size()))); QDataStream cursorStream(&cursorArray, QIODevice::ReadOnly); cursorStream >> mMouseCursor; } }
bool CurveImp::fromXml(DOMNode* pDocument, unsigned int version) { if (pDocument == NULL || !PlotObjectImp::fromXml(pDocument, version)) { return false; } DOMElement* pElem = static_cast<DOMElement*>(pDocument); ColorType color = StringUtilities::fromXmlString<ColorType>(A(pElem->getAttribute(X("color")))); mColor = COLORTYPE_TO_QCOLOR(color); mLineWidth = StringUtilities::fromXmlString<int>(A(pElem->getAttribute(X("lineWidth")))); mLineStyle = StringUtilities::fromXmlString<LineStyle>(A(pElem->getAttribute(X("lineStyle")))); for (DOMNode* pChld = pElem->getFirstChild(); pChld != NULL; pChld = pChld->getNextSibling()) { if (XMLString::equals(pChld->getNodeName(), X("Point"))) { mPoints.push_back(StringUtilities::fromXmlString<LocationType>(A(pChld->getTextContent()))); } } return true; }
// // get_element_value // const XMLCh * Utils:: get_element_value (const xercesc::DOMElement * e, const GAME::Xml::String & element) { using xercesc::DOMNodeList; using xercesc::DOMNode; // There should be only 1 <name> tag in the list. GAME::Xml::String nodename; DOMNode * node = 0; DOMNodeList * list = e->getChildNodes (); size_t len = list->getLength (); for (size_t i = 0; i < len; ++ i) { node = list->item (i); nodename.set (node->getNodeName (), false); if (nodename == element) return node->getTextContent (); } return 0; }
std::vector<std::string> CXercesUtils::GetXpathResults(DOMElement* root, std::string querystr) { std::vector<std::string> values; DOMDocument* doc (root->getOwnerDocument ()); // Obtain namespace resolver. xsd::cxx::xml::dom::auto_ptr<DOMXPathNSResolver> resolver ( doc->createNSResolver (root)); // Create XPath expression. xsd::cxx::xml::dom::auto_ptr<DOMXPathExpression> expr ( doc->createExpression ( xsd::cxx::xml::string (querystr.c_str()).c_str (), resolver.get ())); // Execute the query. xsd::cxx::xml::dom::auto_ptr<DOMXPathResult> r ( expr->evaluate ( root, DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE /*DOMXPathResult::ITERATOR_RESULT_TYPE*/, 0)); // If no query matches, then return empty vector if (!r.get() ) return values; // Iterate over the result. for (int i=0; i < r->getSnapshotLength(); i++) { r->snapshotItem(i); DOMNode* n (r->getNodeValue ()); const XMLCh * value = n->getTextContent ( ); values.push_back(xsd::cxx::xml::transcode<char> (value)); } return values; }
int parse_header_config(char *filename,int is_credit) { int parse_status = 0 ; // if parse_status is non-zero , return FAILURE struct stat st; if(lstat(filename,&st) != 0) { emit_bypass(FILE_LINE,"configuration file %s doesn't exist,please check ENV HEADER_CONFIG_PATH is set",filename); return FAILURE; } DOMNodeList *nodeList = NULL; DOMNode *node = NULL; try { XMLPlatformUtils::Initialize(); } catch (const XMLException& toCatch) { char* message = XMLString::transcode(toCatch.getMessage()); emit_bypass(FILE_LINE, "Failed to process file %s", filename); emit_bypass(FILE_LINE, " Error during initialization %s",message); XMLString::release(&message); return FAILURE; } XercesDOMParser* parser = new XercesDOMParser(); parser->setValidationScheme(XercesDOMParser::Val_Always); parser->setDoNamespaces(true); ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase(); parser->setErrorHandler(errHandler); try { parser->parse(filename); DOMDocument *doc = parser->getDocument(); nodeList = doc->getElementsByTagName(XMLString::transcode("xmlns")); node = nodeList->item(0); if (!node) { emit_bypass(FILE_LINE,"xmlns is not found in configurtion file %s",filename); parse_status = 1; } if (parse_status !=1 ) { if(is_credit!=1) { strcpy(gXmlns_str,XMLString::transcode(node->getTextContent())); if (strlen(gXmlns_str) == 0) { emit_bypass(FILE_LINE,"xmlns is set empty in configurtion file %s",filename); parse_status = 1; } } else { strcpy(gXmlns_str_credit,XMLString::transcode(node->getTextContent())); if(strlen(gXmlns_str_credit) == 0) { emit_bypass(FILE_LINE,"xmlns is set empty in configurtion file %s",filename); parse_status = 1; } } } nodeList = doc->getElementsByTagName(XMLString::transcode("xsi")); node = nodeList->item(0); if (!node) { emit_bypass(FILE_LINE,"xsi is not found in configuration file %s",filename); parse_status = 2; } if (parse_status != 2) { if(is_credit!=1) { strcpy(gXsi_str,XMLString::transcode(node->getTextContent())); if (strlen(gXsi_str) == 0) { emit_bypass(FILE_LINE,"xsi is set empty in configurtion file %s",filename); parse_status = 2; } } else { strcpy(gXsi_str_credit,XMLString::transcode(node->getTextContent())); if (strlen(gXsi_str_credit) == 0) { emit_bypass(FILE_LINE,"xsi is set empty in configurtion file %s",filename); parse_status = 2; } } } nodeList = doc->getElementsByTagName(XMLString::transcode("schemaLocation")); node = nodeList->item(0); if (!node) { emit_bypass(FILE_LINE,"schemaLocation is not found in configuration file %s",filename); parse_status = 3; } if (parse_status !=3) { if(is_credit!=1) { strcpy(gSchemaLocation_str,XMLString::transcode(node->getTextContent())); if (strlen(gSchemaLocation_str) == 0) { emit_bypass(FILE_LINE," schemaLocation is set empty in configurtion file %s",filename); parse_status = 3; } } else { strcpy(gSchemaLocation_str_credit,XMLString::transcode(node->getTextContent())); if (strlen(gSchemaLocation_str_credit) == 0) { emit_bypass(FILE_LINE," schemaLocation is set empty in configurtion file %s",filename); parse_status = 3; } } } delete parser; delete errHandler; XMLPlatformUtils::Terminate(); if (parse_status != 0) return FAILURE; return SUCCESS; } catch (const DOMException& toCatch) { char* message = XMLString::transcode(toCatch.getMessage()); emit_bypass(FILE_LINE, "Failed to process file %s", filename); emit_bypass(FILE_LINE, "Exception message is:%s", message); } catch (exception& e) { emit_bypass(FILE_LINE, "Failed to process file %s", filename); emit_bypass(FILE_LINE, "Exception message is:%s", e.what()); } catch (...){ emit_bypass(FILE_LINE, "Failed to process file %s", filename); } delete parser; delete errHandler; XMLPlatformUtils::Terminate(); return FAILURE; }
bool XmlWorldReader::Read(const std::string &file) { // ワールドを初期化 try { initialize(); if (initFlag) { initializeWorld(); } } catch (...) { return false; } // TODO: ファイルの有無を確認 // XMLファイルをパース const XMLCh gLS[] = {chLatin_L, chLatin_S, chNull}; DOMImplementationLS *impl = DOMImplementationRegistry::getDOMImplementation(gLS); DOMLSParser *parser = impl->createLSParser( DOMImplementationLS::MODE_SYNCHRONOUS, NULL ); DOMDocument *doc = parser->parseURI(file.c_str()); if (doc == nullptr) { return false; } // rootノードを取得 DOMElement *worldElement = doc->getDocumentElement(); if (worldElement == nullptr) { parser->release(); return false; } { YPT::XmlString temp("world"); bool res = XMLString::equals(worldElement->getNodeName(), temp); if (!res) { parser->release(); return false; } } // ロード用クラス作成 YPT::XmlWorldPartReader partReader(doc); // XPathコンテキスト作成 DOMXPathNSResolver *resolver = doc->createNSResolver(worldElement); if (resolver == nullptr) { parser->release(); return false; } YPT::XmlString str, str2; DOMXPathResult *result; // -------------------------------------------------- // ワールド全体の設定 // -------------------------------------------------- // ワールド名 str = worldElement->getAttribute(YPT::XmlString("name")); if (str != "") { name = str; } // 重力ベクトル result = doc->evaluate( YPT::XmlString("./gravity"), worldElement, resolver, DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE, NULL ); if (result != nullptr) { if (result->getSnapshotLength() >= 1) { str = result->getNodeValue()->getTextContent(); b2Vec2 temp; if (!YPT::ConvertStrToVec2(str.ToChar(), &temp)) { world.SetGravity(temp); } } result->release(); } // -------------------------------------------------- // shapes // -------------------------------------------------- result = doc->evaluate( YPT::XmlString("./shape"), worldElement, resolver, DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE, NULL ); if (result != nullptr) { const XMLSize_t len = result->getSnapshotLength(); for (XMLSize_t i = 0; i < len; ++i) { result->snapshotItem(i); DOMNode *node = result->getNodeValue(); if (node == nullptr) { continue; } DOMNamedNodeMap *nodeMap = node->getAttributes(); if (nodeMap == nullptr) { continue; } DOMNode *typeNode = nodeMap->getNamedItem(YPT::XmlString("type")); if (typeNode == nullptr) { continue; } str = typeNode->getNodeValue(); b2Shape::Type type; int index; if (str == "circle") { type = b2Shape::e_circle; b2CircleShape temp; if (partReader.ReadCircleShape(node, &temp)) { circleShapes.push_back(temp); index = circleShapes.size()-1; } else { // 読み込み失敗 continue; } } else if (str == "edge") { type = b2Shape::e_edge; b2EdgeShape temp; if (partReader.ReadEdgeShape(node, &temp)) { edgeShapes.push_back(temp); index = edgeShapes.size()-1; } else { // 読み込み失敗 continue; } } else if (str == "polygon") { type = b2Shape::e_polygon; b2PolygonShape temp; if (partReader.ReadPolygonShape(node, &temp)) { polygonShapes.push_back(temp); index = polygonShapes.size()-1; } else { // 読み込み失敗 continue; } } else if (str == "chain") { type = b2Shape::e_chain; b2ChainShape temp; if (partReader.ReadChainShape(node, &temp)) { chainShapes.push_back(temp); index = chainShapes.size()-1; } else { // 読み込み失敗 continue; } } else { // 未対応 continue; } // nameプロパティがあれば保存 DOMNode *name = nodeMap->getNamedItem(YPT::XmlString("name")); if (name != nullptr) { str = name->getNodeValue(); shapes.insert(ShapesMap::value_type( std::string(str), std::make_pair(type, index) )); } } result->release(); } // -------------------------------------------------- // fixtures // -------------------------------------------------- result = doc->evaluate( YPT::XmlString("./fixture"), worldElement, resolver, DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE, NULL ); if (result != nullptr) { const XMLSize_t len = result->getSnapshotLength(); for (XMLSize_t i = 0; i < len; ++i) { result->snapshotItem(i); DOMNode *node = result->getNodeValue(); if (node == nullptr) { continue; } DOMXPathResult *result2 = doc->evaluate( YPT::XmlString("./shape"), node, resolver, DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE, NULL ); if (result2 == nullptr) { continue; } DOMNode *shapeNode = result2->getNodeValue(); if (shapeNode == nullptr) { continue; } str = shapeNode->getTextContent(); result2->release(); ShapesMap::iterator found = shapes.find(std::string(str)); if (found == shapes.end()) { continue; } // fixture読み込み b2FixtureDef fixtureDef; b2Shape *shape = NULL; int index = found->second.second; switch (found->second.first) { case b2Shape::e_circle: shape = &circleShapes[index]; break; case b2Shape::e_edge: shape = &edgeShapes[index]; break; case b2Shape::e_polygon: shape = &polygonShapes[index]; break; case b2Shape::e_chain: shape = &chainShapes[index]; break; default: // 未対応 break; } if (shape == NULL) { continue; } if (partReader.ReadFixture(node, shape, &fixtureDef)) { // 読み込み成功 // nameプロパティがあれば保存する DOMNamedNodeMap *nodeMap = node->getAttributes(); if (nodeMap == nullptr) { continue; } DOMNode *nameNode = nodeMap->getNamedItem(YPT::XmlString("name")); if (nameNode == nullptr) { continue; } str = nameNode->getNodeValue(); fixtures.insert(FixturesMap::value_type( std::string(str), fixtureDef )); } } result->release(); } // -------------------------------------------------- // bodies // -------------------------------------------------- result = doc->evaluate( YPT::XmlString("./body"), worldElement, resolver, DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE, NULL ); if (result != nullptr) { const XMLSize_t len = result->getSnapshotLength(); for (XMLSize_t i = 0; i < len; ++i) { result->snapshotItem(i); DOMNode *node = result->getNodeValue(); if (node == nullptr) { continue; } DOMXPathResult *result2 = doc->evaluate( YPT::XmlString("./fixtures/fixture"), node, resolver, DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE, NULL ); if (result2 == nullptr) { continue; } std::vector< b2FixtureDef *> fixtureDefs; const XMLSize_t fixturesLen = result2->getSnapshotLength(); for (XMLSize_t j = 0; j < fixturesLen; ++j) { result2->snapshotItem(j); DOMNode *fixtureNode = result2->getNodeValue(); if (fixtureNode == nullptr) { continue; } str = fixtureNode->getTextContent(); FixturesMap::iterator found = fixtures.find( std::string(str) ); if (found != fixtures.end()) { fixtureDefs.push_back(&found->second); } } result2->release(); b2Body *body = partReader.ReadBody(world, node, fixtureDefs); if (body != nullptr) { // 読み込み成功 // nameプロパティがあれば保存する DOMNamedNodeMap *nodeMap = node->getAttributes(); if (nodeMap == nullptr) { continue; } DOMNode *nameNode = nodeMap->getNamedItem(YPT::XmlString("name")); if (nameNode == nullptr) { continue; } str = nameNode->getNodeValue(); bodies.insert(BodiesMap::value_type( std::string(str), body )); } } result->release(); } // -------------------------------------------------- // 読み込み完了 // -------------------------------------------------- resolver->release(); parser->release(); return true; }
//=================================================================================================================== void geometryLoader::acquireInfo(DOMElement * element) { // static const boost::regex matchDoubleQuotes(".*?\"(.*)\".*", boost::regex::perl); DOMNodeList* children = element->getChildNodes(); const XMLSize_t nodeCount = children->getLength() ; double rowPitch=0,colPitch=0; int dutNumbers=0; std::string parentTagName = XMLString::transcode(element->getTagName()) ; std::map<std::string, std::string> keyValue ; for( XMLSize_t j = 0; j < nodeCount; ++j ) { DOMNode* currentNode = children->item(j); if( !(currentNode->getNodeType() && currentNode->getNodeType() == DOMNode::ELEMENT_NODE )) continue ; // is element otherwise close the recursive stack DOMElement * currentElement = dynamic_cast< xercesc::DOMElement* >( currentNode ); // Found node which is an Element. Re-cast node as such. DOMNamedNodeMap * attList = currentNode->getAttributes() ; std::string tagName = XMLString::transcode(currentElement->getTagName()) ; std::string textContent = "" ; std::string textWithBlanks = "" ; if(currentNode->getTextContent()) textWithBlanks = XMLString::transcode(currentElement->getTextContent()) ; textContent = this->stripBlanks(textWithBlanks) ; keyValue.clear() ; bool used = true; for(unsigned int i=0; i<attList->getLength(); ++i) // Set attibutes apart in a temporary hash map { if( attList->item(i)->getTextContent() ) keyValue[ XMLString::transcode(attList->item(i)-> getNodeName())] = this->stripBlanks( XMLString::transcode(attList->item(i)->getTextContent())); } if( tagName == "testBeamGeometry" ) { //theGeometry_-> keyValue["id" ] ; //theGeometry_-> ( this->toLower(keyValue["date"]) ); STDLINE("Entered " + tagName,ACYellow) ; } if( tagName == "stations" ) { ss_.str(""); ss_ << "stations in use: " << keyValue["inUse" ]; STDLINE(ss_.str(),ACYellow) ; } if( tagName == "station" ) { if(this->toLower(keyValue["used"])=="yes") station_ = keyValue["id"]; else used = false ; } if( tagName == "detectors" ) { ss_.str(""); ss_ << "detectors in use: " << keyValue["inUse" ]; STDLINE(ss_.str(),ACYellow) ; } if( tagName == "detector" ) { if( this->toLower(keyValue["used"])=="yes" ) { ss_.str(""); ss_ << "Station: " << station_ << " - " << "Plaq: " << keyValue["id"]; currentPlaqID_ = ss_.str(); theGeometry_->addDetector( currentPlaqID_ ); STDLINE(keyValue["name"] + " detector id: " + currentPlaqID_,ACYellow) ; if( this->toLower(keyValue["isDUT"]) == "yes" ) { theGeometry_->getDetector( currentPlaqID_ )->setDUT(); dutNumbers++; theGeometry_->setDUTnumbers(dutNumbers); } } else used=false; } if( tagName == "largeGranularity" ) { STDLINE("Rotations relative to " + keyValue["relativeRotations"],ACYellow) ; } if( tagName == "xBackFlipped" && this->validContent(tagName,textContent)) { if( this->toLower(textContent) == "yes" || this->toLower(textContent) == "true") { STDLINE("get Detector",ACYellow) ; theGeometry_->getDetector( currentPlaqID_ )->setXBackFlipped(true ); STDLINE("cleared",ACYellow) ; } else theGeometry_->getDetector( currentPlaqID_ )->setXBackFlipped(false); } if( tagName == "yBackFlipped" && this->validContent(tagName,textContent)) { if( this->toLower(textContent) == "yes" || this->toLower(textContent) == "true") theGeometry_->getDetector( currentPlaqID_ )->setYBackFlipped(true ); else theGeometry_->getDetector( currentPlaqID_ )->setYBackFlipped(false); } if( tagName == "xPosition" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setXPosition(Utils::toDouble(textContent)*CONVF); if( tagName == "yPosition" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setYPosition(Utils::toDouble(textContent)*CONVF); if( tagName == "zPosition" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setZPosition(Utils::toDouble(textContent)*CONVF); if( tagName == "xRotation" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setXRotation( Utils::toDouble(textContent)); if( tagName == "yRotation" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setYRotation( Utils::toDouble(textContent)); if( tagName == "zRotation" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setZRotation( Utils::toDouble(textContent) ); if( toRead_ == "correction" || toRead_ == "all" ) { if( tagName == "fineGranularity" ) { STDLINE("Reading fineGranularity",ACGreen); STDLINE("Rotations relative to " + keyValue["relativeRotations"],ACYellow) ; } if( tagName == "xPosCorrection" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setXPositionCorrection(Utils::toDouble(textContent)*CONVF); if( tagName == "xPositionError" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setXPositionError(Utils::toDouble(textContent)*CONVF); if( tagName == "yPosCorrection" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setYPositionCorrection(Utils::toDouble(textContent)*CONVF); if( tagName == "yPositionError" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setYPositionError(Utils::toDouble(textContent)*CONVF); if( tagName == "zPosCorrection" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setZPositionCorrection(Utils::toDouble(textContent)*CONVF); if( tagName == "zPositionError" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setZPositionError(Utils::toDouble(textContent)*CONVF); if( tagName == "xRotationCorrection" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setXRotationCorrection( Utils::toDouble(textContent) ); if( tagName == "xRotationCorrectionError" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setXRotationCorrectionError( Utils::toDouble(textContent) ); if( tagName == "yRotationCorrection" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setYRotationCorrection( Utils::toDouble(textContent) ); if( tagName == "yRotationCorrectionError" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setYRotationCorrectionError( Utils::toDouble(textContent) ); if( tagName == "zRotationCorrection" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setZRotationCorrection( Utils::toDouble(textContent) ); if( tagName == "zRotationCorrectionError" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setZRotationCorrectionError( Utils::toDouble(textContent) ); } if( tagName == "ROCs" ) { STDLINE("ROCs in use: " + keyValue["inUse"],ACYellow) ; theGeometry_->getDetector( currentPlaqID_ )->setXNumberOfROCs( Utils::toInt(keyValue["xChipsNumber"]) ); theGeometry_->getDetector( currentPlaqID_ )->setYNumberOfROCs( Utils::toInt(keyValue["yChipsNumber"]) ); } if( tagName == "ROC" ) { if( this->toLower(keyValue["used"])=="yes" ) { currentROC_ = Utils::toInt(keyValue["pos"]); theGeometry_->getDetector( currentPlaqID_ )->addROC( Utils::toInt(keyValue["pos"]), Utils::toInt(keyValue["id"] ) ); } else used=false; } if ( tagName == "calibrationFilePath" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->getROC( currentROC_ )->setCalibrationFilePath(textContent); if ( tagName == "standardRowPitch" && this->validContent(tagName,textContent)) rowPitch = Utils::toDouble(textContent)*CONVF; if ( tagName == "standardColPitch" && this->validContent(tagName,textContent)) { colPitch = Utils::toDouble(textContent)*CONVF; ss_.str(""); ss_ << ACCyan << ACBold << "Pitch. Row : " << ACWhite << ACBold << rowPitch << ACCyan << ACBold << " Col: " << ACWhite << ACBold << colPitch << ACYellow << ACBold << " (tens of microns)"; STDLINE(ss_.str(),ACRed) ; theGeometry_->getDetector( currentPlaqID_ )->getROC( currentROC_ )->setStandardPixPitch(rowPitch,colPitch); } if ( tagName == "nonStandardRowPitch" && this->validContent(tagName,textContent) ) theGeometry_->getDetector( currentPlaqID_ )->getROC( currentROC_ )->setOneRowPitch(Utils::toInt(keyValue["rowNum"]), Utils::toDouble(textContent)*CONVF ); if ( tagName == "nonStandardColPitch" && this->validContent(tagName,textContent) ) theGeometry_->getDetector( currentPlaqID_ )->getROC( currentROC_ )->setOneColPitch(Utils::toInt(keyValue["colNum"]), Utils::toDouble(textContent)*CONVF ); if( tagName == "MAX_ROWS" && this->validContent(tagName,textContent)) { theGeometry_->getDetector( currentPlaqID_ )->getROC( currentROC_ )->setNumberOfRows(Utils::toInt(textContent)+1 ); } if( tagName == "MAX_COLS" && this->validContent(tagName,textContent)) { theGeometry_->getDetector( currentPlaqID_ )->getROC( currentROC_ )->setNumberOfCols(Utils::toInt(textContent)+1 ); } if( tagName == "orientation" && this->validContent(tagName,textContent)) { theGeometry_->getDetector( currentPlaqID_ )->getROC( currentROC_ )->setOrientation( Utils::toInt(textContent) ); ss_.str("") ; ss_ << ACCyan << ACBold << "Orientation: " << ACWhite << textContent << ACYellow << ACBold << " (degrees)"; STDLINE(ss_.str(),ACGreen) ; } //closingFlag_ = false ; //STDLINE(tagName,ACRed) ; if ( used ) this->acquireInfo(currentElement) ; //STDLINE(tagName,ACGreen) ; //closingFlag_ = true ; } }
/*=========================================================================+ Parse_Block: Parse the specified block from the XML input. The block is expected to be an XML string of the following form: < {sBlockName} > <name1> {value1_1} </name1> <name2> {value2_1} </name2> ... < {sBlockName} > This method is to be used when the Exit XML has been extended, and the Parse_ETA_Input_XML() method might decode the wrong "object" block. This method return -1 if it failed to find the named block or zero on success. The data parsed can be retrieved using the Get_Block_Attribute_Name() and Get_Block_Attribute_Value(). +=========================================================================*/ int ExitXMLBlock::Parse_Block( string sBlockName ) { int iRc = -1; // failure DOMNodeList* pTopNodeList = NULL; DOMNode* pTopNode = NULL; DOMNodeList* pNodeList = NULL; const XMLCh* pxcValue = NULL; string sTagName; string sTagValue; short iTagType; int iTagCount; // Clear previous data, if any m_vsBlockAttributeList.clear(); m_vsBlockAttributes.clear(); m_vsBlockValues.clear(); // Find the XML block. pTopNodeList = Find_Node(m_pXmlDocument, sBlockName); if (!pTopNodeList) { goto exit; } pTopNode = pTopNodeList->item(0); // Should only be one! if (!pTopNode) { goto exit; } // Find all the child nodes. pNodeList = pTopNode->getChildNodes(); /* || Get the number of tags found under the top level node. || If the pNodeList is empty, initialize the tag count to 0. */ iTagCount = pNodeList->getLength(); // Get the tag and value under the top level node and parse each tag. for (int iIndex = 0; iIndex < iTagCount; iIndex++) { DOMNode* pNode = pNodeList->item(iIndex); if (!pNode) { // Error! continue; } iTagType = pNode->getNodeType(); if (iTagType != 1 /* DOMNode::NodeType::ELEMENT_NODE */) { continue; } /* || Get the tag name. If failed to get the tag name, || skip the current tag. */ pxcValue = pNode->getNodeName(); if (pxcValue) { sTagName = UTF16toUTF8(pxcValue); } /* pxcValue = pNode->getNodeValue(); if (pxcValue) { sTagValue = UTF16toUTF8(pxcValue); } */ pxcValue = pNode->getTextContent(); if (pxcValue) { sTagValue = UTF16toUTF8(pxcValue); } #if 0 cout << "BLK Node Name: '" << sTagName << "'" << endl; cout << "BLK Node Type: " << iTagType << endl; cout << "BLK Node Value: '" << (sTagValue.empty() ? "<empty>" : sTagValue) << "'" << endl; cout << endl; #endif /* || Insert the attribute name and value into the end of the || respective attribute and value arrays. || Attribute with multiple values will have multiple elements || in both arrays. */ if (!IsInVector(sTagName, m_vsBlockAttributeList)) { m_vsBlockAttributeList.insert(m_vsBlockAttributeList.end(), sTagName); } m_vsBlockAttributes.insert(m_vsBlockAttributes.end(), sTagName); m_vsBlockValues.insert(m_vsBlockValues.end(), sTagValue); } iRc = 0; exit: return iRc; }
/*=========================================================================+ Parse_Authentication: Parse the authentication block from the input XML block. This is called during the constructor of this object. The Authentication block is an XML block such as <Authentication> <Type> {type of authentication} </Type> <User> {user to authenticate as} </User> <Password> {password} </Password> </Authentication> +=========================================================================*/ void ExitXMLBlock::Parse_Authentication_Block( string sBlockName ) { DOMNodeList* pTopNodeList = NULL; DOMNode* pTopNode = NULL; DOMNodeList* pNodeList = NULL; const XMLCh* pxcValue = NULL; string sTagName; string sTagValue; short iTagType; int iTagCount; // Find the XML block. pTopNodeList = Find_Node(m_pXmlDocument, sBlockName); if (!pTopNodeList) { goto exit; } pTopNode = pTopNodeList->item(0); // Should only be one! // Find all the child nodes. pNodeList = pTopNode->getChildNodes(); /* || Get the number of tags found under the top level node. || If the pNodeList is empty, initialize the tag count to 0. */ iTagCount = pNodeList->getLength(); // Get the tag and value under the top level node and parse each tag. for (int iIndex = 0; iIndex < iTagCount; iIndex++) { DOMNode* pNode = pNodeList->item(iIndex); if (!pNode) { // Error! continue; } iTagType = pNode->getNodeType(); if (iTagType != 1 /* DOMNode::NodeType::ELEMENT_NODE */) { continue; } /* || Get the tag name. If failed to get the tag name, || skip the current tag. */ pxcValue = pNode->getNodeName(); if (pxcValue) { sTagName = UTF16toUTF8(pxcValue); } /* pxcValue = pNode->getNodeValue(); if (pxcValue) { sTagValue = UTF16toUTF8(pxcValue); } */ pxcValue = pNode->getTextContent(); if (pxcValue) { sTagValue = UTF16toUTF8(pxcValue); } #if 0 cout << "AUTH Node Name: '" << sTagName << "'" << endl; cout << "AUTH Node Type: " << iTagType << endl; cout << "AUTH Node Value: '" << (sTagValue.empty() ? "<empty>" : sTagValue) << "'" << endl; cout << endl; #endif if (sTagName == UTFEXIT_AUTHTYPE) { m_sAuthenticationType = Convert_Authentication_Type_String_to_Enum(sTagValue); } else if (sTagName == UTFEXIT_AUTHUSER) { m_sAuthenticationUser = sTagValue; } else if (sTagName == UTFEXIT_AUTHPASSWORD) { m_sAuthenticationPassword = sTagValue; } } exit: ; }
/*=========================================================================+ Parse_Object_Block: Parse an object block from the XML input. The object block is an XML string of the form: < {objectclass} > <eTDN> {dn of object being processed} </eTDN> <eTName> {name of object being processed} </eTName> < {attribute} > {value} </ {attribute} > < {objectclass} > +=========================================================================*/ void ExitXMLBlock::Parse_Object_Block( string sBlockName ) { DOMNodeList* pTopNodeList = NULL; DOMNode* pTopNode = NULL; DOMNodeList* pNodeList = NULL; const XMLCh* pxcValue = NULL; string sTagName; string sTagValue; short iTagType; int iTagCount; // Find the XML block. pTopNodeList = Find_Node(m_pXmlDocument, sBlockName); if (!pTopNodeList) { goto exit; } pTopNode = pTopNodeList->item(0); // Should only be one! // Find all the child nodes. pNodeList = pTopNode->getChildNodes(); /* || Get the number of tags found under the top level node. || If the pNodeList is empty, initialize the tag count to 0. */ iTagCount = pNodeList->getLength(); // Get the tag and value under the top level node and parse each tag. for (int iIndex = 0; iIndex < iTagCount; iIndex++) { DOMNode* pNode = pNodeList->item(iIndex); if (!pNode) { // Error! continue; } iTagType = pNode->getNodeType(); if (iTagType != 1 /* DOMNode::NodeType::ELEMENT_NODE */) { continue; } /* || Get the tag name. If failed to get the tag name, || skip the current tag. */ pxcValue = pNode->getNodeName(); if (pxcValue) { sTagName = UTF16toUTF8(pxcValue); } /* pxcValue = pNode->getNodeValue(); if (pxcValue) { sTagValue = UTF16toUTF8(pxcValue); } */ pxcValue = pNode->getTextContent(); if (pxcValue) { sTagValue = UTF16toUTF8(pxcValue); } #if 0 cout << "OBJ Node Name: '" << sTagName << "'" << endl; cout << "OBJ Node Type: " << iTagType << endl; cout << "OBJ Node Value: '" << (sTagValue.empty() ? "<empty>" : sTagValue) << "'" << endl; cout << endl; #endif if (sTagName == UTFEXIT_DN) { m_sObjectDn = sTagValue; } else if (sTagName == UTFNAME) { m_sObjectName = sTagValue; } else { /* || Any other tag is an attribute name. || Insert the attribute name and value into the end of the || respective attribute and value arrays. || Attribute with multiple values will have multple elements || in both arrays. */ m_vsObjectAttributes.insert(m_vsObjectAttributes.end(), sTagName); m_vsObjectValues.insert(m_vsObjectValues.end(), sTagValue); } } exit: ; }
/*=========================================================================+ Parse_ETA_Input_XML: Parse the input XML block. eTrust Admin sends an XML block containing data of the object being processed. The XML block also contains optional authentication data. The format of the input XML block is: <eTExitInvoke eTExitType={type of exit}> < {objectclass} > <eTDN> {dn of object being processed} </eTDN> <eTName> {name of object being processed} </eTName> < {attribute} > {value} </ {attribute} > < {objectclass} > <Authentication> <Type> {type of authentication} </Type> <User> {user to authenticate as} </User> <Password> {password (in the clear)} </Password> </Authentication> </eTExitInvoke> The {attribute} and {value} are specific to the object being processed. E.g., if the object has attribute "City" and value "Renton", the XML block will contains the tag: <City>Renton</City> If the attribute is multi-valued, each value will have a separate tag: <City>Renton</City> <City>Kirkland</City> +=========================================================================*/ int ExitXMLBlock::Parse_ETA_Input_XML() { int iRc = -1; // failure DOMElement* pElement = NULL; DOMNodeList* pNodeList = NULL; XMLCh* pxcTag = NULL; const XMLCh* pxcValue = NULL; UTF8* pszuValue = NULL; string sTagName; string sTagValue; string sErrMsg; int iTagCount; // Load the XML document. try { m_pXmlBuilder->resetDocumentPool(); MemBufInputSource oSource( (const XMLByte*)m_sInputXML.c_str(), m_sInputXML.length(), "InputBuffer", false); Wrapper4InputSource oWrapper(&oSource, false); m_pXmlDocument = m_pXmlBuilder->parse(oWrapper); } catch (const XMLException& toCatch) { sErrMsg = XMLString::transcode(toCatch.getMessage()); cerr << "\nError during parsing\nException message is: \n" << sErrMsg << "\n"; goto exit; } catch (const DOMException& toCatch) { const unsigned int iMaxChars = 2047; XMLCh pzcErrMsg[iMaxChars + 1]; sErrMsg = XMLString::transcode(toCatch.msg); cerr << "\nDOM Error during parsing\nException message is: \n" << sErrMsg << "\n"; if (DOMImplementation::loadDOMExceptionMsg(toCatch.code, pzcErrMsg, iMaxChars)) cerr << "Message is: " << XMLString::transcode(pzcErrMsg) << endl; goto exit; } catch (...) { cerr << "\nUnexpected exception during parsing\n"; goto exit; } // Get the exit type from the top level node's tag attribute. pElement = m_pXmlDocument->getDocumentElement(); pxcTag = UTF8toUTF16(UTFEXIT_EXITTYPE); pxcValue = pElement->getAttribute(pxcTag); delete pxcTag; if (pxcValue) { this->m_sExitType = UTF16toUTF8(pxcValue); } // Find all the child nodes. pNodeList = pElement->getChildNodes(); if (!pNodeList) { goto exit; } /* || Get the number of tags found under the top level node. || If the node_list is empty initialize the tag count to 0. */ iTagCount = pNodeList->getLength(); // cout << "Tag Count:" << iTagCount << endl; // Get the tag and value under the top level node and parse each tag. for (int iIndex = 0; iIndex < iTagCount; iIndex++) { DOMNode* pNode = pNodeList->item(iIndex); if (!pNode) { // Error! continue; } short siTagType = pNode->getNodeType(); if (siTagType != 1 /* DOMNode::NodeType::ELEMENT_NODE */) { continue; } /* || Get the tag name. If failed to get the tag name, || skip the current tag. */ pxcValue = pNode->getNodeName(); if (pxcValue) { sTagName = UTF16toUTF8(pxcValue); } pxcValue = pNode->getNodeValue(); if (pxcValue) { sTagValue = UTF16toUTF8(pxcValue); } #if 0 cout << "Node Name: '" << sTagName << "'" << endl; cout << "Node Type: " << siTagType << endl; cout << "Node Value: '" << (sTagValue.empty() ? "<empty>" : sTagValue) << "'" << endl; const XMLCh* pxcValue = pNode->getTextContent(); string sTagText = UTF16toUTF8(pxcValue); cout << "Node Text: '" << (sTagText.empty() ? "<empty>" : sTagText) << "'" << endl; cout << endl; #endif if (sTagName == UTFEXIT_AUTHENTICATION) { Parse_Authentication_Block(sTagName); } else { this->m_sObjectClass = sTagName; Parse_Object_Block(this->m_sObjectClass); } } iRc = 0; // success! exit: return iRc; }