QDomNode QDomDocumentProto::cloneNode(bool deep) const { QDomDocument *item = qscriptvalue_cast<QDomDocument*>(thisObject()); if (item) return item->cloneNode(deep); return QDomNode(); }
void writeGetCapabilities( QgsServerInterface* serverIface, const QString& version, const QgsServerRequest& request, QgsServerResponse& response, bool projectSettings ) { QgsServerRequest::Parameters params = request.parameters(); QString configFilePath = serverIface->configFilePath(); QgsServerSettings* serverSettings = serverIface->serverSettings(); QgsAccessControl* accessControl = serverIface->accessControls(); QgsCapabilitiesCache* capabilitiesCache = serverIface->capabilitiesCache(); QStringList cacheKeyList; cacheKeyList << ( projectSettings ? QStringLiteral( "projectSettings" ) : version ); cacheKeyList << getenv( "SERVER_NAME" ); bool cache = true; if ( accessControl ) cache = accessControl->fillCacheKey( cacheKeyList ); QString cacheKey = cacheKeyList.join( QStringLiteral( "-" ) ); const QDomDocument* capabilitiesDocument = capabilitiesCache->searchCapabilitiesDocument( configFilePath, cacheKey ); if ( !capabilitiesDocument ) //capabilities xml not in cache. Create a new one { QgsMessageLog::logMessage( QStringLiteral( "Capabilities document not found in cache" ) ); QDomDocument doc; QgsWmsServer server( configFilePath, *serverSettings, params, getConfigParser( serverIface ), accessControl ); doc = server.getCapabilities( version, projectSettings ); if ( cache ) { capabilitiesCache->insertCapabilitiesDocument( configFilePath, cacheKey, &doc ); capabilitiesDocument = capabilitiesCache->searchCapabilitiesDocument( configFilePath, cacheKey ); } else { doc = doc.cloneNode().toDocument(); capabilitiesDocument = &doc; } } else { QgsMessageLog::logMessage( QStringLiteral( "Found capabilities document in cache" ) ); } response.setHeader( QStringLiteral( "Content-Type" ), QStringLiteral( "text/xml; charset=utf-8" ) ); response.write( capabilitiesDocument->toByteArray() ); }
void writeGetCapabilities( QgsServerInterface* serverIface, const QString& version, const QgsServerRequest& request, QgsServerResponse& response, bool projectSettings ) { QString configFilePath = serverIface->configFilePath(); QgsCapabilitiesCache* capabilitiesCache = serverIface->capabilitiesCache(); QStringList cacheKeyList; cacheKeyList << ( projectSettings ? QStringLiteral( "projectSettings" ) : version ); cacheKeyList << request.url().host(); bool cache = true; #ifdef HAVE_SERVER_PYTHON_PLUGINS QgsAccessControl* accessControl = serverIface->accessControls(); if ( accessControl ) cache = accessControl->fillCacheKey( cacheKeyList ); #endif QString cacheKey = cacheKeyList.join( QStringLiteral( "-" ) ); const QDomDocument* capabilitiesDocument = capabilitiesCache->searchCapabilitiesDocument( configFilePath, cacheKey ); if ( !capabilitiesDocument ) //capabilities xml not in cache. Create a new one { QgsMessageLog::logMessage( QStringLiteral( "Capabilities document not found in cache" ) ); QDomDocument doc; doc = getCapabilities( serverIface, version, request, projectSettings ); if ( cache ) { capabilitiesCache->insertCapabilitiesDocument( configFilePath, cacheKey, &doc ); capabilitiesDocument = capabilitiesCache->searchCapabilitiesDocument( configFilePath, cacheKey ); } else { doc = doc.cloneNode().toDocument(); capabilitiesDocument = &doc; } } else { QgsMessageLog::logMessage( QStringLiteral( "Found capabilities document in cache" ) ); } response.setHeader( QStringLiteral( "Content-Type" ), QStringLiteral( "text/xml; charset=utf-8" ) ); response.write( capabilitiesDocument->toByteArray() ); }
QString qDomDocumentToString(const QDomDocument &pDomDocument) { // Serialise the given DOM document // Note: normally, we would simply be using QDomDocument::save(), but we // want elements' attributes to be sorted when serialised (so that it // is easier to compare two different XML documents). Unfortunately, // QDomDocument::save() doesn't provide such a functionality (since // the order of attributes doesn't matter in XML). So, we make a call // to QDomDocument::save(), but only after having removed all the // elements' attributes, which we serialise manually afterwards... QString res = QString(); // Make a deep copy of the given DOM document and remove all the elements' // attributes (but keep track of them, so that we can later on serialise // them manually) QDomDocument domDocument = pDomDocument.cloneNode().toDocument(); QMap<QString, QString> elementsAttributes = QMap<QString, QString>(); for (QDomElement childElement = domDocument.firstChildElement(); !childElement.isNull(); childElement = childElement.nextSiblingElement()) { cleanDomElement(childElement, elementsAttributes); } // Serialise our 'reduced' DOM document QTextStream textStream(&res, QIODevice::WriteOnly); domDocument.save(textStream, 4); // Manually serialise the elements' attributes foreach (const QString &elementAttribute, elementsAttributes.keys()) res.replace(elementAttribute+"=\"\"", elementsAttributes.value(elementAttribute)); return res; }
/** * Constructs stanza from a DOM document. Constructor makes a deep copy of QDomDocument. * * @param document DOM document */ Stanza::Stanza(const QDomDocument& document) { m_doc = document.cloneNode(true).toDocument(); }
// if no file is open void MainWindow::openFile(QString &xmlFileName, QFile &xmlFile, QDomDocument &xmlDomDocument, QDomDocument &xmlDomDocumentOrg, bool createFile) { QString filename; // open file diaglog if(createFile == OPEN_EXISTING_FILE){ // Open diaglog to -- open existing file filename = QFileDialog::getOpenFileName(this, tr("Open File"), "", tr("Files (*.xml)")); } else{ // Open diaglog to -- create new file filename = QFileDialog::getSaveFileName(this, tr("Save File"), "", tr("Files (*.xml)")); } // Check if cancel button is pressed in the QFileDialog if(filename != "") { //copy file name to globalobject xmlFileName = filename; // create new xml file & text stream //xmlOpenFile(); // Add a delay xmlLibObject.xmlOpenFile( xmlFileName, xmlFile, xmlStream); if(createFile == OPEN_EXISTING_FILE){ //Load the XML file //xmlLoadFile(); xmlLibObject.xmlLoadFile(xmlDomDocument, xmlFile); //close file //xmlCloseFile(); //xmlLibObject.xmlCloseFile(xmlStream, xmlDomDocument, xmlFile); //Now again open & truncate the file //xmlOpenFileTruncate(); //xmlLibObject.xmlOpenFileTruncate( xmlFileName, xmlFile, xmlStream); //Get the root element //xmlGetRoot(); xmlLibObject.xmlGetRoot(xmlRoot, xmlDomDocument); // copy data to the tree view // copy data to the text view loadXmltoTreeAndTextView(); //Its not new file b_newFileCreationSignal = FALSE; //create backup for original xml. xmlDomDocumentOrg.clear(); xmlDomDocumentOrg = xmlDomDocument.cloneNode(true).toDocument(); } else{ //Add root node //xmlAddRoot(); xmlLibObject.xmlAddRoot(xmlRoot, xmlDomDocument); // File contains new node b_fileDoesNotContainsNode = TRUE; //New file creation signal b_newFileCreationSignal = TRUE; //New file created xmlDomDocumentOrg.clear(); } // xml file is already open b_xmlFileAlreadyOpen = TRUE; } else { // Do nothing cancel presses } }