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