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

Generated by: LCOV version 1.11