LCOV - code coverage report
Current view: top level - configmgr/source - xcdparser.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 61 66 92.4 %
Date: 2012-08-25 Functions: 7 7 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 49 95 51.6 %

           Branch data     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                 :            : 
      25                 :            : #include "com/sun/star/uno/Reference.hxx"
      26                 :            : #include "com/sun/star/uno/RuntimeException.hpp"
      27                 :            : #include "com/sun/star/uno/XInterface.hpp"
      28                 :            : #include "rtl/string.h"
      29                 :            : #include "rtl/ustring.h"
      30                 :            : #include "rtl/ustring.hxx"
      31                 :            : #include "xmlreader/span.hxx"
      32                 :            : #include "xmlreader/xmlreader.hxx"
      33                 :            : 
      34                 :            : #include "parsemanager.hxx"
      35                 :            : #include "xcdparser.hxx"
      36                 :            : #include "xcsparser.hxx"
      37                 :            : #include "xcuparser.hxx"
      38                 :            : #include "xmldata.hxx"
      39                 :            : 
      40                 :            : namespace configmgr {
      41                 :            : 
      42                 :            : namespace {
      43                 :            : 
      44                 :            : namespace css = com::sun::star;
      45                 :            : 
      46                 :            : }
      47                 :            : 
      48                 :       2954 : XcdParser::XcdParser(int layer, Dependencies const & dependencies, Data & data):
      49                 :       2954 :     layer_(layer), dependencies_(dependencies), data_(data), state_(STATE_START)
      50                 :       2954 : {}
      51                 :            : 
      52 [ +  - ][ -  + ]:       5908 : XcdParser::~XcdParser() {}
      53                 :            : 
      54                 :   20224770 : xmlreader::XmlReader::Text XcdParser::getTextMode() {
      55                 :   20224770 :     return nestedParser_.is()
      56         [ +  + ]:   20224770 :         ? nestedParser_->getTextMode() : xmlreader::XmlReader::TEXT_NONE;
      57                 :            : }
      58                 :            : 
      59                 :    8534280 : bool XcdParser::startElement(
      60                 :            :     xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name)
      61                 :            : {
      62         [ +  + ]:    8534280 :     if (nestedParser_.is()) {
      63                 :            :         assert(nesting_ != LONG_MAX);
      64                 :    8487978 :         ++nesting_;
      65                 :    8487978 :         return nestedParser_->startElement(reader, nsId, name);
      66                 :            :     }
      67   [ +  +  +  - ]:      46302 :     switch (state_) {
      68                 :            :     case STATE_START:
      69   [ +  -  +  - ]:       5908 :         if (nsId == ParseManager::NAMESPACE_OOR &&
                 [ +  - ]
      70                 :       2954 :             name.equals(RTL_CONSTASCII_STRINGPARAM("data")))
      71                 :            :         {
      72                 :       2954 :             state_ = STATE_DEPENDENCIES;
      73                 :       2954 :             return true;
      74                 :            :         }
      75                 :          0 :         break;
      76                 :            :     case STATE_DEPENDENCIES:
      77   [ +  +  +  - ]:       8714 :         if (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
                 [ +  + ]
      78                 :       2880 :             name.equals(RTL_CONSTASCII_STRINGPARAM("dependency")))
      79                 :            :         {
      80         [ +  + ]:       2880 :             if (dependency_.isEmpty()) {
      81                 :       2560 :                 xmlreader::Span attrFile;
      82                 :       2560 :                 for (;;) {
      83                 :            :                     int attrNsId;
      84                 :       5120 :                     xmlreader::Span attrLn;
      85 [ +  + ][ +  - ]:       5120 :                     if (!reader.nextAttribute(&attrNsId, &attrLn)) {
      86                 :            :                         break;
      87                 :            :                     }
      88   [ +  -  +  - ]:       5120 :                     if (attrNsId == xmlreader::XmlReader::NAMESPACE_NONE &&
                 [ +  - ]
      89                 :            :                             //TODO: _OOR
      90                 :       2560 :                         attrLn.equals(RTL_CONSTASCII_STRINGPARAM("file")))
      91                 :            :                     {
      92         [ +  - ]:       2560 :                         attrFile = reader.getAttributeValue(false);
      93                 :            :                     }
      94                 :            :                 }
      95         [ -  + ]:       2560 :                 if (!attrFile.is()) {
      96                 :            :                     throw css::uno::RuntimeException(
      97                 :            :                         (rtl::OUString(
      98                 :            :                             RTL_CONSTASCII_USTRINGPARAM(
      99                 :            :                                 "no dependency file attribute in ")) +
     100                 :            :                          reader.getUrl()),
     101 [ #  # ][ #  # ]:          0 :                         css::uno::Reference< css::uno::XInterface >());
                 [ #  # ]
     102                 :            :                 }
     103         [ +  - ]:       2560 :                 dependency_ = attrFile.convertFromUtf8();
     104         [ -  + ]:       2560 :                 if (dependency_.isEmpty()) {
     105                 :            :                     throw css::uno::RuntimeException(
     106                 :            :                         (rtl::OUString(
     107                 :            :                             RTL_CONSTASCII_USTRINGPARAM(
     108                 :            :                                 "bad dependency file attribute in ")) +
     109                 :            :                          reader.getUrl()),
     110 [ #  # ][ #  # ]:       2560 :                         css::uno::Reference< css::uno::XInterface >());
                 [ #  # ]
     111                 :            :                 }
     112                 :            :             }
     113 [ +  - ][ +  + ]:       2880 :             if (dependencies_.find(dependency_) == dependencies_.end()) {
     114                 :        320 :                 return false;
     115                 :            :             }
     116                 :       2560 :             state_ = STATE_DEPENDENCY;
     117                 :       2560 :             dependency_ = rtl::OUString();
     118                 :       2560 :             return true;
     119                 :            :         }
     120                 :       2954 :         state_ = STATE_COMPONENTS;
     121                 :            :         // fall through
     122                 :            :     case STATE_COMPONENTS:
     123   [ +  -  +  + ]:      80936 :         if (nsId == ParseManager::NAMESPACE_OOR &&
                 [ +  + ]
     124                 :      40468 :             name.equals(RTL_CONSTASCII_STRINGPARAM("component-schema")))
     125                 :            :         {
     126         [ +  - ]:      15680 :             nestedParser_ = new XcsParser(layer_, data_);
     127                 :      15680 :             nesting_ = 1;
     128                 :      15680 :             return nestedParser_->startElement(reader, nsId, name);
     129                 :            :         }
     130   [ +  -  +  - ]:      49576 :         if (nsId == ParseManager::NAMESPACE_OOR &&
                 [ +  - ]
     131                 :      24788 :             name.equals(RTL_CONSTASCII_STRINGPARAM("component-data")))
     132                 :            :         {
     133         [ +  - ]:      24788 :             nestedParser_ = new XcuParser(layer_ + 1, data_, 0, 0, 0);
     134                 :      24788 :             nesting_ = 1;
     135                 :      24788 :             return nestedParser_->startElement(reader, nsId, name);
     136                 :            :         }
     137                 :          0 :         break;
     138                 :            :     default: // STATE_DEPENDENCY
     139                 :            :         assert(false); // this cannot happen
     140                 :          0 :         break;
     141                 :            :     }
     142                 :            :     throw css::uno::RuntimeException(
     143                 :            :         (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bad member <")) +
     144                 :            :          name.convertFromUtf8() +
     145                 :            :          rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("> in ")) + reader.getUrl()),
     146 [ #  # ][ #  # ]:    8534280 :         css::uno::Reference< css::uno::XInterface >());
         [ #  # ][ #  # ]
                 [ #  # ]
     147                 :            : }
     148                 :            : 
     149                 :    8533960 : void XcdParser::endElement(xmlreader::XmlReader const & reader) {
     150         [ +  + ]:    8533960 :     if (nestedParser_.is()) {
     151                 :    8528446 :         nestedParser_->endElement(reader);
     152         [ +  + ]:    8528446 :         if (--nesting_ == 0) {
     153                 :      40468 :             nestedParser_.clear();
     154                 :            :         }
     155                 :            :     } else {
     156      [ +  +  - ]:       5514 :         switch (state_) {
     157                 :            :         case STATE_DEPENDENCY:
     158                 :       2560 :             state_ = STATE_DEPENDENCIES;
     159                 :       2560 :             break;
     160                 :            :         case STATE_DEPENDENCIES:
     161                 :            :         case STATE_COMPONENTS:
     162                 :       2954 :             break;
     163                 :            :         default:
     164                 :            :             assert(false); // this cannot happen
     165                 :          0 :             break;
     166                 :            :         }
     167                 :            :     }
     168                 :    8533960 : }
     169                 :            : 
     170                 :    3153896 : void XcdParser::characters(xmlreader::Span const & text) {
     171         [ +  - ]:    3153896 :     if (nestedParser_.is()) {
     172                 :    3153896 :         nestedParser_->characters(text);
     173                 :            :     }
     174                 :    3153896 : }
     175                 :            : 
     176                 :            : }
     177                 :            : 
     178                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10