1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
26 #include <com/sun/star/uno/RuntimeException.hpp>
27 #include <rtl/ustring.hxx>
28 #include <xmlreader/span.hxx>
29 #include <xmlreader/xmlreader.hxx>
31 #include "parsemanager.hxx"
32 #include "xcdparser.hxx"
33 #include "xcsparser.hxx"
34 #include "xcuparser.hxx"
35 #include "xmldata.hxx"
40 int layer
, std::set
< OUString
> const & processedDependencies
, Data
& data
):
41 layer_(layer
), processedDependencies_(processedDependencies
), data_(data
),
42 state_(STATE_START
), dependencyOptional_(), nesting_()
45 XcdParser::~XcdParser() {}
47 xmlreader::XmlReader::Text
XcdParser::getTextMode() {
48 return nestedParser_
.is()
49 ? nestedParser_
->getTextMode() : xmlreader::XmlReader::Text::NONE
;
52 bool XcdParser::startElement(
53 xmlreader::XmlReader
& reader
, int nsId
, xmlreader::Span
const & name
,
54 std::set
< OUString
> const * existingDependencies
)
56 if (nestedParser_
.is()) {
57 assert(nesting_
!= LONG_MAX
);
59 return nestedParser_
->startElement(
60 reader
, nsId
, name
, existingDependencies
);
64 if (nsId
== ParseManager::NAMESPACE_OOR
&& name
== "data") {
65 state_
= STATE_DEPENDENCIES
;
69 case STATE_DEPENDENCIES
:
70 if (nsId
== xmlreader::XmlReader::NAMESPACE_NONE
&&
73 if (dependencyFile_
.isEmpty()) {
74 dependencyOptional_
= false;
75 xmlreader::Span attrFile
;
78 xmlreader::Span attrLn
;
79 if (!reader
.nextAttribute(&attrNsId
, &attrLn
)) {
82 if (attrNsId
== xmlreader::XmlReader::NAMESPACE_NONE
&&
86 attrFile
= reader
.getAttributeValue(false);
87 } else if ((attrNsId
==
88 xmlreader::XmlReader::NAMESPACE_NONE
) &&
91 dependencyOptional_
= xmldata::parseBoolean(
92 reader
.getAttributeValue(true));
96 throw css::uno::RuntimeException(
97 "no dependency file attribute in " + reader
.getUrl());
99 dependencyFile_
= attrFile
.convertFromUtf8();
100 if (dependencyFile_
.isEmpty()) {
101 throw css::uno::RuntimeException(
102 "bad dependency file attribute in " + reader
.getUrl());
105 if ((processedDependencies_
.find(dependencyFile_
) ==
106 processedDependencies_
.end()) &&
107 (!dependencyOptional_
|| existingDependencies
== nullptr ||
108 (existingDependencies
->find(dependencyFile_
) !=
109 existingDependencies
->end())))
113 state_
= STATE_DEPENDENCY
;
114 dependencyFile_
.clear();
117 state_
= STATE_COMPONENTS
;
119 case STATE_COMPONENTS
:
120 if (nsId
== ParseManager::NAMESPACE_OOR
&&
121 name
== "component-schema")
123 nestedParser_
= new XcsParser(layer_
, data_
);
125 return nestedParser_
->startElement(
126 reader
, nsId
, name
, existingDependencies
);
128 if (nsId
== ParseManager::NAMESPACE_OOR
&&
129 (name
== "component-data" || name
== "items"))
131 nestedParser_
= new XcuParser(layer_
+ 1, data_
, nullptr, nullptr, nullptr);
133 return nestedParser_
->startElement(
134 reader
, nsId
, name
, existingDependencies
);
137 default: // STATE_DEPENDENCY
138 assert(false); // this cannot happen
141 throw css::uno::RuntimeException(
142 "bad member <" + name
.convertFromUtf8() + "> in " + reader
.getUrl());
145 void XcdParser::endElement(xmlreader::XmlReader
const & reader
) {
146 if (nestedParser_
.is()) {
147 nestedParser_
->endElement(reader
);
148 if (--nesting_
== 0) {
149 nestedParser_
.clear();
153 case STATE_DEPENDENCY
:
154 state_
= STATE_DEPENDENCIES
;
156 case STATE_DEPENDENCIES
:
157 case STATE_COMPONENTS
:
160 assert(false); // this cannot happen
166 void XcdParser::characters(xmlreader::Span
const & text
) {
167 if (nestedParser_
.is()) {
168 nestedParser_
->characters(text
);
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */