LCOV - code coverage report
Current view: top level - configmgr/source - xcdparser.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 70 80 87.5 %
Date: 2014-04-11 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        3897 : XcdParser::XcdParser(
      42             :     int layer, std::set< OUString > const & processedDependencies, Data & data):
      43             :     layer_(layer), processedDependencies_(processedDependencies), data_(data),
      44        3897 :     state_(STATE_START), dependencyOptional_(), nesting_()
      45        3897 : {}
      46             : 
      47        7794 : XcdParser::~XcdParser() {}
      48             : 
      49    19642633 : xmlreader::XmlReader::Text XcdParser::getTextMode() {
      50    19642633 :     return nestedParser_.is()
      51    19642633 :         ? nestedParser_->getTextMode() : xmlreader::XmlReader::TEXT_NONE;
      52             : }
      53             : 
      54     8303166 : bool XcdParser::startElement(
      55             :     xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name,
      56             :     std::set< OUString > const * existingDependencies)
      57             : {
      58     8303166 :     if (nestedParser_.is()) {
      59             :         assert(nesting_ != LONG_MAX);
      60     8241650 :         ++nesting_;
      61     8241650 :         return nestedParser_->startElement(
      62     8241650 :             reader, nsId, name, existingDependencies);
      63             :     }
      64       61516 :     switch (state_) {
      65             :     case STATE_START:
      66        3897 :         if (nsId == ParseManager::NAMESPACE_OOR && name.equals("data")) {
      67        3897 :             state_ = STATE_DEPENDENCIES;
      68        3897 :             return true;
      69             :         }
      70           0 :         break;
      71             :     case STATE_DEPENDENCIES:
      72       15153 :         if (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
      73        5712 :             name.equals("dependency"))
      74             :         {
      75        5712 :             if (dependencyFile_.isEmpty()) {
      76        4200 :                 dependencyOptional_ = false;
      77        4200 :                 xmlreader::Span attrFile;
      78             :                 for (;;) {
      79             :                     int attrNsId;
      80        9240 :                     xmlreader::Span attrLn;
      81        9240 :                     if (!reader.nextAttribute(&attrNsId, &attrLn)) {
      82        4200 :                         break;
      83             :                     }
      84       10080 :                     if (attrNsId == xmlreader::XmlReader::NAMESPACE_NONE &&
      85             :                             //TODO: _OOR
      86        5040 :                         attrLn.equals("file"))
      87             :                     {
      88        4200 :                         attrFile = reader.getAttributeValue(false);
      89        1680 :                     } else if ((attrNsId ==
      90        1680 :                                 xmlreader::XmlReader::NAMESPACE_NONE) &&
      91         840 :                                attrLn.equals("optional"))
      92             :                     {
      93             :                         dependencyOptional_ = xmldata::parseBoolean(
      94         840 :                             reader.getAttributeValue(true));
      95             :                     }
      96        5040 :                 }
      97        4200 :                 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        4200 :                 dependencyFile_ = attrFile.convertFromUtf8();
     103        4200 :                 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       28560 :             if ((processedDependencies_.find(dependencyFile_) ==
     110       25872 :                  processedDependencies_.end()) &&
     111        1680 :                 (!dependencyOptional_ || existingDependencies == 0 ||
     112        5712 :                  (existingDependencies->find(dependencyFile_) !=
     113             :                   existingDependencies->end())))
     114             :             {
     115        1512 :                 return false;
     116             :             }
     117        4200 :             state_ = STATE_DEPENDENCY;
     118        4200 :             dependencyFile_ = "";
     119        4200 :             return true;
     120             :         }
     121        3729 :         state_ = STATE_COMPONENTS;
     122             :         // fall through
     123             :     case STATE_COMPONENTS:
     124      103814 :         if (nsId == ParseManager::NAMESPACE_OOR &&
     125       51907 :             name.equals("component-schema"))
     126             :         {
     127       17640 :             nestedParser_ = new XcsParser(layer_, data_);
     128       17640 :             nesting_ = 1;
     129       17640 :             return nestedParser_->startElement(
     130       17640 :                 reader, nsId, name, existingDependencies);
     131             :         }
     132       68534 :         if (nsId == ParseManager::NAMESPACE_OOR &&
     133       34267 :             name.equals("component-data"))
     134             :         {
     135       34267 :             nestedParser_ = new XcuParser(layer_ + 1, data_, 0, 0, 0);
     136       34267 :             nesting_ = 1;
     137       34267 :             return nestedParser_->startElement(
     138       34267 :                 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     8301654 : void XcdParser::endElement(xmlreader::XmlReader const & reader) {
     151     8301654 :     if (nestedParser_.is()) {
     152     8293557 :         nestedParser_->endElement(reader);
     153     8293557 :         if (--nesting_ == 0) {
     154       51907 :             nestedParser_.clear();
     155             :         }
     156             :     } else {
     157        8097 :         switch (state_) {
     158             :         case STATE_DEPENDENCY:
     159        4200 :             state_ = STATE_DEPENDENCIES;
     160        4200 :             break;
     161             :         case STATE_DEPENDENCIES:
     162             :         case STATE_COMPONENTS:
     163        3897 :             break;
     164             :         default:
     165             :             assert(false); // this cannot happen
     166           0 :             break;
     167             :         }
     168             :     }
     169     8301654 : }
     170             : 
     171     3035428 : void XcdParser::characters(xmlreader::Span const & text) {
     172     3035428 :     if (nestedParser_.is()) {
     173     3035428 :         nestedParser_->characters(text);
     174             :     }
     175     3035428 : }
     176             : 
     177             : }
     178             : 
     179             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10