Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / configmgr / source / xcdparser.cxx
blob0f267db95ad45d525fa26cfc133b0e0e817fc78d
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/string.h"
30 #include "rtl/ustring.h"
31 #include "rtl/ustring.hxx"
32 #include "xmlreader/span.hxx"
33 #include "xmlreader/xmlreader.hxx"
35 #include "parsemanager.hxx"
36 #include "xcdparser.hxx"
37 #include "xcsparser.hxx"
38 #include "xcuparser.hxx"
39 #include "xmldata.hxx"
41 namespace configmgr {
43 XcdParser::XcdParser(
44 int layer, std::set< OUString > const & processedDependencies, Data & data):
45 layer_(layer), processedDependencies_(processedDependencies), data_(data),
46 state_(STATE_START)
49 XcdParser::~XcdParser() {}
51 xmlreader::XmlReader::Text XcdParser::getTextMode() {
52 return nestedParser_.is()
53 ? nestedParser_->getTextMode() : xmlreader::XmlReader::TEXT_NONE;
56 bool XcdParser::startElement(
57 xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name,
58 std::set< OUString > const * existingDependencies)
60 if (nestedParser_.is()) {
61 assert(nesting_ != LONG_MAX);
62 ++nesting_;
63 return nestedParser_->startElement(
64 reader, nsId, name, existingDependencies);
66 switch (state_) {
67 case STATE_START:
68 if (nsId == ParseManager::NAMESPACE_OOR &&
69 name.equals(RTL_CONSTASCII_STRINGPARAM("data")))
71 state_ = STATE_DEPENDENCIES;
72 return true;
74 break;
75 case STATE_DEPENDENCIES:
76 if (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
77 name.equals(RTL_CONSTASCII_STRINGPARAM("dependency")))
79 if (dependencyFile_.isEmpty()) {
80 dependencyOptional_ = false;
81 xmlreader::Span attrFile;
82 for (;;) {
83 int attrNsId;
84 xmlreader::Span attrLn;
85 if (!reader.nextAttribute(&attrNsId, &attrLn)) {
86 break;
88 if (attrNsId == xmlreader::XmlReader::NAMESPACE_NONE &&
89 //TODO: _OOR
90 attrLn.equals(RTL_CONSTASCII_STRINGPARAM("file")))
92 attrFile = reader.getAttributeValue(false);
93 } else if ((attrNsId ==
94 xmlreader::XmlReader::NAMESPACE_NONE) &&
95 attrLn.equals(
96 RTL_CONSTASCII_STRINGPARAM("optional")))
98 dependencyOptional_ = xmldata::parseBoolean(
99 reader.getAttributeValue(true));
102 if (!attrFile.is()) {
103 throw css::uno::RuntimeException(
104 (rtl::OUString(
105 RTL_CONSTASCII_USTRINGPARAM(
106 "no dependency file attribute in ")) +
107 reader.getUrl()),
108 css::uno::Reference< css::uno::XInterface >());
110 dependencyFile_ = attrFile.convertFromUtf8();
111 if (dependencyFile_.isEmpty()) {
112 throw css::uno::RuntimeException(
113 (rtl::OUString(
114 RTL_CONSTASCII_USTRINGPARAM(
115 "bad dependency file attribute in ")) +
116 reader.getUrl()),
117 css::uno::Reference< css::uno::XInterface >());
120 if ((processedDependencies_.find(dependencyFile_) ==
121 processedDependencies_.end()) &&
122 (!dependencyOptional_ || existingDependencies == 0 ||
123 (existingDependencies->find(dependencyFile_) !=
124 existingDependencies->end())))
126 return false;
128 state_ = STATE_DEPENDENCY;
129 dependencyFile_ = rtl::OUString();
130 return true;
132 state_ = STATE_COMPONENTS;
133 // fall through
134 case STATE_COMPONENTS:
135 if (nsId == ParseManager::NAMESPACE_OOR &&
136 name.equals(RTL_CONSTASCII_STRINGPARAM("component-schema")))
138 nestedParser_ = new XcsParser(layer_, data_);
139 nesting_ = 1;
140 return nestedParser_->startElement(
141 reader, nsId, name, existingDependencies);
143 if (nsId == ParseManager::NAMESPACE_OOR &&
144 name.equals(RTL_CONSTASCII_STRINGPARAM("component-data")))
146 nestedParser_ = new XcuParser(layer_ + 1, data_, 0, 0, 0);
147 nesting_ = 1;
148 return nestedParser_->startElement(
149 reader, nsId, name, existingDependencies);
151 break;
152 default: // STATE_DEPENDENCY
153 assert(false); // this cannot happen
154 break;
156 throw css::uno::RuntimeException(
157 (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bad member <")) +
158 name.convertFromUtf8() +
159 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("> in ")) + reader.getUrl()),
160 css::uno::Reference< css::uno::XInterface >());
163 void XcdParser::endElement(xmlreader::XmlReader const & reader) {
164 if (nestedParser_.is()) {
165 nestedParser_->endElement(reader);
166 if (--nesting_ == 0) {
167 nestedParser_.clear();
169 } else {
170 switch (state_) {
171 case STATE_DEPENDENCY:
172 state_ = STATE_DEPENDENCIES;
173 break;
174 case STATE_DEPENDENCIES:
175 case STATE_COMPONENTS:
176 break;
177 default:
178 assert(false); // this cannot happen
179 break;
184 void XcdParser::characters(xmlreader::Span const & text) {
185 if (nestedParser_.is()) {
186 nestedParser_->characters(text);
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */