diff options
author | Benoit Foucher <benoit@zeroc.com> | 2002-11-23 18:01:47 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2002-11-23 18:01:47 +0000 |
commit | 6a4ecdceae2d8f1100fd98fcc7ae34c3edea1da7 (patch) | |
tree | 469c19b535cfa3fd96793e5f9d0e13618955a08b /cpp/src/XMLTransform/XMLTransform.cpp | |
parent | bug fix for NullPointerException during oneway request (diff) | |
download | ice-6a4ecdceae2d8f1100fd98fcc7ae34c3edea1da7.tar.bz2 ice-6a4ecdceae2d8f1100fd98fcc7ae34c3edea1da7.tar.xz ice-6a4ecdceae2d8f1100fd98fcc7ae34c3edea1da7.zip |
XMLTransformer doesn't import twice the same file anymore.
Diffstat (limited to 'cpp/src/XMLTransform/XMLTransform.cpp')
-rw-r--r-- | cpp/src/XMLTransform/XMLTransform.cpp | 75 |
1 files changed, 54 insertions, 21 deletions
diff --git a/cpp/src/XMLTransform/XMLTransform.cpp b/cpp/src/XMLTransform/XMLTransform.cpp index 279f8691e94..d0998c96516 100644 --- a/cpp/src/XMLTransform/XMLTransform.cpp +++ b/cpp/src/XMLTransform/XMLTransform.cpp @@ -22,10 +22,13 @@ #include <xercesc/util/XMLString.hpp> #include <xercesc/util/Janitor.hpp> #include <xercesc/framework/MemBufInputSource.hpp> +#include <xercesc/framework/LocalFileInputSource.hpp> #include <xercesc/dom/DOM.hpp> #include <xercesc/parsers/XercesDOMParser.hpp> #include <xercesc/sax/SAXParseException.hpp> +#include <set> + #include <sys/stat.h> #ifdef _WIN32 @@ -1159,13 +1162,13 @@ private: // // Load all schemas in a list of directories. // - void load(DocumentMap&, const string&, const Ice::StringSeq&); + void load(DocumentMap&, set<string>&, const string&, const Ice::StringSeq&); // // Schema import/include handling. // - void import(DocumentMap&, const string&, const string&, const Ice::StringSeq&); - void processImport(DOMDocument*, DocumentMap&, const Ice::StringSeq&); + void import(DocumentMap&, set<string>&, const string&, const string&, const Ice::StringSeq&); + void processImport(DOMDocument*, DocumentMap&, set<string>&, const Ice::StringSeq&); // // Element processing. @@ -1252,6 +1255,12 @@ private: TransformMap _defaultInitializedTransforms; // + // Set of already imported file. + // + set<string> _fromImportedFiles; + set<string> _toImportedFiles; + + // // Why won't MSVC allow name to be a string? // struct StringTypeTable @@ -1348,11 +1357,11 @@ XMLTransform::TransformFactory::create(DOMDocument* fromDoc, DOMDocument* toDoc, Ice::StringSeq::size_type i; for(i = 0; i < loadFrom.size(); i++) { - load(_fromDocs, loadFrom[i], pathFrom); + load(_fromDocs, _fromImportedFiles, loadFrom[i], pathFrom); } for(i = 0; i < loadTo.size(); i++) { - load(_toDocs, loadTo[i], pathTo); + load(_toDocs, _toImportedFiles, loadTo[i], pathTo); } // @@ -1373,8 +1382,8 @@ XMLTransform::TransformFactory::create(DOMDocument* fromDoc, DOMDocument* toDoc, // // Process the import/include declarations for the source schema documents. // - processImport(fromDoc, _fromDocs, pathFrom); - processImport(toDoc, _toDocs, pathTo); + processImport(fromDoc, _fromDocs, _fromImportedFiles, pathFrom); + processImport(toDoc, _toDocs, _toImportedFiles, pathTo); // // Finally process each element from the old schema document. @@ -1386,7 +1395,8 @@ XMLTransform::TransformFactory::create(DOMDocument* fromDoc, DOMDocument* toDoc, } void -XMLTransform::TransformFactory::load(DocumentMap& documents, const string& path, const Ice::StringSeq& paths) +XMLTransform::TransformFactory::load(DocumentMap& documents, set<string>& importedFiles, const string& path, + const Ice::StringSeq& paths) { // // If the path ends in ".xsd", then assume it's a schema file @@ -1399,7 +1409,7 @@ XMLTransform::TransformFactory::load(DocumentMap& documents, const string& path, // if(path.rfind(".xsd") != string::npos) { - import(documents, "", path, paths); + import(documents, importedFiles, "", path, paths); } else { @@ -1432,12 +1442,12 @@ XMLTransform::TransformFactory::load(DocumentMap& documents, const string& path, { if(name != ".." && name != ".") { - load(documents, fullPath, paths); // Recurse through subdirectories + load(documents, importedFiles, fullPath, paths); // Recurse through subdirectories } } else if(S_ISREG(buf.st_mode) && name.rfind(".xsd") != string::npos) { - import(documents, "", fullPath, paths); + import(documents, importedFiles, "", fullPath, paths); } if(_findnext(h, &data) == -1) @@ -1487,12 +1497,12 @@ XMLTransform::TransformFactory::load(DocumentMap& documents, const string& path, { if(name != ".." && name != ".") { - load(documents, fullPath, paths); // Recurse through subdirectories + load(documents, importedFiles, fullPath, paths); // Recurse through subdirectories } } else if(S_ISREG(buf.st_mode) && name.rfind(".xsd") != string::npos) { - import(documents, "", fullPath, paths); + import(documents, importedFiles, "", fullPath, paths); } } @@ -1503,9 +1513,27 @@ XMLTransform::TransformFactory::load(DocumentMap& documents, const string& path, } void -XMLTransform::TransformFactory::import(DocumentMap& documents, const string& ns, const string& loc, - const Ice::StringSeq& paths) +XMLTransform::TransformFactory::import(DocumentMap& documents, set<string>& importedFiles, const string& ns, + const string& loc, const Ice::StringSeq& paths) { + // + // Find the file and ensure we didn't already imported it. + // + string file = findFile(loc, paths); + + ArrayJanitor<XMLCh> s(XMLString::transcode(file.c_str())); + LocalFileInputSource source(s.get()); + + string systemId = toString(source.getSystemId()); + + if(importedFiles.find(systemId) != importedFiles.end()) + { + // + // Already imported, nothing to do. + // + return; + } + DOMTreeErrorReporter errorReporter; XercesDOMParser parser; parser.setValidationScheme(AbstractDOMParser::Val_Never); @@ -1514,8 +1542,7 @@ XMLTransform::TransformFactory::import(DocumentMap& documents, const string& ns, try { - string file = findFile(loc, paths); - parser.parse(file.c_str()); + parser.parse(source); } catch(const XMLException& ex) { @@ -1557,13 +1584,19 @@ XMLTransform::TransformFactory::import(DocumentMap& documents, const string& ns, documents.insert(make_pair(info->getTargetNamespace(), info)); // + // Add the file to the list of imported files. + // + importedFiles.insert(systemId); + + // // Process any imports or includes in the imported document. // - processImport(document, documents, paths); + processImport(document, documents, importedFiles, paths); } void -XMLTransform::TransformFactory::processImport(DOMDocument* parent, DocumentMap& documents, const Ice::StringSeq& paths) +XMLTransform::TransformFactory::processImport(DOMDocument* parent, DocumentMap& documents, + set<string>& importedFiles, const Ice::StringSeq& paths) { DOMNode* schema = findSchemaRoot(parent); assert(schema); @@ -1577,13 +1610,13 @@ XMLTransform::TransformFactory::processImport(DOMDocument* parent, DocumentMap& string ns = getAttributeByName(child, "namespace"); string loc = getAttributeByName(child, "schemaLocation"); - import(documents, ns, loc, paths); + import(documents, importedFiles, ns, loc, paths); } else if(nodeName == includeElementName) { string loc = getAttributeByName(child, "schemaLocation"); - import(documents, "", loc, paths); + import(documents, importedFiles, "", loc, paths); } child = child->getNextSibling(); } |