Debian Codegraph @

Source/Parser/COWL2QtXMLOntologySAXParser.cpp

raw
1 /*
2 * Copyright (C) 2013-2015, 2019 by the Konclude Developer Team.
3 *
4 * This file is part of the reasoning system Konclude.
5 * For details and support, see <http://konclude.com/>.
6 *
7 * Konclude is free software: you can redistribute it and/or modify
8 * it under the terms of version 3 of the GNU Lesser General Public
9 * License (LGPLv3) as published by the Free Software Foundation.
10 *
11 * Konclude is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU (Lesser) General Public License for more details.
15 *
16 * You should have received a copy of the GNU (Lesser) General Public
17 * License along with Konclude. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include "COWL2QtXMLOntologySAXParser.h"
22
23
24 namespace Konclude {
25
26 namespace Parser {
27
28
29
30 COWL2QtXMLOntologySAXParser::COWL2QtXMLOntologySAXParser(COntologyBuilder* ontologyBuilder) {
31 mOntologyBuilder = ontologyBuilder;
32
33 mMemoryPoolProvider = new CNewAllocationMemoryPoolProvider();
34 mMemoryPoolAllocationMan = new CMemoryPoolAllocationManager(mMemoryPoolProvider);
35 mContextBase = new CContextBase(mMemoryPoolAllocationMan);
36
37 mHandlerStack = new CXMLHandlerStackBase();
38 mOWLXMLStackHandler = new CXMLOWL2Handler(mOntologyBuilder);
39 mParsingHandlingContext = new CXMLParsingHandlingContextBase(mHandlerStack,mMemoryPoolAllocationMan);
40 mHandlerStack->pushStackedHandler(mOWLXMLStackHandler,true,mParsingHandlingContext);
41 }
42
43
44 COWL2QtXMLOntologySAXParser::~COWL2QtXMLOntologySAXParser() {
45 delete mMemoryPoolAllocationMan;
46 delete mMemoryPoolProvider;
47 delete mHandlerStack;
48 delete mOWLXMLStackHandler;
49 delete mParsingHandlingContext;
50 delete mContextBase;
51 }
52
53
54 bool COWL2QtXMLOntologySAXParser::parseOntology(const QString& fileString) {
55 QFile file(fileString);
56 bool succParsed = false;
57 if (file.open(QIODevice::ReadOnly)) {
58 succParsed = parseOntology(&file);
59 file.close();
60 }
61 return succParsed;
62 }
63
64 bool COWL2QtXMLOntologySAXParser::parseOntology(QIODevice* ioDevice) {
65 //QHash<QStringRef,QString> testHash;
66 //QString testString("test");
67 //testHash.insert(testString.leftRef(-1),"test");
68
69 QXmlSimpleReader xmlReader;
70 QXmlInputSource* source = new QXmlInputSource(ioDevice);
71
72 CQtXMLContentHandlerConverter* xmlConHanCon = new CQtXMLContentHandlerConverter(mHandlerStack,mParsingHandlingContext);
73 xmlReader.setContentHandler(xmlConHanCon);
74 xmlReader.setErrorHandler(xmlConHanCon);
75 xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
76
77 bool succParsed = xmlReader.parse(source);
78
79 delete xmlConHanCon;
80 delete source;
81 return succParsed;
82
83 //QStringRef baseNameRef;
84
85 //QXmlStreamReader xmlReader(ioDevice);
86 //while (!xmlReader.atEnd()) {
87 // QXmlStreamReader::TokenType token(xmlReader.readNext());
88 // if (token == QXmlStreamReader::StartElement) {
89 // QStringRef nameRef(xmlReader.name());
90 // baseNameRef = nameRef;
91 // }
92 //}
93 //return true;
94 }
95
96
97 }; // end namespace Parser
98
99 }; // end namespace Konclude