void MgResourceDefinitionManager::ValidateDocument(XmlDocument& xmlDoc) { MG_RESOURCE_SERVICE_TRY() MgResourceIdentifier resource(MgUtil::MultiByteToWideChar(xmlDoc.getName())); // Skip XML schema validation on runtime resources. if (!resource.IsRuntimeResource()) { std::string xmlContent; MgXmlUtil xmlUtil(xmlDoc.getContent(xmlContent)); DOMElement* rootNode = xmlUtil.GetRootNode(); if(NULL != rootNode) { assert(NULL != rootNode); STRING rootName; const XMLCh* tag = rootNode->getTagName(); if (NULL != tag) { rootName = X2W(tag); assert(!rootName.empty()); } STRING schemaName; const XMLCh* attr = rootNode->getAttribute(X("xsi:noNamespaceSchemaLocation")); if (NULL != attr) { schemaName = X2W(attr); } ValidateDocument(resource, rootName, schemaName); } } MG_RESOURCE_CONTAINER_CATCH_AND_THROW(L"MgResourceDefinitionManager.ValidateDocument") }
void doContextQuery( XmlTransaction &txn, XmlManager &mgr, const std::string cname, const std::string &query, XmlQueryContext &context ) { //////////////////////////////////////////////////////////////////////// ////// Performs a simple query (with context) against the /////// ////// provided container. /////// //////////////////////////////////////////////////////////////////////// ///// some defensive code eliminated for clarity // // Perform the query. Result type is by default Result Document std::string fullQuery = "collection('" + cname + "')" + query; try { std::cout << "Exercising query '" << fullQuery << "' " << std::endl; std::cout << "Return to continue: "; getc(stdin); std::cout << "\n"; XmlResults results( mgr.query(txn, fullQuery, context ) ); XmlValue value; while(results.next(value)) { // Get the document's name and print it to the console XmlDocument theDocument = value.asDocument(); std::cout << "Document name: " << theDocument.getName() << std::endl; std::cout << value.asString() << std::endl; } std::cout << (unsigned int)results.size() << " objects returned for expression '" << fullQuery << "'\n" << std::endl; } //Catches XmlException catch(std::exception &e) { std::cerr << "Query " << fullQuery << " failed\n"; std::cerr << e.what() << "\n"; txn.abort(); exit( -1 ); } }
//Get a document from the container using the document name void doGetDocument( XmlTransaction &txn, XmlContainer &container, const std::string docname) { try { std::cout << "Getting document '" << docname << "' from the container." << std::endl; std::cout << "Return to continue: "; getc(stdin); std::cout << "\n"; //Get the document from the container using the document name XmlDocument theDocument = container.getDocument(txn, docname); std::string content; std::cout << "Document name: " << theDocument.getName() << std::endl; std::cout << theDocument.getContent(content) << std::endl; } //Catches XmlException catch(std::exception &e) { std::cerr << "Get document from container failed.\n"; std::cerr << e.what() << "\n"; txn.abort(); exit( -1 ); } }
void MgResourceDefinitionManager::DeleteResource( MgResourceIdentifier* resource, bool strict) { assert(NULL != resource); MG_RESOURCE_SERVICE_TRY() string resourcePathname; MgUtil::WideCharToMultiByte(resource->ToString(), resourcePathname); // Set up an XQuery. string query; if (resource->IsFolder()) { query = "for $i in collection('"; query += m_container.getName(); query += "')"; query += "/*[starts-with(dbxml:metadata('dbxml:name'),'"; query += resourcePathname; query += "')]"; query += " order by dbxml:metadata('dbxml:name', $i) descending return $i"; } else { query = "collection('"; query += m_container.getName(); query += "')"; query += "/*[dbxml:metadata('dbxml:name')='"; query += resourcePathname; query += "']"; } // Execute the XQuery. XmlManager& xmlManager = m_container.getManager(); XmlQueryContext queryContext = xmlManager.createQueryContext(); queryContext.setNamespace(MgResourceInfo::sm_metadataPrefix, MgResourceInfo::sm_metadataUri); XmlResults results = IsTransacted() ? xmlManager.query(GetXmlTxn(), query, queryContext, 0) : xmlManager.query(query, queryContext, 0); if (0 == results.size()) { if (!strict || (IsResourceContentManager() && resource->IsFolder())) { return; } else { m_repositoryMan.ThrowResourceNotFoundException(*resource, L"MgResourceDefinitionManager.DeleteResource", __LINE__, __WFILE__); } } // Delete the resources. MgResourceIdentifier currResource; XmlUpdateContext updateContext = xmlManager.createUpdateContext(); XmlValue xmlValue; while (results.next(xmlValue)) { XmlDocument xmlDoc = xmlValue.asDocument(); currResource.SetResource(MgUtil::MultiByteToWideChar(xmlDoc.getName())); if (!currResource.IsRoot()) { DeleteDocument(currResource, xmlDoc, updateContext); } } if (!resource->IsRoot()) { m_repositoryMan.UpdateDateModifiedResourceSet(resource->GetFullPath(true)); } MG_RESOURCE_CONTAINER_CATCH_AND_THROW(L"MgResourceDefinitionManager.DeleteResource") }