LCOV - code coverage report
Current view: top level - libreoffice/xmloff/source/text - XMLSectionSourceDDEImportContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 52 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 "XMLSectionSourceDDEImportContext.hxx"
      21             : #include "XMLSectionImportContext.hxx"
      22             : #include <com/sun/star/text/SectionFileLink.hpp>
      23             : #include <xmloff/xmlictxt.hxx>
      24             : #include <xmloff/xmlimp.hxx>
      25             : #include <xmloff/txtimp.hxx>
      26             : #include <xmloff/nmspmap.hxx>
      27             : #include "xmloff/xmlnmspe.hxx"
      28             : #include <xmloff/xmltoken.hxx>
      29             : #include <sax/tools/converter.hxx>
      30             : #include <com/sun/star/uno/Reference.h>
      31             : #include <com/sun/star/beans/XPropertySet.hpp>
      32             : #include <com/sun/star/beans/XMultiPropertySet.hpp>
      33             : #include <tools/debug.hxx>
      34             : 
      35             : using ::rtl::OUString;
      36             : using ::com::sun::star::beans::XPropertySet;
      37             : using ::com::sun::star::beans::XMultiPropertySet;
      38             : using ::com::sun::star::uno::Reference;
      39             : using ::com::sun::star::xml::sax::XAttributeList;
      40             : 
      41             : using namespace ::com::sun::star::uno;
      42             : using namespace ::com::sun::star::text;
      43             : using namespace ::xmloff::token;
      44             : 
      45             : const sal_Char sAPI_DDECommandFile[] = "DDECommandFile";
      46             : const sal_Char sAPI_DDECommandType[] = "DDECommandType";
      47             : const sal_Char sAPI_DDECommandElement[] = "DDECommandElement";
      48             : const sal_Char sAPI_IsAutomaticUpdate[] = "IsAutomaticUpdate";
      49             : 
      50             : 
      51           0 : TYPEINIT1(XMLSectionSourceDDEImportContext, SvXMLImportContext);
      52             : 
      53           0 : XMLSectionSourceDDEImportContext::XMLSectionSourceDDEImportContext(
      54             :     SvXMLImport& rImport,
      55             :     sal_uInt16 nPrfx,
      56             :     const OUString& rLocalName,
      57             :     Reference<XPropertySet> & rSectPropSet) :
      58             :         SvXMLImportContext(rImport, nPrfx, rLocalName),
      59             :         rSectionPropertySet(rSectPropSet),
      60             :         sDdeCommandFile(RTL_CONSTASCII_USTRINGPARAM(sAPI_DDECommandFile)),
      61             :         sDdeCommandType(RTL_CONSTASCII_USTRINGPARAM(sAPI_DDECommandType)),
      62             :        sDdeCommandElement(RTL_CONSTASCII_USTRINGPARAM(sAPI_DDECommandElement)),
      63           0 :         sIsAutomaticUpdate(RTL_CONSTASCII_USTRINGPARAM(sAPI_IsAutomaticUpdate))
      64             : {
      65           0 : }
      66             : 
      67           0 : XMLSectionSourceDDEImportContext::~XMLSectionSourceDDEImportContext()
      68             : {
      69           0 : }
      70             : 
      71             : enum XMLSectionSourceDDEToken
      72             : {
      73             :     XML_TOK_SECTION_DDE_APPLICATION,
      74             :     XML_TOK_SECTION_DDE_TOPIC,
      75             :     XML_TOK_SECTION_DDE_ITEM,
      76             :     XML_TOK_SECTION_IS_AUTOMATIC_UPDATE
      77             : };
      78             : 
      79             : static SvXMLTokenMapEntry aSectionSourceDDETokenMap[] =
      80             : {
      81             :     { XML_NAMESPACE_OFFICE, XML_DDE_APPLICATION,
      82             :           XML_TOK_SECTION_DDE_APPLICATION },
      83             :     { XML_NAMESPACE_OFFICE, XML_DDE_TOPIC, XML_TOK_SECTION_DDE_TOPIC },
      84             :     { XML_NAMESPACE_OFFICE, XML_DDE_ITEM, XML_TOK_SECTION_DDE_ITEM },
      85             :     { XML_NAMESPACE_OFFICE, XML_AUTOMATIC_UPDATE,
      86             :           XML_TOK_SECTION_IS_AUTOMATIC_UPDATE },
      87             :     XML_TOKEN_MAP_END
      88             : };
      89             : 
      90             : 
      91           0 : void XMLSectionSourceDDEImportContext::StartElement(
      92             :     const Reference<XAttributeList> & xAttrList)
      93             : {
      94           0 :     SvXMLTokenMap aTokenMap(aSectionSourceDDETokenMap);
      95           0 :     OUString sApplication;
      96           0 :     OUString sTopic;
      97           0 :     OUString sItem;
      98           0 :     sal_Bool bAutomaticUpdate = sal_False;
      99             : 
     100           0 :     sal_Int16 nLength = xAttrList->getLength();
     101           0 :     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
     102             :     {
     103           0 :         OUString sLocalName;
     104           0 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
     105           0 :             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
     106           0 :                               &sLocalName );
     107             : 
     108           0 :         switch (aTokenMap.Get(nPrefix, sLocalName))
     109             :         {
     110             :             case XML_TOK_SECTION_DDE_APPLICATION:
     111           0 :                 sApplication = xAttrList->getValueByIndex(nAttr);
     112           0 :                 break;
     113             :             case XML_TOK_SECTION_DDE_TOPIC:
     114           0 :                 sTopic = xAttrList->getValueByIndex(nAttr);
     115           0 :                 break;
     116             :             case XML_TOK_SECTION_DDE_ITEM:
     117           0 :                 sItem = xAttrList->getValueByIndex(nAttr);
     118           0 :                 break;
     119             :             case XML_TOK_SECTION_IS_AUTOMATIC_UPDATE:
     120             :             {
     121           0 :                 bool bTmp(false);
     122           0 :                 if (::sax::Converter::convertBool(
     123           0 :                     bTmp, xAttrList->getValueByIndex(nAttr)))
     124             :                 {
     125           0 :                     bAutomaticUpdate = bTmp;
     126             :                 }
     127             :                 break;
     128             :             }
     129             :             default:
     130             :                 ; // ignore
     131           0 :                 break;
     132             :         }
     133           0 :     }
     134             : 
     135             :     // DDE not supported on all platforms; query property first
     136           0 :     if (rSectionPropertySet->getPropertySetInfo()->
     137           0 :         hasPropertyByName(sDdeCommandFile))
     138             :     {
     139             :         // use multi property set to force single update of connection #83654#
     140           0 :         Sequence<OUString> aNames(4);
     141           0 :         Sequence<Any> aValues(4);
     142             : 
     143           0 :         aValues[0] <<= sApplication;
     144           0 :         aNames[0] = sDdeCommandFile;
     145             : 
     146           0 :         aValues[1] <<= sTopic;
     147           0 :         aNames[1] = sDdeCommandType;
     148             : 
     149           0 :         aValues[2] <<= sItem;
     150           0 :         aNames[2] = sDdeCommandElement;
     151             : 
     152           0 :         aValues[3].setValue(&bAutomaticUpdate, ::getBooleanCppuType());
     153           0 :         aNames[3] = sIsAutomaticUpdate;
     154             : 
     155             :         Reference<XMultiPropertySet> rMultiPropSet(rSectionPropertySet,
     156           0 :                                                    UNO_QUERY);
     157             :         DBG_ASSERT(rMultiPropSet.is(), "we'd really like a XMultiPropertySet");
     158           0 :         if (rMultiPropSet.is())
     159           0 :             rMultiPropSet->setPropertyValues(aNames, aValues);
     160             :         // else: ignore
     161           0 :     }
     162           0 : }
     163             : 
     164           0 : void XMLSectionSourceDDEImportContext::EndElement()
     165             : {
     166             :     // nothing to be done!
     167           0 : }
     168             : 
     169           0 : SvXMLImportContext* XMLSectionSourceDDEImportContext::CreateChildContext(
     170             :     sal_uInt16 nPrefix,
     171             :     const OUString& rLocalName,
     172             :     const Reference<XAttributeList> & )
     173             : {
     174             :     // ignore -> default context
     175           0 :     return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
     176             : }
     177             : 
     178             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10