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