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

Generated by: LCOV version 1.10