bump product version to 5.0.4.1
[LibreOffice.git] / configmgr / source / xcdparser.cxx
blob11502e347f2d5a25d9ed32ff5625c4864403d960
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/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"
39 namespace configmgr {
41 XcdParser::XcdParser(
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);
60 ++nesting_;
61 return nestedParser_->startElement(
62 reader, nsId, name, existingDependencies);
64 switch (state_) {
65 case STATE_START:
66 if (nsId == ParseManager::NAMESPACE_OOR && name.equals("data")) {
67 state_ = STATE_DEPENDENCIES;
68 return true;
70 break;
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;
78 for (;;) {
79 int attrNsId;
80 xmlreader::Span attrLn;
81 if (!reader.nextAttribute(&attrNsId, &attrLn)) {
82 break;
84 if (attrNsId == xmlreader::XmlReader::NAMESPACE_NONE &&
85 //TODO: _OOR
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));
97 if (!attrFile.is()) {
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())))
113 return false;
115 state_ = STATE_DEPENDENCY;
116 dependencyFile_.clear();
117 return true;
119 state_ = STATE_COMPONENTS;
120 // fall through
121 case STATE_COMPONENTS:
122 if (nsId == ParseManager::NAMESPACE_OOR &&
123 name.equals("component-schema"))
125 nestedParser_ = new XcsParser(layer_, data_);
126 nesting_ = 1;
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);
134 nesting_ = 1;
135 return nestedParser_->startElement(
136 reader, nsId, name, existingDependencies);
138 break;
139 default: // STATE_DEPENDENCY
140 assert(false); // this cannot happen
141 break;
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();
153 } else {
154 switch (state_) {
155 case STATE_DEPENDENCY:
156 state_ = STATE_DEPENDENCIES;
157 break;
158 case STATE_DEPENDENCIES:
159 case STATE_COMPONENTS:
160 break;
161 default:
162 assert(false); // this cannot happen
163 break;
168 void XcdParser::characters(xmlreader::Span const & text) {
169 if (nestedParser_.is()) {
170 nestedParser_->characters(text);
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */