1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "parsers.hxx"
26 #include "Runtime.hxx"
28 #include "ProcCataLoader.hxx"
31 #include "rootParser.hxx"
34 #include "YacsTrace.hxx"
36 #include <libxml/parser.h>
37 #include <libxml/tree.h>
38 #include <libxml/xmlreader.h>
39 #include <libxml/parserInternals.h>
40 YACS::ENGINE::Runtime* theRuntime=0;
46 extern YACS::ENGINE::Proc* currentProc;
47 extern _xmlParserCtxt* saxContext;
51 YACSLoader::YACSLoader()
53 _defaultParsersMap.clear();
54 theRuntime = ENGINE::getRuntime();
57 void YACSLoader::registerProcCataLoader()
59 YACS::ENGINE::ProcCataLoader* factory= new YACS::ENGINE::ProcCataLoader(this);
60 theRuntime->setCatalogLoaderFactory("proc",factory);
63 ENGINE::Proc* YACSLoader::load(const char * file)
65 DEBTRACE("YACSLoader::load: " << file);
66 parser::main_parser.init();
67 parser::main_parser._stackParser.push(&parser::main_parser);
68 xmlSAXHandler baseHandler =
70 0, // internal_subset,
72 0, // hasInternalSubset
73 0, // hasExternalSubset
80 0, // unparsedEntityDecl
81 0, // setDocumentLocator
82 parser::start_document, // startDocument
83 parser::end_document, // endDocument
84 parser::start_element, // startElement
85 parser::end_element, // endElement
87 parser::characters, // characters
88 0, // ignorableWhitespace
89 0, // processingInstruction
90 parser::comment, // comment
91 parser::warning, // warning
92 parser::error, // error
93 parser::fatal_error, // fatalError
94 0, // getParameterEntity
95 parser::cdata_block, // cdataBlock
99 FILE* fin=fopen(file,"r");
102 std::cerr << "Couldn't open schema file" << std::endl;
103 throw std::invalid_argument("Couldn't open schema file");
106 saxContext = xmlCreateFileParserCtxt(file);
110 std::cerr << "Couldn't allocate memory for parser" << std::endl;
111 throw Exception("Couldn't allocate memory for parser");
113 saxContext->sax = &baseHandler;
114 parser::main_parser.SetUserDataAndPush(&YACS::roottypeParser::rootParser);
115 if ( !_defaultParsersMap.empty() )
116 roottypeParser::rootParser.setDefaultMap(&_defaultParsersMap);
118 roottypeParser::rootParser.setDefaultMap(0);
120 parser::main_parser._file = file;
125 if ( xmlParseDocument(saxContext) == -1 )
128 throw Exception("Basic error during parsing.");
129 YACS::ENGINE::Logger* logger = currentProc->getLogger("parser");
130 logger->fatal( saxContext->lastError.message, file, saxContext->input->line );
139 YACS::ENGINE::Logger* logger = currentProc->getLogger("parser");
140 logger->fatal(e.what(), file, saxContext->input->line);
146 YACSLoader::~YACSLoader()