LCOV - code coverage report
Current view: top level - xmloff/source/transform - FormPropOASISTContext.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 100 0.0 %
Date: 2014-04-14 Functions: 0 11 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 "MutableAttrList.hxx"
      21             : #include <xmloff/xmlnmspe.hxx>
      22             : #include <xmloff/nmspmap.hxx>
      23             : #include "ActionMapTypesOASIS.hxx"
      24             : #include "AttrTransformerAction.hxx"
      25             : #include "TransformerActions.hxx"
      26             : #include "TransformerBase.hxx"
      27             : #include "FormPropOASISTContext.hxx"
      28             : 
      29             : using namespace ::com::sun::star::uno;
      30             : using namespace ::com::sun::star::xml::sax;
      31             : using namespace ::xmloff::token;
      32             : 
      33           0 : TYPEINIT1( XMLFormPropOASISTransformerContext,
      34             :                 XMLRenameElemTransformerContext );
      35             : 
      36           0 : XMLTokenEnum XMLFormPropOASISTransformerContext::GetValueType(
      37             :                 const OUString& rValue )
      38             : {
      39           0 :     XMLTokenEnum eRet = XML_DOUBLE;
      40           0 :     sal_Bool bNeg = sal_False;
      41           0 :     sal_uInt32 nVal = 0;
      42             : 
      43           0 :     sal_Int32 nPos = 0;
      44           0 :     sal_Int32 nLen = rValue.getLength();
      45             : 
      46             :     // skip white space
      47           0 :     while( nPos < nLen && ' ' == rValue[nPos] )
      48           0 :         nPos++;
      49             : 
      50           0 :     if( nPos < nLen && '-' == rValue[nPos] )
      51             :     {
      52           0 :         bNeg = sal_True;
      53           0 :         nPos++;
      54             :     }
      55             : 
      56             :     // get number
      57           0 :     bool bOverflow = false;
      58           0 :     while( nPos < nLen &&
      59           0 :            '0' <= rValue[nPos] &&
      60           0 :            '9' >= rValue[nPos] )
      61             :     {
      62           0 :         nVal *= 10;
      63           0 :         nVal += (rValue[nPos] - '0');
      64           0 :         bOverflow |= (nVal > (bNeg ? 2147483648UL : 2147483647UL));
      65           0 :         nPos++;
      66             :     }
      67             : 
      68             :     // skip white space
      69           0 :     while( nPos < nLen && ' ' == rValue[nPos] )
      70           0 :         nPos++;
      71             : 
      72           0 :     if( nPos == nLen )
      73             :     {
      74             :         // It's a integer number
      75           0 :         if( bOverflow )
      76           0 :             eRet = XML_LONG;
      77           0 :         else if( nVal > (bNeg ? 32768UL : 32767UL) )
      78           0 :             eRet = XML_INT;
      79             :         else
      80           0 :             eRet = XML_SHORT;
      81             :     }
      82             : 
      83           0 :     return eRet;
      84             : }
      85             : 
      86           0 : XMLFormPropOASISTransformerContext::XMLFormPropOASISTransformerContext(
      87             :         XMLTransformerBase& rImp,
      88             :         const OUString& rQName,
      89             :         XMLTokenEnum eLocalName ) :
      90             :     XMLRenameElemTransformerContext( rImp, rQName, XML_NAMESPACE_FORM,
      91             :                                        XML_PROPERTY ),
      92           0 :     m_bIsList( XML_LIST_PROPERTY == eLocalName),
      93           0 :     m_bIsListValue( XML_LIST_VALUE == eLocalName)
      94             : {
      95           0 : }
      96             : 
      97           0 : XMLFormPropOASISTransformerContext::~XMLFormPropOASISTransformerContext()
      98             : {
      99           0 : }
     100             : 
     101           0 : void XMLFormPropOASISTransformerContext::StartElement(
     102             :     const Reference< XAttributeList >& rAttrList )
     103             : {
     104             : 
     105             :     XMLTransformerActions *pActions =
     106           0 :         GetTransformer().GetUserDefinedActions( OASIS_FORM_PROP_ACTIONS );
     107             :     OSL_ENSURE( pActions, "go no actions" );
     108             : 
     109             :     XMLMutableAttributeList *pMutableAttrList =
     110           0 :         new XMLMutableAttributeList( rAttrList );
     111           0 :     Reference< XAttributeList > xAttrList( pMutableAttrList );
     112             : 
     113           0 :     sal_Int16 nValueTypeAttr = -1;
     114           0 :     OUString aValue;
     115           0 :     sal_Bool bIsVoid = sal_False;
     116           0 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     117           0 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
     118             :     {
     119           0 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
     120           0 :         OUString aLocalName;
     121             :         sal_uInt16 nPrefix =
     122           0 :             GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
     123           0 :                                                                  &aLocalName );
     124           0 :         XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
     125             :         XMLTransformerActions::const_iterator aIter =
     126           0 :             pActions->find( aKey );
     127           0 :         if( !(aIter == pActions->end() ) )
     128             :         {
     129           0 :             const OUString& rAttrValue = xAttrList->getValueByIndex( i );
     130           0 :             switch( (*aIter).second.m_nActionType )
     131             :             {
     132             :             case XML_ATACTION_RENAME:
     133           0 :                 if( IsXMLToken( aLocalName, XML_VALUE_TYPE ) )
     134             :                 {
     135           0 :                     if( IsXMLToken( rAttrValue, XML_FLOAT ) )
     136             :                     {
     137           0 :                         nValueTypeAttr = i;
     138             :                     }
     139           0 :                     else if( IsXMLToken( rAttrValue, XML_VOID ) )
     140             :                     {
     141             :                         pMutableAttrList->SetValueByIndex( i,
     142           0 :                                 GetXMLToken( XML_SHORT ) );
     143           0 :                         bIsVoid = sal_True;
     144             :                     }
     145             :                 }
     146             :                 {
     147             :                     OUString aNewAttrQName(
     148           0 :                         GetTransformer().GetNamespaceMap().GetQNameByKey(
     149           0 :                                 (*aIter).second.GetQNamePrefixFromParam1(),
     150             :                                 ::xmloff::token::GetXMLToken(
     151           0 :                                     (*aIter).second.GetQNameTokenFromParam1()) ) );
     152           0 :                     pMutableAttrList->RenameAttributeByIndex( i, aNewAttrQName );
     153             :                 }
     154           0 :                 break;
     155             :             case XML_ATACTION_REMOVE:
     156           0 :                 if( !IsXMLToken( aLocalName, XML_CURRENCY ) )
     157           0 :                     aValue = rAttrValue;
     158           0 :                 pMutableAttrList->RemoveAttributeByIndex( i );
     159           0 :                 --i;
     160           0 :                 --nAttrCount;
     161           0 :                 break;
     162             :             default:
     163             :                 OSL_ENSURE( !this, "unknown action" );
     164           0 :                 break;
     165           0 :             }
     166             :         }
     167           0 :     }
     168           0 :     if( m_bIsList )
     169             :     {
     170             :         OUString aNewAttrQName(
     171           0 :                 GetTransformer().GetNamespaceMap().GetQNameByKey(
     172             :                     XML_NAMESPACE_FORM,
     173           0 :                     GetXMLToken( XML_PROPERTY_IS_LIST ) ) );
     174             :         pMutableAttrList->AddAttribute( aNewAttrQName,
     175           0 :                                         GetXMLToken( XML_TRUE ) );
     176             :     }
     177             : 
     178           0 :     if( nValueTypeAttr != -1 )
     179             :         pMutableAttrList->SetValueByIndex( nValueTypeAttr,
     180           0 :                                 GetXMLToken( GetValueType( aValue ) ) );
     181             : 
     182           0 :     if( !m_bIsListValue )
     183           0 :         XMLRenameElemTransformerContext::StartElement( xAttrList );
     184           0 :     if( !m_bIsList )
     185             :     {
     186             :         pMutableAttrList =
     187           0 :             new XMLMutableAttributeList;
     188           0 :         xAttrList = pMutableAttrList;
     189           0 :         if( bIsVoid )
     190             :         {
     191             :             OUString aNewAttrQName(
     192           0 :                 GetTransformer().GetNamespaceMap().GetQNameByKey(
     193           0 :                     XML_NAMESPACE_FORM, GetXMLToken( XML_PROPERTY_IS_VOID ) ) );
     194             :             pMutableAttrList->AddAttribute( aNewAttrQName,
     195           0 :                                         GetXMLToken( XML_TRUE ) );
     196             :         }
     197             : 
     198             :         OUString aValueElemQName(
     199           0 :             GetTransformer().GetNamespaceMap().GetQNameByKey(
     200           0 :                     XML_NAMESPACE_FORM, GetXMLToken( XML_PROPERTY_VALUE ) ) );
     201           0 :         GetTransformer().GetDocHandler()->startElement( aValueElemQName,
     202           0 :                                                         xAttrList );
     203           0 :         GetTransformer().GetDocHandler()->characters( aValue );
     204           0 :         GetTransformer().GetDocHandler()->endElement( aValueElemQName );
     205           0 :     }
     206           0 : }
     207             : 
     208           0 : void XMLFormPropOASISTransformerContext::EndElement()
     209             : {
     210           0 :     if( !m_bIsListValue )
     211           0 :         XMLRenameElemTransformerContext::EndElement();
     212           0 : }
     213             : 
     214             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10