LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
XMLPropertyHandler.cpp
Go to the documentation of this file.
1// Copyright 2002-2013 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6/***************************************************************************
7 * Copyright (C) 2004 by CEA LIST *
8 * *
9 ***************************************************************************/
10
11#include "XMLPropertyHandler.h"
12#include "common/LimaCommon.h"
13
14using namespace std;
15
16namespace Lima
17{
18namespace Common
19{
20namespace PropertyCode
21{
22
23XMLPropertyHandler::XMLPropertyHandler() : m_currentProp(NONE) {}
24
25XMLPropertyHandler::~XMLPropertyHandler() {}
26
27// -----------------------------------------------------------------------
28// Implementations of the SAX DocumentHandler interface
29// -----------------------------------------------------------------------
30bool XMLPropertyHandler::endDocument()
31{ return true;
32}
33
34bool XMLPropertyHandler::endElement(const QString & namespaceURI, const QString & name, const QString & qName)
35{
36 LIMA_UNUSED(namespaceURI);
37 LIMA_UNUSED(qName);
38 const QString& stringName = name;
39 if (m_currentProp==PROP && stringName == "property")
40 {
41 m_currentProp=NONE;
42 }
43 else if (m_currentProp==SUBPROP && stringName == "subproperty")
44 {
45 m_currentProp=NONE;
46 }
47 return true;
48}
49
50bool XMLPropertyHandler::startElement(const QString & namespaceURI, const QString & name, const QString & qName, const QXmlAttributes & attributes)
51{
52 LIMA_UNUSED(namespaceURI);
53 LIMA_UNUSED(qName);
54#ifdef DEBUG_LP
56#endif
57 const QString& stringName = name;
58 if (stringName == "property")
59 {
60 m_currentProp=PROP;
61 m_properties.push_back(PropertyDescription());
62 m_properties.back().name = attributes.value("name").toUtf8().data();
63#ifdef DEBUG_LP
64 LDEBUG << "read property " << m_properties.back().name;
65#endif
66 }
67 else if (stringName == "subproperty")
68 {
69 m_currentProp=SUBPROP;
70 m_subproperties.push_back(SubPropertyDescription());
71 m_subproperties.back().name = attributes.value("name").toUtf8().data();
72 m_subproperties.back().parentName = attributes.value("parent").toUtf8().data();
73#ifdef DEBUG_LP
74 LDEBUG << "read subproperty " << m_subproperties.back().name << " of parent property " << m_subproperties.back().parentName;
75#endif
76 }
77 else if (stringName == "value")
78 {
79 string value=attributes.value("name").toUtf8().data();
80#ifdef DEBUG_LP
81 LDEBUG << "read value " << value;
82#endif
83 if (m_currentProp == PROP)
84 {
85 m_properties.back().values.push_back(value);
86 }
87 else if (m_currentProp == SUBPROP)
88 {
89 m_subproperties.back().values.back().second.push_back(value);
90 }
91 else
92 {
94 LERROR << "Don't know what to do with value " << value << " !";
95 }
96 }
97 else if (stringName == "subvalues")
98 {
99 string value=attributes.value("value").toUtf8().data();
100#ifdef DEBUG_LP
101 LDEBUG << "read subvalues " << value;
102#endif
103 if (m_currentProp == SUBPROP)
104 {
105 m_subproperties.back().values.push_back(make_pair(value,vector<string>()));
106 }
107 else
108 {
110 LERROR << "Don't know what to do with subvalues " << value << " !";
111 }
112 }
113 return true;
114}
115
116
117const std::vector<XMLPropertyHandler::PropertyDescription>& XMLPropertyHandler::getProperties()
118{
119 return m_properties;
120}
121
122const std::vector<XMLPropertyHandler::SubPropertyDescription>& XMLPropertyHandler::getSubProperties()
123{
124 return m_subproperties;
125}
126
127} // closing namespace PropertyCode
128} // closing namespace Common
129} // closing namespace Lima
#define LIMA_UNUSED(x)
Definition LimaCommon.h:224
#define LDEBUG
Definition LimaCommon.h:157
#define LERROR
Definition LimaCommon.h:161
#define PROPERTYCODELOGINIT
Definition LimaCommon.h:213
NAUTITIA.
STL namespace.