1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
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
;
40 using namespace ::com::sun::star::uno
;
41 using namespace ::com::sun::star::text
;
42 using namespace ::xmloff::token
;
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";
50 TYPEINIT1(XMLSectionSourceDDEImportContext
, SvXMLImportContext
);
52 XMLSectionSourceDDEImportContext::XMLSectionSourceDDEImportContext(
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 sIsAutomaticUpdate(sAPI_IsAutomaticUpdate
)
66 XMLSectionSourceDDEImportContext::~XMLSectionSourceDDEImportContext()
70 enum XMLSectionSourceDDEToken
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
78 static const SvXMLTokenMapEntry aSectionSourceDDETokenMap
[] =
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
},
90 void XMLSectionSourceDDEImportContext::StartElement(
91 const Reference
<XAttributeList
> & xAttrList
)
93 SvXMLTokenMap
aTokenMap(aSectionSourceDDETokenMap
);
94 OUString sApplication
;
97 sal_Bool bAutomaticUpdate
= sal_False
;
99 sal_Int16 nLength
= xAttrList
->getLength();
100 for(sal_Int16 nAttr
= 0; nAttr
< nLength
; nAttr
++)
103 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
104 GetKeyByAttrName( xAttrList
->getNameByIndex(nAttr
),
107 switch (aTokenMap
.Get(nPrefix
, sLocalName
))
109 case XML_TOK_SECTION_DDE_APPLICATION
:
110 sApplication
= xAttrList
->getValueByIndex(nAttr
);
112 case XML_TOK_SECTION_DDE_TOPIC
:
113 sTopic
= xAttrList
->getValueByIndex(nAttr
);
115 case XML_TOK_SECTION_DDE_ITEM
:
116 sItem
= xAttrList
->getValueByIndex(nAttr
);
118 case XML_TOK_SECTION_IS_AUTOMATIC_UPDATE
:
121 if (::sax::Converter::convertBool(
122 bTmp
, xAttrList
->getValueByIndex(nAttr
)))
124 bAutomaticUpdate
= bTmp
;
134 // DDE not supported on all platforms; query property first
135 if (rSectionPropertySet
->getPropertySetInfo()->
136 hasPropertyByName(sDdeCommandFile
))
138 // use multi property set to force single update of connection #83654#
139 Sequence
<OUString
> aNames(4);
140 Sequence
<Any
> aValues(4);
142 aValues
[0] <<= sApplication
;
143 aNames
[0] = sDdeCommandFile
;
145 aValues
[1] <<= sTopic
;
146 aNames
[1] = sDdeCommandType
;
148 aValues
[2] <<= sItem
;
149 aNames
[2] = sDdeCommandElement
;
151 aValues
[3].setValue(&bAutomaticUpdate
, cppu::UnoType
<bool>::get());
152 aNames
[3] = sIsAutomaticUpdate
;
154 Reference
<XMultiPropertySet
> rMultiPropSet(rSectionPropertySet
,
156 DBG_ASSERT(rMultiPropSet
.is(), "we'd really like a XMultiPropertySet");
157 if (rMultiPropSet
.is())
158 rMultiPropSet
->setPropertyValues(aNames
, aValues
);
163 void XMLSectionSourceDDEImportContext::EndElement()
165 // nothing to be done!
168 SvXMLImportContext
* XMLSectionSourceDDEImportContext::CreateChildContext(
170 const OUString
& rLocalName
,
171 const Reference
<XAttributeList
> & )
173 // ignore -> default context
174 return new SvXMLImportContext(GetImport(), nPrefix
, rLocalName
);
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */