LibreOffice Module configmgr (master) 1
xcdparser.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21
22#include <cassert>
23#include <climits>
24#include <set>
25
26#include <com/sun/star/uno/RuntimeException.hpp>
27#include <rtl/ustring.hxx>
28#include <xmlreader/span.hxx>
30
31#include "parsemanager.hxx"
32#include "xcdparser.hxx"
33#include "xcsparser.hxx"
34#include "xcuparser.hxx"
35#include "xmldata.hxx"
36
37namespace configmgr {
38
40 int layer, std::set< OUString > const & processedDependencies, Data & data):
41 layer_(layer), processedDependencies_(processedDependencies), data_(data),
42 state_(STATE_START), dependencyOptional_(), nesting_()
43{}
44
46
48 return nestedParser_.is()
49 ? nestedParser_->getTextMode() : xmlreader::XmlReader::Text::NONE;
50}
51
53 xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name,
54 std::set< OUString > const * existingDependencies)
55{
56 if (nestedParser_.is()) {
57 assert(nesting_ != LONG_MAX);
58 ++nesting_;
59 return nestedParser_->startElement(
60 reader, nsId, name, existingDependencies);
61 }
62 switch (state_) {
63 case STATE_START:
64 if (nsId == ParseManager::NAMESPACE_OOR && name == "data") {
66 return true;
67 }
68 break;
71 name == "dependency")
72 {
73 if (dependencyFile_.isEmpty()) {
74 dependencyOptional_ = false;
75 xmlreader::Span attrFile;
76 for (;;) {
77 int attrNsId;
78 xmlreader::Span attrLn;
79 if (!reader.nextAttribute(&attrNsId, &attrLn)) {
80 break;
81 }
83 //TODO: _OOR
84 attrLn == "file")
85 {
86 attrFile = reader.getAttributeValue(false);
87 } else if ((attrNsId ==
89 attrLn == "optional")
90 {
92 reader.getAttributeValue(true));
93 }
94 }
95 if (!attrFile.is()) {
96 throw css::uno::RuntimeException(
97 "no dependency file attribute in " + reader.getUrl());
98 }
100 if (dependencyFile_.isEmpty()) {
101 throw css::uno::RuntimeException(
102 "bad dependency file attribute in " + reader.getUrl());
103 }
104 }
106 processedDependencies_.end()) &&
107 (!dependencyOptional_ || existingDependencies == nullptr ||
108 (existingDependencies->find(dependencyFile_) !=
109 existingDependencies->end())))
110 {
111 return false;
112 }
114 dependencyFile_.clear();
115 return true;
116 }
118 [[fallthrough]];
119 case STATE_COMPONENTS:
120 if (nsId == ParseManager::NAMESPACE_OOR &&
121 name == "component-schema")
122 {
124 nesting_ = 1;
125 return nestedParser_->startElement(
126 reader, nsId, name, existingDependencies);
127 }
128 if (nsId == ParseManager::NAMESPACE_OOR &&
129 (name == "component-data" || name == "items"))
130 {
131 nestedParser_ = new XcuParser(layer_ + 1, data_, nullptr, nullptr, nullptr);
132 nesting_ = 1;
133 return nestedParser_->startElement(
134 reader, nsId, name, existingDependencies);
135 }
136 break;
137 default: // STATE_DEPENDENCY
138 assert(false); // this cannot happen
139 break;
140 }
141 throw css::uno::RuntimeException(
142 "bad member <" + name.convertFromUtf8() + "> in " + reader.getUrl());
143}
144
146 if (nestedParser_.is()) {
147 nestedParser_->endElement(reader);
148 if (--nesting_ == 0) {
149 nestedParser_.clear();
150 }
151 } else {
152 switch (state_) {
153 case STATE_DEPENDENCY:
155 break;
157 case STATE_COMPONENTS:
158 break;
159 default:
160 assert(false); // this cannot happen
161 break;
162 }
163 }
164}
165
167 if (nestedParser_.is()) {
168 nestedParser_->characters(text);
169 }
170}
171
172}
173
174/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
rtl::Reference< Parser > nestedParser_
Definition: xcdparser.hxx:66
XcdParser(int layer, std::set< OUString > const &processedDependencies, Data &data)
Definition: xcdparser.cxx:39
virtual ~XcdParser() override
Definition: xcdparser.cxx:45
virtual xmlreader::XmlReader::Text getTextMode() override
Definition: xcdparser.cxx:47
virtual void endElement(xmlreader::XmlReader const &reader) override
Definition: xcdparser.cxx:145
virtual bool startElement(xmlreader::XmlReader &reader, int nsId, xmlreader::Span const &name, std::set< OUString > const *existingDependencies) override
Definition: xcdparser.cxx:52
virtual void characters(xmlreader::Span const &text) override
Definition: xcdparser.cxx:166
std::set< OUString > const & processedDependencies_
Definition: xcdparser.hxx:61
OUString dependencyFile_
Definition: xcdparser.hxx:64
const OUString & getUrl() const
bool nextAttribute(int *nsId, Span *localName)
Span getAttributeValue(bool fullyNormalize)
OUString name
Definition: components.cxx:85
const long LONG_MAX
def text(shape, orig_st)
bool parseBoolean(xmlreader::Span const &text)
Definition: xmldata.cxx:105
rtl::OUString convertFromUtf8() const
bool is() const