EppCommand * EppCommand::fromXML( const DOMNode& root ) { unsigned int i; EppCommand * cmd = null; DOMNode* command; bool found = false; DOMNodeList* list = root.getChildNodes(); for( i = 0; i < list->getLength(); i++ ) { DOMNode* node = list->item(i); DOMString name = node->getLocalName(); if( name.isNull() ) { name = node->getNodeName(); } if( name.isNull() ) { continue; } if( name.equals("command") ) { command = node; found = true; break; } } if( found == false ) { return null; } list = command->getChildNodes(); for( i = 0; i < list->getLength(); i++ ) { DOMNode* node = list->item(i); DOMString name = node->getLocalName(); if( name.isNull() ) { name = node->getNodeName(); } if( name.isNull() ) { continue; } if( name.equals("login") ) { cmd = EppCommandLogin::fromXML(*node); } else if( name.equals("logout") ) { cmd = EppCommandLogout::fromXML(*node); } else if( name.equals("poll") ) { cmd = EppCommandPoll::fromXML(*node); } else if( name.equals("create") ) { cmd = EppCommandCreate::fromXML(*node); } else if( name.equals("delete") ) { cmd = EppCommandDelete::fromXML(*node); } else if( name.equals("info") ) { cmd = EppCommandInfo::fromXML(*node); } else if( name.equals("check") ) { cmd = EppCommandCheck::fromXML(*node); } else if( name.equals("renew") ) { cmd = EppCommandRenew::fromXML(*node); } else if( name.equals("transfer") ) { cmd = EppCommandTransfer::fromXML(*node); } else if( name.equals("update") ) { cmd = EppCommandUpdate::fromXML(*node); } /* * other commands */ if( cmd != null ) { break; } } if( cmd == null ) { return null; } for( i = 0; i < list->getLength(); i++ ) { DOMNode* node = list->item(i); DOMString name = node->getLocalName(); if( name.isNull() ) { name = node->getNodeName(); } if( name.isNull() ) { continue; } if( name.equals("creds") ) { if( cmd->creds == null ) { //cmd->creds = EppCreds::fromXML(node); } } else if( name.equals("extension") ) { DOMNodeList* clist = node->getChildNodes(); for( unsigned int j = 0; j < clist->getLength(); j++ ) { DOMNode* cnode = clist->item(j); DOMString prefix = cnode->getPrefix(); DOMString cname = cnode->getLocalName(); DOMString nsURI = cnode->getNamespaceURI(); if( cname.isNull() ) { cname = cnode->getNodeName(); } if( cname.isNull() ) { continue; } if( cname.equals("neulevel:extension") || ( (prefix.isNotNull()) && prefix.equals("neulevel") && (cname.isNotNull()) && cname.equals("extension") ) || cname.equals("ex01:extension") ) { EppUnspec * unspec = EppUnspec::fromXML(*cnode); if( unspec != null ) { cmd->addExtension(unspec); } } else if( cname.isNotNull() ) { EppExtension * ext = EppExtension::fromXML(*cnode); if( ext != null ) { cmd->addExtension(ext); } // else other extensions } else { // other extensions } } } else if( name.equals("clTRID") ) { cmd->clTRID = EppUtil::getText(*node); } } return cmd; }
bool CConfigParser::ParseDevices(DOMNodeList* deviceNodeList, ADeviceListener& configClass) { ASSERT(deviceNodeList->getLength() >= 1); DOMNode* deviceNode = deviceNodeList->item(0); DOMNodeList* devices = deviceNode->getChildNodes(); for(unsigned long idx = 0; idx < devices->getLength(); idx++) { DOMNode* currentDevice = devices->item(idx); wstring deviceNodeName = currentDevice->getNodeName(); if(deviceNodeName.compare(L"#text") == 0) continue; wstring deviceName = currentDevice->getAttributes()->getNamedItem(L"name")->getNodeValue(); //wstring deviceType = currentDevice->getAttributes()->getNamedItem(L"type")->getNodeValue(); wstring deviceType = deviceNodeName; if(deviceType.compare(L"mouse") == 0) { configClass.AddDevice(deviceName, new CMouseProc()); } else { CWin32SpaceNavigatorHIDCapture* deviceToAdd = new CWin32SpaceNavigatorHIDCapture(); if(currentDevice->hasChildNodes()) { if(!ParseHIDDeviceCommands(currentDevice->getChildNodes(), deviceToAdd)) return false; } configClass.AddDevice(deviceName, deviceToAdd); } } return true; }
bool CConfigParser::ParseDeviceContexts(DOMNodeList* deviceContextNodes, ADeviceListener& configClass) { ASSERT(deviceContextNodes->getLength() == 1); DOMNode* deviceContextNode = deviceContextNodes->item(0); DOMNodeList* deviceContexts = deviceContextNode->getChildNodes(); for(unsigned long idx = 0; idx < deviceContexts->getLength(); idx++) { DOMNode* currentDeviceContext = deviceContexts->item(idx); wstring deviceContextNodeName = currentDeviceContext->getNodeName(); if(deviceContextNodeName.compare(L"#text") == 0) continue; if(deviceContextNodeName.compare(L"#comment") == 0) continue; wstring deviceContextName = currentDeviceContext->getAttributes()->getNamedItem(L"name")->getNodeValue(); wstring deviceName = currentDeviceContext->getAttributes()->getNamedItem(L"device")->getNodeValue(); bool gestures = false; if(currentDeviceContext->getAttributes()->getNamedItem(L"gestures") != NULL) gestures = true; // Create the device context to add CDeviceContext* deviceContextToAdd = NULL; if(configClass.GetDevices()[deviceName]->GetType().compare("mouse") == 0) deviceContextToAdd = new CMouseDeviceContext(gestures, deviceName); else deviceContextToAdd = new CDeviceContext(gestures, deviceName); // Get the device contexts axis and buttons added if(currentDeviceContext->hasChildNodes()) { unsigned char axeIdx = 0; DOMNodeList* children = currentDeviceContext->getChildNodes(); unsigned long childCount = children->getLength(); for(unsigned long idx = 0; idx < childCount; idx++) { DOMNode* childNode = children->item(idx); wstring nodeName = childNode->getNodeName(); if(nodeName.compare(L"axe") == 0) { ParseAxe(childNode, configClass.GetActions(), deviceContextToAdd, axeIdx); axeIdx++; } if(nodeName.compare(L"buttons") == 0) ParseButtons(childNode, configClass.GetActions(), deviceContextToAdd); if(nodeName.compare(L"gesture") == 0) ParseGesture(childNode, configClass.GetActions(), deviceContextToAdd); } } configClass.AddDeviceContext(deviceContextName, deviceContextToAdd); TRACE("Device Context <%S> is 0x%X\r\n", deviceContextName.c_str(), deviceContextToAdd); } return true; }
map<string, DatasetSpecification> Specifications::readDatasetIndex(string str){ map<string, DatasetSpecification> result; XERCES_CPP_NAMESPACE_USE 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(); DOMNodeList *entries = elementRoot->getElementsByTagName(XMLString::transcode("dataset")); cout << "Databases in index:\n"; for(size_t i = 0; i < entries->getLength(); ++i){ DOMNode *current = entries->item(i); DatasetSpecification dss; dss.name = XMLString::transcode(current->getAttributes()-> getNamedItem(XMLString::transcode("name"))-> getNodeValue()); dss.root = XMLString::transcode(current->getAttributes()-> getNamedItem(XMLString::transcode("root"))-> getNodeValue()); cout << " name: " << dss.name << " root: " << dss.root << endl; DOMNodeList *categories = current->getChildNodes(); for(size_t j = 0; j < categories->getLength(); ++j) if((string) XMLString::transcode(categories->item(j)->getNodeName()) == "category") dss.categories.push_back(XMLString::transcode(categories->item(j)->getTextContent())); result[dss.name] = dss; } return result; }
bool CConfigParser::ParseContexts(DOMNodeList* contextNodes, ADeviceListener& configClass) { ASSERT(contextNodes->getLength() == 1); DOMNode* contextNode = contextNodes->item(0); DOMNodeList* contexts = contextNode->getChildNodes(); for(unsigned long idx = 0; idx < contexts->getLength(); idx++) { DOMNode* currentContext = contexts->item(idx); wstring contextNodeName = currentContext->getNodeName(); if(contextNodeName.compare(L"#text") == 0) continue; wstring contextName = currentContext->getAttributes()->getNamedItem(L"name")->getNodeValue(); CContext* contextToAdd = new CContext(); unsigned long attrLen = currentContext->getAttributes()->getLength(); for(unsigned long attr = 0; attr < attrLen; attr++) { DOMNode* deviceContextAttr = currentContext->getAttributes()->item(attr); if(wcscmp(deviceContextAttr->getNodeName(), L"deviceContext") == 0) { wstring deviceContextName = deviceContextAttr->getNodeValue(); CDeviceContext* deviceContext = configClass.GetDeviceContexts()[deviceContextName]; IDeviceCapture* device = configClass.GetDevices()[deviceContext->GetDeviceName()]; contextToAdd->AddDeviceContext(device, deviceContext); } } configClass.AddContext(contextName, contextToAdd); } return true; }
//DR-2-023-245 fill data with pmtinf field in XML void create_CdtTrn_PmtInf_body(PmtInf *PmtOBj) { DOMNode *pmtInf =PmtOBj->getPmtInf_node(); int counter = 0; DOMNodeList *pmtChildList = pmtInf->getChildNodes(); DOMNode* node = NULL; char s[64] = { 0 }; char ccy[4] = { 0 }; char *temp = NULL; Arb_numeric out_num = ARB_NUMERIC_ZERO; double e_amount = 0.0; double s_amount = 0.0; XMLCh *tempStr = NULL; XmlNode pmtNode(pmtInf,cdtTrndoc); char endtoend[99]={0}; sprintf(endtoend, "%02d%010d%03d%010d%03d%s", gTrans.tracking_id_serv, gTrans.tracking_id, gTrans.counter, gTrans.bill_ref_no, gTrans.bill_ref_resets, gTrans.sequence_type); arb_num_rate(&out_num,&gTrans.amount,1,(gEur_impl_decimal - 2),gEur_round_method); arb_numeric_to_double(&out_num,&e_amount); sprintf(s,"%d.%02.0f",(int)e_amount/100,fmod(e_amount,100)); s_amount += atof(s); sprintf(s, "%.2f", s_amount); sprintf(ccy,"%d",gTrans.currency_code); XmlNode cdtTrnTxInfNode = pmtNode.addChild("CdtTrfTxInf"); XmlNode pmtIdNode = cdtTrnTxInfNode.addChild("PmtId"); pmtIdNode.addChild("EndToEndId",endtoend); cdtTrnTxInfNode.addChild("Amt").addChild("InstdAmt",s).addAttribute("Ccy", ccy); }
DOMNode* Triggerconf::selectSubmodule (string modulename, string submodulename) { DOMNode* currentModule = selectModule (modulename); if (currentModule == NULL) { setError ("invalid module: " + modulename); return NULL; } DOMNodeList* childs = currentModule->getChildNodes (); if (childs == NULL) { if (autocreate == false) { setError ("submodule " + modulename + " not found"); return NULL; } else { resetError (); createSubmodule (modulename, submodulename); return selectSubmodule (modulename, submodulename); } } // if (childs == NULL) for (unsigned int i=0; i<childs->getLength (); i++) { DOMNode* node = childs->item (i); if (node == NULL || node->getNodeType () != DOMNode::ELEMENT_NODE) continue; char* xmlstring = XMLString::transcode (node->getNodeName ()); if (((string) ELEMENT_SUBMODULE_NAME).compare (xmlstring) != 0) { XMLString::release (&xmlstring); continue; } XMLString::release (&xmlstring); if ((getAttributeValue (node, ATTRIBUTE_NAME)).compare (submodulename) == 0) { resetError (); return node; } } // for (unsigned int i=0; i<childs->getLength (); i++) if (autocreate == false) { setError ("submodule " + submodulename + " not found"); return NULL; } else { resetError (); createSubmodule (modulename, submodulename); return selectSubmodule (modulename, submodulename); } }
void EppResponseInfoFeeType::fromXMLCommon( const DOMNode& root, EppResponseInfoFeeType* data ) { if( NULL == data ) { return; } EppCommandInfoFeeType::fromXMLCommon(root, data); DOMNodeList* list = root.getChildNodes(); if( NULL == list ) { return; } for( unsigned int i = 0; i < list->getLength(); i++ ) { DOMNode* node = list->item(i); if( NULL == node ) { continue; } DOMString name = node->getLocalName(); if( name.isNull() ) { name = node->getNodeName(); } if( name.isNull() ) { continue; } if( name.equals("fee") || name.equals("fee:fee") ) { EppFeeFee* f = EppFeeFee::fromXML(*node); if( NULL != f ) { data->addFee(f); } continue; } if( name.equals("class") || name.equals("fee:class") ) { data->setFeeClass(EppUtil::getText(*node)); continue; } } }
/** * Returns the value of a names child element * @param element parent element * @param name name of child element value is stored in * @return the value of the child element with the given name or NULL if there are 0 or >1 elements with the given name */ char* getChildValue(DOMElement* element, const char* name) { DOMNode* child = getElement(element, name); if (child == NULL) return NULL; DOMNodeList* contentList = child->getChildNodes(); if (contentList->getLength() != 1) return NULL; DOMNode* firstContent = contentList->item(0); if (firstContent == NULL) return NULL; return XMLString::transcode(firstContent->getNodeValue()); }
DOMNode* Triggerconf::selectConfigElement (string modulename, string submodulename, string configname) { DOMNode* currentSubmodule = selectSubmodule (modulename, submodulename); if (currentSubmodule == NULL) { setError ("invalid submodule " + submodulename + " in module " + modulename); return NULL; } DOMNodeList* childs = currentSubmodule->getChildNodes (); if (childs == NULL) { setError ("submodule " + submodulename + " in module " + modulename + " not found"); return NULL; } for (unsigned int i=0; i<childs->getLength (); i++) { DOMNode* child = childs->item (i); if (child == NULL || child->getNodeType () != DOMNode::ELEMENT_NODE) continue; char* xmlstring = XMLString::transcode (child->getNodeName ()); if (((string) ELEMENT_CONFIGITEM_NAME).compare (xmlstring) != 0) { XMLString::release (&xmlstring); continue; } XMLString::release (&xmlstring); if ((getAttributeValue (child, ATTRIBUTE_NAME)).compare (configname) == 0) { resetError (); return child; } } // for (unsigned int i=0; i<childs->getLength (); i++) if (autocreate == false) { setError ("configelement " + configname + " not found"); return NULL; } else { resetError (); createConfigElement (modulename, submodulename, configname); return selectConfigElement (modulename, submodulename, configname); } }
void EppCommandCheckFeeType::fromXMLCommon( const DOMNode& root, EppCommandCheckFeeType* data ) { if( NULL == data ) { return; } EppCommandInfoFeeType::fromXMLCommon(root, data); DOMNodeList* list = root.getChildNodes(); if( NULL == list ) { return; } for( unsigned int i = 0; i < list->getLength(); i++ ) { DOMNode* node = list->item(i); if( NULL == node ) { continue; } DOMString name = node->getLocalName(); if( name.isNull() ) { name = node->getNodeName(); } if( name.isNull() ) { continue; } if( name.equals("name") || name.equals("fee:name") ) { data->setName(EppUtil::getText(*node)); continue; } } }
DOMString EppUtil::getText( const DOMNode &root ) { DOMNodeList* list = root.getChildNodes(); if( list->getLength() == 0 ) { return root.getNodeValue(); } DOMString str = DOMString(""); for( unsigned int i = 0; i < list->getLength(); i++ ) { DOMNode* node = list->item(i); if( (node->getNodeType() == DOMNode::TEXT_NODE) || (node->getNodeType() == DOMNode::CDATA_SECTION_NODE) ) { DOMString val = node->getNodeValue(); str += val; } } return str; }
void create_PmtInf_body(PmtInf *PmtOBj) { DOMNode *pmtInf =PmtOBj->getPmtInf_node(); int counter = 0; DOMNodeList *pmtChildList = pmtInf->getChildNodes(); DOMNode* node = NULL; char s[64] = { 0 }; char *temp = NULL; Arb_numeric out_num = ARB_NUMERIC_ZERO; double e_amount; double s_amount; XMLCh *tempStr = NULL; //1,add nboftxs counter=PmtOBj->getNbOftxs(); counter +=1; PmtOBj->setNbOftxs(counter); //2,add ctrlSum. arb_num_rate(&out_num, &gTrans.amount, 1, (gEur_impl_decimal - 2),gEur_round_method); arb_numeric_to_double(&out_num, &e_amount); PmtOBj->addCtrlSum(&out_num); /*for (size_t i = 0; i < pmtChildList->getLength(); ++i) { node = pmtChildList->item(i); tempStr = XMLString::transcode("NbOfTxs"); if (XMLString::equals(node->getNodeName(), tempStr)) { XMLString::release(&tempStr); temp = XMLString::transcode(node->getTextContent()); sprintf(s, "%d", atoi(temp) + 1); XMLString::release(&temp); tempStr = XMLString::transcode(s); node->setTextContent(tempStr); XMLString::release(&tempStr); counter++; } tempStr = XMLString::transcode("CtrlSum"); if (XMLString::equals(node->getNodeName(), tempStr)) { XMLString::release(&tempStr); temp = XMLString::transcode(node->getTextContent()); s_amount = atof(temp); XMLString::release(&temp); arb_num_rate(&out_num, &gTrans.amount, 1, (gEur_impl_decimal - 2), gEur_round_method); arb_numeric_to_double(&out_num, &e_amount); sprintf(s, "%d.%02.0f", (int) e_amount / 100, fmod(e_amount, 100)); s_amount += atof(s); sprintf(s, "%.2f", s_amount); tempStr = XMLString::transcode(s); node->setTextContent(tempStr); XMLString::release(&tempStr); counter++; } if (counter == 2) break; }*/ XmlNode pmtNode(pmtInf,doc); char endtoend[99]={0}; sprintf(endtoend, "%02d%010d%03d%010d%03d%s", gTrans.tracking_id_serv, gTrans.tracking_id, gTrans.counter, gTrans.bill_ref_no, gTrans.bill_ref_resets, gTrans.sequence_type); sprintf(s, "%d.%02.0f", (int) e_amount / 100, fmod(e_amount, 100)); char ustrd[99]={0}; sprintf(ustrd, "%d/%d/%d/%d/%s/%s", gTrans.tracking_id_serv, gTrans.tracking_id, gTrans.bill_ref_no, gTrans.bill_ref_resets, gTrans.acct_ext_id, gTrans.mandate_id); XmlNode drctDbtTxInfNode = pmtNode.addChild("DrctDbtTxInf"); drctDbtTxInfNode.addChild("PmtId").addChild("EndToEndId", endtoend); drctDbtTxInfNode.addChild("InstdAmt", s).addAttribute("Ccy", "EUR"); XmlNode drectDbtTxNode = drctDbtTxInfNode.addChild("DrctDbtTx"); XmlNode mndtRltdInfNode = drectDbtTxNode.addChild("MndtRltdInf"); mndtRltdInfNode.addChild("MndtId", gTrans.mandate_id); mndtRltdInfNode.addChild("DtOfSgntr", gTrans.mandate_sign_date); if (strncmp(gTrans.mandate_reset, "Y", 1) == 0) { if ((strlen(gTrans.cust_bank_iban) != 0 && strcmp( gTrans.cust_bank_iban_hist, gTrans.cust_bank_iban) != 0) && (strlen(gTrans.cust_bank_bic) != 0 && strcmp( gTrans.cust_bank_bic_hist, gTrans.cust_bank_bic) != 0)) { mndtRltdInfNode.addChild("AmdmntInd", "true"); XmlNode AmdmntInfDtlsNode = mndtRltdInfNode.addChild( "AmdmntInfDtls"); AmdmntInfDtlsNode.addChild("OrgnlDbtrAcct").addChild("Id").addChild( "IBAN", gTrans.cust_bank_iban_hist); AmdmntInfDtlsNode.addChild("OrgnlDbtrAgt").addChild("FinInstnId").addChild( "Othr").addChild("Id", "SMNDA"); } else if (strlen(gTrans.cust_bank_iban) != 0 && strcmp( gTrans.cust_bank_iban_hist, gTrans.cust_bank_iban) != 0) { mndtRltdInfNode.addChild("AmdmntInd", "true"); mndtRltdInfNode.addChild("AmdmntInfDtls").addChild("OrgnlDbtrAcct").addChild( "Id").addChild("IBAN", gTrans.cust_bank_iban_hist); } else if (strlen(gTrans.cust_bank_bic) != 0 && strcmp( gTrans.cust_bank_bic_hist, gTrans.cust_bank_bic) != 0) { mndtRltdInfNode.addChild("AmdmntInd", "true"); mndtRltdInfNode.addChild("AmdmntInfDtls").addChild("OrgnlDbtrAgt").addChild( "FinInstnId").addChild("Othr").addChild("Id", "SMNDA"); } else { mndtRltdInfNode.addChild("AmdmntInd", "false"); } } else { if ((strlen(gTrans.c_cust_bank_iban) != 0 && strcmp( gTrans.c_cust_bank_iban, gTrans.cust_bank_iban)) && (strlen( gTrans.c_cust_bank_bic) != 0 && strcmp(gTrans.c_cust_bank_bic, gTrans.cust_bank_bic))) { mndtRltdInfNode.addChild("AmdmntInd", "true"); XmlNode AmdmntInfDtlsNode = mndtRltdInfNode.addChild( "AmdmntInfDtls"); AmdmntInfDtlsNode.addChild("OrgnlDbtrAcct").addChild("Id").addChild( "IBAN", gTrans.c_cust_bank_iban); AmdmntInfDtlsNode.addChild("OrgnlDbtrAgt").addChild("FinInstnId").addChild( "Othr").addChild("Id", "SMNDA"); } else if (strlen(gTrans.c_cust_bank_iban) != 0 && strcmp( gTrans.c_cust_bank_iban, gTrans.cust_bank_iban)) { mndtRltdInfNode.addChild("AmdmntInd", "true"); mndtRltdInfNode.addChild("AmdmntInfDtls").addChild("OrgnlDbtrAcct").addChild( "Id").addChild("IBAN", gTrans.c_cust_bank_iban); } else if (strlen(gTrans.c_cust_bank_bic) != 0 && strcmp( gTrans.c_cust_bank_bic, gTrans.cust_bank_bic)) { mndtRltdInfNode.addChild("AmdmntInd", "true"); mndtRltdInfNode.addChild("AmdmntInfDtls").addChild("OrgnlDbtrAgt").addChild( "FinInstnId").addChild("Othr").addChild("Id", "SMNDA"); } else { mndtRltdInfNode.addChild("AmdmntInd", "false"); } } drctDbtTxInfNode.addChild("DbtrAgt").addChild("FinInstnId").addChild("BIC", gTrans.cust_bank_bic); drctDbtTxInfNode.addChild("Dbtr").addChild("Nm").addTextForAcctOwner( gTrans.acct_owner); drctDbtTxInfNode.addChild("DbtrAcct").addChild("Id").addChild("IBAN", gTrans.cust_bank_iban); drctDbtTxInfNode.addChild("RmtInf").addChild("Ustrd", ustrd); }
bool CConfigParser::ParseActions(DOMNodeList* actionNodeList, ADeviceListener& configClass) { USES_CONVERSION; // Parse all the actions if(actionNodeList != NULL && actionNodeList->getLength() > 0) { DOMNodeList* actionNodes = actionNodeList->item(0)->getChildNodes(); for(unsigned long i = 0; i < actionNodes->getLength(); i++) { DOMNode* actionNode = actionNodes->item(i); wstring actionType = actionNode->getNodeName(); if(actionType.compare(L"#text") == 0) continue; XMLCh* xmlChNameTxt = L"name"; wstring actionName; if(actionNode->hasAttributes()) { DOMNode* nameAttribute = actionNode->getAttributes()->getNamedItem(xmlChNameTxt); actionName = nameAttribute->getNodeValue(); } if(actionType.compare(L"sendCopyDataWindowMessage") == 0 || actionType.compare(L"sendCommandWindowMessage") == 0) { wstring message = actionNode->getAttributes()->getNamedItem(L"message")->getNodeValue(); bool findByClass = FALSE; wstring windowAttributeName = L"window"; if(actionNode->getAttributes()->getNamedItem(L"window") == NULL) { findByClass = TRUE; windowAttributeName = L"windowClass"; } wstring window = actionNode->getAttributes()->getNamedItem(windowAttributeName.c_str())->getNodeValue(); CSendWindowMessageAction* messageActionToAdd = NULL; if(actionType.compare(L"sendCommandWindowMessage") == 0) { messageActionToAdd = new CSendWindowMessageAction(_wtol(message.c_str()), OLE2T(window.c_str()), findByClass); } if(actionType.compare(L"sendCopyDataWindowMessage") == 0) { messageActionToAdd = new CSendWindowMessageAction(OLE2T(message.c_str()), OLE2T(window.c_str()), findByClass); } if(messageActionToAdd != NULL) configClass.AddAction(actionName, messageActionToAdd); } if(actionType.compare(L"execute") == 0) { char* executable = XMLString::transcode( actionNode->getAttributes()->getNamedItem(L"executable")->getNodeValue()); char* commandline = XMLString::transcode( actionNode->getAttributes()->getNamedItem(L"commandline")->getNodeValue()); configClass.AddAction(actionName, new CExecuteAction(executable, commandline)); XMLString::release(&executable); XMLString::release(&commandline); } if(actionType.compare(L"keyPress") == 0) { TKeyList keys; DOMNodeList* keyNodes = actionNode->getChildNodes(); unsigned long count = keyNodes->getLength(); for(unsigned long keyIdx=0; keyIdx < keyNodes->getLength(); keyIdx++) { DOMNode* keyNode = keyNodes->item(keyIdx); if(wcscmp(keyNode->getNodeName(), L"#text") == 0) continue; const XMLCh* keyValue = keyNode->getFirstChild()->getNodeValue(); if(keyValue == NULL) continue; int test = VK_CONTROL; keys.push_back(_wtoi(keyValue)); } configClass.AddAction(actionName, new CKeyboardAction(keys)); } if(actionType.compare(L"winampPlayPause") == 0) { configClass.AddAction(actionName, new CWinampPlayPause()); } if(actionType.compare(L"winampMute") == 0) { configClass.AddAction(actionName, new CWinampMute()); } // We make the assumption that the macros were put at the end of the // config file, otherwise the actions they execute may not exist! if(actionType.compare(L"macro") == 0) { wstring type = actionNode->getAttributes()->getNamedItem(L"type")->getNodeValue(); CMacroAction* actionToAdd = new CMacroAction(type.compare(L"all") == 0 ? true : false); DOMNodeList* macroActions = actionNode->getChildNodes(); unsigned long count = macroActions->getLength(); for(unsigned long actionIdx=0; actionIdx < count; actionIdx++) { DOMNode* macroActionNode = macroActions->item(actionIdx); if(wcscmp(macroActionNode->getNodeName(), L"#text") == 0) continue; wstring macroActionName = macroActionNode->getAttributes()->getNamedItem(L"name")->getNodeValue(); actionToAdd->AddAction(configClass.GetActions()[macroActionName]); } configClass.AddAction(actionName, actionToAdd); } } } return true; }
EppServiceMenu * EppServiceMenu::fromXML( const DOMNode& root ) { EppServiceMenu * svcmenu = new EppServiceMenu(); DOMNodeList* list = root.getChildNodes(); 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.equals("version") ) { svcmenu->addVersion(EppUtil::getText(*node)); } else if( name.equals("lang") ) { svcmenu->addLanguage(EppUtil::getText(*node)); } else if( name.equals("objURI") ) { DOMString uri = EppUtil::getText(*node); if( uri.isNotNull() && uri.length() > 0 ) { svcmenu->addService(uri); } } else if( name.equals("svcExtension") ) { DOMNodeList* ulist = node->getChildNodes(); for( unsigned int j = 0; j < ulist->getLength(); j++ ) { DOMNode* unode = ulist->item(j); name = unode->getLocalName(); if( name.isNull() ) { name = unode->getNodeName(); } if( name.isNull() ) { continue; } else if( name.equals("extURI") ) { DOMString ext = EppUtil::getText(*unode); if( ext.isNotNull() && ext.length() > 0 ) { svcmenu->addServiceExtension(ext); } } } } } return svcmenu; }
void FDPLoader::loadFDPItem(DOMNode* pFDPItem) { DOMNamedNodeMap* attrList = pFDPItem->getAttributes(); FDPItem* pItem = 0; // get the name (id) DOMNode* attr = attrList->getNamedItem(XercesString("name")); if(attr) { char* name = XMLString::transcode(attr->getNodeValue()); // create a new item (will be deleted in dtor of FDP class) pItem = new FDPItem(name); XMLString::release(&name); } else return; // get the control vertex index attr = attrList->getNamedItem(XercesString("index")); if(attr) { char* index = XMLString::transcode(attr->getNodeValue()); pItem->setControlPoint((unsigned short)atoi(index)); XMLString::release(&index); } // get the affecting mesh name attr = attrList->getNamedItem(XercesString("affects")); if(attr) { char* affects = XMLString::transcode(attr->getNodeValue()); pItem->setAffects(affects); XMLString::release(&affects); } DOMNodeIterator* iterator = m_pDoc->createNodeIterator(pFDPItem, DOMNodeFilter::SHOW_ELEMENT | DOMNodeFilter::SHOW_ATTRIBUTE, NULL, true); // use the tree walker to print out the text nodes. for ( DOMNode* current = iterator->nextNode(); current != 0; current = iterator->nextNode() ) { if(XercesString(current->getNodeName()) == "indices") { DOMNodeList* children = current->getChildNodes(); // we should have only one child, text node, just a safety net here if ( (children->getLength() == 1) && (children->item(0)->getNodeType() == DOMNode::TEXT_NODE) )//(XercesString(children->item(0)->getNodeName()) == "#text") ) { char* pStr = XMLString::transcode(children->item(0)->getNodeValue()); std::string str(pStr); processIndices(str, pItem); XMLString::release(&pStr); } } else if (XercesString(current->getNodeName()) == "influence") // can have multiple of those { // sample: <influence weight="0.25" fap="3" type="RaisedCosInfluenceWaveY" /> DOMNamedNodeMap* influenceAttr = current->getAttributes(); // get the weight float w = toFloat(influenceAttr->getNamedItem(XercesString("weight"))->getNodeValue()); unsigned short fap = (unsigned short)toFloat(influenceAttr->getNamedItem(XercesString("fap"))->getNodeValue()); char* type = XMLString::transcode(influenceAttr->getNamedItem(XercesString("type"))->getNodeValue()); IInfluenceCalculator* pInfluence = InfluenceCalculatorMaker::newInfluenceCalculator(type, w, fap); if(pInfluence) pItem->addInfluenceCalculator(pInfluence); } } m_pFDP->insertItem(pItem); }
/*=========================================================================+ 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: ; }
void EppWriter::print( const DOMNode &node, int level, DOMString prefix ) { unsigned int i = 0; int j = 0; DOMNodeList* list; DOMNamedNodeMap* attrs; DOMString newPrefix; int type = node.getNodeType(); switch( type ) { case DOMNode::DOCUMENT_NODE: if( ! canonical ) { out += XS("<?xml version=\"1.0\" encoding=\"") + encoding + "\"?>"; out += "\n"; } list = node.getChildNodes(); if( list != null ) { for( i = 0; i < list->getLength(); i++ ) { print(*list->item(i), level, prefix); } } break; case DOMNode::ELEMENT_NODE: for( j = 0; j < level; j++ ) { out += " "; } out += "<"; newPrefix = node.getPrefix(); if( newPrefix.isNotNull() ) { prefix = newPrefix; } if( (newPrefix.isNull()) && (prefix.isNotNull()) ) { out += prefix; out += ":"; } out += node.getNodeName(); attrs = node.getAttributes(); if( attrs != null ) { for( i = 0; i < attrs->getLength(); i++ ) { DOMNode* attr = attrs->item(i); out += " "; out += attr->getNodeName(); out += "=\""; out += attr->getNodeValue(); out += "\""; } } list = node.getChildNodes(); if( (list == null) || (list->getLength() == 0) ) { out += "/>\n"; } else { bool cr = false; out += ">"; for( i = 0; i < list->getLength(); i++ ) { if( i == 0 ) { if( list->item(0)->getNodeType() != DOMNode::TEXT_NODE ) { out += "\n"; cr = true; } } print(*list->item(i), level + 1, prefix); } if( cr ) { for( j = 0; j < level; j++ ) { out += " "; } } out += "</"; if( (newPrefix.isNull()) && (prefix.isNotNull()) ) { out += prefix; out += ":"; } out += node.getNodeName(); out += ">\n"; } break; case DOMNode::TEXT_NODE: { DOMString p = node.getNodeValue(); this->normalize(out, p); // out += node.getNodeValue(); } break; default: break; } }
int C_SatXmlParser::GetDcpInfoList_parser( std::vector< Satellite::DCPInfo > &DcpList ) { bool IsFind_dcplistNode = false; DOMDOC* xmlDoc = NULL; if ( m_xml_parser == NULL ) { return XML_PARSER_ERROR; } else { xmlDoc = m_xml_parser->getDocument(); if ( xmlDoc == NULL ) { return XML_PARSER_ERROR; } } DOMNodeList* children = xmlDoc->getElementsByTagNameNS( C2X("*") , C2X("response") ); if ( children == NULL ) { return RESPONSE_FORMAT_ERROR; } else //find "response" node { XMLSize_t count_of_node = children->getLength(); if ( count_of_node <= 0 ) { return RESPONSE_FORMAT_ERROR; } else { //如果 "response" node存在,则取出"status"属性;如果"status"属性不存在,则表示格式错误 DOMNode* xNode = children->item( 0 ); if ( xNode == NULL ) return RESPONSE_FORMAT_ERROR; XMLCh2Char tmpXmlch2Char( ((DOMElement*)xNode)->getAttribute( C2X("status") ) ); std::string tmp = tmpXmlch2Char.get_char_str(); if ( tmp.length() == 0 ) { return RESPONSE_FORMAT_ERROR; } if ( strstr( tmpXmlch2Char.get_char_str() , "OK" ) == NULL ) //如果"status"属性不等于"OK",则表示状态错误 { //如果"status"属性不等于"OK",则表示状态错误 return RESPONSE_STATUS_ERROR; } else { //检查是否存在节点"dcp_list",如果不存在,则表示格式错误 DOMNodeList* children = xNode->getChildNodes(); count_of_node = children->getLength(); if ( count_of_node <= 0 ) { return RESPONSE_FORMAT_ERROR; } // DOMNode* current_Node = children->item(0); if ( current_Node == NULL ) return RESPONSE_FORMAT_ERROR; XMLCh2Char Xmlch2Char(current_Node->getNodeName()); if ( strstr( Xmlch2Char.get_char_str() , "dcp_list" ) ) //判断节点名字是否为"dcp_list",相同则表示节点找到设置IsFind_dcplistNode=true; { IsFind_dcplistNode = true; //"dcp_list"节点已经找到 } else { IsFind_dcplistNode = false; //"dcp_list"节点没找到 } } } } //如果<dcp_list>节点找到,则继续解析每个<dcp>节点。 if ( IsFind_dcplistNode ) { //搜索所有的节点<dcp>,然后进行逐个解析 DOMNodeList* dcp_children = xmlDoc->getElementsByTagNameNS( C2X("*") , C2X("dcp") ); if ( dcp_children == NULL ) { return RESPONSE_FORMAT_ERROR; } else { XMLSize_t dcp_count_of_node = dcp_children->getLength(); if ( dcp_count_of_node <= 0 ) { return RESPONSE_FORMAT_ERROR; } else { XMLSize_t count_of_node = 0; for ( XMLSize_t i = 0; i < dcp_count_of_node; i++ ) { //取出每个<dcp>节点 DOMNode* xNode = dcp_children->item( i ); if ( xNode == NULL ) { return XML_NODE_NOEXIST_ERROR; } DOMNodeList* children = xNode->getChildNodes(); if ( children == NULL ) { return RESPONSE_FORMAT_ERROR; } count_of_node = children->getLength(); if ( count_of_node <= 0 ) { return RESPONSE_FORMAT_ERROR; } Satellite::DCPInfo info; for ( XMLSize_t xx = 0; xx < count_of_node; xx++ ) { DOMNode* current_Node = children->item( xx ); if ( current_Node == NULL ) { return XML_NODE_NOEXIST_ERROR; } XMLCh2Char Xmlch2Char(current_Node->getNodeName()); if ( strstr( Xmlch2Char.get_char_str() , "uuid" ) ) //DCP的uuid { XMLCh2Char tmpXmlch2Char(((DOMElement*)current_Node)->getFirstChild()->getNodeValue()); info.PklUuid = tmpXmlch2Char.get_char_str() + strlen("urn:uuid:"); } else if ( strstr( Xmlch2Char.get_char_str() , "issuer" ) ) //DCP的发行者 { XMLCh2Char tmpXmlch2Char(((DOMElement*)current_Node)->getFirstChild()->getNodeValue()); info.issuer = tmpXmlch2Char.get_char_str(); } else if ( strstr( Xmlch2Char.get_char_str() , "creator" ) ) //DCP的创建者 { XMLCh2Char tmpXmlch2Char(((DOMElement*)current_Node)->getFirstChild()->getNodeValue()); info.Creater = tmpXmlch2Char.get_char_str(); } else if ( strstr( Xmlch2Char.get_char_str() , "issueDate" ) ) //DCP的发行时间 { XMLCh2Char tmpXmlch2Char(((DOMElement*)current_Node)->getFirstChild()->getNodeValue()); info.issueDate = tmpXmlch2Char.get_char_str(); } else if ( strstr( Xmlch2Char.get_char_str() , "name" ) ) { XMLCh2Char tmpXmlch2Char(((DOMElement*)current_Node)->getFirstChild()->getNodeValue()); info.Name = tmpXmlch2Char.get_char_str(); } } if( info.Creater.size() && info.issueDate.size() && info.PklUuid.size() && info.issuer.size() ) DcpList.push_back( info ); } } } } else { return RESPONSE_FORMAT_ERROR; } return 0; }
int C_SatXmlParser::GetFilmFtpInfo_parser( Satellite::FTP_DCPInfo& rFTP_DCPInfo ) { DOMDOC* xmlDoc = NULL; if ( m_xml_parser == NULL ) { return XML_PARSER_ERROR; } else { xmlDoc = m_xml_parser->getDocument(); if ( xmlDoc == NULL ) { return XML_PARSER_ERROR; } } DOMNodeList* children = xmlDoc->getElementsByTagNameNS( C2X("*") , C2X("response") ); if ( children == NULL ) { return RESPONSE_FORMAT_ERROR; } else //find "response" node { XMLSize_t count_of_node = children->getLength(); if ( count_of_node <= 0 ) { return RESPONSE_FORMAT_ERROR; } else { //如果 "response" node存在,则取出"status"属性;如果"status"属性不存在,则表示格式错误 DOMNode* xNode = children->item( 0 ); if ( xNode == NULL ) return RESPONSE_FORMAT_ERROR; XMLCh2Char tmpXmlch2Char( ((DOMElement*)xNode)->getAttribute( C2X("status") ) ); std::string tmp = tmpXmlch2Char.get_char_str(); if ( tmp.length() == 0 ) { return RESPONSE_FORMAT_ERROR; } if ( strstr( tmpXmlch2Char.get_char_str() , "OK" ) == NULL ) //如果"status"属性不等于"OK",则表示状态错误 { //如果"status"属性不等于"OK",则表示状态错误 return RESPONSE_STATUS_ERROR; } else { DOMNodeList* children = xNode->getChildNodes(); count_of_node = children->getLength(); if ( count_of_node <= 0 ) { return RESPONSE_FORMAT_ERROR; } for ( XMLSize_t xx = 0; xx < count_of_node; xx++ ) { DOMNode* current_Node = children->item( xx ); if ( current_Node == NULL ) { return XML_NODE_NOEXIST_ERROR; } XMLCh2Char Xmlch2Char(current_Node->getNodeName()); if ( strstr( Xmlch2Char.get_char_str() , "asset_type" ) ) //DCP下载类型(PKL或者CPL) { XMLCh2Char tmpXmlch2Char(((DOMElement*)current_Node)->getFirstChild()->getNodeValue()); rFTP_DCPInfo.asset_type = tmpXmlch2Char.get_char_str(); } else if ( strstr( Xmlch2Char.get_char_str() , "source" ) ) //DCP在ftp存放的路径 { XMLCh2Char tmpXmlch2Char(((DOMElement*)current_Node)->getFirstChild()->getNodeValue()); rFTP_DCPInfo.source = tmpXmlch2Char.get_char_str(); } else if ( strstr( Xmlch2Char.get_char_str() , "path" ) ) //ftp服务器的位置 { XMLCh2Char tmpXmlch2Char(((DOMElement*)current_Node)->getFirstChild()->getNodeValue()); rFTP_DCPInfo.path = tmpXmlch2Char.get_char_str(); } else if ( strstr( Xmlch2Char.get_char_str() , "username" ) ) //登陆ftp的用户名 { XMLCh2Char tmpXmlch2Char(((DOMElement*)current_Node)->getFirstChild()->getNodeValue()); rFTP_DCPInfo.username = tmpXmlch2Char.get_char_str(); } else if ( strstr( Xmlch2Char.get_char_str() , "password" ) ) //登陆ftp的密码 { XMLCh2Char tmpXmlch2Char(((DOMElement*)current_Node)->getFirstChild()->getNodeValue()); rFTP_DCPInfo.password = tmpXmlch2Char.get_char_str(); } } std::string::size_type bgn = rFTP_DCPInfo.source.find( "//" ); if( bgn == string::npos ) return -1; bgn += 2; if( bgn >= rFTP_DCPInfo.source.size() ) return -1; /* ftp_url格式如下: FTP://账号:密码@主机/子目录或文件 */ rFTP_DCPInfo.ftp_url = rFTP_DCPInfo.source + rFTP_DCPInfo.path; rFTP_DCPInfo.ftp_url.insert( bgn , rFTP_DCPInfo.username + ":" + rFTP_DCPInfo.password + "@" ); rFTP_DCPInfo.ftp_url_path = rFTP_DCPInfo.ftp_url.substr( 0 , rFTP_DCPInfo.ftp_url.rfind("/") + 1 ); } } } return 0; }
static void osmloader_step(ubx_block_t *c) { LOG(INFO) << "osmloader: executing: " << c->name; /* Just print what the world model has to offer. */ wmPrinter->reset(); wmHandle->scene.executeGraphTraverser(wmPrinter, wmHandle->getRootNodeId()); LOG(DEBUG) << "osmloader: Current state of the world model: " << std::endl << wmPrinter->getDotGraph(); /* read Id(s) from input port */ std::vector<brics_3d::rsg::Id> inputDataIds; inputDataIds.clear(); ubx_port_t* inputPort = ubx_port_get(c, "inputDataIds"); rsg_ids recievedInputDataIs; recievedInputDataIs.numberOfIds = 0u; int ret = read_rsg_ids(inputPort, &recievedInputDataIs); if (ret < 1) { LOG(WARNING) << "osmloader: No input IDs given."; } brics_3d::rsg::Id outputHookId; brics_3d::rsg::UbxTypecaster::convertIdsFromUbx(recievedInputDataIs, inputDataIds); if (inputDataIds.size() < 1) { LOG(WARNING) << "osmloader: Not enough IDs specified. Expected 1 but it is: " << inputDataIds.size() << std::endl << "Using root instead."; outputHookId = wmHandle->getRootNodeId(); } else { outputHookId = inputDataIds[0]; // First ID is always the output hook. } std::vector<brics_3d::rsg::Id> output; output.clear(); output.push_back(outputHookId); // First ID is always the output hook. /* The origin */ brics_3d::rsg::Id originId; std::vector<brics_3d::rsg::Attribute> originAttributes; if(convertToUtm) { originAttributes.push_back(brics_3d::rsg::Attribute("gis:origin","utm")); } else { originAttributes.push_back(brics_3d::rsg::Attribute("gis:origin","wgs84")); } /* check if it exists already */ vector<brics_3d::rsg::Id> resultIds; wmHandle->scene.getNodes(originAttributes, resultIds); if(resultIds.size() > 0) { if(resultIds.size() > 1) { LOG(INFO) << "osmloader: Multiple origins found. Taking first one."; } originId = resultIds[0]; // We take the first one. LOG(INFO) << "osmloader: Existing origin found with Id = " << originId; } else { LOG(INFO) << "osmloader: Adding a new origin node"; wmHandle->scene.addGroup(outputHookId, originId, originAttributes); } /* * get and set config data */ std::string dataSetFolder = "/opt/src/sandbox/brics_3d_function_blocks/data"; std::string dataSet = *fileName; LOG(INFO) << "osmloader: Using file " << dataSet << " ."; /* * define where to store results */ /* * do computation */ vector<brics_3d::rsg::Id> osmNodesIds; /* Open xml file */ try { XMLPlatformUtils::Initialize(); } catch (const XMLException& e) { char *pMsg = XMLString::transcode(e.getMessage()); cerr << "ERROR: An error occured during Xerces initialization.\n" << " Exception message:" << pMsg; XMLString::release(&pMsg); return; } // // Create our parser, then attach an error handler to the parser. // The parser will call back to methods of the ErrorHandler if it // discovers errors during the course of parsing the XML document. // parser = new XercesDOMParser; parser->setValidationScheme(XercesDOMParser::Val_Auto); parser->setDoNamespaces(false); parser->setDoSchema(false); parser->setValidationSchemaFullChecking(false); parser->setCreateEntityReferenceNodes(false); // // Parse the XML file, catching any XML exceptions that might propagate // out of it. // bool errorsOccured = false; try { parser->parse(dataSet.c_str()); int errorCount = parser->getErrorCount(); if (errorCount > 0) { errorsOccured = true; LOG(ERROR) << "XML document has " << errorsOccured << " error(s)."; } } catch (const XMLException& e) { LOG(ERROR) << "An error occured during parsing\n Message: " << e.getMessage(); errorsOccured = true; } catch (const DOMException& e) { LOG(ERROR) << "A DOM error occured during parsing\n DOMException code: " << e.code; errorsOccured = true; } catch (...) { LOG(ERROR) << "An error occured during parsing\n" << endl; errorsOccured = true; } LOG(INFO) << "osmloader: Read file. Error: " << errorsOccured; if(errorsOccured) { return; } /* parse xml file */ DOMNode* current = 0; DOMNode* currentChild = 0; DOMNode* attributeNode = 0; DOMNamedNodeMap* attributesList = 0; DOMNamedNodeMap* childAttributesList = 0; XMLCh* rootName = XMLString::transcode("osm"); XMLCh* nodeName = XMLString::transcode("node"); XMLCh* tagName = XMLString::transcode("tag"); XMLCh* kName = XMLString::transcode("k"); XMLCh* vName = XMLString::transcode("v"); XMLCh* idName = XMLString::transcode("id"); XMLCh* latName = XMLString::transcode("lat"); XMLCh* lonName = XMLString::transcode("lon"); XMLCh* wayName = XMLString::transcode("way"); XMLCh* refName = XMLString::transcode("ref"); XMLCh* versionName = XMLString::transcode("version"); string tmpResult; string osmAttributePrefix = "osm:"; unsigned int nodeCounter = 0; unsigned int wayCounter = 0; /* <osm version="0.6" generator="Overpass API"> * <note>The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.</note> * <meta osm_base="2015-01-07T12:43:02Z"/> * <node id="21101298" lat="50.7776577" lon="7.1853241"><tag k="crossing" v="traffic_signals"/> * <tag k="highway" v="traffic_signals"/> * </node> * </osm> */ DOMDocument* doc = parser->getDocument(); /* root node */ DOMNodeList* root = doc->getElementsByTagName(rootName); if (root->getLength() > 1) { LOG(WARNING) << "More than one osm elemnt found, taking the first one"; } else if(root->getLength() < 1) { LOG(ERROR) << "No osm elemnt found."; return ; } current = root->item(0); attributesList = current->getAttributes(); attributeNode = attributesList->getNamedItem(versionName); if (attributeNode != 0) { tmpResult = XMLString::transcode(attributeNode->getNodeValue()); LOG(INFO) << "osm version = " << tmpResult; } /* osm nodes */ DOMNodeList* osmNodes = doc->getElementsByTagName(nodeName); double x = -1.0; double y = -1.0; double z = 0.0; for (int i = 0; i < osmNodes->getLength(); ++i) { unsigned int id = 0; double lon = -1.0; double lat = -1.0; vector<brics_3d::rsg::Attribute> tags; brics_3d::rsg::TimeStamp time = wmHandle->now(); current = osmNodes->item(i); attributesList = current->getAttributes(); // Id attributeNode = attributesList->getNamedItem(idName); if (attributeNode != 0) { tmpResult = XMLString::transcode(attributeNode->getNodeValue()); LOG(DEBUG) << "node id = " << tmpResult; tags.push_back(brics_3d::rsg::Attribute(osmAttributePrefix+"node_id", tmpResult)); id = atoi(tmpResult.c_str()); } // lon attributeNode = attributesList->getNamedItem(lonName); if (attributeNode != 0) { tmpResult = XMLString::transcode(attributeNode->getNodeValue()); LOG(DEBUG) << "\t node lon = " << tmpResult; lon = atof(tmpResult.c_str()); } // lat attributeNode = attributesList->getNamedItem(latName); if (attributeNode != 0) { tmpResult = XMLString::transcode(attributeNode->getNodeValue()); LOG(DEBUG) << "\t node lat = " << tmpResult; lat = atof(tmpResult.c_str()); } //tags are in the child nodes DOMNodeList* childs = current->getChildNodes(); for (int j = 0; j < childs->getLength(); ++j) { currentChild = childs->item(j); childAttributesList = currentChild->getAttributes(); tmpResult = XMLString::transcode(currentChild->getNodeName()); // LOG(DEBUG) << "\t childName = " << tmpResult; if(tmpResult.compare("tag") == 0) { // LOG(DEBUG) << "\t found a tag: "; brics_3d::rsg::Attribute tag; // k attributeNode = childAttributesList->getNamedItem(kName); if (attributeNode != 0) { tmpResult = XMLString::transcode(attributeNode->getNodeValue()); LOG(DEBUG) << "\t\t node k = " << tmpResult; tag.key = osmAttributePrefix+tmpResult; } else { continue; } // v attributeNode = childAttributesList->getNamedItem(vName); if (attributeNode != 0) { tmpResult = XMLString::transcode(attributeNode->getNodeValue()); LOG(DEBUG) << "\t\t node v = " << tmpResult; tag.value = tmpResult; } else { continue; } tags.push_back(tag); } } string zone; if(convertToUtm) { UTM::LLtoUTM(lon, lat, x, y, zone); } else { x = lat; y = lon; } LOG(DEBUG) << "Pose = (" << x << ", " << y << ", " << z << ") in zone: " << zone; /* Add to RSG */ brics_3d::rsg::Id poseId; brics_3d::rsg::Id nodeId = id; vector<brics_3d::rsg::Attribute> poseAttributes; poseAttributes.push_back(brics_3d::rsg::Attribute(osmAttributePrefix + "tf","pose")); if(convertToUtm) { poseAttributes.push_back(brics_3d::rsg::Attribute("tf:type","utm")); poseAttributes.push_back(brics_3d::rsg::Attribute("tf:utm_zone", zone)); } else { poseAttributes.push_back(brics_3d::rsg::Attribute("tf:type","wgs84")); } brics_3d::HomogeneousMatrix44::IHomogeneousMatrix44Ptr poseOfNode(new brics_3d::HomogeneousMatrix44(1,0,0, 0,1,0, 0,0,1, x,y,z)); wmHandle->scene.addTransformNode(originId, poseId, poseAttributes, poseOfNode, time); output.push_back(poseId); wmHandle->scene.addNode(poseId, nodeId, tags, true); output.push_back(nodeId); nodeCounter++; } LOG(INFO) << "osmloader: " << nodeCounter <<" nodes loaded."; /* place the camera for the visualizer, based on the last loaded node */ brics_3d::rsg::Id camearaId; vector<brics_3d::rsg::Attribute> cameraAttributes; cameraAttributes.push_back(brics_3d::rsg::Attribute("osg:camera","home")); cameraAttributes.push_back(brics_3d::rsg::Attribute("tf:type","wgs84")); brics_3d::HomogeneousMatrix44::IHomogeneousMatrix44Ptr poseOfCamera(new brics_3d::HomogeneousMatrix44(1,0,0, 0,1,0, 0,0,1, x,y,z)); wmHandle->scene.addTransformNode(originId, camearaId, cameraAttributes, poseOfCamera, wmHandle->now()); //output.push_back(camearaId); /* osm ways */ /* e.g. * <way id="139281027"> * <nd ref="1526916568"/> * <nd ref="2280218902"/> * <nd ref="1526916486"/> * <tag k="highway" v="residential"/> * <tag k="maxspeed" v="30"/> * <tag k="name" v="Südstraße"/> * </way> */ DOMNodeList* wayNodes = doc->getElementsByTagName(wayName); for (int i = 0; i < wayNodes->getLength(); ++i) { unsigned int id = 0; current = wayNodes->item(i); attributesList = current->getAttributes(); attributeNode = attributesList->getNamedItem(idName); vector<brics_3d::rsg::Attribute> tags; vector<brics_3d::rsg::Id> nodeReferences; // id if (attributeNode != 0) { tmpResult = XMLString::transcode(attributeNode->getNodeValue()); LOG(DEBUG) << "way id = " << tmpResult; tags.push_back(brics_3d::rsg::Attribute(osmAttributePrefix+"way_id", tmpResult)); id = atoi(tmpResult.c_str()); } /* * check children for tags node references */ DOMNodeList* childs = current->getChildNodes(); for (int j = 0; j < childs->getLength(); ++j) { currentChild = childs->item(j); childAttributesList = currentChild->getAttributes(); tmpResult = XMLString::transcode(currentChild->getNodeName()); LOG(DEBUG) << "\t childName = " << tmpResult; if(tmpResult.compare("tag") == 0) { LOG(DEBUG) << "\t found a tag: "; brics_3d::rsg::Attribute tag; // k attributeNode = childAttributesList->getNamedItem(kName); if (attributeNode != 0) { tmpResult = XMLString::transcode(attributeNode->getNodeValue()); LOG(DEBUG) << "\t\t node k = " << tmpResult; tag.key = osmAttributePrefix+tmpResult; } else { continue; } // v attributeNode = childAttributesList->getNamedItem(vName); if (attributeNode != 0) { tmpResult = XMLString::transcode(attributeNode->getNodeValue()); LOG(DEBUG) << "\t\t node v = " << tmpResult; tag.value = tmpResult; } else { continue; } tags.push_back(tag); } else if (tmpResult.compare("nd") == 0) { LOG(DEBUG) << "\t found a reference: "; unsigned int tmpId; // ref attributeNode = childAttributesList->getNamedItem(refName); if (attributeNode != 0) { tmpResult = XMLString::transcode(attributeNode->getNodeValue()); LOG(DEBUG) << "\t\t node ref = " << tmpResult; tmpId = atoi(tmpResult.c_str()); } else { continue; } brics_3d::rsg::Id refId = tmpId; nodeReferences.push_back(refId); } } /* Add to RSG as Connection */ brics_3d::rsg::Id wayId = id; //TODO add mask vector<brics_3d::rsg::Id> emptyList; LOG(DEBUG) << "Adding Connection with ID " << id << ", containing " << nodeReferences.size() << " references."; wmHandle->scene.addConnection(originId, wayId, tags, emptyList, nodeReferences , wmHandle->now(), wmHandle-> now(), true); wayCounter++; /* Add a mesh as visualization of the connection, NOTE: this is static */ if(nodeReferences.size() >= 2) { brics_3d::rsg::Id currentNode = nodeReferences[1]; brics_3d::rsg::Id lastNode = nodeReferences[0]; brics_3d::HomogeneousMatrix44::IHomogeneousMatrix44Ptr resultTf(new brics_3d::HomogeneousMatrix44()); brics_3d::ITriangleMesh::ITriangleMeshPtr newMesh(new brics_3d::TriangleMeshExplicit()); brics_3d::rsg::Mesh<brics_3d::ITriangleMesh>::MeshPtr newMeshContainer(new brics_3d::rsg::Mesh<brics_3d::ITriangleMesh>()); newMeshContainer->data = newMesh; for (int i = 1; i < nodeReferences.size(); ++i) { currentNode = nodeReferences[i]; double x1, y1, x2, y2; if( wmHandle->scene.getTransformForNode(lastNode, originId, wmHandle->now(), resultTf)) { x1 = resultTf->getRawData()[brics_3d::matrixEntry::x]; y1 = resultTf->getRawData()[brics_3d::matrixEntry::y]; } else { continue; } if( wmHandle->scene.getTransformForNode(currentNode, originId, wmHandle->now(), resultTf)) { x2 = resultTf->getRawData()[brics_3d::matrixEntry::x]; y2 = resultTf->getRawData()[brics_3d::matrixEntry::y]; } else { continue; } lastNode = currentNode; LOG(DEBUG) << "Segment:" << x1 << ", " << y1 << ", " << x2 << ", " << y2; double yOffset = -0.1; //m if(!convertToUtm) { yOffset *= 0.000014; // delta in WGS 84 } newMesh->addTriangle(brics_3d::Point3D(x1,y1,0), brics_3d::Point3D(x1,y1+yOffset,0), brics_3d::Point3D(x2,y2,0) ); } LOG(DEBUG) << "Adding a mesh with " << newMesh->getSize() << " triangles to visualize a way."; brics_3d::rsg::Id meshId; vector<brics_3d::rsg::Attribute> meshAttributes; meshAttributes.push_back(brics_3d::rsg::Attribute("geo:crs","wgs84")); meshAttributes.push_back(brics_3d::rsg::Attribute("osm:dbg","way_mesh")); wmHandle->scene.addGeometricNode(originId, meshId, meshAttributes, newMeshContainer, wmHandle->now()); } } LOG(INFO) << "osmloader: " << wayCounter <<" ways loaded."; /* clean up xml dom */ XMLString::release(&nodeName); XMLString::release(&tagName); XMLString::release(&wayName ); XMLString::release(&kName); XMLString::release(&vName); XMLString::release(&idName); XMLString::release(&latName ); XMLString::release(&lonName); XMLString::release(& wayName); XMLString::release(&refName); XMLString::release(&versionName); /* push output to microblx */ ubx_port_t* outputPort = ubx_port_get(c, "outputDataIds"); rsg_ids toBeSendOutputDataIs; toBeSendOutputDataIs.numberOfIds = 0u; brics_3d::rsg::UbxTypecaster::convertIdsToUbx(output, toBeSendOutputDataIs); write_rsg_ids(outputPort, &toBeSendOutputDataIs); }
EppResponse * EppResponse::fromXML( const DOMNode& root ) { unsigned int i; EppResponse * rsp = null; DOMNode* response; bool found = false; DOMNodeList* list = root.getChildNodes(); for( i = 0; i < list->getLength(); i++ ) { DOMNode* node = list->item(i); DOMString name = node->getLocalName(); if( name.isNull() ) { name = node->getNodeName(); } if( name.isNull() ) { continue; } if( name.equals("response") ) { response = node; found = true; break; } } if( found == false ) { return null; } rsp = new EppResponse(); list = response->getChildNodes(); for( i = 0; i < list->getLength(); i++ ) { DOMNode* node = list->item(i); DOMString name = node->getLocalName(); if( name.isNull() ) { name = node->getNodeName(); } if( name.isNull() ) { continue; } if( name.equals("result") ) { EppResult * r = EppResult::fromXML(*node); if( r != null ) { rsp->result->addElement(r); } } else if( name.equals("msgQ") ) { DOMElement * elm = (DOMElement *) node; DOMString id = elm->getAttribute(XS("id")); if( id.isNotNull() && id.length() > 0 ) { rsp->msgId = id; } DOMString str = elm->getAttribute(XS("count")); if( str.isNotNull() && str.length() > 0 ) { char * p = str.transcode(); if( p != null ) { rsp->msgQCount = atoi(p); XercesString::Delete(p); } } DOMNodeList* qlist = node->getChildNodes(); for( unsigned int j = 0; j < qlist->getLength(); j++ ) { node = qlist->item(j); name = node->getLocalName(); if( name.isNull() ) { name = node->getNodeName(); } if( name.isNull() ) { continue; } if( name.equals("qDate") ) { rsp->msgQDate = EppUtil::getDate(*node); } else if( name.equals("msg") ) { rsp->msgQText = EppUtil::getText(*node); } } } else if( name.equals("resData") ) { if( rsp->resData == null ) { rsp->resData = EppResponseData::fromXML(*node); rsp->freeable = true; } } else if( name.equals("extension") ) { DOMNodeList* clist = node->getChildNodes(); for( unsigned int j = 0; j < clist->getLength(); j++ ) { DOMNode* cnode = clist->item(j); DOMString prefix = cnode->getPrefix(); DOMString cname = cnode->getLocalName(); if( cname.isNull() ) { cname = cnode->getNodeName(); } if( cname.isNull() ) { continue; } if( cname.equals("neulevel:extension") || ( (prefix.isNotNull()) && prefix.equals("neulevel") && (cname.isNotNull()) && cname.equals("extension") ) ) { EppUnspec * unspec = EppUnspec::fromXML(*cnode); if( unspec != null ) { rsp->addExtension(unspec); } } else if( cname.isNotNull() ) { EppExtension * ext = EppExtension::fromXML(*cnode); if( ext != null ) { rsp->addExtension(ext); } // else other extension } else { // other extensions } } } else if( name.equals("trID") ) { if( rsp->trID == null ) { rsp->trID = EppTransactionId::fromXML(*node); } } } return rsp; }
void CTibiaItem::refreshItemLists() { if (!criticalSectionInitialized) { InitializeCriticalSection(&ItemsInitCriticalSection); criticalSectionInitialized = true; } EnterCriticalSection(&ItemsInitCriticalSection); if (itemListsFresh) { LeaveCriticalSection(&ItemsInitCriticalSection); return; } itemListsFresh = 1; if (!xmlInitialised) { XMLPlatformUtils::Initialize(); xmlInitialised = 1; } XercesDOMParser *parser = new XercesDOMParser(); try { int listNr, itemNr, rootNr; //reset all lists constCodeList.RemoveAll(); foodList.RemoveAll(); lootList.RemoveAll(); itemList.RemoveAll(); if (itemTree) delete itemTree; itemTree = new CTibiaTree(new CTibiaTreeBranchData("Root")); char pathBuf[2048]; sprintf(pathBuf, "%s\\data\\tibiaauto-items.xml", CInstallPath::getInstallPath().c_str()); parser->parse(pathBuf); DOMNode *doc = parser->getDocument(); for (rootNr = 0; rootNr < (int)doc->getChildNodes()->getLength(); rootNr++) { DOMNode *root = doc->getChildNodes()->item(rootNr); if (wcscmp(root->getNodeName(), L"item-definitions")) continue; for (listNr = 0; listNr < (int)root->getChildNodes()->getLength(); listNr++) { DOMNode *listNode = root->getChildNodes()->item(listNr); //ITEMS if (!wcscmp(listNode->getNodeName(), L"items")) //recursively add to itemTree from XML tree, works with older versions parseItemsBranch(listNode, itemTree); //FOOD if (!wcscmp(listNode->getNodeName(), L"foods")) { for (itemNr = 0; itemNr < (int)listNode->getChildNodes()->getLength(); itemNr++) { int attrNr; DOMNode *item = listNode->getChildNodes()->item(itemNr); if (wcscmp(item->getNodeName(), L"item")) continue; int objectId = 0; int eatTime = 0; char *objectName = NULL; for (attrNr = 0; attrNr < (int)item->getAttributes()->getLength(); attrNr++) { DOMNode *attrNode = item->getAttributes()->item(attrNr); if (!wcscmp(attrNode->getNodeName(), L"name")) objectName = CUtil::wc2c(attrNode->getNodeValue()); if (!wcscmp(attrNode->getNodeName(), L"id")) { char *idTmp = CUtil::wc2c(attrNode->getNodeValue()); sscanf(idTmp, "0x%x", &objectId); if (objectId == 0) sscanf(idTmp, "%d", &objectId); free(idTmp); } if (!wcscmp(attrNode->getNodeName(), L"time")) { char *idTmp = CUtil::wc2c(attrNode->getNodeValue()); sscanf(idTmp, "%d", &eatTime); free(idTmp); } } if (!objectId || !objectName || !strlen(objectName)) { if (objectName) free(objectName); continue; } foodList.Add(objectId, objectName, eatTime); if (objectName) free(objectName); //delete item;//wis } } //CONSTS //SECTION IS UNUSED, FOR CURRENT TIBIA see next section for loading from const file if (!wcscmp(listNode->getNodeName(), L"consts")) { for (itemNr = 0; itemNr < (int)listNode->getChildNodes()->getLength(); itemNr++) { int attrNr; DOMNode *item = listNode->getChildNodes()->item(itemNr); if (wcscmp(item->getNodeName(), L"const")) continue; int constValue = 0; char *constCode = NULL; for (attrNr = 0; attrNr < (int)item->getAttributes()->getLength(); attrNr++) { DOMNode *attrNode = item->getAttributes()->item(attrNr); if (!wcscmp(attrNode->getNodeName(), L"code")) constCode = CUtil::wc2c(attrNode->getNodeValue()); if (!wcscmp(attrNode->getNodeName(), L"value")) { char *idTmp = CUtil::wc2c(attrNode->getNodeValue()); sscanf(idTmp, "0x%x", &constValue); if (constValue == 0) sscanf(idTmp, "%d", &constValue); free(idTmp); } } if (!constCode || !strlen(constCode)) { if (constCode) free(constCode); continue; } int i, len; len = strlen(constCode); for (i = 0; i < len; i++) constCode[i] = tolower(constCode[i]); constCodeList.Add(constValue, constCode, 0); if (constCode) free(constCode); //delete item;//wis } } //LOOT //SECTION IS UNUSED, FOR CURRENT TIBIA if (!wcscmp(listNode->getNodeName(), L"looted")) { for (itemNr = 0; itemNr < (int)listNode->getChildNodes()->getLength(); itemNr++) { int attrNr; DOMNode *item = listNode->getChildNodes()->item(itemNr); if (wcscmp(item->getNodeName(), L"item")) continue; int objectId = 0; char *objectName = NULL; for (attrNr = 0; attrNr < (int)item->getAttributes()->getLength(); attrNr++) { DOMNode *attrNode = item->getAttributes()->item(attrNr); if (!wcscmp(attrNode->getNodeName(), L"name")) objectName = CUtil::wc2c(attrNode->getNodeValue()); if (!wcscmp(attrNode->getNodeName(), L"id")) { char *idTmp = CUtil::wc2c(attrNode->getNodeValue()); sscanf(idTmp, "0x%x", &objectId); free(idTmp); } } if (!objectId || !objectName || !strlen(objectName)) { if (objectName) free(objectName); continue; } lootList.Add(objectId, objectName, 0); if (objectName) free(objectName); } } } } //Create data lists from tree structure loaded by XML traverseTreeForItemList(itemTree, &itemList); if (lootList.GetCount() == 0) traverseTreeForLootList(itemTree, &lootList); // get loot from tree if not loaded from file sprintf(pathBuf, "%s\\data\\tibiaauto-consts.xml", CInstallPath::getInstallPath().c_str()); OFSTRUCT lpOpen; if (OpenFile(pathBuf, &lpOpen, OF_EXIST) != HFILE_ERROR) { constCodeList.RemoveAll(); delete parser; parser = new XercesDOMParser(); parser->parse(pathBuf); doc = parser->getDocument(); for (rootNr = 0; rootNr < (int)doc->getChildNodes()->getLength(); rootNr++) { DOMNode *root = doc->getChildNodes()->item(rootNr); if (wcscmp(root->getNodeName(), L"const-definitions")) continue; for (listNr = 0; listNr < (int)root->getChildNodes()->getLength(); listNr++) { DOMNode *listNode = root->getChildNodes()->item(listNr); //CONSTS if (!wcscmp(listNode->getNodeName(), L"consts")) { for (itemNr = 0; itemNr < (int)listNode->getChildNodes()->getLength(); itemNr++) { int attrNr; DOMNode *item = listNode->getChildNodes()->item(itemNr); if (wcscmp(item->getNodeName(), L"const")) continue; int constValue = 0; char *constCode = NULL; for (attrNr = 0; attrNr < (int)item->getAttributes()->getLength(); attrNr++) { DOMNode *attrNode = item->getAttributes()->item(attrNr); if (!wcscmp(attrNode->getNodeName(), L"code")) constCode = CUtil::wc2c(attrNode->getNodeValue()); if (!wcscmp(attrNode->getNodeName(), L"value")) { char *idTmp = CUtil::wc2c(attrNode->getNodeValue()); sscanf(idTmp, "0x%x", &constValue); if (constValue == 0) sscanf(idTmp, "%d", &constValue); free(idTmp); } } if (!constCode || !strlen(constCode)) { if (constCode) free(constCode); continue; } int i, len; len = strlen(constCode); for (i = 0; i < len; i++) constCode[i] = tolower(constCode[i]); constCodeList.Add(constValue, constCode, 0); if (constCode) free(constCode); } } } } }//if file tibiaauto-consts.xml exists } catch (...) { AfxMessageBox("Unable to load const/item definitions!"); /* AfxMessageBox("Debug Item Tree"); char buf[11111]; itemTree->toString(buf); AfxMessageBox(buf); AfxMessageBox("Debug Food"); foodList.toString(buf); AfxMessageBox(buf); AfxMessageBox("Debug Consts"); constCodeList.toString(buf); AfxMessageBox(buf); */ } delete parser; LeaveCriticalSection(&ItemsInitCriticalSection); }
EppCommandCreateLaunchRegistration* EppCommandCreateLaunchRegistration::fromXML( const DOMNode& root ) { EppCommandCreateLaunchRegistration* cmd = new EppCommandCreateLaunchRegistration(); 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); } else if( (name.length() > 4) && name.substringData(0, 4).equals("smd:") ) { name = name.substringData(4, name.length() - 4); } if( name.equals("phase") ) { EppLaunchPhase *_pptr = EppLaunchPhase::fromXML(*node); if( null != _pptr ) { cmd->_phase = *_pptr; delete _pptr; } _pptr = null; } else if ( name.equals("notice") ) { DOMNodeList* noticeChildren = node->getChildNodes(); for( unsigned int j = 0; j < noticeChildren->getLength(); j++ ) { DOMNode* child = noticeChildren->item(j); DOMString chName = child->getLocalName(); if( chName.isNull() ) { chName = child->getNodeName(); } if( chName.isNull() ) { continue; } if( (chName.length() > 7) && chName.substringData(0, 7).equals("launch:") ) { chName = chName.substringData(7, chName.length() - 7); } if ( chName.equals("noticeID") ) { DOMString s = EppUtil::getText(*child); cmd->noticeID(s); } else if ( chName.equals("notAfter") ) { DOMString s = EppUtil::getText(*child); cmd->notAfter(s); } else if ( chName.equals("acceptedDate") ) { DOMString s = EppUtil::getText(*child); cmd->acceptedDate(s); } } } else if( name.equals("signedMark") ) { EppSignedMarkData *_nd = EppSignedMarkData::fromXML(*node); if( null != _nd ) { _nd->hasSMD(true); cmd->_signedMark = *_nd; delete _nd; } _nd = null; } else if( name.equals("encodedSignedMark") ) { EppEncodedSignedMarkData *_nd = EppEncodedSignedMarkData::fromXML(*node); if( null != _nd ) { _nd->hasSMD(true); cmd->_encSignedMark = *_nd; delete _nd; } _nd = null; } } for( unsigned int i = 0; i<attrs->getLength(); i++ ) { DOMNode* attr = attrs->item(i); DOMString _v = attr->getNodeValue(); if( XS(attr->getNodeName()).equals("type") ) { cmd->_type = attr->getNodeValue(); break; } } return cmd; }
/*=========================================================================+ 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: ; }
int main() { try { XMLPlatformUtils::Initialize(); } catch (const XMLException& toCatch) { char *pMessage = XMLString::transcode(toCatch.getMessage()); fprintf(stderr, "Error during XMLPlatformUtils::Initialize(). \n" " Message is: %s\n", pMessage); XMLString::release(&pMessage); return -1; } /* Range tests include testing of createRange setStart, setStartBefore. setStartAfter, setEnd, setEndBefore. setEndAfter getStartContainer, getStartOffset getEndContainer, getEndOffset getCommonAncestorContainer selectNode selectNodeContents insertNode deleteContents collapse getCollapsed surroundContents compareBoundaryPoints cloneRange cloneContents extractContents toString detach removeChild */ { XMLCh tempStr[100]; XMLString::transcode("Range",tempStr,99); { DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(tempStr); DOMDocument* doc = impl->createDocument(); //Creating a root element DOMElement* root = doc->createElement(xBody); doc->appendChild(root); //Creating the siblings of root DOMElement* E11 = doc->createElement(xH1); root->appendChild(E11); DOMElement* E12 = doc->createElement(xP); root->appendChild(E12); //Attaching texts to siblings DOMText* textNode1 = doc->createTextNode(xTitle); E11->appendChild(textNode1); DOMText* textNode11 = doc->createTextNode(xAnotherText); E11->appendChild(textNode11); DOMText* textNode2 = doc->createTextNode(xBlahxyz); E12->appendChild(textNode2); DOMText* E210 = doc->createTextNode(xInsertedText); doc->release(); } { //DOM Tree and some usable node creation DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(tempStr); DOMDocument* doc = impl->createDocument(); //Creating a root element DOMElement* root = doc->createElement(xBody); doc->appendChild(root); //Creating the siblings of root DOMElement* E11 = doc->createElement(xH1); root->appendChild(E11); DOMElement* E12 = doc->createElement(xP); root->appendChild(E12); //Attaching texts to siblings DOMText* textNode1 = doc->createTextNode(xTitle); E11->appendChild(textNode1); DOMText* textNode11 = doc->createTextNode(xAnotherText); E11->appendChild(textNode11); DOMText* textNode2 = doc->createTextNode(xBlahxyz); E12->appendChild(textNode2); //experimental nodes DOMElement* E120 = doc->createElement(xElement1); DOMElement* E121 = doc->createElement(xElement2); DOMElement* E122 = doc->createElement(xElement3); DOMElement* E311 = doc->createElement(xSurroundNode1); DOMText* E210 = doc->createTextNode(xInsertedText); DOMNode* rt = doc->getDocumentElement(); DOMRange* range = ((DOMDocumentRange*)doc)->createRange(); //Tests start here // Initial dom tree looks like : // <Body><H1>TitleAnother Text</H1><P>Blah xyz</P></Body> //i.e., Body(rt) // _____________|________________ // | | // ___H1(E11)___ P(E12) // | | | // "Title" "Another Text" "Blah xyz" //test for start and end settings of a range range->setStart(rt->getFirstChild(), 0); TASSERT(range->getStartContainer() == rt->getFirstChild() ); TASSERT(range->getStartOffset() == 0); range->setEnd(rt->getFirstChild(), 1); TASSERT(range->getEndContainer() == rt->getFirstChild() ); TASSERT(range->getEndOffset() == 1); //DOMNode* node = range->getCommonAncestorContainer(); TASSERT(range->getCommonAncestorContainer() == rt->getFirstChild()); //selection related test range->selectNode(rt->getLastChild()); TASSERT(range->getStartContainer() == rt); TASSERT(range->getStartOffset() == 1); TASSERT(range->getEndContainer() == rt); TASSERT(range->getEndOffset() == 2); //insertion related tests range->insertNode(E120); //only end offset moves and new node gets into range as being inserted at boundary point TASSERT(range->getStartContainer() == rt); TASSERT(range->getStartOffset() == 1); TASSERT(range->getEndContainer() == rt); TASSERT(range->getEndOffset() == 3); range->insertNode(E121); //only end offset moves and new node gets into range as being inserted at boundary point TASSERT(range->getStartContainer() == rt); TASSERT(range->getStartOffset() == 1); TASSERT(range->getEndContainer() == rt); TASSERT(range->getEndOffset() == 4); rt->insertBefore(E122, rt->getFirstChild()); //both offsets move as new node is not part of the range TASSERT(range->getStartContainer() == rt); TASSERT(range->getStartOffset() == 2); TASSERT(range->getEndContainer() == rt); TASSERT(range->getEndOffset() == 5); //After above operations, now the tree looks like: // <Body><Element3/><H1>TitleAnother Text</H1><Element2/><Element1/><P>Blah xyz</P></Body> //i.e., Body(rt) // _____________|_______________________________________________________________ // | | | | | // Element3(E122) ___H1(E11)___ Element2(E121) Element1(E120) P(E12) // | | | // "Title" "Another Text" "Blah xyz" // // range has rt as start and end container, and 2 as start offset, 5 as end offset //changing selection range->selectNode(rt->getLastChild()->getPreviousSibling()); TASSERT(range->getStartContainer() == rt); TASSERT(range->getStartOffset() == 3); TASSERT(range->getEndContainer() == rt); TASSERT(range->getEndOffset() == 4); //deleting related tests range->deleteContents(); TASSERT(rt->getLastChild()->getPreviousSibling() == E121); range->setStart(rt->getFirstChild()->getNextSibling()->getFirstChild(), 2); TASSERT(range->getStartContainer() == rt->getFirstChild()->getNextSibling()->getFirstChild()); TASSERT(!XMLString::compareString(range->getStartContainer()->getNodeValue(),xTitle)); TASSERT(range->getStartOffset() == 2); range->setEnd(rt->getFirstChild()->getNextSibling()->getFirstChild(), 4); TASSERT(range->getEndContainer() == rt->getFirstChild()->getNextSibling()->getFirstChild()); TASSERT(!XMLString::compareString(range->getEndContainer()->getNodeValue(),xTitle)); TASSERT(range->getEndOffset() == 4); TASSERT(!XMLString::compareString(range->toString(),xtl)); //inserting text between a text node range->insertNode(E210); //only end offset moves and new node gets into range as being inserted at boundary point TASSERT(range->getStartContainer() == rt->getFirstChild()->getNextSibling()->getFirstChild()); TASSERT(range->getStartOffset() == 2); TASSERT(range->getEndContainer() == rt->getFirstChild()->getNextSibling()->getLastChild()->getPreviousSibling()); TASSERT(range->getEndOffset() == 2); //inserting element node before the selected text node range->insertNode(E120); //only end offset moves and new node gets into range as being inserted at boundary point TASSERT(range->getStartContainer() == rt->getFirstChild()->getNextSibling()->getFirstChild()); TASSERT(!XMLString::compareString(range->getStartContainer()->getNodeValue(),xTi)); TASSERT(range->getStartOffset() == 2); TASSERT(range->getEndContainer() == rt->getFirstChild()->getNextSibling()->getLastChild()->getPreviousSibling()); TASSERT(!XMLString::compareString(range->getEndContainer()->getNodeValue(),xtle)); TASSERT(range->getEndOffset() == 2); TASSERT(E11->getChildNodes()->getLength()==6); //checking the text replacment range->getStartContainer()->setNodeValue(xReplacedText); //only the start offset is impact TASSERT(range->getStartContainer() == rt->getFirstChild()->getNextSibling()->getFirstChild()); TASSERT(!XMLString::compareString(range->getStartContainer()->getNodeValue(),xReplacedText)); TASSERT(range->getStartOffset() == 0); TASSERT(range->getEndContainer() == rt->getFirstChild()->getNextSibling()->getLastChild()->getPreviousSibling()); TASSERT(!XMLString::compareString(range->getEndContainer()->getNodeValue(),xtle)); TASSERT(range->getEndOffset() == 2); //After above operations, now the tree looks like: // <Body><Element3/><H1>ReplacedText<Element1/>InsertedTexttleAnother Text</H1><Element2/><P>Blah xyz</P></Body> //i.e., Body(rt) // _____________|_______________________________________________________________________________________________ // | | | | // Element3(E122) ___H1(E11)___________________________________________________________ Element2(E121) P(E12) // | | | | | | | // "ReplacedText" "" Element1(E120) "InsertedText"(E210) "tle" "Another Text" "Blah xyz" // // range has "ReplacedText" as start container and "tle" as end container // and 0 as start offset, 2 as end offset //changing the selection. Preparing for 'surround' range->setStart(range->getStartContainer()->getParentNode(), 2); range->setEnd(range->getStartContainer(), 5); TASSERT(!XMLString::compareString(range->getStartContainer()->getNodeName(),xH1)); TASSERT(!XMLString::compareString(range->getEndContainer()->getNodeName(),xH1)); TASSERT(!XMLString::compareString(range->toString(),xInsertedTexttle)); range->surroundContents(E311); TASSERT(!XMLString::compareString(range->getStartContainer()->getNodeName(),xH1)); TASSERT(range->getStartOffset() == 2); TASSERT(!XMLString::compareString(range->getEndContainer()->getNodeName(),xH1)); TASSERT(range->getEndOffset() == 3); TASSERT(E11->getChildNodes()->getLength()==4); TASSERT(E311->getChildNodes()->getLength()==3); TASSERT(!XMLString::compareString(range->toString(),xInsertedTexttle)); //After above operations, now the tree looks like: // <Body><Element3/><H1>ReplacedText<SurroundNode1><Element1/>InsertedTexttle</SurroundNode1>Another Text</H1><Element2/><P>Blah xyz</P></Body> //i.e., Body(rt) // _____________|_________________________________________________________________________ // | | | | // Element3(E122) ___H1(E11)___________________________________ Element2(E121) P(E12) // | | | | | // "ReplacedText" "" SurroundNode1(E311) "Another Text" "Blah xyz" // ____________ |_____________________________ // | | | // Element1(E120) "InsertedText"(E210) "tle" // // range has H1 as start and end container and 2 as start offset, 3 as end offset //testing cloning DOMRange* aRange = range->cloneRange(); TASSERT(aRange->getStartContainer() == range->getStartContainer()); TASSERT(aRange->getEndContainer() == range->getEndContainer()); TASSERT(aRange->getStartOffset() == 2); TASSERT(aRange->getEndOffset() == 3); //changing the new ranges start aRange->setStart(aRange->getStartContainer()->getFirstChild(), 1); //comparing the ranges short compVal = range->compareBoundaryPoints(DOMRange::END_TO_END, aRange); TASSERT(compVal == 0); compVal = range->compareBoundaryPoints(DOMRange::START_TO_START, aRange); TASSERT(compVal == 1); compVal = range->compareBoundaryPoints(DOMRange::START_TO_END, aRange); TASSERT(compVal == 1); compVal = range->compareBoundaryPoints(DOMRange::END_TO_START, aRange); TASSERT(compVal == -1); //testing collapse //not collapsed TASSERT(range->getCollapsed() == false); TASSERT(range->getStartOffset() == 2); TASSERT(range->getEndOffset() == 3); //selectNodeContents range->selectNodeContents(rt->getLastChild()->getFirstChild()); TASSERT(range->getStartContainer() == rt->getLastChild()->getFirstChild()); TASSERT(range->getEndContainer() == rt->getLastChild()->getFirstChild()); TASSERT(range->getStartOffset() == 0); TASSERT(range->getEndOffset() == 8); TASSERT(!XMLString::compareString(range->toString(),xBlahxyz)); //testing collapse range->collapse(true); //collapse to start TASSERT(range->getCollapsed() == true); TASSERT(range->getStartOffset() == 0); TASSERT(range->getEndOffset() == 0); TASSERT(!XMLString::compareString(range->toString(),XMLUni::fgZeroLenString)); TASSERT(aRange->getEndOffset() == 3); //other range is unaffected TASSERT(!XMLString::compareString(aRange->toString(),xeplacedTextInsertedTexttle)); //After above operations, now the tree looks like: // <Body><Element3/><H1>ReplacedText<SurroundNode1><Element1/>InsertedTexttle</SurroundNode1>Another Text</H1><Element2/><P>Blah xyz</P></Body> //i.e., Body(rt) // _____________|_________________________________________________________________________ // | | | | // Element3(E122) ___H1(E11)___________________________________ Element2(E121) P(E12) // | | | | | // "ReplacedText" "" SurroundNode1(E311) "Another Text" "Blah xyz" // ____________ |_____________________________ // | | | // Element1(E120) "InsertedText"(E210) "tle" // // range has "Blah xyz" as start and end container and 0 as start and end offset (collapsed) // aRange has "ReplacedText" as start container and H1 as end container // and 1 as start offset and 3 as end offset DOMDocumentFragment* docFrag = aRange->cloneContents(); TASSERT( docFrag != 0); range->selectNode(rt->getFirstChild()); TASSERT(range->getStartContainer() == rt); TASSERT(range->getEndContainer() == rt); TASSERT(range->getStartOffset() == 0); TASSERT(range->getEndOffset() == 1); //Testing toString() const XMLCh* str = aRange->toString(); TASSERT(!XMLString::compareString(str, xeplacedTextInsertedTexttle)); //start and end before and after tests range->setStartBefore(rt->getFirstChild()); TASSERT(range->getStartOffset() == 0); range->setEndBefore(rt->getFirstChild()); TASSERT(range->getEndOffset() == 0); range->setStartAfter(rt->getLastChild()); TASSERT(range->getStartOffset() == 4); range->setStartAfter(rt->getFirstChild()); TASSERT(range->getStartOffset() == 1); range->setEndBefore(rt->getLastChild()); TASSERT(range->getEndOffset() == 3); range->setEndAfter(rt->getLastChild()); TASSERT(range->getEndOffset() == 4); //testing extract() DOMDocumentFragment* frag2 = range->extractContents(); TASSERT( frag2 != 0); //After above operations, now the tree looks like: // <Body><Element3/></Body> //i.e., Body(rt) // | // Element3(E122) // // aRange has rt as start and end container, and 1 as start and end offset (collapsed) // range has rt as start and end container, and 1 as start and end offset (collapsed) // //and frag2 looks: // <Body>ReplacedText<SurroundNode1><Element1/>InsertedTexttle</SurroundNode1>Another Text</H1><Element2/><P>Blah xyz</P></Body> //i.e., Body(rt) // ______________|________________________________________________________ // | | | // ___H1(E11)___________________________________ Element2(E121) P(E12) // | | | | | //"ReplacedText" "" SurroundNode1(E311) "Another Text" "Blah xyz" // ____________ |_____________________________ // | | | // Element1(E120) "InsertedText"(E210) "tle" // //the tree do not have those node anymore after extract //only Element3 left TASSERT(rt->getChildNodes()->getLength()==1); //aRange is collapsed TASSERT(aRange->getCollapsed() == true); TASSERT(aRange->getStartContainer() == rt); TASSERT(aRange->getStartOffset() == 1); TASSERT(aRange->getEndContainer() == rt); TASSERT(aRange->getEndOffset() == 1); //range is collapsed as well TASSERT(range->getCollapsed() == true); TASSERT(range->getStartContainer() == rt); TASSERT(range->getStartOffset() == 1); TASSERT(range->getEndContainer() == rt); TASSERT(range->getEndOffset() == 1); //test the document fragment frag2 TASSERT(frag2->getChildNodes()->getLength()==3); //detaching the other range aRange->detach(); range->detach(); //*************************************************************** //another set of test //TEST createRange, setStart and setEnd, insertnode //*************************************************************** DOMImplementation* impl2 = DOMImplementationRegistry::getDOMImplementation(tempStr); DOMDocument* doc2 = impl2->createDocument(); DOMElement* root2 = doc2->createElement(xroot2); doc2->appendChild(root2); //case 1: simple text node, start==end // <body>text1</body> DOMElement* body = doc2->createElement(xBody); DOMText* text1 = doc2->createTextNode(xtext1); body->appendChild(text1); root2->appendChild(body); //set range DOMRange* range1 = doc2->createRange(); range1->setStart(text1,1); range1->setEnd(text1,3); TASSERT(!XMLString::compareString(range1->toString(),xex)); TASSERT(range1->getStartOffset()==1); TASSERT(!XMLString::compareString(range1->getStartContainer()->getNodeValue(),xtext1)); TASSERT(range1->getEndOffset()==3); TASSERT(!XMLString::compareString(range1->getEndContainer()->getNodeValue(),xtext1)); //now insert a text node //<body>ttext2ext1</body> DOMText* text2 = doc2->createTextNode(xtext2); range1->insertNode(text2); TASSERT(!XMLString::compareString(range1->toString(),xtext2ex)); TASSERT(range1->getStartOffset()==1); TASSERT(!XMLString::compareString(range1->getStartContainer()->getNodeValue(),xt)); TASSERT(range1->getEndOffset()==2); TASSERT(!XMLString::compareString(range1->getEndContainer()->getNodeValue(),xext1)); //now insert a non-text node //<body>t<p1/>text2ext1</body> DOMElement* p1 = doc2->createElement(xp1); range1->insertNode(p1); TASSERT(!XMLString::compareString(range1->toString(),xtext2ex)); TASSERT(range1->getStartOffset()==1); TASSERT(!XMLString::compareString(range1->getStartContainer()->getNodeValue(),xt)); TASSERT(range1->getEndOffset()==2); TASSERT(!XMLString::compareString(range1->getEndContainer()->getNodeValue(),xext1)); //case 2: non-text node, start==end // <head><h1/></head> DOMElement* head = doc2->createElement(xhead); DOMElement* h1 = doc2->createElement(xH1); head->appendChild(h1); root2->appendChild(head); //set range DOMRange* range2 = doc2->createRange(); range2->setStart(head,0); range2->setEnd(head,1); TASSERT(!XMLString::compareString(range2->toString(),XMLUni::fgZeroLenString)); TASSERT(range2->getStartOffset()==0); TASSERT(!XMLString::compareString(range2->getStartContainer()->getNodeName(),xhead)); TASSERT(range2->getEndOffset()==1); TASSERT(!XMLString::compareString(range2->getEndContainer()->getNodeName(),xhead)); //now insert a non-text node //<head><h2/><h1/></head> DOMElement* h2 = doc2->createElement(xh2); range2->insertNode(h2); TASSERT(!XMLString::compareString(range2->toString(),XMLUni::fgZeroLenString)); TASSERT(range2->getStartOffset()==0); TASSERT(!XMLString::compareString(range2->getStartContainer()->getNodeName(),xhead)); TASSERT(range2->getEndOffset()==2); TASSERT(!XMLString::compareString(range2->getEndContainer()->getNodeName(),xhead)); //now insert a text node //<head>text5<h2/><h1/></head> DOMText* text5 = doc2->createTextNode(xtext5); range2->insertNode(text5); TASSERT(!XMLString::compareString(range2->toString(),xtext5)); TASSERT(range2->getStartOffset()==0); TASSERT(!XMLString::compareString(range2->getStartContainer()->getNodeName(),xhead)); TASSERT(range2->getEndOffset()==3); TASSERT(!XMLString::compareString(range2->getEndContainer()->getNodeName(),xhead)); //case 3: simple text node, start!=end // <body2>text3</body2> DOMElement* body2 = doc2->createElement(xbody2); DOMText* text3 = doc2->createTextNode(xtext3); body2->appendChild(text3); root2->appendChild(body2); //set range DOMRange* range3 = ((DOMDocumentRange*)doc2)->createRange(); range3->setStart(text3,1); range3->setEnd(body2,1); TASSERT(!XMLString::compareString(range3->toString(),xext3)); TASSERT(range3->getStartOffset()==1); TASSERT(!XMLString::compareString(range3->getStartContainer()->getNodeValue(),xtext3)); TASSERT(range3->getEndOffset()==1); TASSERT(!XMLString::compareString(range3->getEndContainer()->getNodeName(),xbody2)); //now insert a textnode //<body2>ttext4ext3</body2> DOMText* text4 = doc2->createTextNode(xtext4); range3->insertNode(text4); TASSERT(!XMLString::compareString(range3->toString(),XMLUni::fgZeroLenString)); TASSERT(range3->getStartOffset()==1); TASSERT(!XMLString::compareString(range3->getStartContainer()->getNodeValue(),xt)); TASSERT(range3->getEndOffset()==1); TASSERT(!XMLString::compareString(range3->getEndContainer()->getNodeName(),xbody2)); //now insert a non-text node //<body2>t<p2/>text4ext3</body2> DOMElement* p2 = doc2->createElement(xp2); range3->insertNode(p2); //extra empty node caused by splitting 't' TASSERT(!XMLString::compareString(range3->toString(),XMLUni::fgZeroLenString)); TASSERT(range3->getStartOffset()==1); TASSERT(!XMLString::compareString(range3->getStartContainer()->getNodeValue(),xt)); TASSERT(range3->getEndOffset()==1); TASSERT(!XMLString::compareString(range3->getEndContainer()->getNodeName(),xbody2)); //test toString a bit range3->setStart(body2,1); range3->setEnd(body2,5); TASSERT(!XMLString::compareString(range3->toString(),xtext4ext3)); range3->setStart(body2,0); range3->setEnd(body2,5); TASSERT(!XMLString::compareString(range3->toString(),xttext4ext3)); //case 4: non-text node, start!=end // <head2><h3/></head2> DOMElement* head2 = doc2->createElement(xhead2); DOMElement* h3 = doc2->createElement(xh3); head2->appendChild(h3); root2->appendChild(head2); //set range DOMRange* range4 = doc2->createRange(); range4->setStart(head2,0); range4->setEnd(h3,0); TASSERT(!XMLString::compareString(range4->toString(),XMLUni::fgZeroLenString)); TASSERT(range4->getStartOffset()==0); TASSERT(!XMLString::compareString(range4->getStartContainer()->getNodeName(),xhead2)); TASSERT(range4->getEndOffset()==0); TASSERT(!XMLString::compareString(range4->getEndContainer()->getNodeName(),xh3)); //now insert a non-text node //<head2><h4/><h3/></head2> DOMElement* h4 = doc2->createElement(xh4); range4->insertNode(h4); TASSERT(!XMLString::compareString(range4->toString(),XMLUni::fgZeroLenString)); TASSERT(range4->getStartOffset()==0); TASSERT(!XMLString::compareString(range4->getStartContainer()->getNodeName(),xhead2)); TASSERT(range4->getEndOffset()==0); TASSERT(!XMLString::compareString(range4->getEndContainer()->getNodeName(),xh3)); //now insert a text node //<head2>text6<h4/><h3/></head2> DOMText* text6 = doc2->createTextNode(xtext6); range4->insertNode(text6); TASSERT(!XMLString::compareString(range4->toString(),xtext6)); TASSERT(range4->getStartOffset()==0); TASSERT(!XMLString::compareString(range4->getStartContainer()->getNodeName(),xhead2)); TASSERT(range4->getEndOffset()==0); TASSERT(!XMLString::compareString(range4->getEndContainer()->getNodeName(),xh3)); //*************************************************************** // quick test of updating //*************************************************************** // <upbody>text1</upbody> DOMElement* upbody = doc2->createElement(xupbody); DOMText* uptext1 = doc2->createTextNode(xuptext1); upbody->appendChild(uptext1); root2->appendChild(upbody); DOMRange* uprange = ((DOMDocumentRange*)doc2)->createRange(); uprange->setStart(upbody,0); uprange->setEnd(upbody,1); TASSERT(!XMLString::compareString(uprange->toString(),xuptext1)); TASSERT(uprange->getStartOffset()==0); TASSERT(!XMLString::compareString(uprange->getStartContainer()->getNodeName(),xupbody)); TASSERT(uprange->getEndOffset()==1); TASSERT(!XMLString::compareString(uprange->getEndContainer()->getNodeName(),xupbody)); // split text uptext1->splitText(1); TASSERT(!XMLString::compareString(uprange->toString(),xu)); TASSERT(uprange->getStartOffset()==0); TASSERT(!XMLString::compareString(uprange->getStartContainer()->getNodeName(),xupbody)); TASSERT(uprange->getEndOffset()==1); TASSERT(!XMLString::compareString(uprange->getEndContainer()->getNodeName(),xupbody)); //insert node DOMElement* upbody2 = doc2->createElement(xupbody2); DOMText* uptext2 = doc2->createTextNode(xuptext2); upbody2->appendChild(uptext2); root2->appendChild(upbody2); DOMRange* uprange2 = ((DOMDocumentRange*)doc2)->createRange(); uprange2->setStart(uptext2,1); uprange2->setEnd(upbody2,1); DOMRange* uprange3 = doc2->createRange(); uprange3->setStart(uptext2,1); uprange3->setEnd(upbody2,1); TASSERT(!XMLString::compareString(uprange2->toString(),xptext2)); TASSERT(uprange2->getStartOffset()==1); TASSERT(!XMLString::compareString(uprange2->getStartContainer()->getNodeValue(),xuptext2)); TASSERT(uprange2->getEndOffset()==1); TASSERT(!XMLString::compareString(uprange2->getEndContainer()->getNodeName(),xupbody2)); TASSERT(!XMLString::compareString(uprange3->toString(),xptext2)); TASSERT(uprange3->getStartOffset()==1); TASSERT(!XMLString::compareString(uprange3->getStartContainer()->getNodeValue(),xuptext2)); TASSERT(uprange3->getEndOffset()==1); TASSERT(!XMLString::compareString(uprange3->getEndContainer()->getNodeName(),xupbody2)); DOMElement* upp1 = doc2->createElement(xupp1); uprange2->insertNode(upp1); TASSERT(!XMLString::compareString(uprange2->toString(),XMLUni::fgZeroLenString)); TASSERT(uprange2->getStartOffset()==1); TASSERT(!XMLString::compareString(uprange2->getStartContainer()->getNodeValue(),xu)); TASSERT(uprange2->getEndOffset()==1); TASSERT(!XMLString::compareString(uprange2->getEndContainer()->getNodeName(),xupbody2)); TASSERT(!XMLString::compareString(uprange3->toString(),XMLUni::fgZeroLenString)); TASSERT(uprange3->getStartOffset()==1); TASSERT(!XMLString::compareString(uprange3->getStartContainer()->getNodeValue(),xu)); TASSERT(uprange3->getEndOffset()==1); TASSERT(!XMLString::compareString(uprange3->getEndContainer()->getNodeName(),xupbody2)); //*************************************************************** //another set of test //<foo><c/><moo><b/></moo>ab<a>Hello cd</a><cool>ef</cool></foo> // // ______________________foo_____________________ // | | | | | // c moo "ab" a cool // | | | // b "Hello cd" "ef" // DOMImplementation* impl3 = DOMImplementationRegistry::getDOMImplementation(tempStr); DOMDocument* doc3 = impl3->createDocument(); DOMElement* root3 = doc3->createElement(xroot); doc3->appendChild(root3); DOMElement* foo = doc3->createElement(xfoo); DOMElement* moo = doc3->createElement(xmoo); DOMElement* cool = doc3->createElement(xcool); DOMText* ab = doc3->createTextNode(xab); DOMText* cd = doc3->createTextNode(xHellocd); DOMText* ef = doc3->createTextNode(xef); DOMElement* a = doc3->createElement(xa); DOMElement* b = doc3->createElement(xb); DOMElement* c = doc3->createElement(xc); root3->appendChild(foo); foo->appendChild(c); foo->appendChild(moo); foo->appendChild(ab); foo->appendChild(a); foo->appendChild(cool); moo->appendChild(b); a->appendChild(cd); cool->appendChild(ef); //*************************************************************** //TEST toString //*************************************************************** DOMRange* newtestrange = ((DOMDocumentRange*)doc3)->createRange(); //case 1: //start container is text node // i) end container is also text node // a) start==end // b) start!=end // ii) end container is not text node // a) start==end => impossible // b) start!=end // //case 2: //start container is not text node // i) end container is text node // a) start==end => impossible // b) start!=end // ii) end container is not text node // a) start==end // b) start!=end //case 1, i, a newtestrange->setStart( cd, 1 ); newtestrange->setEnd( cd, 4 ); TASSERT(!XMLString::compareString(newtestrange->toString(),xell)); //case 1, i, b newtestrange->setStart( cd, 1 ); newtestrange->setEnd( ef, 2 ); TASSERT(!XMLString::compareString(newtestrange->toString(),xellocdef)); //case 1, ii, b newtestrange->setStart( cd, 1 ); newtestrange->setEnd( foo, 4 ); TASSERT(!XMLString::compareString(newtestrange->toString(),xellocd)); //case 2, i, b newtestrange->setStart( foo, 1 ); newtestrange->setEnd( cd, 5 ); TASSERT(!XMLString::compareString(newtestrange->toString(),xabHello)); //case 2, ii, a newtestrange->setStart( foo, 1 ); newtestrange->setEnd( foo, 4 ); TASSERT(!XMLString::compareString(newtestrange->toString(),xabHellocd)); //case 2, ii, b newtestrange->setStart( moo, 1 ); newtestrange->setEnd( foo, 4 ); TASSERT(!XMLString::compareString(newtestrange->toString(),xabHellocd)); //*************************************************************** //test removeChild //*************************************************************** DOMRange* newrange = doc3->createRange(); newrange->setStart( moo, 0 ); newrange->setEnd( foo, 4 ); TASSERT(newrange->getStartOffset()==0); TASSERT(!XMLString::compareString(newrange->getStartContainer()->getNodeName(),xmoo)); TASSERT(newrange->getEndOffset()==4); TASSERT(!XMLString::compareString(newrange->getEndContainer()->getNodeName(),xfoo)); TASSERT(!XMLString::compareString(newrange->toString(),xabHellocd)); DOMNode* n = newrange->cloneContents(); DOMNodeList* nol = foo->getChildNodes(); //removing moo DOMNode* rem = foo->removeChild(nol->item(1)); rem->release(); TASSERT(newrange->getStartOffset()==1); TASSERT(!XMLString::compareString(newrange->getStartContainer()->getNodeName(),xfoo)); TASSERT(newrange->getEndOffset()==3); TASSERT(!XMLString::compareString(newrange->getEndContainer()->getNodeName(),xfoo)); TASSERT(!XMLString::compareString(newrange->toString(),xabHellocd)); TASSERT(newtestrange->getStartOffset()==1); TASSERT(!XMLString::compareString(newtestrange->getStartContainer()->getNodeName(),xfoo)); TASSERT(newtestrange->getEndOffset()==3); TASSERT(!XMLString::compareString(newtestrange->getEndContainer()->getNodeName(),xfoo)); TASSERT(!XMLString::compareString(newtestrange->toString(),xabHellocd)); // Now do some exception test newrange->detach(); EXCEPTION_TEST(newrange->setStart( moo, 0 ), DOMException::INVALID_STATE_ERR); EXCEPTION_TEST(newtestrange->setStartBefore(moo), DOMRangeException::INVALID_NODE_TYPE_ERR); doc->release(); doc2->release(); doc3->release(); } } //creating the dom tree and tests // And call the termination method XMLPlatformUtils::Terminate(); if (errorOccurred) { printf("Test Failed\n"); return 4; } printf("Test Run Successfully\n"); return 0; };
list<ClsDataClientConfig> ClsDataClientConfigReader::getDataClientConfig(string strFileName) { #ifdef DEBUG_CLSDATACLIENTCONFIGREADER cout << "ClsDataClientConfigReader::getDataClientConfig()" << endl; #endif list<ClsDataClientConfig> lstConfigs; #ifdef DEBUG_CLSDATACLIENTCONFIGREADER cout << "reading settings from: " << strFileName << endl; #endif bool errorsOccured = false; static bool gDoNamespaces = false; if(!bXMLPlatformInitialized){ try { XMLPlatformUtils::Initialize(); } catch(const XMLException& toCatch) { cerr << "Error during Xerces-c Initialization.\n" << " Exception message:" << toCatch.getMessage() << endl; bXMLPlatformInitialized = false; errorsOccured = true; // return; } bXMLPlatformInitialized = true; errorsOccured = false; } //-------------------- if (!errorsOccured) { XercesDOMParser* parser = new XercesDOMParser(); parser->setValidationScheme(XercesDOMParser::Val_Never); /* XercesDOMParser::Val_Never; XercesDOMParser::Val_Auto; XercesDOMParser::Val_Always; */ parser->setDoNamespaces(gDoNamespaces); ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase(); parser->setErrorHandler(errHandler); try { parser->parse(strFileName.c_str()); int errorCount = parser->getErrorCount(); if (errorCount > 0){ errorsOccured = true; } } catch (const XMLException& e) { cerr << "An error occured during parsing (XMLException)\n NMessage: " << XMLString::transcode(e.getMessage()) << endl; ClsDataClientConfigReaderException clsDataClientConfigReaderException(XMLString::transcode(e.getMessage())); errorsOccured = true; throw clsDataClientConfigReaderException; } catch (const DOMException& e) { cerr << "An error occured during parsing (DOMException)\n DMessage: " << XMLString::transcode(e.msg) << endl; ClsDataClientConfigReaderException clsDataClientConfigReaderException(XMLString::transcode(e.msg)); errorsOccured = true; throw clsDataClientConfigReaderException; } catch (const SAXException& e) { cerr << "An error occured during parsing (SAXException)\n DMessage: " << XMLString::transcode(e.getMessage()) << endl; ClsDataClientConfigReaderException clsDataClientConfigReaderException(XMLString::transcode(e.getMessage())); errorsOccured = true; throw clsDataClientConfigReaderException; } catch (...) { cerr << "An error occured during parsing\n " << endl; errorsOccured = true; ClsDataClientConfigReaderException clsDataClientConfigReaderException(ClsDataClientConfigReaderException::PARSE_ERROR); throw clsDataClientConfigReaderException; } /* DOMNode* dnIqrConfig; */ DOMDocument *ddocConfig = parser->getDocument(); DOMNodeList* dnlstClients = ddocConfig->getElementsByTagName(XMLString::transcode(ConfigTagLibrary::DataClientTag())); try{ if(dnlstClients->getLength()>0){ DOMNode* dnValue = NULL; unsigned int ii = 0; while( ii< dnlstClients->getLength()){ DOMNode* dnClient = dnlstClients->item(ii); ii++; string strType = getAttributeValue(dnClient, ConfigTagLibrary::TypeTag(), true); string strID = getAttributeValue(dnClient, ConfigTagLibrary::IDTag(), false); ClsDataClientConfig clsDataClientConfig(strID, strType); DOMNodeList* dnlstClientChildren = dnClient->getChildNodes(); unsigned int i2 = 0; while( i2< dnlstClientChildren->getLength()){ DOMNode* dnClientChild = dnlstClientChildren->item(i2); if(dnClientChild->getNodeType() == 1){ string strName = XMLString::transcode(dnClientChild->getNodeName()); if(!strName.compare(ConfigTagLibrary::PositionTag())){ int iX = 0; int iY = 0; iX = iqrUtils::string2int(getAttributeValue(dnClientChild, ConfigTagLibrary::PositionXTag(), true)); iY = iqrUtils::string2int(getAttributeValue(dnClientChild, ConfigTagLibrary::PositionYTag(), true)); clsDataClientConfig.setPosition(iX, iY); } else if(!strName.compare(ConfigTagLibrary::Geometry())){ int iWidth = 0; int iHeight = 0; iWidth = iqrUtils::string2int(getAttributeValue(dnClientChild, ConfigTagLibrary::GeometryWidthTag(), true)); iHeight = iqrUtils::string2int(getAttributeValue(dnClientChild, ConfigTagLibrary::GeometryHeightTag(), true)); clsDataClientConfig.setGeometry(iWidth, iHeight); } else if(!strName.compare(ConfigTagLibrary::StateVariableDisplayTag())){ DOMNodeList* dnlstSVD = dnClientChild->getChildNodes(); unsigned int i3 = 0; while( i3< dnlstSVD->getLength()){ DOMNode* dnSVD = dnlstSVD->item(i3); if(dnSVD->getNodeType() == 1){ string strSVDID = getAttributeValue(dnSVD, ConfigTagLibrary::IDTag(), true); //-- string strItemType = getAttributeValue(dnSVD, ConfigTagLibrary::TypeTag(), true); string strItemID = getAttributeValue(dnSVD, ConfigTagLibrary::ItemIDTag(), true); string strSelectedIndices = getAttributeValue(dnSVD, ConfigTagLibrary::SelectedIndicesTag(), true); ClsStateVariableDisplayConfig clsStateVariableDisplayConfig(/*strItemType,*/ strSVDID, strItemID, strSelectedIndices); DOMNodeList* dnlstSVDParams = dnSVD->getChildNodes(); unsigned int i4 = 0; while( i4< dnlstSVDParams->getLength()){ DOMNode* dnSVDParam = dnlstSVDParams->item(i4); if(dnSVDParam->getNodeType() == 1){ string strParamName = XMLString::transcode(dnSVDParam->getNodeName()); dnValue = dnSVDParam->getFirstChild(); string strParamValue = ""; if(dnValue!=NULL){ strParamValue = XMLString::transcode(dnValue->getNodeValue()); } pair<string, string> pParam(strParamName, strParamValue); clsStateVariableDisplayConfig.addParameter(pParam); } i4++; } clsDataClientConfig.addStateVariableDisplayConfig(clsStateVariableDisplayConfig); } i3++; } } else { string strValue = ""; dnValue = dnClientChild->getFirstChild(); if(dnValue!=NULL){ strValue = XMLString::transcode(dnValue->getNodeValue()); } pair<string, string> pParam(strName, strValue); clsDataClientConfig.addParameter(pParam); } } i2++; } lstConfigs.push_back(clsDataClientConfig); } } } catch (...) { ClsDataClientConfigReaderException clsDataClientConfigReaderException(ClsDataClientConfigReaderException::PARSE_ERROR); throw clsDataClientConfigReaderException; } delete errHandler; } return lstConfigs; };