/* * * ProLinga-Repository * * Copyright (C) 2002-2010 Xobas Software. * All rights reserved. * * This file is part of ProLinga-Repository. * * ProLinga-Repository is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ProLinga-Repository is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ProLinga-Repository. If not, see . * * More information is available at the following addresses: * * Website : http://www.prolinga.org * * Email : prolinga-list@prolinga.org * * */ #include "RepCommon.h" #include #include #include #include "RepMain.hpp" using namespace DbXml; int DocumentList(char *applicationName, char *objectType, char *objectName, char **externalError, xmlDocPtr *docList) { xmlDocPtr docTmp; xmlNodePtr curTmp, curList; int dbStatus = 0; bool listDoc = false; char xpathExecQuery[1024]; try { extern XmlManager *mgrPtr; /* Create context */ XmlQueryContext qc = mgrPtr->createQueryContext(); qc.setVariableValue("application",applicationName); qc.setVariableValue("type",objectType); qc.setVariableValue("name",objectName); /* Query container for document */ if (objectName[0] == '*' && strlen(objectName)>1) { objectName = objectName + 1; if (objectName[(strlen(objectName)-1)] == '*') { objectName[(strlen(objectName)-1)] = '\0'; } qc.setVariableValue("name",objectName); sprintf(xpathExecQuery, "collection(\"%s\")%sObject[attribute::Application=$application and attribute::Type=$type and contains(attribute::Name,$name)]", REP_SYSTEM_NAME, OBJECT_PATH); } else if (objectName[(strlen(objectName)-1)] == '*') { objectName[(strlen(objectName)-1)] = '\0'; qc.setVariableValue("name",objectName); sprintf(xpathExecQuery, "collection(\"%s\")%sObject[attribute::Application=$application and attribute::Type=$type and starts-with(attribute::Name,$name)]", REP_SYSTEM_NAME, OBJECT_PATH); } else { sprintf(xpathExecQuery, "collection(\"%s\")%sObject[attribute::Application=$application and attribute::Type=$type and attribute::Name=$name]", REP_SYSTEM_NAME, OBJECT_PATH); } XmlResults results = mgrPtr->query(xpathExecQuery, qc); /* Create Document object */ XmlDocument document = mgrPtr->createDocument(); /* Create return document */ *docList = xmlNewDoc((const xmlChar *)XML_VERSION); (*docList)->children = xmlNewDocNode(*docList, NULL, (const xmlChar *)ROOT_ELEM, NULL); curList = xmlDocGetRootElement(*docList); while (results.next(document)) { std::string content; document.getContent(content); /* Parse return string */ docTmp = xmlParseMemory(content.c_str(), strlen(content.c_str())); if (docTmp == 0) return 10008; /* Remove doc details (work arround) */ curTmp = xmlDocGetRootElement(docTmp); curTmp = curTmp->xmlChildrenNode; while (curTmp != NULL) { if (!xmlStrcmp(curTmp->name, (const xmlChar *) REPOSITORY_OBJECT)) break; curTmp = curTmp->next; } curTmp = curTmp->xmlChildrenNode; while (curTmp != NULL) { if (!xmlStrcmp(curTmp->name, (const xmlChar *) OBJECT)) break; curTmp = curTmp->next; } curTmp = curTmp->xmlChildrenNode; while (curTmp != NULL) { if (!xmlStrcmp(curTmp->name, (const xmlChar *)objectType)) break; curTmp = curTmp->next; } xmlUnlinkNode(curTmp); xmlFreeNode(curTmp); /* Merge into return doc */ curTmp = xmlDocGetRootElement(docTmp); curTmp = curTmp->xmlChildrenNode; while (curTmp != NULL) { if (!xmlStrcmp(curTmp->name, (const xmlChar *) REPOSITORY_OBJECT)) break; curTmp = curTmp->next; } curTmp = curTmp->xmlChildrenNode; while (curTmp != NULL) { if (!xmlStrcmp(curTmp->name, (const xmlChar *) OBJECT)) break; curTmp = curTmp->next; } /* Link in return document */ xmlAddChild(curList, xmlCopyNodeList(curTmp)); /* Release */ xmlFreeDoc(docTmp); listDoc = true; } if (listDoc == false) dbStatus = 10005; } catch(XmlException &e) { dbStatus = 90001; *externalError = new char[strlen(e.what())]; strcpy(*externalError, e.what()); } catch(std::exception &e) { dbStatus = 90001; *externalError = new char[strlen(e.what())]; strcpy(*externalError, e.what()); } return dbStatus; }