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 <com/sun/star/uno/XInterface.hpp>
28 #include <rtl/ustring.hxx>
29 #include <xmlreader/span.hxx>
30 #include <xmlreader/xmlreader.hxx>
32 #include "parsemanager.hxx"
33 #include "xcdparser.hxx"
34 #include "xcsparser.hxx"
35 #include "xcuparser.hxx"
36 #include "xmldata.hxx"
41 int layer
, std::set
< OUString
> const & processedDependencies
, Data
& data
):
42 layer_(layer
), processedDependencies_(processedDependencies
), data_(data
),
43 state_(STATE_START
), dependencyOptional_(), nesting_()
46 XcdParser::~XcdParser() {}
48 xmlreader::XmlReader::Text
XcdParser::getTextMode() {
49 return nestedParser_
.is()
50 ? nestedParser_
->getTextMode() : xmlreader::XmlReader::Text::NONE
;
53 bool XcdParser::startElement(
54 xmlreader::XmlReader
& reader
, int nsId
, xmlreader::Span
const & name
,
55 std::set
< OUString
> const * existingDependencies
)
57 if (nestedParser_
.is()) {
58 assert(nesting_
!= LONG_MAX
);
60 return nestedParser_
->startElement(
61 reader
, nsId
, name
, existingDependencies
);
65 if (nsId
== ParseManager::NAMESPACE_OOR
&& name
.equals("data")) {
66 state_
= STATE_DEPENDENCIES
;
70 case STATE_DEPENDENCIES
:
71 if (nsId
== xmlreader::XmlReader::NAMESPACE_NONE
&&
72 name
.equals("dependency"))
74 if (dependencyFile_
.isEmpty()) {
75 dependencyOptional_
= false;
76 xmlreader::Span attrFile
;
79 xmlreader::Span attrLn
;
80 if (!reader
.nextAttribute(&attrNsId
, &attrLn
)) {
83 if (attrNsId
== xmlreader::XmlReader::NAMESPACE_NONE
&&
85 attrLn
.equals("file"))
87 attrFile
= reader
.getAttributeValue(false);
88 } else if ((attrNsId
==
89 xmlreader::XmlReader::NAMESPACE_NONE
) &&
90 attrLn
.equals("optional"))
92 dependencyOptional_
= xmldata::parseBoolean(
93 reader
.getAttributeValue(true));
97 throw css::uno::RuntimeException(
98 "no dependency file attribute in " + reader
.getUrl());
100 dependencyFile_
= attrFile
.convertFromUtf8();
101 if (dependencyFile_
.isEmpty()) {
102 throw css::uno::RuntimeException(
103 "bad dependency file attribute in " + reader
.getUrl());
106 if ((processedDependencies_
.find(dependencyFile_
) ==
107 processedDependencies_
.end()) &&
108 (!dependencyOptional_
|| existingDependencies
== nullptr ||
109 (existingDependencies
->find(dependencyFile_
) !=
110 existingDependencies
->end())))
114 state_
= STATE_DEPENDENCY
;
115 dependencyFile_
.clear();
118 state_
= STATE_COMPONENTS
;
120 case STATE_COMPONENTS
:
121 if (nsId
== ParseManager::NAMESPACE_OOR
&&
122 name
.equals("component-schema"))
124 nestedParser_
= new XcsParser(layer_
, data_
);
126 return nestedParser_
->startElement(
127 reader
, nsId
, name
, existingDependencies
);
129 if (nsId
== ParseManager::NAMESPACE_OOR
&&
130 name
.equals("component-data"))
132 nestedParser_
= new XcuParser(layer_
+ 1, data_
, nullptr, nullptr, nullptr);
134 return nestedParser_
->startElement(
135 reader
, nsId
, name
, existingDependencies
);
138 default: // STATE_DEPENDENCY
139 assert(false); // this cannot happen
142 throw css::uno::RuntimeException(
143 "bad member <" + name
.convertFromUtf8() + "> in " + reader
.getUrl());
146 void XcdParser::endElement(xmlreader::XmlReader
const & reader
) {
147 if (nestedParser_
.is()) {
148 nestedParser_
->endElement(reader
);
149 if (--nesting_
== 0) {
150 nestedParser_
.clear();
154 case STATE_DEPENDENCY
:
155 state_
= STATE_DEPENDENCIES
;
157 case STATE_DEPENDENCIES
:
158 case STATE_COMPONENTS
:
161 assert(false); // this cannot happen
167 void XcdParser::characters(xmlreader::Span
const & text
) {
168 if (nestedParser_
.is()) {
169 nestedParser_
->characters(text
);
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */