示例#1
0
void
docTree::repaint( const pugi::xml_document& doc )
{
    QStandardItemModel& model = *model_;

    std::string xml;
    doc_->save( xml );

    model.clear();
    model.setColumnCount( 2 );

    if ( const pugi::xpath_node node = doc.select_single_node( "/article|/book" ) ) {
        try {
            detail::model_writer writer( *model_ );
            writer( node, QModelIndex() );
            expandAll();
        }
        catch ( pugi::xpath_exception& ex ) {
            QMessageBox::warning( this, "adpublisher::docTree", ex.what() );
        }
    }
    else if ( const pugi::xpath_node node = doc.select_single_node( "/qtplatz_document" ) ) {
        try {
            detail::model_writer writer( *model_ );
            writer( node, QModelIndex() );
            expandAll();
        }
        catch ( pugi::xpath_exception& ex ) {
            QMessageBox::warning( this, "adpublisher::docTree", ex.what() );
        }
    }

}
示例#2
0
void
docEdit::repaint( const pugi::xml_document& doc )
{
    if ( const pugi::xpath_node node = doc.select_single_node( "/article|/book" ) ) {
        try {
            detail::text_writer writer( *this );
            writer( node );
            auto cursor = textCursor();
            cursor.movePosition( QTextCursor::Start );
            ensureCursorVisible();
        } catch ( pugi::xpath_exception& ex ) {
            QMessageBox::warning( this, "adpublisher::docEdit", ex.what() );
        }
    }
    else if ( const pugi::xpath_node node = doc.select_single_node( "/qtplatz_document" ) ) {
        // do nothing
    }
    else {
        try {
            detail::xhtml_writer writer( *this );
            writer( doc.select_single_node( "/" ) );
            auto cursor = textCursor();
            cursor.movePosition( QTextCursor::Start );
            ensureCursorVisible();
        }
        catch ( pugi::xpath_exception& ex ) {
            QMessageBox::warning( this, "adpublisher::docEdit", ex.what() );
        }
    }
}
示例#3
0
int InitConfig(pugi::xml_document& config) {
	//check folders, create in dont exist
	wstring appDataPath = AppPath();

	wstring logPath;
	wstring rawCurrentPath;
	wstring logDailyPath;
	//config
	wstring configFile = appDataPath + L"\\etc\\sdr.xml";
	//because service runs at windows/System32 folder
	//we forced to use absolute path

	pugi::xml_parse_result result = config.load_file(configFile.data());
	if (result.status != pugi::status_ok) {
		return status_config_file_not_found;
	}
	//first install build directory tree

	logPath = L"\\log";
	rawCurrentPath = logPath + L"\\current\\";
	logDailyPath = logPath + L"\\daily\\";

	config.select_single_node(L"/sdr/recording/logs/base").node().attribute(
			L"path").set_value(logPath.data());
	config.select_single_node(L"/sdr/recording/logs/current").node().attribute(
			L"path").set_value(rawCurrentPath.data());
	config.select_single_node(L"/sdr/recording/logs/daily").node().attribute(
			L"path").set_value(logDailyPath.data());

	config.save_file(configFile.data());

	logPath = appDataPath + logPath;
	rawCurrentPath = appDataPath + rawCurrentPath;
	logDailyPath = appDataPath + logDailyPath;

	//create config folderst
	CreateDirectory(logPath.data(), 0);
	if (GetLastError() == ERROR_PATH_NOT_FOUND)
		return status_path_not_found;
	CreateDirectory(rawCurrentPath.data(), 0);
	if (GetLastError() == ERROR_PATH_NOT_FOUND)
		return status_path_not_found;
	CreateDirectory(logDailyPath.data(), 0);
	if (GetLastError() == ERROR_PATH_NOT_FOUND)
		return status_path_not_found;

	return status_ok;
}
示例#4
0
pugi::xml_node appendValue(pugi::xml_document & doc, string tag, string attribute, string newValue, bool overwriteMultiple){

    if (overwriteMultiple == true){
        // find the existing node...
        char xpathExpression[1024];
        sprintf(xpathExpression, "//%s[@%s='%s']", tag.c_str(), attribute.c_str(), newValue.c_str());
        pugi::xpath_node node = doc.select_single_node(xpathExpression);
        if(string(node.node().attribute(attribute.c_str()).value()).size() > 0){ // for some reason we get nulls here?
            // ...delete the existing node
            cout << "DELETING: " << node.node().name() << ": " << " " << node.node().attribute(attribute.c_str()).value() << endl;
            node.node().parent().remove_child(node.node());
        }
    }

    if (!doesTagAndAttributeExist(doc, tag, attribute, newValue)){
        // otherwise, add it please:
        char xpathExpression[1024];
        sprintf(xpathExpression, "//%s[@%s]", tag.c_str(), attribute.c_str());
        //cout << xpathExpression << endl;
        pugi::xpath_node_set add = doc.select_nodes(xpathExpression);
        pugi::xml_node node = add[add.size()-1].node();
        pugi::xml_node nodeAdded = node.parent().append_copy(node);
        nodeAdded.attribute(attribute.c_str()).set_value(newValue.c_str());
        return nodeAdded;
    }else{
    	return pugi::xml_node();
    }

}
void shader_configuration::serialize_xml(pugi::xml_document& document, const std::string& path)
{
pugi::xpath_node node;
node = document.select_single_node((path + "/shader").c_str());
std::string filename = node.node().attribute("filename").as_string();
configuration::set_attribute("/shader/filename", std::make_shared<configuration_attribute>(filename));
}
	bool FontExportSerializer::deserialization(pugi::xml_document& _doc)
	{
		if (_doc.select_single_node("MyGUI[@type=\"Resource\"]").node().empty())
			return false;

		pugi::xpath_node_set nodes = _doc.select_nodes("MyGUI/Resource[@type=\"ResourceTrueTypeFont\"]");
		for (pugi::xpath_node_set::const_iterator node = nodes.begin(); node != nodes.end(); node ++)
			parseFont((*node).node());

		return true;
	}
示例#7
0
	bool ImageExportSerializer::deserialization(pugi::xml_document& _doc)
	{
		if (_doc.select_single_node("MyGUI[@type=\"Resource\"]").node().empty())
			return false;

		pugi::xpath_node_set nodes = _doc.select_nodes("MyGUI/Resource[@type=\"ResourceImageSet\"]");
		for (pugi::xpath_node_set::const_iterator node = nodes.begin(); node != nodes.end(); node ++)
			parseImage((*node).node());

		updateImageProperty(DataManager::getInstance().getRoot());
		return true;
	}
示例#8
0
文件: Engine.cpp 项目: Mokon/mfit
  std::string Engine::getNode( const pugi::xml_document& cfg,
      const std::string xpath ) {
    const pugi::xpath_node xpnode = cfg.select_single_node(xpath.c_str()) ;

    DLOG(INFO) << xpath << " " <<  xpnode.node().name() << " "
      << xpnode.node().last_child().value() << std::endl ;

    std::string ret(xpnode.node().last_child().value());
    if( ret.size( ) == 0 ) {
      throw StatMissingException( "xpath [" + xpath + "] returns no value." ) ;
    }
    return ret ;
  }
示例#9
0
void Column::init(const pugi::xml_document &doc, const std::string &alias, bool aggregate) throw(std::invalid_argument)
{
	this->format = NULL;
	this->parse = NULL;

	/* search xml for an alias */
	pugi::xpath_node column = doc.select_single_node(("/configuration/columns/column[alias='"+alias+"']").c_str());
	/* check what we found */
	if (column == NULL) {
		throw std::invalid_argument(std::string("Column '") + alias + "' not defined");
	}

	/* set default value */
	if (column.node().child("default-value") != NULL) {
		this->nullStr = column.node().child_value("default-value");
	}

	this->setName(column.node().child_value("name"));
	this->setAggregation(aggregate);

#ifdef DEBUG
	std::cerr << "Creating column '" << this->name << "'" << std::endl;
#endif

	/* set alignment */
	if (column.node().child("alignLeft") != NULL) {
		this->setAlignLeft(true);
	}

	/* set width */
	if (column.node().child("width") != NULL) {
		this->setWidth(atoi(column.node().child_value("width")));
	}

	/* set value according to type */
	if (column.node().child("value").attribute("type").value() == std::string("plain")) {
		/* simple element */
		this->setAST(createValueElement(column.node().child("value").child("element"), doc));
	} else if (column.node().child("value").attribute("type").value() == std::string("operation")) {
		/* operation */
		this->setAST(createOperationElement(column.node().child("value").child("operation"), doc));
	}

	/* add aliases from XML to column (with starting %) */
	pugi::xpath_node_set aliases = column.node().select_nodes("alias");
	for (pugi::xpath_node_set::const_iterator it = aliases.begin(); it != aliases.end(); ++it) {
		this->addAlias(it->node().child_value());
	}

	/* element is name of the file, which contains actual data for this column */
	if (column.node().child("value").child("element") != 0) {
		this->element = column.node().child("value").child_value("element");
	}

	/* check whether this is a summary column */
	pugi::xpath_node_set sumColumns = doc.select_nodes("/configuration/summary/column");
	for (stringSet::const_iterator it = this->aliases.begin(); it != this->aliases.end(); it++) {
		for (pugi::xpath_node_set::const_iterator i = sumColumns.begin(); i != sumColumns.end(); ++i) {
			if (*it == i->node().child_value()) {
				this->summary = true;
			
				if (!i->node().attribute("type")) {
					throw std::invalid_argument("Summary column '" + alias + "' without specified summary type!");
				}

				this->summaryType = i->node().attribute("type").value();
			}
		}
	}
	
	/* set alias for select clause */
	if (this->getSemantics() == "flows") {
		this->selectName = "flows";
	} else if (this->isOperation()) {
		this->selectName = alias.substr(1);
	} else {
		this->selectName = this->element;
	}
}