LCOV - code coverage report
Current view: top level - libreoffice/configmgr/source - xcdparser.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 39 81 48.1 %
Date: 2012-12-27 Functions: 7 7 100.0 %
Legend: Lines: hit not hit

          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          10 : XcdParser::XcdParser(
      44             :     int layer, std::set< OUString > const & processedDependencies, Data & data):
      45             :     layer_(layer), processedDependencies_(processedDependencies), data_(data),
      46          10 :     state_(STATE_START)
      47          10 : {}
      48             : 
      49          20 : XcdParser::~XcdParser() {}
      50             : 
      51         450 : xmlreader::XmlReader::Text XcdParser::getTextMode() {
      52         450 :     return nestedParser_.is()
      53         450 :         ? nestedParser_->getTextMode() : xmlreader::XmlReader::TEXT_NONE;
      54             : }
      55             : 
      56         200 : bool XcdParser::startElement(
      57             :     xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name,
      58             :     std::set< OUString > const * existingDependencies)
      59             : {
      60         200 :     if (nestedParser_.is()) {
      61             :         assert(nesting_ != LONG_MAX);
      62         170 :         ++nesting_;
      63         170 :         return nestedParser_->startElement(
      64         170 :             reader, nsId, name, existingDependencies);
      65             :     }
      66          30 :     switch (state_) {
      67             :     case STATE_START:
      68          20 :         if (nsId == ParseManager::NAMESPACE_OOR &&
      69          10 :             name.equals(RTL_CONSTASCII_STRINGPARAM("data")))
      70             :         {
      71          10 :             state_ = STATE_DEPENDENCIES;
      72          10 :             return true;
      73             :         }
      74           0 :         break;
      75             :     case STATE_DEPENDENCIES:
      76          10 :         if (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
      77           0 :             name.equals(RTL_CONSTASCII_STRINGPARAM("dependency")))
      78             :         {
      79           0 :             if (dependencyFile_.isEmpty()) {
      80           0 :                 dependencyOptional_ = false;
      81           0 :                 xmlreader::Span attrFile;
      82           0 :                 for (;;) {
      83             :                     int attrNsId;
      84           0 :                     xmlreader::Span attrLn;
      85           0 :                     if (!reader.nextAttribute(&attrNsId, &attrLn)) {
      86             :                         break;
      87             :                     }
      88           0 :                     if (attrNsId == xmlreader::XmlReader::NAMESPACE_NONE &&
      89             :                             //TODO: _OOR
      90           0 :                         attrLn.equals(RTL_CONSTASCII_STRINGPARAM("file")))
      91             :                     {
      92           0 :                         attrFile = reader.getAttributeValue(false);
      93           0 :                     } else if ((attrNsId ==
      94             :                                 xmlreader::XmlReader::NAMESPACE_NONE) &&
      95             :                                attrLn.equals(
      96           0 :                                    RTL_CONSTASCII_STRINGPARAM("optional")))
      97             :                     {
      98             :                         dependencyOptional_ = xmldata::parseBoolean(
      99           0 :                             reader.getAttributeValue(true));
     100             :                     }
     101             :                 }
     102           0 :                 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           0 :                 dependencyFile_ = attrFile.convertFromUtf8();
     109           0 :                 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           0 :             if ((processedDependencies_.find(dependencyFile_) ==
     117           0 :                  processedDependencies_.end()) &&
     118           0 :                 (!dependencyOptional_ || existingDependencies == 0 ||
     119           0 :                  (existingDependencies->find(dependencyFile_) !=
     120           0 :                   existingDependencies->end())))
     121             :             {
     122           0 :                 return false;
     123             :             }
     124           0 :             state_ = STATE_DEPENDENCY;
     125           0 :             dependencyFile_ = OUString();
     126           0 :             return true;
     127             :         }
     128          10 :         state_ = STATE_COMPONENTS;
     129             :         // fall through
     130             :     case STATE_COMPONENTS:
     131          40 :         if (nsId == ParseManager::NAMESPACE_OOR &&
     132          20 :             name.equals(RTL_CONSTASCII_STRINGPARAM("component-schema")))
     133             :         {
     134           0 :             nestedParser_ = new XcsParser(layer_, data_);
     135           0 :             nesting_ = 1;
     136           0 :             return nestedParser_->startElement(
     137           0 :                 reader, nsId, name, existingDependencies);
     138             :         }
     139          40 :         if (nsId == ParseManager::NAMESPACE_OOR &&
     140          20 :             name.equals(RTL_CONSTASCII_STRINGPARAM("component-data")))
     141             :         {
     142          20 :             nestedParser_ = new XcuParser(layer_ + 1, data_, 0, 0, 0);
     143          20 :             nesting_ = 1;
     144          20 :             return nestedParser_->startElement(
     145          20 :                 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         200 : void XcdParser::endElement(xmlreader::XmlReader const & reader) {
     160         200 :     if (nestedParser_.is()) {
     161         190 :         nestedParser_->endElement(reader);
     162         190 :         if (--nesting_ == 0) {
     163          20 :             nestedParser_.clear();
     164             :         }
     165             :     } else {
     166          10 :         switch (state_) {
     167             :         case STATE_DEPENDENCY:
     168           0 :             state_ = STATE_DEPENDENCIES;
     169           0 :             break;
     170             :         case STATE_DEPENDENCIES:
     171             :         case STATE_COMPONENTS:
     172          10 :             break;
     173             :         default:
     174             :             assert(false); // this cannot happen
     175           0 :             break;
     176             :         }
     177             :     }
     178         200 : }
     179             : 
     180          40 : void XcdParser::characters(xmlreader::Span const & text) {
     181          40 :     if (nestedParser_.is()) {
     182          40 :         nestedParser_->characters(text);
     183             :     }
     184          40 : }
     185             : 
     186             : }
     187             : 
     188             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10