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/ustring.hxx>
30 #include <xmlreader/span.hxx>
31 #include <xmlreader/xmlreader.hxx>
33 #include "parsemanager.hxx"
34 #include "xcdparser.hxx"
35 #include "xcsparser.hxx"
36 #include "xcuparser.hxx"
37 #include "xmldata.hxx"
42 int layer
, std::set
< OUString
> const & processedDependencies
, Data
& data
):
43 layer_(layer
), processedDependencies_(processedDependencies
), data_(data
),
44 state_(STATE_START
), dependencyOptional_(), nesting_()
47 XcdParser::~XcdParser() {}
49 xmlreader::XmlReader::Text
XcdParser::getTextMode() {
50 return nestedParser_
.is()
51 ? nestedParser_
->getTextMode() : xmlreader::XmlReader::TEXT_NONE
;
54 bool XcdParser::startElement(
55 xmlreader::XmlReader
& reader
, int nsId
, xmlreader::Span
const & name
,
56 std::set
< OUString
> const * existingDependencies
)
58 if (nestedParser_
.is()) {
59 assert(nesting_
!= LONG_MAX
);
61 return nestedParser_
->startElement(
62 reader
, nsId
, name
, existingDependencies
);
66 if (nsId
== ParseManager::NAMESPACE_OOR
&& name
.equals("data")) {
67 state_
= STATE_DEPENDENCIES
;
71 case STATE_DEPENDENCIES
:
72 if (nsId
== xmlreader::XmlReader::NAMESPACE_NONE
&&
73 name
.equals("dependency"))
75 if (dependencyFile_
.isEmpty()) {
76 dependencyOptional_
= false;
77 xmlreader::Span attrFile
;
80 xmlreader::Span attrLn
;
81 if (!reader
.nextAttribute(&attrNsId
, &attrLn
)) {
84 if (attrNsId
== xmlreader::XmlReader::NAMESPACE_NONE
&&
86 attrLn
.equals("file"))
88 attrFile
= reader
.getAttributeValue(false);
89 } else if ((attrNsId
==
90 xmlreader::XmlReader::NAMESPACE_NONE
) &&
91 attrLn
.equals("optional"))
93 dependencyOptional_
= xmldata::parseBoolean(
94 reader
.getAttributeValue(true));
98 throw css::uno::RuntimeException(
99 "no dependency file attribute in " + reader
.getUrl());
101 dependencyFile_
= attrFile
.convertFromUtf8();
102 if (dependencyFile_
.isEmpty()) {
103 throw css::uno::RuntimeException(
104 "bad dependency file attribute in " + reader
.getUrl());
107 if ((processedDependencies_
.find(dependencyFile_
) ==
108 processedDependencies_
.end()) &&
109 (!dependencyOptional_
|| existingDependencies
== 0 ||
110 (existingDependencies
->find(dependencyFile_
) !=
111 existingDependencies
->end())))
115 state_
= STATE_DEPENDENCY
;
116 dependencyFile_
.clear();
119 state_
= STATE_COMPONENTS
;
121 case STATE_COMPONENTS
:
122 if (nsId
== ParseManager::NAMESPACE_OOR
&&
123 name
.equals("component-schema"))
125 nestedParser_
= new XcsParser(layer_
, data_
);
127 return nestedParser_
->startElement(
128 reader
, nsId
, name
, existingDependencies
);
130 if (nsId
== ParseManager::NAMESPACE_OOR
&&
131 name
.equals("component-data"))
133 nestedParser_
= new XcuParser(layer_
+ 1, data_
, 0, 0, 0);
135 return nestedParser_
->startElement(
136 reader
, nsId
, name
, existingDependencies
);
139 default: // STATE_DEPENDENCY
140 assert(false); // this cannot happen
143 throw css::uno::RuntimeException(
144 "bad member <" + name
.convertFromUtf8() + "> in " + reader
.getUrl());
147 void XcdParser::endElement(xmlreader::XmlReader
const & reader
) {
148 if (nestedParser_
.is()) {
149 nestedParser_
->endElement(reader
);
150 if (--nesting_
== 0) {
151 nestedParser_
.clear();
155 case STATE_DEPENDENCY
:
156 state_
= STATE_DEPENDENCIES
;
158 case STATE_DEPENDENCIES
:
159 case STATE_COMPONENTS
:
162 assert(false); // this cannot happen
168 void XcdParser::characters(xmlreader::Span
const & text
) {
169 if (nestedParser_
.is()) {
170 nestedParser_
->characters(text
);
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */