1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*63bba73cSAndrew Rist * distributed with this work for additional information
6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at
10*63bba73cSAndrew Rist *
11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist *
13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the
17*63bba73cSAndrew Rist * specific language governing permissions and limitations
18*63bba73cSAndrew Rist * under the License.
19*63bba73cSAndrew Rist *
20*63bba73cSAndrew Rist *************************************************************/
21*63bba73cSAndrew Rist
22*63bba73cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir #include "XMLSectionSourceDDEImportContext.hxx"
27cdf0e10cSrcweir #include "XMLSectionImportContext.hxx"
28cdf0e10cSrcweir #include <com/sun/star/text/SectionFileLink.hpp>
29cdf0e10cSrcweir #include <xmloff/xmlictxt.hxx>
30cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
31cdf0e10cSrcweir #include <xmloff/txtimp.hxx>
32cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
33cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
34cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
35cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
36cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h>
37cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
38cdf0e10cSrcweir #include <com/sun/star/beans/XMultiPropertySet.hpp>
39cdf0e10cSrcweir #include <tools/debug.hxx>
40cdf0e10cSrcweir
41cdf0e10cSrcweir using ::rtl::OUString;
42cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySet;
43cdf0e10cSrcweir using ::com::sun::star::beans::XMultiPropertySet;
44cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
45cdf0e10cSrcweir using ::com::sun::star::xml::sax::XAttributeList;
46cdf0e10cSrcweir
47cdf0e10cSrcweir using namespace ::com::sun::star::uno;
48cdf0e10cSrcweir using namespace ::com::sun::star::text;
49cdf0e10cSrcweir using namespace ::xmloff::token;
50cdf0e10cSrcweir
51cdf0e10cSrcweir const sal_Char sAPI_DDECommandFile[] = "DDECommandFile";
52cdf0e10cSrcweir const sal_Char sAPI_DDECommandType[] = "DDECommandType";
53cdf0e10cSrcweir const sal_Char sAPI_DDECommandElement[] = "DDECommandElement";
54cdf0e10cSrcweir const sal_Char sAPI_IsAutomaticUpdate[] = "IsAutomaticUpdate";
55cdf0e10cSrcweir
56cdf0e10cSrcweir
57cdf0e10cSrcweir TYPEINIT1(XMLSectionSourceDDEImportContext, SvXMLImportContext);
58cdf0e10cSrcweir
XMLSectionSourceDDEImportContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLocalName,Reference<XPropertySet> & rSectPropSet)59cdf0e10cSrcweir XMLSectionSourceDDEImportContext::XMLSectionSourceDDEImportContext(
60cdf0e10cSrcweir SvXMLImport& rImport,
61cdf0e10cSrcweir sal_uInt16 nPrfx,
62cdf0e10cSrcweir const OUString& rLocalName,
63cdf0e10cSrcweir Reference<XPropertySet> & rSectPropSet) :
64cdf0e10cSrcweir SvXMLImportContext(rImport, nPrfx, rLocalName),
65cdf0e10cSrcweir rSectionPropertySet(rSectPropSet),
66cdf0e10cSrcweir sDdeCommandFile(RTL_CONSTASCII_USTRINGPARAM(sAPI_DDECommandFile)),
67cdf0e10cSrcweir sDdeCommandType(RTL_CONSTASCII_USTRINGPARAM(sAPI_DDECommandType)),
68cdf0e10cSrcweir sDdeCommandElement(RTL_CONSTASCII_USTRINGPARAM(sAPI_DDECommandElement)),
69cdf0e10cSrcweir sIsAutomaticUpdate(RTL_CONSTASCII_USTRINGPARAM(sAPI_IsAutomaticUpdate))
70cdf0e10cSrcweir {
71cdf0e10cSrcweir }
72cdf0e10cSrcweir
~XMLSectionSourceDDEImportContext()73cdf0e10cSrcweir XMLSectionSourceDDEImportContext::~XMLSectionSourceDDEImportContext()
74cdf0e10cSrcweir {
75cdf0e10cSrcweir }
76cdf0e10cSrcweir
77cdf0e10cSrcweir enum XMLSectionSourceDDEToken
78cdf0e10cSrcweir {
79cdf0e10cSrcweir XML_TOK_SECTION_DDE_APPLICATION,
80cdf0e10cSrcweir XML_TOK_SECTION_DDE_TOPIC,
81cdf0e10cSrcweir XML_TOK_SECTION_DDE_ITEM,
82cdf0e10cSrcweir XML_TOK_SECTION_IS_AUTOMATIC_UPDATE
83cdf0e10cSrcweir };
84cdf0e10cSrcweir
85cdf0e10cSrcweir static __FAR_DATA SvXMLTokenMapEntry aSectionSourceDDETokenMap[] =
86cdf0e10cSrcweir {
87cdf0e10cSrcweir { XML_NAMESPACE_OFFICE, XML_DDE_APPLICATION,
88cdf0e10cSrcweir XML_TOK_SECTION_DDE_APPLICATION },
89cdf0e10cSrcweir { XML_NAMESPACE_OFFICE, XML_DDE_TOPIC, XML_TOK_SECTION_DDE_TOPIC },
90cdf0e10cSrcweir { XML_NAMESPACE_OFFICE, XML_DDE_ITEM, XML_TOK_SECTION_DDE_ITEM },
91cdf0e10cSrcweir { XML_NAMESPACE_OFFICE, XML_AUTOMATIC_UPDATE,
92cdf0e10cSrcweir XML_TOK_SECTION_IS_AUTOMATIC_UPDATE },
93cdf0e10cSrcweir XML_TOKEN_MAP_END
94cdf0e10cSrcweir };
95cdf0e10cSrcweir
96cdf0e10cSrcweir
StartElement(const Reference<XAttributeList> & xAttrList)97cdf0e10cSrcweir void XMLSectionSourceDDEImportContext::StartElement(
98cdf0e10cSrcweir const Reference<XAttributeList> & xAttrList)
99cdf0e10cSrcweir {
100cdf0e10cSrcweir SvXMLTokenMap aTokenMap(aSectionSourceDDETokenMap);
101cdf0e10cSrcweir OUString sApplication;
102cdf0e10cSrcweir OUString sTopic;
103cdf0e10cSrcweir OUString sItem;
104cdf0e10cSrcweir sal_Bool bAutomaticUpdate = sal_False;
105cdf0e10cSrcweir
106cdf0e10cSrcweir sal_Int16 nLength = xAttrList->getLength();
107cdf0e10cSrcweir for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
108cdf0e10cSrcweir {
109cdf0e10cSrcweir OUString sLocalName;
110cdf0e10cSrcweir sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
111cdf0e10cSrcweir GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
112cdf0e10cSrcweir &sLocalName );
113cdf0e10cSrcweir
114cdf0e10cSrcweir switch (aTokenMap.Get(nPrefix, sLocalName))
115cdf0e10cSrcweir {
116cdf0e10cSrcweir case XML_TOK_SECTION_DDE_APPLICATION:
117cdf0e10cSrcweir sApplication = xAttrList->getValueByIndex(nAttr);
118cdf0e10cSrcweir break;
119cdf0e10cSrcweir case XML_TOK_SECTION_DDE_TOPIC:
120cdf0e10cSrcweir sTopic = xAttrList->getValueByIndex(nAttr);
121cdf0e10cSrcweir break;
122cdf0e10cSrcweir case XML_TOK_SECTION_DDE_ITEM:
123cdf0e10cSrcweir sItem = xAttrList->getValueByIndex(nAttr);
124cdf0e10cSrcweir break;
125cdf0e10cSrcweir case XML_TOK_SECTION_IS_AUTOMATIC_UPDATE:
126cdf0e10cSrcweir {
127cdf0e10cSrcweir sal_Bool bTmp;
128cdf0e10cSrcweir if (SvXMLUnitConverter::convertBool(
129cdf0e10cSrcweir bTmp, xAttrList->getValueByIndex(nAttr)))
130cdf0e10cSrcweir {
131cdf0e10cSrcweir bAutomaticUpdate = bTmp;
132cdf0e10cSrcweir }
133cdf0e10cSrcweir break;
134cdf0e10cSrcweir }
135cdf0e10cSrcweir default:
136cdf0e10cSrcweir ; // ignore
137cdf0e10cSrcweir break;
138cdf0e10cSrcweir }
139cdf0e10cSrcweir }
140cdf0e10cSrcweir
141cdf0e10cSrcweir // DDE not supported on all platforms; query property first
142cdf0e10cSrcweir if (rSectionPropertySet->getPropertySetInfo()->
143cdf0e10cSrcweir hasPropertyByName(sDdeCommandFile))
144cdf0e10cSrcweir {
145cdf0e10cSrcweir // use multi property set to force single update of connection #83654#
146cdf0e10cSrcweir Sequence<OUString> aNames(4);
147cdf0e10cSrcweir Sequence<Any> aValues(4);
148cdf0e10cSrcweir
149cdf0e10cSrcweir aValues[0] <<= sApplication;
150cdf0e10cSrcweir aNames[0] = sDdeCommandFile;
151cdf0e10cSrcweir
152cdf0e10cSrcweir aValues[1] <<= sTopic;
153cdf0e10cSrcweir aNames[1] = sDdeCommandType;
154cdf0e10cSrcweir
155cdf0e10cSrcweir aValues[2] <<= sItem;
156cdf0e10cSrcweir aNames[2] = sDdeCommandElement;
157cdf0e10cSrcweir
158cdf0e10cSrcweir aValues[3].setValue(&bAutomaticUpdate, ::getBooleanCppuType());
159cdf0e10cSrcweir aNames[3] = sIsAutomaticUpdate;
160cdf0e10cSrcweir
161cdf0e10cSrcweir Reference<XMultiPropertySet> rMultiPropSet(rSectionPropertySet,
162cdf0e10cSrcweir UNO_QUERY);
163cdf0e10cSrcweir DBG_ASSERT(rMultiPropSet.is(), "we'd really like a XMultiPropertySet");
164cdf0e10cSrcweir if (rMultiPropSet.is())
165cdf0e10cSrcweir rMultiPropSet->setPropertyValues(aNames, aValues);
166cdf0e10cSrcweir // else: ignore
167cdf0e10cSrcweir }
168cdf0e10cSrcweir }
169cdf0e10cSrcweir
EndElement()170cdf0e10cSrcweir void XMLSectionSourceDDEImportContext::EndElement()
171cdf0e10cSrcweir {
172cdf0e10cSrcweir // nothing to be done!
173cdf0e10cSrcweir }
174cdf0e10cSrcweir
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> &)175cdf0e10cSrcweir SvXMLImportContext* XMLSectionSourceDDEImportContext::CreateChildContext(
176cdf0e10cSrcweir sal_uInt16 nPrefix,
177cdf0e10cSrcweir const OUString& rLocalName,
178cdf0e10cSrcweir const Reference<XAttributeList> & )
179cdf0e10cSrcweir {
180cdf0e10cSrcweir // ignore -> default context
181cdf0e10cSrcweir return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
182cdf0e10cSrcweir }
183