bump product version to 7.2.5.1
[LibreOffice.git] / configmgr / source / xcdparser.cxx
bloba069c6b99c6f709aec1e8f8eae5add6f775fb024
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 <rtl/ustring.hxx>
28 #include <xmlreader/span.hxx>
29 #include <xmlreader/xmlreader.hxx>
31 #include "parsemanager.hxx"
32 #include "xcdparser.hxx"
33 #include "xcsparser.hxx"
34 #include "xcuparser.hxx"
35 #include "xmldata.hxx"
37 namespace configmgr {
39 XcdParser::XcdParser(
40 int layer, std::set< OUString > const & processedDependencies, Data & data):
41 layer_(layer), processedDependencies_(processedDependencies), data_(data),
42 state_(STATE_START), dependencyOptional_(), nesting_()
45 XcdParser::~XcdParser() {}
47 xmlreader::XmlReader::Text XcdParser::getTextMode() {
48 return nestedParser_.is()
49 ? nestedParser_->getTextMode() : xmlreader::XmlReader::Text::NONE;
52 bool XcdParser::startElement(
53 xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name,
54 std::set< OUString > const * existingDependencies)
56 if (nestedParser_.is()) {
57 assert(nesting_ != LONG_MAX);
58 ++nesting_;
59 return nestedParser_->startElement(
60 reader, nsId, name, existingDependencies);
62 switch (state_) {
63 case STATE_START:
64 if (nsId == ParseManager::NAMESPACE_OOR && name == "data") {
65 state_ = STATE_DEPENDENCIES;
66 return true;
68 break;
69 case STATE_DEPENDENCIES:
70 if (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
71 name == "dependency")
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;
82 if (attrNsId == xmlreader::XmlReader::NAMESPACE_NONE &&
83 //TODO: _OOR
84 attrLn == "file")
86 attrFile = reader.getAttributeValue(false);
87 } else if ((attrNsId ==
88 xmlreader::XmlReader::NAMESPACE_NONE) &&
89 attrLn == "optional")
91 dependencyOptional_ = xmldata::parseBoolean(
92 reader.getAttributeValue(true));
95 if (!attrFile.is()) {
96 throw css::uno::RuntimeException(
97 "no dependency file attribute in " + reader.getUrl());
99 dependencyFile_ = attrFile.convertFromUtf8();
100 if (dependencyFile_.isEmpty()) {
101 throw css::uno::RuntimeException(
102 "bad dependency file attribute in " + reader.getUrl());
105 if ((processedDependencies_.find(dependencyFile_) ==
106 processedDependencies_.end()) &&
107 (!dependencyOptional_ || existingDependencies == nullptr ||
108 (existingDependencies->find(dependencyFile_) !=
109 existingDependencies->end())))
111 return false;
113 state_ = STATE_DEPENDENCY;
114 dependencyFile_.clear();
115 return true;
117 state_ = STATE_COMPONENTS;
118 [[fallthrough]];
119 case STATE_COMPONENTS:
120 if (nsId == ParseManager::NAMESPACE_OOR &&
121 name == "component-schema")
123 nestedParser_ = new XcsParser(layer_, data_);
124 nesting_ = 1;
125 return nestedParser_->startElement(
126 reader, nsId, name, existingDependencies);
128 if (nsId == ParseManager::NAMESPACE_OOR &&
129 (name == "component-data" || name == "items"))
131 nestedParser_ = new XcuParser(layer_ + 1, data_, nullptr, nullptr, nullptr);
132 nesting_ = 1;
133 return nestedParser_->startElement(
134 reader, nsId, name, existingDependencies);
136 break;
137 default: // STATE_DEPENDENCY
138 assert(false); // this cannot happen
139 break;
141 throw css::uno::RuntimeException(
142 "bad member <" + name.convertFromUtf8() + "> in " + reader.getUrl());
145 void XcdParser::endElement(xmlreader::XmlReader const & reader) {
146 if (nestedParser_.is()) {
147 nestedParser_->endElement(reader);
148 if (--nesting_ == 0) {
149 nestedParser_.clear();
151 } else {
152 switch (state_) {
153 case STATE_DEPENDENCY:
154 state_ = STATE_DEPENDENCIES;
155 break;
156 case STATE_DEPENDENCIES:
157 case STATE_COMPONENTS:
158 break;
159 default:
160 assert(false); // this cannot happen
161 break;
166 void XcdParser::characters(xmlreader::Span const & text) {
167 if (nestedParser_.is()) {
168 nestedParser_->characters(text);
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */