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/Reference.hxx"
27 #include "com/sun/star/uno/RuntimeException.hpp"
28 #include "com/sun/star/uno/XInterface.hpp"
29 #include "rtl/string.h"
30 #include "rtl/ustring.h"
31 #include "rtl/ustring.hxx"
32 #include "xmlreader/span.hxx"
33 #include "xmlreader/xmlreader.hxx"
35 #include "parsemanager.hxx"
36 #include "xcdparser.hxx"
37 #include "xcsparser.hxx"
38 #include "xcuparser.hxx"
39 #include "xmldata.hxx"
44 int layer
, std::set
< OUString
> const & processedDependencies
, Data
& data
):
45 layer_(layer
), processedDependencies_(processedDependencies
), data_(data
),
49 XcdParser::~XcdParser() {}
51 xmlreader::XmlReader::Text
XcdParser::getTextMode() {
52 return nestedParser_
.is()
53 ? nestedParser_
->getTextMode() : xmlreader::XmlReader::TEXT_NONE
;
56 bool XcdParser::startElement(
57 xmlreader::XmlReader
& reader
, int nsId
, xmlreader::Span
const & name
,
58 std::set
< OUString
> const * existingDependencies
)
60 if (nestedParser_
.is()) {
61 assert(nesting_
!= LONG_MAX
);
63 return nestedParser_
->startElement(
64 reader
, nsId
, name
, existingDependencies
);
68 if (nsId
== ParseManager::NAMESPACE_OOR
&&
69 name
.equals(RTL_CONSTASCII_STRINGPARAM("data")))
71 state_
= STATE_DEPENDENCIES
;
75 case STATE_DEPENDENCIES
:
76 if (nsId
== xmlreader::XmlReader::NAMESPACE_NONE
&&
77 name
.equals(RTL_CONSTASCII_STRINGPARAM("dependency")))
79 if (dependencyFile_
.isEmpty()) {
80 dependencyOptional_
= false;
81 xmlreader::Span attrFile
;
84 xmlreader::Span attrLn
;
85 if (!reader
.nextAttribute(&attrNsId
, &attrLn
)) {
88 if (attrNsId
== xmlreader::XmlReader::NAMESPACE_NONE
&&
90 attrLn
.equals(RTL_CONSTASCII_STRINGPARAM("file")))
92 attrFile
= reader
.getAttributeValue(false);
93 } else if ((attrNsId
==
94 xmlreader::XmlReader::NAMESPACE_NONE
) &&
96 RTL_CONSTASCII_STRINGPARAM("optional")))
98 dependencyOptional_
= xmldata::parseBoolean(
99 reader
.getAttributeValue(true));
102 if (!attrFile
.is()) {
103 throw css::uno::RuntimeException(
105 RTL_CONSTASCII_USTRINGPARAM(
106 "no dependency file attribute in ")) +
108 css::uno::Reference
< css::uno::XInterface
>());
110 dependencyFile_
= attrFile
.convertFromUtf8();
111 if (dependencyFile_
.isEmpty()) {
112 throw css::uno::RuntimeException(
114 RTL_CONSTASCII_USTRINGPARAM(
115 "bad dependency file attribute in ")) +
117 css::uno::Reference
< css::uno::XInterface
>());
120 if ((processedDependencies_
.find(dependencyFile_
) ==
121 processedDependencies_
.end()) &&
122 (!dependencyOptional_
|| existingDependencies
== 0 ||
123 (existingDependencies
->find(dependencyFile_
) !=
124 existingDependencies
->end())))
128 state_
= STATE_DEPENDENCY
;
129 dependencyFile_
= rtl::OUString();
132 state_
= STATE_COMPONENTS
;
134 case STATE_COMPONENTS
:
135 if (nsId
== ParseManager::NAMESPACE_OOR
&&
136 name
.equals(RTL_CONSTASCII_STRINGPARAM("component-schema")))
138 nestedParser_
= new XcsParser(layer_
, data_
);
140 return nestedParser_
->startElement(
141 reader
, nsId
, name
, existingDependencies
);
143 if (nsId
== ParseManager::NAMESPACE_OOR
&&
144 name
.equals(RTL_CONSTASCII_STRINGPARAM("component-data")))
146 nestedParser_
= new XcuParser(layer_
+ 1, data_
, 0, 0, 0);
148 return nestedParser_
->startElement(
149 reader
, nsId
, name
, existingDependencies
);
152 default: // STATE_DEPENDENCY
153 assert(false); // this cannot happen
156 throw css::uno::RuntimeException(
157 (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bad member <")) +
158 name
.convertFromUtf8() +
159 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("> in ")) + reader
.getUrl()),
160 css::uno::Reference
< css::uno::XInterface
>());
163 void XcdParser::endElement(xmlreader::XmlReader
const & reader
) {
164 if (nestedParser_
.is()) {
165 nestedParser_
->endElement(reader
);
166 if (--nesting_
== 0) {
167 nestedParser_
.clear();
171 case STATE_DEPENDENCY
:
172 state_
= STATE_DEPENDENCIES
;
174 case STATE_DEPENDENCIES
:
175 case STATE_COMPONENTS
:
178 assert(false); // this cannot happen
184 void XcdParser::characters(xmlreader::Span
const & text
) {
185 if (nestedParser_
.is()) {
186 nestedParser_
->characters(text
);
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */