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

Generated by: LCOV version 1.10