Line data Source code
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/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"
34 :
35 : #include "parsemanager.hxx"
36 : #include "xcdparser.hxx"
37 : #include "xcsparser.hxx"
38 : #include "xcuparser.hxx"
39 : #include "xmldata.hxx"
40 :
41 : namespace configmgr {
42 :
43 206 : XcdParser::XcdParser(
44 : int layer, std::set< OUString > const & processedDependencies, Data & data):
45 : layer_(layer), processedDependencies_(processedDependencies), data_(data),
46 206 : state_(STATE_START)
47 206 : {}
48 :
49 412 : XcdParser::~XcdParser() {}
50 :
51 1047294 : xmlreader::XmlReader::Text XcdParser::getTextMode() {
52 1047294 : return nestedParser_.is()
53 1047294 : ? nestedParser_->getTextMode() : xmlreader::XmlReader::TEXT_NONE;
54 : }
55 :
56 442000 : bool XcdParser::startElement(
57 : xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name,
58 : std::set< OUString > const * existingDependencies)
59 : {
60 442000 : if (nestedParser_.is()) {
61 : assert(nesting_ != LONG_MAX);
62 439382 : ++nesting_;
63 439382 : return nestedParser_->startElement(
64 439382 : reader, nsId, name, existingDependencies);
65 : }
66 2618 : switch (state_) {
67 : case STATE_START:
68 412 : if (nsId == ParseManager::NAMESPACE_OOR &&
69 206 : name.equals(RTL_CONSTASCII_STRINGPARAM("data")))
70 : {
71 206 : state_ = STATE_DEPENDENCIES;
72 206 : return true;
73 : }
74 0 : break;
75 : case STATE_DEPENDENCIES:
76 638 : if (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
77 216 : name.equals(RTL_CONSTASCII_STRINGPARAM("dependency")))
78 : {
79 216 : if (dependencyFile_.isEmpty()) {
80 184 : dependencyOptional_ = false;
81 184 : xmlreader::Span attrFile;
82 224 : for (;;) {
83 : int attrNsId;
84 408 : xmlreader::Span attrLn;
85 408 : if (!reader.nextAttribute(&attrNsId, &attrLn)) {
86 : break;
87 : }
88 448 : if (attrNsId == xmlreader::XmlReader::NAMESPACE_NONE &&
89 : //TODO: _OOR
90 224 : attrLn.equals(RTL_CONSTASCII_STRINGPARAM("file")))
91 : {
92 184 : attrFile = reader.getAttributeValue(false);
93 80 : } else if ((attrNsId ==
94 : xmlreader::XmlReader::NAMESPACE_NONE) &&
95 : attrLn.equals(
96 40 : RTL_CONSTASCII_STRINGPARAM("optional")))
97 : {
98 : dependencyOptional_ = xmldata::parseBoolean(
99 40 : reader.getAttributeValue(true));
100 : }
101 : }
102 184 : if (!attrFile.is()) {
103 : throw css::uno::RuntimeException(
104 : (OUString("no dependency file attribute in ") +
105 0 : reader.getUrl()),
106 0 : css::uno::Reference< css::uno::XInterface >());
107 : }
108 184 : dependencyFile_ = attrFile.convertFromUtf8();
109 184 : if (dependencyFile_.isEmpty()) {
110 : throw css::uno::RuntimeException(
111 : (OUString("bad dependency file attribute in ") +
112 0 : reader.getUrl()),
113 0 : css::uno::Reference< css::uno::XInterface >());
114 : }
115 : }
116 1112 : if ((processedDependencies_.find(dependencyFile_) ==
117 864 : processedDependencies_.end()) &&
118 32 : (!dependencyOptional_ || existingDependencies == 0 ||
119 0 : (existingDependencies->find(dependencyFile_) !=
120 216 : existingDependencies->end())))
121 : {
122 32 : return false;
123 : }
124 184 : state_ = STATE_DEPENDENCY;
125 184 : dependencyFile_ = OUString();
126 184 : return true;
127 : }
128 206 : state_ = STATE_COMPONENTS;
129 : // fall through
130 : case STATE_COMPONENTS:
131 4392 : if (nsId == ParseManager::NAMESPACE_OOR &&
132 2196 : name.equals(RTL_CONSTASCII_STRINGPARAM("component-schema")))
133 : {
134 800 : nestedParser_ = new XcsParser(layer_, data_);
135 800 : nesting_ = 1;
136 800 : return nestedParser_->startElement(
137 800 : reader, nsId, name, existingDependencies);
138 : }
139 2792 : if (nsId == ParseManager::NAMESPACE_OOR &&
140 1396 : name.equals(RTL_CONSTASCII_STRINGPARAM("component-data")))
141 : {
142 1396 : nestedParser_ = new XcuParser(layer_ + 1, data_, 0, 0, 0);
143 1396 : nesting_ = 1;
144 1396 : return nestedParser_->startElement(
145 1396 : reader, nsId, name, existingDependencies);
146 : }
147 0 : break;
148 : default: // STATE_DEPENDENCY
149 : assert(false); // this cannot happen
150 0 : break;
151 : }
152 : throw css::uno::RuntimeException(
153 : (OUString("bad member <") +
154 0 : name.convertFromUtf8() +
155 0 : OUString("> in ") + reader.getUrl()),
156 0 : css::uno::Reference< css::uno::XInterface >());
157 : }
158 :
159 441968 : void XcdParser::endElement(xmlreader::XmlReader const & reader) {
160 441968 : if (nestedParser_.is()) {
161 441578 : nestedParser_->endElement(reader);
162 441578 : if (--nesting_ == 0) {
163 2196 : nestedParser_.clear();
164 : }
165 : } else {
166 390 : switch (state_) {
167 : case STATE_DEPENDENCY:
168 184 : state_ = STATE_DEPENDENCIES;
169 184 : break;
170 : case STATE_DEPENDENCIES:
171 : case STATE_COMPONENTS:
172 206 : break;
173 : default:
174 : assert(false); // this cannot happen
175 0 : break;
176 : }
177 : }
178 441968 : }
179 :
180 163152 : void XcdParser::characters(xmlreader::Span const & text) {
181 163152 : if (nestedParser_.is()) {
182 163152 : nestedParser_->characters(text);
183 : }
184 163152 : }
185 :
186 : }
187 :
188 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|