1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "XMLStarBasicContextFactory.hxx"
21 #include <xmloff/XMLEventsImportContext.hxx>
22 #include <xmloff/xmlimp.hxx>
23 #include <xmloff/nmspmap.hxx>
24 #include <xmloff/xmlnmspe.hxx>
25 #include <xmloff/xmltoken.hxx>
28 using namespace ::xmloff::token
;
30 using ::com::sun::star::xml::sax::XAttributeList
;
31 using ::com::sun::star::beans::PropertyValue
;
32 using ::com::sun::star::uno::Reference
;
33 using ::com::sun::star::uno::Sequence
;
34 using ::com::sun::star::uno::Any
;
37 XMLStarBasicContextFactory::XMLStarBasicContextFactory() :
38 sEventType("EventType"),
40 sMacroName("MacroName"),
41 sStarBasic("StarBasic")
45 XMLStarBasicContextFactory::~XMLStarBasicContextFactory()
49 SvXMLImportContext
* XMLStarBasicContextFactory::CreateContext(
52 const OUString
& rLocalName
,
53 const Reference
<XAttributeList
> & xAttrList
,
54 XMLEventsImportContext
* rEvents
,
55 const OUString
& rApiEventName
,
56 const OUString
& /*rApiLanguage*/)
59 OUString sMacroNameVal
;
61 sal_Int16 nCount
= xAttrList
->getLength();
62 for(sal_Int16 nAttr
= 0; nAttr
< nCount
; nAttr
++)
65 sal_uInt16 nPrefix
= rImport
.GetNamespaceMap().
66 GetKeyByAttrName( xAttrList
->getNameByIndex(nAttr
), &sLocalName
);
68 if (XML_NAMESPACE_SCRIPT
== nPrefix
)
70 if (IsXMLToken(sLocalName
, XML_MACRO_NAME
))
72 sMacroNameVal
= xAttrList
->getValueByIndex(nAttr
);
79 const OUString
& rApp
= GetXMLToken( XML_APPLICATION
);
80 const OUString
& rDoc
= GetXMLToken( XML_DOCUMENT
);
81 if( sMacroNameVal
.getLength() > rApp
.getLength()+1 &&
82 sMacroNameVal
.copy(0,rApp
.getLength()).equalsIgnoreAsciiCase( rApp
) &&
83 ':' == sMacroNameVal
[rApp
.getLength()] )
85 sLibraryVal
= "StarOffice";
86 sMacroNameVal
= sMacroNameVal
.copy( rApp
.getLength()+1 );
88 else if( sMacroNameVal
.getLength() > rDoc
.getLength()+1 &&
89 sMacroNameVal
.copy(0,rDoc
.getLength()).equalsIgnoreAsciiCase( rDoc
) &&
90 ':' == sMacroNameVal
[rDoc
.getLength()] )
93 sMacroNameVal
= sMacroNameVal
.copy( rDoc
.getLength()+1 );
96 Sequence
<PropertyValue
> aValues(3);
99 aValues
[0].Name
= sEventType
;
100 aValues
[0].Value
<<= sStarBasic
;
103 aValues
[1].Name
= sLibrary
;
104 aValues
[1].Value
<<= sLibraryVal
;
107 aValues
[2].Name
= sMacroName
;
108 aValues
[2].Value
<<= sMacroNameVal
;
110 // add values for event now
111 rEvents
->AddEventValues(rApiEventName
, aValues
);
113 // return dummy context
114 return new SvXMLImportContext(rImport
, p_nPrefix
, rLocalName
);
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */