BOOL gdipp_setting::load_setting(const wchar_t *setting_path) { if (!_xml_doc->load_file(as_utf8(setting_path).c_str())) return FALSE; const xpath_node_set proc_list = _xml_doc->select_nodes(L"/gdipp/gdimm/process"); if (!proc_list.empty()) load_gdimm_process(proc_list); const xpath_node_set font_list = _xml_doc->select_nodes(L"/gdipp/gdimm/font"); if (!font_list.empty()) load_gdimm_font(font_list); const xml_node demo_node = _xml_doc->select_single_node(L"/gdipp/demo").node(); if (!demo_node.empty()) load_demo(demo_node); const xml_node exclude_node = _xml_doc->select_single_node(L"/gdipp/exclude").node(); if (!exclude_node.empty()) load_exclude(exclude_node); return TRUE; }
/// @brief Creates an IDoc file based on an XML template and returns it as a string /// @param a string containing the IDoc's XML template /// @return a string containing a new flat-text IDoc IDOCREPLAYDLL_API LPCSTR idoc_create_direct(const LPCSTR idocXml) { if (idocXml == NULL) { lr_error_message("[%s] IDoc XML cannot be NULL.", __FUNCTION__); return FALSE; } if (!ensure_valid_license()) { return NULL; } const LPCSTR idocXmlPartiallyProcessed = idoc_eval_string(idocXml); const char* idocXmlProcessed = lr_eval_string(idocXmlPartiallyProcessed); const char* idocXmlFinal = idocXmlProcessed == NULL ? idocXmlPartiallyProcessed : idocXmlProcessed; xml_document doc; doc.load(idocXmlFinal); if (doc.empty()) { lr_error_message("[%s] The specified IDoc XML document is empty.", __FUNCTION__); return NULL; } const xpath_node_set segmentNodeSet = doc.root().select_nodes("//IDOC/*[@SEGMENT='1']"); if (segmentNodeSet.empty()) { lr_error_message("[%s] The specified IDoc XML is not a valid IDoc.", __FUNCTION__); return NULL; } stringstream resultStream; for (xpath_node_set::const_iterator segmentIterator = segmentNodeSet.begin(); segmentIterator != segmentNodeSet.end(); ++segmentIterator) { const xml_node segmentNode = segmentIterator->node(); const xpath_node_set fieldNodeSet = segmentNode.select_nodes("./*"); if (fieldNodeSet.empty()) { lr_error_message( "[%s] The specified IDoc XML contains segment '%s' without fields.", __FUNCTION__, segmentNode.name()); return NULL; } for (xpath_node_set::const_iterator fieldIterator = fieldNodeSet.begin(); fieldIterator != fieldNodeSet.end(); ++fieldIterator) { static const unsigned int InvalidLength = 0xFFFFFFFF; const xml_node fieldNode = fieldIterator->node(); const unsigned int length = fieldNode.attribute("length").as_uint(InvalidLength); if (length == InvalidLength) { lr_error_message( "[%s]: The specified IDoc XML contains field '%s:%s' without length or with invalid one.", __FUNCTION__, segmentNode.name(), fieldNode.name()); return NULL; } string fieldText(fieldNode.text().as_string()); if (fieldText.length() > length) { lr_error_message( "[%s] The specified IDoc XML contains field '%s:%s' which actual length (%u) is greater" " than declared (%u).", __FUNCTION__, segmentNode.name(), fieldNode.name(), fieldText.length(), length); return NULL; } const size_t padCount = length - fieldText.length(); if (padCount > 0) { fieldText.append(padCount, ' '); } resultStream << fieldText; } resultStream << endl; } g_allocatedStrings.push_back(resultStream.str()); const string& resultingDocument = g_allocatedStrings.back(); return resultingDocument.c_str(); }