Debian Codegraph @

Source/Parser/CXMLHandlerStackBase.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 "CXMLHandlerStackBase.h"
22
23
24 namespace Konclude {
25
26 namespace Parser {
27
28
29
30 CXMLHandlerStackBase::CXMLHandlerStackBase() : CLogIdentifier("::Konclude::Parser::XMLHandlerStackBase",this) {
31 mCurrentHandlerData = nullptr;
32 mParseElementLevel = 0;
33 }
34
35 bool CXMLHandlerStackBase::pushStackedHandler(CXMLHandler* handler, bool automaticallyPop, CParsingHandlingContext* handlingContext) {
36 if (handler) {
37 CXMLHandlerData* newHandlerData = new CXMLHandlerData(handler,automaticallyPop,mParseElementLevel);
38 mHandlerDataStack.push(newHandlerData);
39 mCurrentHandlerData = newHandlerData;
40 return true;
41 }
42 return false;
43 }
44
45 bool CXMLHandlerStackBase::popStackedHandler(CXMLHandler* handler, CParsingHandlingContext* handlingContext) {
46 if (!mCurrentHandlerData || mCurrentHandlerData->mHandler != handler) {
47 return false;
48 }
49 mHandlerDataStack.pop();
50 mCurrentHandlerData = nullptr;
51 if (mHandlerDataStack.count() > 0) {
52 mCurrentHandlerData = mHandlerDataStack.top();
53 }
54 return true;
55 }
56
57
58 bool CXMLHandlerStackBase::startElement(const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts, CParsingHandlingContext* handlingContext) {
59 ++mParseElementLevel;
60 if (mCurrentHandlerData) {
61 if (!mCurrentHandlerData->mStartDocumentCalled) {
62 mCurrentHandlerData->mStartDocumentCalled = true;
63 mCurrentHandlerData->mHandler->startDocument(handlingContext);
64 }
65 return mCurrentHandlerData->mHandler->startElement(namespaceURI,localName,qName,atts,handlingContext);
66 }
67 return false;
68 }
69
70 bool CXMLHandlerStackBase::endElement(const QString& namespaceURI, const QString& localName, const QString& qName, CParsingHandlingContext* handlingContext) {
71 --mParseElementLevel;
72 if (mCurrentHandlerData) {
73 if (mCurrentHandlerData->mParseElementLevel > mParseElementLevel) {
74 bool autoPop = mCurrentHandlerData->mAutoPop;
75 mCurrentHandlerData->mHandler->endDocument(handlingContext);
76 if (autoPop) {
77 popStackedHandler(mCurrentHandlerData->mHandler,handlingContext);
78 }
79 }
80 }
81
82 if (mCurrentHandlerData) {
83 return mCurrentHandlerData->mHandler->endElement(namespaceURI,localName,qName,handlingContext);
84 }
85
86 return false;
87 }
88
89
90 bool CXMLHandlerStackBase::startDocument(CParsingHandlingContext* handlingContext) {
91 return true;
92 }
93
94 bool CXMLHandlerStackBase::endDocument(CParsingHandlingContext* handlingContext) {
95 while (mCurrentHandlerData) {
96 bool autoPop = mCurrentHandlerData->mAutoPop;
97 mCurrentHandlerData->mHandler->endDocument(handlingContext);
98 if (autoPop) {
99 popStackedHandler(mCurrentHandlerData->mHandler,handlingContext);
100 }
101 }
102 return true;
103 }
104
105
106
107 }; // end namespace Parser
108
109 }; // end namespace Konclude