2010-10-12 08:53:47 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-12 15:00:32 -05:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2009-09-08 07:59:07 -05:00
|
|
|
|
2014-05-28 08:24:46 -05:00
|
|
|
#include <sal/config.h>
|
2009-09-08 07:59:07 -05:00
|
|
|
|
2011-12-14 02:20:15 -06:00
|
|
|
#include <cassert>
|
2010-03-10 04:52:17 -06:00
|
|
|
#include <climits>
|
2012-11-29 04:23:09 -06:00
|
|
|
#include <set>
|
2009-09-08 07:59:07 -05:00
|
|
|
|
2014-05-28 08:24:46 -05:00
|
|
|
#include <com/sun/star/uno/Reference.hxx>
|
|
|
|
#include <com/sun/star/uno/RuntimeException.hpp>
|
|
|
|
#include <com/sun/star/uno/XInterface.hpp>
|
|
|
|
#include <rtl/ustring.hxx>
|
|
|
|
#include <xmlreader/span.hxx>
|
|
|
|
#include <xmlreader/xmlreader.hxx>
|
2009-09-08 07:59:07 -05:00
|
|
|
|
2010-09-10 06:09:38 -05:00
|
|
|
#include "parsemanager.hxx"
|
2009-09-08 07:59:07 -05:00
|
|
|
#include "xcdparser.hxx"
|
|
|
|
#include "xcsparser.hxx"
|
|
|
|
#include "xcuparser.hxx"
|
|
|
|
#include "xmldata.hxx"
|
|
|
|
|
|
|
|
namespace configmgr {
|
|
|
|
|
2012-11-29 04:23:09 -06:00
|
|
|
XcdParser::XcdParser(
|
|
|
|
int layer, std::set< OUString > const & processedDependencies, Data & data):
|
|
|
|
layer_(layer), processedDependencies_(processedDependencies), data_(data),
|
2013-06-20 03:07:21 -05:00
|
|
|
state_(STATE_START), dependencyOptional_(), nesting_()
|
2009-10-01 09:48:00 -05:00
|
|
|
{}
|
2009-09-08 07:59:07 -05:00
|
|
|
|
|
|
|
XcdParser::~XcdParser() {}
|
|
|
|
|
2010-09-10 06:09:38 -05:00
|
|
|
xmlreader::XmlReader::Text XcdParser::getTextMode() {
|
2009-09-08 07:59:07 -05:00
|
|
|
return nestedParser_.is()
|
2010-09-10 06:09:38 -05:00
|
|
|
? nestedParser_->getTextMode() : xmlreader::XmlReader::TEXT_NONE;
|
2009-09-08 07:59:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool XcdParser::startElement(
|
2012-11-29 04:23:09 -06:00
|
|
|
xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name,
|
|
|
|
std::set< OUString > const * existingDependencies)
|
2009-09-08 07:59:07 -05:00
|
|
|
{
|
|
|
|
if (nestedParser_.is()) {
|
2011-12-14 02:20:15 -06:00
|
|
|
assert(nesting_ != LONG_MAX);
|
2009-09-08 07:59:07 -05:00
|
|
|
++nesting_;
|
2012-11-29 04:23:09 -06:00
|
|
|
return nestedParser_->startElement(
|
|
|
|
reader, nsId, name, existingDependencies);
|
2009-09-08 07:59:07 -05:00
|
|
|
}
|
|
|
|
switch (state_) {
|
|
|
|
case STATE_START:
|
2013-05-16 02:24:31 -05:00
|
|
|
if (nsId == ParseManager::NAMESPACE_OOR && name.equals("data")) {
|
2009-09-08 07:59:07 -05:00
|
|
|
state_ = STATE_DEPENDENCIES;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STATE_DEPENDENCIES:
|
2010-09-10 06:09:38 -05:00
|
|
|
if (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
|
2013-05-16 02:24:31 -05:00
|
|
|
name.equals("dependency"))
|
2009-09-08 07:59:07 -05:00
|
|
|
{
|
2012-11-29 04:23:09 -06:00
|
|
|
if (dependencyFile_.isEmpty()) {
|
|
|
|
dependencyOptional_ = false;
|
2010-09-10 06:09:38 -05:00
|
|
|
xmlreader::Span attrFile;
|
2009-09-08 07:59:07 -05:00
|
|
|
for (;;) {
|
2010-09-10 06:09:38 -05:00
|
|
|
int attrNsId;
|
|
|
|
xmlreader::Span attrLn;
|
|
|
|
if (!reader.nextAttribute(&attrNsId, &attrLn)) {
|
2009-09-08 07:59:07 -05:00
|
|
|
break;
|
|
|
|
}
|
2010-09-10 06:09:38 -05:00
|
|
|
if (attrNsId == xmlreader::XmlReader::NAMESPACE_NONE &&
|
|
|
|
//TODO: _OOR
|
2013-05-16 02:24:31 -05:00
|
|
|
attrLn.equals("file"))
|
2009-09-08 07:59:07 -05:00
|
|
|
{
|
2009-09-08 09:25:16 -05:00
|
|
|
attrFile = reader.getAttributeValue(false);
|
2012-11-29 04:23:09 -06:00
|
|
|
} else if ((attrNsId ==
|
|
|
|
xmlreader::XmlReader::NAMESPACE_NONE) &&
|
2013-05-16 02:24:31 -05:00
|
|
|
attrLn.equals("optional"))
|
2012-11-29 04:23:09 -06:00
|
|
|
{
|
|
|
|
dependencyOptional_ = xmldata::parseBoolean(
|
|
|
|
reader.getAttributeValue(true));
|
2009-09-08 07:59:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!attrFile.is()) {
|
|
|
|
throw css::uno::RuntimeException(
|
2014-05-23 05:03:21 -05:00
|
|
|
"no dependency file attribute in " + reader.getUrl());
|
2009-09-08 07:59:07 -05:00
|
|
|
}
|
2012-11-29 04:23:09 -06:00
|
|
|
dependencyFile_ = attrFile.convertFromUtf8();
|
|
|
|
if (dependencyFile_.isEmpty()) {
|
2009-09-08 07:59:07 -05:00
|
|
|
throw css::uno::RuntimeException(
|
2014-05-23 05:03:21 -05:00
|
|
|
"bad dependency file attribute in " + reader.getUrl());
|
2009-09-08 07:59:07 -05:00
|
|
|
}
|
|
|
|
}
|
2012-11-29 04:23:09 -06:00
|
|
|
if ((processedDependencies_.find(dependencyFile_) ==
|
|
|
|
processedDependencies_.end()) &&
|
|
|
|
(!dependencyOptional_ || existingDependencies == 0 ||
|
|
|
|
(existingDependencies->find(dependencyFile_) !=
|
|
|
|
existingDependencies->end())))
|
|
|
|
{
|
2009-09-08 07:59:07 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
state_ = STATE_DEPENDENCY;
|
2013-07-23 06:09:55 -05:00
|
|
|
dependencyFile_ = "";
|
2009-09-08 07:59:07 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
state_ = STATE_COMPONENTS;
|
|
|
|
// fall through
|
|
|
|
case STATE_COMPONENTS:
|
2010-09-10 06:09:38 -05:00
|
|
|
if (nsId == ParseManager::NAMESPACE_OOR &&
|
2013-05-16 02:24:31 -05:00
|
|
|
name.equals("component-schema"))
|
2009-09-08 07:59:07 -05:00
|
|
|
{
|
|
|
|
nestedParser_ = new XcsParser(layer_, data_);
|
|
|
|
nesting_ = 1;
|
2012-11-29 04:23:09 -06:00
|
|
|
return nestedParser_->startElement(
|
|
|
|
reader, nsId, name, existingDependencies);
|
2009-09-08 07:59:07 -05:00
|
|
|
}
|
2010-09-10 06:09:38 -05:00
|
|
|
if (nsId == ParseManager::NAMESPACE_OOR &&
|
2013-05-16 02:24:31 -05:00
|
|
|
name.equals("component-data"))
|
2009-09-08 07:59:07 -05:00
|
|
|
{
|
2010-08-12 03:22:02 -05:00
|
|
|
nestedParser_ = new XcuParser(layer_ + 1, data_, 0, 0, 0);
|
2009-09-08 07:59:07 -05:00
|
|
|
nesting_ = 1;
|
2012-11-29 04:23:09 -06:00
|
|
|
return nestedParser_->startElement(
|
|
|
|
reader, nsId, name, existingDependencies);
|
2009-09-08 07:59:07 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: // STATE_DEPENDENCY
|
2011-12-14 02:20:15 -06:00
|
|
|
assert(false); // this cannot happen
|
2009-09-08 07:59:07 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
throw css::uno::RuntimeException(
|
2014-05-23 05:03:21 -05:00
|
|
|
"bad member <" + name.convertFromUtf8() + "> in " + reader.getUrl());
|
2009-09-08 07:59:07 -05:00
|
|
|
}
|
|
|
|
|
2010-09-10 06:09:38 -05:00
|
|
|
void XcdParser::endElement(xmlreader::XmlReader const & reader) {
|
2009-09-08 07:59:07 -05:00
|
|
|
if (nestedParser_.is()) {
|
|
|
|
nestedParser_->endElement(reader);
|
|
|
|
if (--nesting_ == 0) {
|
|
|
|
nestedParser_.clear();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (state_) {
|
|
|
|
case STATE_DEPENDENCY:
|
|
|
|
state_ = STATE_DEPENDENCIES;
|
|
|
|
break;
|
|
|
|
case STATE_DEPENDENCIES:
|
|
|
|
case STATE_COMPONENTS:
|
|
|
|
break;
|
|
|
|
default:
|
2011-12-14 02:20:15 -06:00
|
|
|
assert(false); // this cannot happen
|
2009-09-08 07:59:07 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-10 06:09:38 -05:00
|
|
|
void XcdParser::characters(xmlreader::Span const & text) {
|
2009-09-08 07:59:07 -05:00
|
|
|
if (nestedParser_.is()) {
|
|
|
|
nestedParser_->characters(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-10-12 08:53:47 -05:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|