LCOV - code coverage report
Current view: top level - dbaccess/source/filter/xml - xmlColumn.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 54 73 74.0 %
Date: 2014-04-11 Functions: 5 5 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 "xmlColumn.hxx"
      21             : #include "xmlfilter.hxx"
      22             : #include <xmloff/xmltoken.hxx>
      23             : #include <xmloff/xmluconv.hxx>
      24             : #include <xmloff/xmlnmspe.hxx>
      25             : #include <xmloff/nmspmap.hxx>
      26             : #include "xmlEnums.hxx"
      27             : #include "xmlstrings.hrc"
      28             : #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
      29             : #include <com/sun/star/sdbcx/XAppend.hpp>
      30             : #include <com/sun/star/beans/PropertyValue.hpp>
      31             : #include <com/sun/star/container/XNameContainer.hpp>
      32             : #include <com/sun/star/container/XChild.hpp>
      33             : #include "xmlStyleImport.hxx"
      34             : #include <tools/debug.hxx>
      35             : 
      36             : namespace dbaxml
      37             : {
      38             :     using namespace ::com::sun::star::uno;
      39             :     using namespace ::com::sun::star::beans;
      40             :     using namespace ::com::sun::star::sdbcx;
      41             :     using namespace ::com::sun::star::container;
      42             :     using namespace ::com::sun::star::xml::sax;
      43             : 
      44         245 : OXMLColumn::OXMLColumn( ODBFilter& rImport
      45             :                 ,sal_uInt16 nPrfx
      46             :                 ,const OUString& _sLocalName
      47             :                 ,const Reference< XAttributeList > & _xAttrList
      48             :                 ,const Reference< XNameAccess >& _xParentContainer
      49             :                 ,const Reference< XPropertySet >& _xTable
      50             :                 ) :
      51             :     SvXMLImportContext( rImport, nPrfx, _sLocalName )
      52             :     ,m_xParentContainer(_xParentContainer)
      53             :     ,m_xTable(_xTable)
      54         245 :     ,m_bHidden(sal_False)
      55             : {
      56             : 
      57             :     OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
      58         245 :     const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
      59         245 :     const SvXMLTokenMap& rTokenMap = rImport.GetColumnElemTokenMap();
      60             : 
      61         245 :     sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
      62         245 :     OUString sType;
      63         980 :     for(sal_Int16 i = 0; i < nLength; ++i)
      64             :     {
      65         735 :         OUString sLocalName;
      66        1470 :         OUString sAttrName = _xAttrList->getNameByIndex( i );
      67         735 :         sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
      68        1470 :         OUString sValue = _xAttrList->getValueByIndex( i );
      69             : 
      70         735 :         switch( rTokenMap.Get( nPrefix, sLocalName ) )
      71             :         {
      72             :             case XML_TOK_COLUMN_NAME:
      73         245 :                 m_sName = sValue;
      74         245 :                 break;
      75             :             case XML_TOK_COLUMN_STYLE_NAME:
      76         245 :                 m_sStyleName = sValue;
      77         245 :                 break;
      78             :             case XML_TOK_COLUMN_HELP_MESSAGE:
      79           0 :                 m_sHelpMessage = sValue;
      80           0 :                 break;
      81             :             case XML_TOK_COLUMN_VISIBILITY:
      82           0 :                 m_bHidden = sValue != "visible";
      83           0 :                 break;
      84             :             case XML_TOK_COLUMN_TYPE_NAME:
      85           0 :                 sType = sValue;
      86             :                 OSL_ENSURE(!sType.isEmpty(),"No type name set");
      87           0 :                 break;
      88             :             case XML_TOK_COLUMN_DEFAULT_VALUE:
      89           0 :                 if ( !(sValue.isEmpty() || sType.isEmpty()) )
      90           0 :                     m_aDefaultValue <<= sValue;
      91           0 :                 break;
      92             :             case XML_TOK_COLUMN_VISIBLE:
      93           0 :                 m_bHidden = sValue == "false";
      94           0 :                 break;
      95             :             case XML_TOK_DEFAULT_CELL_STYLE_NAME:
      96         245 :                 m_sCellStyleName = sValue;
      97         245 :                 break;
      98             :         }
      99         980 :     }
     100         245 : }
     101             : 
     102         490 : OXMLColumn::~OXMLColumn()
     103             : {
     104             : 
     105         490 : }
     106             : 
     107         245 : void OXMLColumn::EndElement()
     108             : {
     109         245 :     Reference<XDataDescriptorFactory> xFac(m_xParentContainer,UNO_QUERY);
     110         245 :     if ( xFac.is() && !m_sName.isEmpty() )
     111             :     {
     112         245 :         Reference<XPropertySet> xProp(xFac->createDataDescriptor());
     113         245 :         if ( xProp.is() )
     114             :         {
     115         245 :             xProp->setPropertyValue(PROPERTY_NAME,makeAny(m_sName));
     116         245 :             xProp->setPropertyValue(PROPERTY_HIDDEN,makeAny(m_bHidden));
     117         245 :             if ( !m_sHelpMessage.isEmpty() )
     118           0 :                 xProp->setPropertyValue(PROPERTY_HELPTEXT,makeAny(m_sHelpMessage));
     119             : 
     120         245 :             if ( m_aDefaultValue.hasValue() )
     121           0 :                 xProp->setPropertyValue(PROPERTY_CONTROLDEFAULT,m_aDefaultValue);
     122             : 
     123         245 :             Reference<XAppend> xAppend(m_xParentContainer,UNO_QUERY);
     124         245 :             if ( xAppend.is() )
     125         245 :                 xAppend->appendByDescriptor(xProp);
     126         245 :             m_xParentContainer->getByName(m_sName) >>= xProp;
     127             : 
     128         245 :             if ( !m_sStyleName.isEmpty() )
     129             :             {
     130         245 :                 const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles();
     131         245 :                 if ( pAutoStyles )
     132             :                 {
     133         245 :                     OTableStyleContext* pAutoStyle = PTR_CAST(OTableStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_COLUMN,m_sStyleName));
     134         245 :                     if ( pAutoStyle )
     135             :                     {
     136         245 :                         pAutoStyle->FillPropertySet(xProp);
     137             :                     }
     138             :                 }
     139             :             }
     140         245 :             if ( !m_sCellStyleName.isEmpty() )
     141             :             {
     142         245 :                 const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles();
     143         245 :                 if ( pAutoStyles )
     144             :                 {
     145         245 :                     OTableStyleContext* pAutoStyle = PTR_CAST(OTableStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_CELL,m_sCellStyleName));
     146         245 :                     if ( pAutoStyle )
     147             :                     {
     148         245 :                         pAutoStyle->FillPropertySet(xProp);
     149             :                         // we also have to do this on the table to import text-properties
     150         245 :                         pAutoStyle->FillPropertySet(m_xTable);
     151             :                     }
     152             :                 }
     153         245 :             }
     154             : 
     155         245 :         }
     156             :     }
     157           0 :     else if ( !m_sCellStyleName.isEmpty() )
     158             :     {
     159           0 :         const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles();
     160           0 :         if ( pAutoStyles )
     161             :         {
     162           0 :             OTableStyleContext* pAutoStyle = PTR_CAST(OTableStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_CELL,m_sCellStyleName));
     163           0 :             if ( pAutoStyle )
     164             :             {
     165             :                 // we also have to do this on the table to import text-properties
     166           0 :                 pAutoStyle->FillPropertySet(m_xTable);
     167             :             }
     168             :         }
     169         245 :     }
     170         245 : }
     171             : 
     172         490 : ODBFilter& OXMLColumn::GetOwnImport()
     173             : {
     174         490 :     return static_cast<ODBFilter&>(GetImport());
     175             : }
     176             : 
     177             : } // namespace dbaxml
     178             : 
     179             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10