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: XMLStarBasicContextFactory.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 "XMLStarBasicContextFactory.hxx"
34 #include <xmloff/XMLEventsImportContext.hxx>
35 #include <tools/debug.hxx>
36 #include <xmloff/xmlimp.hxx>
37 #include <xmloff/nmspmap.hxx>
38 #include "xmlnmspe.hxx"
39 #include <xmloff/xmltoken.hxx>
42 using namespace ::xmloff::token
;
44 using ::rtl::OUString
;
45 using ::com::sun::star::xml::sax::XAttributeList
;
46 using ::com::sun::star::beans::PropertyValue
;
47 using ::com::sun::star::uno::Reference
;
48 using ::com::sun::star::uno::Sequence
;
49 using ::com::sun::star::uno::Any
;
52 XMLStarBasicContextFactory::XMLStarBasicContextFactory() :
53 sEventType(RTL_CONSTASCII_USTRINGPARAM("EventType")),
54 sLibrary(RTL_CONSTASCII_USTRINGPARAM("Library")),
55 sMacroName(RTL_CONSTASCII_USTRINGPARAM("MacroName")),
56 sStarBasic(RTL_CONSTASCII_USTRINGPARAM("StarBasic"))
60 XMLStarBasicContextFactory::~XMLStarBasicContextFactory()
64 SvXMLImportContext
* XMLStarBasicContextFactory::CreateContext(
67 const OUString
& rLocalName
,
68 const Reference
<XAttributeList
> & xAttrList
,
69 XMLEventsImportContext
* rEvents
,
70 const OUString
& rApiEventName
,
71 const OUString
& /*rApiLanguage*/)
74 OUString sMacroNameVal
;
76 sal_Int16 nCount
= xAttrList
->getLength();
77 for(sal_Int16 nAttr
= 0; nAttr
< nCount
; nAttr
++)
80 sal_uInt16 nPrefix
= rImport
.GetNamespaceMap().
81 GetKeyByAttrName( xAttrList
->getNameByIndex(nAttr
), &sLocalName
);
83 if (XML_NAMESPACE_SCRIPT
== nPrefix
)
85 // if (IsXMLToken(sLocalName, XML_LIBRARY))
87 // sLibraryVal = xAttrList->getValueByIndex(nAttr);
89 // if (IsXMLToken(sLocalName, XML_LOCATION))
91 // sLibraryVal = xAttrList->getValueByIndex(nAttr);
92 // if ( IsXMLToken( sLibraryVal, XML_APPLICATION ) )
94 // OUString(RTL_CONSTASCII_USTRINGPARAM("StarOffice"));
97 if (IsXMLToken(sLocalName
, XML_MACRO_NAME
))
99 sMacroNameVal
= xAttrList
->getValueByIndex(nAttr
);
106 const OUString
& rApp
= GetXMLToken( XML_APPLICATION
);
107 const OUString
& rDoc
= GetXMLToken( XML_DOCUMENT
);
108 if( sMacroNameVal
.getLength() > rApp
.getLength()+1 &&
109 sMacroNameVal
.copy(0,rApp
.getLength()).equalsIgnoreAsciiCase( rApp
) &&
110 ':' == sMacroNameVal
[rApp
.getLength()] )
112 sLibraryVal
= OUString(RTL_CONSTASCII_USTRINGPARAM("StarOffice"));
113 sMacroNameVal
= sMacroNameVal
.copy( rApp
.getLength()+1 );
115 else if( sMacroNameVal
.getLength() > rDoc
.getLength()+1 &&
116 sMacroNameVal
.copy(0,rDoc
.getLength()).equalsIgnoreAsciiCase( rDoc
) &&
117 ':' == sMacroNameVal
[rDoc
.getLength()] )
120 sMacroNameVal
= sMacroNameVal
.copy( rDoc
.getLength()+1 );
123 Sequence
<PropertyValue
> aValues(3);
126 aValues
[0].Name
= sEventType
;
127 aValues
[0].Value
<<= sStarBasic
;
130 aValues
[1].Name
= sLibrary
;
131 aValues
[1].Value
<<= sLibraryVal
;
134 aValues
[2].Name
= sMacroName
;
135 aValues
[2].Value
<<= sMacroNameVal
;
137 // add values for event now
138 rEvents
->AddEventValues(rApiEventName
, aValues
);
140 // return dummy context
141 return new SvXMLImportContext(rImport
, p_nPrefix
, rLocalName
);