LCOV - code coverage report
Current view: top level - configmgr/source - xcdparser.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 80 0.0 %
Date: 2014-04-14 Functions: 0 7 0.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/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           0 : XcdParser::XcdParser(
      42             :     int layer, std::set< OUString > const & processedDependencies, Data & data):
      43             :     layer_(layer), processedDependencies_(processedDependencies), data_(data),
      44           0 :     state_(STATE_START), dependencyOptional_(), nesting_()
      45           0 : {}
      46             : 
      47           0 : XcdParser::~XcdParser() {}
      48             : 
      49           0 : xmlreader::XmlReader::Text XcdParser::getTextMode() {
      50           0 :     return nestedParser_.is()
      51           0 :         ? nestedParser_->getTextMode() : xmlreader::XmlReader::TEXT_NONE;
      52             : }
      53             : 
      54           0 : bool XcdParser::startElement(
      55             :     xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name,
      56             :     std::set< OUString > const * existingDependencies)
      57             : {
      58           0 :     if (nestedParser_.is()) {
      59             :         assert(nesting_ != LONG_MAX);
      60           0 :         ++nesting_;
      61           0 :         return nestedParser_->startElement(
      62           0 :             reader, nsId, name, existingDependencies);
      63             :     }
      64           0 :     switch (state_) {
      65             :     case STATE_START:
      66           0 :         if (nsId == ParseManager::NAMESPACE_OOR && name.equals("data")) {
      67           0 :             state_ = STATE_DEPENDENCIES;
      68           0 :             return true;
      69             :         }
      70           0 :         break;
      71             :     case STATE_DEPENDENCIES:
      72           0 :         if (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
      73           0 :             name.equals("dependency"))
      74             :         {
      75           0 :             if (dependencyFile_.isEmpty()) {
      76           0 :                 dependencyOptional_ = false;
      77           0 :                 xmlreader::Span attrFile;
      78             :                 for (;;) {
      79             :                     int attrNsId;
      80           0 :                     xmlreader::Span attrLn;
      81           0 :                     if (!reader.nextAttribute(&attrNsId, &attrLn)) {
      82           0 :                         break;
      83             :                     }
      84           0 :                     if (attrNsId == xmlreader::XmlReader::NAMESPACE_NONE &&
      85             :                             //TODO: _OOR
      86           0 :                         attrLn.equals("file"))
      87             :                     {
      88           0 :                         attrFile = reader.getAttributeValue(false);
      89           0 :                     } else if ((attrNsId ==
      90           0 :                                 xmlreader::XmlReader::NAMESPACE_NONE) &&
      91           0 :                                attrLn.equals("optional"))
      92             :                     {
      93             :                         dependencyOptional_ = xmldata::parseBoolean(
      94           0 :                             reader.getAttributeValue(true));
      95             :                     }
      96           0 :                 }
      97           0 :                 if (!attrFile.is()) {
      98             :                     throw css::uno::RuntimeException(
      99           0 :                         "no dependency file attribute in " + reader.getUrl(),
     100           0 :                         css::uno::Reference< css::uno::XInterface >());
     101             :                 }
     102           0 :                 dependencyFile_ = attrFile.convertFromUtf8();
     103           0 :                 if (dependencyFile_.isEmpty()) {
     104             :                     throw css::uno::RuntimeException(
     105           0 :                         "bad dependency file attribute in " + reader.getUrl(),
     106           0 :                         css::uno::Reference< css::uno::XInterface >());
     107             :                 }
     108             :             }
     109           0 :             if ((processedDependencies_.find(dependencyFile_) ==
     110           0 :                  processedDependencies_.end()) &&
     111           0 :                 (!dependencyOptional_ || existingDependencies == 0 ||
     112           0 :                  (existingDependencies->find(dependencyFile_) !=
     113             :                   existingDependencies->end())))
     114             :             {
     115           0 :                 return false;
     116             :             }
     117           0 :             state_ = STATE_DEPENDENCY;
     118           0 :             dependencyFile_ = "";
     119           0 :             return true;
     120             :         }
     121           0 :         state_ = STATE_COMPONENTS;
     122             :         // fall through
     123             :     case STATE_COMPONENTS:
     124           0 :         if (nsId == ParseManager::NAMESPACE_OOR &&
     125           0 :             name.equals("component-schema"))
     126             :         {
     127           0 :             nestedParser_ = new XcsParser(layer_, data_);
     128           0 :             nesting_ = 1;
     129           0 :             return nestedParser_->startElement(
     130           0 :                 reader, nsId, name, existingDependencies);
     131             :         }
     132           0 :         if (nsId == ParseManager::NAMESPACE_OOR &&
     133           0 :             name.equals("component-data"))
     134             :         {
     135           0 :             nestedParser_ = new XcuParser(layer_ + 1, data_, 0, 0, 0);
     136           0 :             nesting_ = 1;
     137           0 :             return nestedParser_->startElement(
     138           0 :                 reader, nsId, name, existingDependencies);
     139             :         }
     140           0 :         break;
     141             :     default: // STATE_DEPENDENCY
     142             :         assert(false); // this cannot happen
     143           0 :         break;
     144             :     }
     145             :     throw css::uno::RuntimeException(
     146           0 :         "bad member <" + name.convertFromUtf8() + "> in " + reader.getUrl(),
     147           0 :         css::uno::Reference< css::uno::XInterface >());
     148             : }
     149             : 
     150           0 : void XcdParser::endElement(xmlreader::XmlReader const & reader) {
     151           0 :     if (nestedParser_.is()) {
     152           0 :         nestedParser_->endElement(reader);
     153           0 :         if (--nesting_ == 0) {
     154           0 :             nestedParser_.clear();
     155             :         }
     156             :     } else {
     157           0 :         switch (state_) {
     158             :         case STATE_DEPENDENCY:
     159           0 :             state_ = STATE_DEPENDENCIES;
     160           0 :             break;
     161             :         case STATE_DEPENDENCIES:
     162             :         case STATE_COMPONENTS:
     163           0 :             break;
     164             :         default:
     165             :             assert(false); // this cannot happen
     166           0 :             break;
     167             :         }
     168             :     }
     169           0 : }
     170             : 
     171           0 : void XcdParser::characters(xmlreader::Span const & text) {
     172           0 :     if (nestedParser_.is()) {
     173           0 :         nestedParser_->characters(text);
     174             :     }
     175           0 : }
     176             : 
     177             : }
     178             : 
     179             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10