Update ooo320-m1
[ooovba.git] / xmloff / source / script / XMLStarBasicContextFactory.cxx
blob26eb08813a178de6fa09e3b56ba4596828085743
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLStarBasicContextFactory.cxx,v $
10 * $Revision: 1.10 $
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(
65 SvXMLImport& rImport,
66 sal_uInt16 p_nPrefix,
67 const OUString& rLocalName,
68 const Reference<XAttributeList> & xAttrList,
69 XMLEventsImportContext* rEvents,
70 const OUString& rApiEventName,
71 const OUString& /*rApiLanguage*/)
73 OUString sLibraryVal;
74 OUString sMacroNameVal;
76 sal_Int16 nCount = xAttrList->getLength();
77 for(sal_Int16 nAttr = 0; nAttr < nCount; nAttr++)
79 OUString sLocalName;
80 sal_uInt16 nPrefix = rImport.GetNamespaceMap().
81 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), &sLocalName );
83 if (XML_NAMESPACE_SCRIPT == nPrefix)
85 // if (IsXMLToken(sLocalName, XML_LIBRARY))
86 // {
87 // sLibraryVal = xAttrList->getValueByIndex(nAttr);
88 // }
89 // if (IsXMLToken(sLocalName, XML_LOCATION))
90 // {
91 // sLibraryVal = xAttrList->getValueByIndex(nAttr);
92 // if ( IsXMLToken( sLibraryVal, XML_APPLICATION ) )
93 // sLibraryVal =
94 // OUString(RTL_CONSTASCII_USTRINGPARAM("StarOffice"));
95 // }
96 // else
97 if (IsXMLToken(sLocalName, XML_MACRO_NAME))
99 sMacroNameVal = xAttrList->getValueByIndex(nAttr);
101 // else: ingore
103 // else: ignore
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()] )
119 sLibraryVal = rDoc;
120 sMacroNameVal = sMacroNameVal.copy( rDoc.getLength()+1 );
123 Sequence<PropertyValue> aValues(3);
125 // EventType
126 aValues[0].Name = sEventType;
127 aValues[0].Value <<= sStarBasic;
129 // library name
130 aValues[1].Name = sLibrary;
131 aValues[1].Value <<= sLibraryVal;
133 // macro name
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);