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

Generated by: LCOV version 1.10