xref: /trunk/main/xmloff/source/text/XMLSectionSourceDDEImportContext.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 #include "XMLSectionSourceDDEImportContext.hxx"
31 #include "XMLSectionImportContext.hxx"
32 #include <com/sun/star/text/SectionFileLink.hpp>
33 #include <xmloff/xmlictxt.hxx>
34 #include <xmloff/xmlimp.hxx>
35 #include <xmloff/txtimp.hxx>
36 #include <xmloff/nmspmap.hxx>
37 #include "xmloff/xmlnmspe.hxx"
38 #include <xmloff/xmltoken.hxx>
39 #include <xmloff/xmluconv.hxx>
40 #include <com/sun/star/uno/Reference.h>
41 #include <com/sun/star/beans/XPropertySet.hpp>
42 #include <com/sun/star/beans/XMultiPropertySet.hpp>
43 #include <tools/debug.hxx>
44 
45 using ::rtl::OUString;
46 using ::com::sun::star::beans::XPropertySet;
47 using ::com::sun::star::beans::XMultiPropertySet;
48 using ::com::sun::star::uno::Reference;
49 using ::com::sun::star::xml::sax::XAttributeList;
50 
51 using namespace ::com::sun::star::uno;
52 using namespace ::com::sun::star::text;
53 using namespace ::xmloff::token;
54 
55 const sal_Char sAPI_DDECommandFile[] = "DDECommandFile";
56 const sal_Char sAPI_DDECommandType[] = "DDECommandType";
57 const sal_Char sAPI_DDECommandElement[] = "DDECommandElement";
58 const sal_Char sAPI_IsAutomaticUpdate[] = "IsAutomaticUpdate";
59 
60 
61 TYPEINIT1(XMLSectionSourceDDEImportContext, SvXMLImportContext);
62 
63 XMLSectionSourceDDEImportContext::XMLSectionSourceDDEImportContext(
64     SvXMLImport& rImport,
65     sal_uInt16 nPrfx,
66     const OUString& rLocalName,
67     Reference<XPropertySet> & rSectPropSet) :
68         SvXMLImportContext(rImport, nPrfx, rLocalName),
69         rSectionPropertySet(rSectPropSet),
70         sDdeCommandFile(RTL_CONSTASCII_USTRINGPARAM(sAPI_DDECommandFile)),
71         sDdeCommandType(RTL_CONSTASCII_USTRINGPARAM(sAPI_DDECommandType)),
72        sDdeCommandElement(RTL_CONSTASCII_USTRINGPARAM(sAPI_DDECommandElement)),
73         sIsAutomaticUpdate(RTL_CONSTASCII_USTRINGPARAM(sAPI_IsAutomaticUpdate))
74 {
75 }
76 
77 XMLSectionSourceDDEImportContext::~XMLSectionSourceDDEImportContext()
78 {
79 }
80 
81 enum XMLSectionSourceDDEToken
82 {
83     XML_TOK_SECTION_DDE_APPLICATION,
84     XML_TOK_SECTION_DDE_TOPIC,
85     XML_TOK_SECTION_DDE_ITEM,
86     XML_TOK_SECTION_IS_AUTOMATIC_UPDATE
87 };
88 
89 static __FAR_DATA SvXMLTokenMapEntry aSectionSourceDDETokenMap[] =
90 {
91     { XML_NAMESPACE_OFFICE, XML_DDE_APPLICATION,
92           XML_TOK_SECTION_DDE_APPLICATION },
93     { XML_NAMESPACE_OFFICE, XML_DDE_TOPIC, XML_TOK_SECTION_DDE_TOPIC },
94     { XML_NAMESPACE_OFFICE, XML_DDE_ITEM, XML_TOK_SECTION_DDE_ITEM },
95     { XML_NAMESPACE_OFFICE, XML_AUTOMATIC_UPDATE,
96           XML_TOK_SECTION_IS_AUTOMATIC_UPDATE },
97     XML_TOKEN_MAP_END
98 };
99 
100 
101 void XMLSectionSourceDDEImportContext::StartElement(
102     const Reference<XAttributeList> & xAttrList)
103 {
104     SvXMLTokenMap aTokenMap(aSectionSourceDDETokenMap);
105     OUString sApplication;
106     OUString sTopic;
107     OUString sItem;
108     sal_Bool bAutomaticUpdate = sal_False;
109 
110     sal_Int16 nLength = xAttrList->getLength();
111     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
112     {
113         OUString sLocalName;
114         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
115             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
116                               &sLocalName );
117 
118         switch (aTokenMap.Get(nPrefix, sLocalName))
119         {
120             case XML_TOK_SECTION_DDE_APPLICATION:
121                 sApplication = xAttrList->getValueByIndex(nAttr);
122                 break;
123             case XML_TOK_SECTION_DDE_TOPIC:
124                 sTopic = xAttrList->getValueByIndex(nAttr);
125                 break;
126             case XML_TOK_SECTION_DDE_ITEM:
127                 sItem = xAttrList->getValueByIndex(nAttr);
128                 break;
129             case XML_TOK_SECTION_IS_AUTOMATIC_UPDATE:
130             {
131                 sal_Bool bTmp;
132                 if (SvXMLUnitConverter::convertBool(
133                     bTmp, xAttrList->getValueByIndex(nAttr)))
134                 {
135                     bAutomaticUpdate = bTmp;
136                 }
137                 break;
138             }
139             default:
140                 ; // ignore
141                 break;
142         }
143     }
144 
145     // DDE not supported on all platforms; query property first
146     if (rSectionPropertySet->getPropertySetInfo()->
147         hasPropertyByName(sDdeCommandFile))
148     {
149         // use multi property set to force single update of connection #83654#
150         Sequence<OUString> aNames(4);
151         Sequence<Any> aValues(4);
152 
153         aValues[0] <<= sApplication;
154         aNames[0] = sDdeCommandFile;
155 
156         aValues[1] <<= sTopic;
157         aNames[1] = sDdeCommandType;
158 
159         aValues[2] <<= sItem;
160         aNames[2] = sDdeCommandElement;
161 
162         aValues[3].setValue(&bAutomaticUpdate, ::getBooleanCppuType());
163         aNames[3] = sIsAutomaticUpdate;
164 
165         Reference<XMultiPropertySet> rMultiPropSet(rSectionPropertySet,
166                                                    UNO_QUERY);
167         DBG_ASSERT(rMultiPropSet.is(), "we'd really like a XMultiPropertySet");
168         if (rMultiPropSet.is())
169             rMultiPropSet->setPropertyValues(aNames, aValues);
170         // else: ignore
171     }
172 }
173 
174 void XMLSectionSourceDDEImportContext::EndElement()
175 {
176     // nothing to be done!
177 }
178 
179 SvXMLImportContext* XMLSectionSourceDDEImportContext::CreateChildContext(
180     sal_uInt16 nPrefix,
181     const OUString& rLocalName,
182     const Reference<XAttributeList> & )
183 {
184     // ignore -> default context
185     return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
186 }
187