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