00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "xercesc/util/PlatformUtils.hpp"
00036 #include <algorithm>
00037
00038 #include <list>
00039
00040 #include <iostream>
00041 using std::cout;
00042
00043 #include "LCD_DocManager.hh"
00044 #include "LCD_Document.hh"
00045 #include "LCD_DocErrorReporter.hh"
00046 XERCES_CPP_NAMESPACE_USE
00047
00048
00049 std::list <LCD_DocumentImpl*> *LCD_DocManager::active = 0;
00050 bool LCD_DocManager::initDone = false;
00051
00052
00053
00054
00055
00056 int LCD_DocManager::deleteDocument(LCD_Document *pDoc) {
00057
00058
00059 LCD_DocumentImpl *pDocImpl = dynamic_cast <LCD_DocumentImpl*>(pDoc);
00060 if ( pDocImpl ) {
00061
00062 std::list<LCD_DocumentImpl*>::iterator which;
00063
00064 which = std::find(active->begin(), active->end(), pDocImpl);
00065 if (which != active->end()) {
00066
00067
00068 active->erase(which);
00069
00070
00071 delete pDocImpl;
00072 }
00073 else {
00074 return 1;
00075 }
00076 }
00077 else {
00078 return 2;
00079 }
00080 return 0;
00081 }
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 std::vector<LCD_Document*> *LCD_DocManager::getLCD_Documents(DOMString
00092 docTypeName) {
00093 std::vector<LCD_Document*> *docs = new std::vector<LCD_Document*>;
00094 std::list<LCD_DocumentImpl*>::iterator docIt = active->begin();
00095 bool wild = ( docTypeName.equals(DOMString("*")) );
00096
00097 while (docIt != active->end() ) {
00098 if ((wild) || (docTypeName.equals((*docIt)->getDocTypeName()) ) ) {
00099 docs->push_back(*docIt);
00100 }
00101 docIt++;
00102 }
00103 return docs;
00104
00105 }
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 DOM_Element LCD_DocManager::getElement(DOMString id, DOMString elementName,
00117 DOMString docTypeName) {
00118 std::list<LCD_DocumentImpl*>::iterator docIt = active->begin();
00119 bool wild = (docTypeName.equals(DOMString("*")));
00120
00121 while (docIt != active->end() ) {
00122 LCD_DocumentImpl* pDoc = *docIt;
00123 if ((wild) || (docTypeName.equals(pDoc->getDocTypeName()) )) {
00124 DOM_Element elt = pDoc->getElement(id, elementName);
00125 if (elt != 0) return elt;
00126 }
00127 docIt++;
00128 }
00129 return DOM_Element();
00130 }
00131
00132
00133
00134
00135
00136 LCD_Document *LCD_DocManager::makeDocument(const std::string& XMLfilespec) {
00137 LCD_DocumentImpl *pNewDoc;
00138
00139
00140 if (active == 0) {
00141
00142 try
00143 {
00144 XMLPlatformUtils::Initialize();
00145 active = new std::list<LCD_DocumentImpl*>;
00146 initDone = true;
00147 }
00148
00149
00150
00151 catch (const XMLException& toCatch)
00152 {
00153 cout << "Error during xml4c platform initialization! :\n"
00154 << toCatch.getMessage() << "\n";
00155 return 0;
00156 }
00157 }
00158
00159 pNewDoc = new LCD_DocumentImpl(XMLfilespec);
00160
00161 try {
00162 pNewDoc->parse();
00163
00164 }
00165 catch (const XMLException& toCatch2) {
00166
00167
00168 cout << toCatch2.getMessage() << "\n";
00169 delete pNewDoc;
00170 return 0;
00171 }
00172
00173
00174 if ((pNewDoc->errReporter->getErrorCount()) ||
00175 (pNewDoc->errReporter->getFatalCount()) ) {
00176 cout << "Invalid XML source; cannot create document\n";
00177 delete pNewDoc;
00178 return 0;
00179 }
00180
00181 active->push_front(pNewDoc);
00182
00183 return pNewDoc;
00184 }
00185
00186
00187
00188
00189
00190 LCD_Document *LCD_DocManager::getLCDDoc(DOM_Document domDoc) {
00191 std::list<LCD_DocumentImpl*>::iterator which = active->begin();
00192
00193 while (which != active->end()) {
00194 if ( domDoc == (*which)->getDocument()) return *which;
00195 which++;
00196 }
00197 return 0;
00198 }
00199