Esempio n. 1
0
void gdipp_setting::load_gdimm_process(const xpath_node_set &process_nodes)
{
	// backward iterate so that first-coming process settings overwrites last-coming ones

	xpath_node_set::const_iterator node_iter = process_nodes.end();
	node_iter--;

	for (size_t i = 0; i < process_nodes.size(); i++, node_iter--)
	{
		// only store the setting items which match the current process name

		const xml_node curr_proc = node_iter->node();
		const xml_attribute name_attr = curr_proc.attribute(L"name");

		bool process_matched = name_attr.empty();
		if (!process_matched)
		{
			const wregex name_ex(name_attr.value(), regex_flags);
			process_matched = regex_match(_process_name, name_ex);
		}

		if (process_matched)
		{
			for (xml_node::iterator set_iter = node_iter->node().begin(); set_iter != node_iter->node().end(); set_iter++)
				parse_gdimm_setting_node(*set_iter, _process_setting);
		}
	}
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
void gdipp_setting::load_gdimm_font(const xpath_node_set &font_node)
{
	for (xpath_node_set::const_iterator node_iter = font_node.begin(); node_iter != font_node.end(); node_iter++)
	{
		setting_map curr_settings;

		for (xml_node::iterator set_iter = node_iter->node().begin(); set_iter != node_iter->node().end(); set_iter++)
			parse_gdimm_setting_node(*set_iter, curr_settings);

		const xml_node curr_font = node_iter->node();
		const xml_attribute name_attr = curr_font.attribute(L"name");
		const xml_attribute bold_attr = curr_font.attribute(L"bold");
		const xml_attribute italic_attr = curr_font.attribute(L"italic");
		const xml_attribute max_height_attr = curr_font.attribute(L"max_height");

		// negative indicates such optional attribute is not specified
		const gdimm_font_node new_font = {(name_attr.empty() ? wstring() : name_attr.value()),
			(bold_attr.empty() ? -1 : bold_attr.as_uint()),
			(italic_attr.empty() ? -1 : italic_attr.as_uint()),
			(max_height_attr.empty() ? -1 : max_height_attr.as_uint()),
			curr_settings};
		_gdimm_font.push_back(new_font);
	}
}
Esempio n. 4
0
/// @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();
}