MG_RESOURCE_SERVICE_TRY() try { // Ensure the current operation is transactionally protected. m_repositoryMan.ValidateTransaction(); // Perform the XML validation. ValidateDocument(xmlDoc); // Update the resource. m_container.updateDocument(GetXmlTxn(), xmlDoc, updateContext); } catch (XmlException& e) { if (XmlException::DOCUMENT_NOT_FOUND == e.getExceptionCode()) { MgResourceIdentifier resource( MgUtil::MultiByteToWideChar(xmlDoc.getName())); m_repositoryMan.ThrowResourceNotFoundException(resource, L"MgResourceDefinitionManager.UpdateDocument", __LINE__, __WFILE__); } else { throw e; } }
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") }
//************************************************************************* // Method: LoadDatabase // Description: load the database into this object // // Parameters: // databaseFolder - The folder that contains the database files // // Return Value: true if loaded successfully, false otherwise //************************************************************************* bool ErrorCodeDB::LoadDatabase(String *databaseFolder) { String *xmlFileName = new String(""); // get the full path to the database file if (databaseFolder != NULL) { if (databaseFolder->EndsWith("\\")) xmlFileName = String::Concat(databaseFolder, ERROR_CODE_DB_FILE_NAME); else xmlFileName = String::Concat(databaseFolder, "\\", ERROR_CODE_DB_FILE_NAME); } else xmlFileName = ERROR_CODE_DB_FILE_NAME; ValidateDocument(xmlFileName); this->byCodeKeyTable->Clear(); this->byStringKeyTable->Clear(); try { XPathDocument *doc = new XPathDocument(xmlFileName); XPathNavigator *navigator = doc->CreateNavigator(); bool hasMoreErrorCodes = false; navigator->MoveToFirstChild(); // check for comments while (navigator->NodeType == XPathNodeType::Comment) navigator->MoveToNext(); if (navigator->HasChildren) { navigator->MoveToFirstChild(); hasMoreErrorCodes = true; } while (hasMoreErrorCodes) { String *str = NULL; String *code = NULL; bool hasMoreAttributes = navigator->MoveToFirstAttribute(); while (hasMoreAttributes) { if (navigator->Name->CompareTo("String") == 0) str = navigator->Value; else if (navigator->Name->CompareTo("Code") == 0) code = navigator->Value; hasMoreAttributes = navigator->MoveToNextAttribute(); } // get back to the parent tag navigator->MoveToParent(); if ((str != NULL) && (code != NULL)) { this->byCodeKeyTable->Add(code, str); this->byStringKeyTable->Add(str, code); } hasMoreErrorCodes = navigator->MoveToNext(); } } catch(System::IO::FileNotFoundException *e) { String *msg = new String("Could not find the error code database file: \""); msg->Concat(e->FileName); throw new Exception(msg); } isLoaded = true; return true; }