lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / configmgr / source / xcdparser.cxx
blob553087a38c4a7559538bdd0f5d12bd205367f752
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
22 #include <cassert>
23 #include <climits>
24 #include <set>
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"
38 namespace configmgr {
40 XcdParser::XcdParser(
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);
59 ++nesting_;
60 return nestedParser_->startElement(
61 reader, nsId, name, existingDependencies);
63 switch (state_) {
64 case STATE_START:
65 if (nsId == ParseManager::NAMESPACE_OOR && name.equals("data")) {
66 state_ = STATE_DEPENDENCIES;
67 return true;
69 break;
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;
77 for (;;) {
78 int attrNsId;
79 xmlreader::Span attrLn;
80 if (!reader.nextAttribute(&attrNsId, &attrLn)) {
81 break;
83 if (attrNsId == xmlreader::XmlReader::NAMESPACE_NONE &&
84 //TODO: _OOR
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));
96 if (!attrFile.is()) {
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())))
112 return false;
114 state_ = STATE_DEPENDENCY;
115 dependencyFile_.clear();
116 return true;
118 state_ = STATE_COMPONENTS;
119 SAL_FALLTHROUGH;
120 case STATE_COMPONENTS:
121 if (nsId == ParseManager::NAMESPACE_OOR &&
122 name.equals("component-schema"))
124 nestedParser_ = new XcsParser(layer_, data_);
125 nesting_ = 1;
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);
133 nesting_ = 1;
134 return nestedParser_->startElement(
135 reader, nsId, name, existingDependencies);
137 break;
138 default: // STATE_DEPENDENCY
139 assert(false); // this cannot happen
140 break;
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();
152 } else {
153 switch (state_) {
154 case STATE_DEPENDENCY:
155 state_ = STATE_DEPENDENCIES;
156 break;
157 case STATE_DEPENDENCIES:
158 case STATE_COMPONENTS:
159 break;
160 default:
161 assert(false); // this cannot happen
162 break;
167 void XcdParser::characters(xmlreader::Span const & text) {
168 if (nestedParser_.is()) {
169 nestedParser_->characters(text);
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */