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