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 <comphelper/propertyvalue.hxx>
21 #include <XMLStarBasicContextFactory.hxx>
22 #include <xmloff/XMLEventsImportContext.hxx>
23 #include <xmloff/xmlimp.hxx>
24 #include <xmloff/namespacemap.hxx>
25 #include <xmloff/xmlnamespace.hxx>
26 #include <xmloff/xmltoken.hxx>
27 #include <o3tl/string_view.hxx>
30 using namespace ::xmloff::token
;
32 using ::com::sun::star::xml::sax::XFastAttributeList
;
33 using ::com::sun::star::beans::PropertyValue
;
34 using ::com::sun::star::uno::Reference
;
35 using ::com::sun::star::uno::Sequence
;
38 constexpr OUString
gsEventType(u
"EventType"_ustr
);
39 constexpr OUString
gsLibrary(u
"Library"_ustr
);
40 constexpr OUString
gsMacroName(u
"MacroName"_ustr
);
41 constexpr OUString
gsStarBasic(u
"StarBasic"_ustr
);
43 XMLStarBasicContextFactory::XMLStarBasicContextFactory()
47 XMLStarBasicContextFactory::~XMLStarBasicContextFactory()
51 SvXMLImportContext
* XMLStarBasicContextFactory::CreateContext(
53 const Reference
<XFastAttributeList
> & xAttrList
,
54 XMLEventsImportContext
* rEvents
,
55 const OUString
& rApiEventName
)
58 OUString sMacroNameVal
;
60 for( auto& aIter
: sax_fastparser::castToFastAttributeList(xAttrList
) )
62 if (aIter
.getToken() == XML_ELEMENT(SCRIPT
, XML_MACRO_NAME
))
63 sMacroNameVal
= aIter
.toString();
67 const OUString
& rApp
= GetXMLToken( XML_APPLICATION
);
68 const OUString
& rDoc
= GetXMLToken( XML_DOCUMENT
);
69 if( sMacroNameVal
.getLength() > rApp
.getLength()+1 &&
70 o3tl::equalsIgnoreAsciiCase(sMacroNameVal
.subView(0,rApp
.getLength()), rApp
) &&
71 ':' == sMacroNameVal
[rApp
.getLength()] )
73 sLibraryVal
= "StarOffice";
74 sMacroNameVal
= sMacroNameVal
.copy( rApp
.getLength()+1 );
76 else if( sMacroNameVal
.getLength() > rDoc
.getLength()+1 &&
77 o3tl::equalsIgnoreAsciiCase(sMacroNameVal
.subView(0,rDoc
.getLength()), rDoc
) &&
78 ':' == sMacroNameVal
[rDoc
.getLength()] )
81 sMacroNameVal
= sMacroNameVal
.copy( rDoc
.getLength()+1 );
84 if (!sMacroNameVal
.isEmpty())
85 rImport
.NotifyMacroEventRead();
87 Sequence
<PropertyValue
> aValues
89 comphelper::makePropertyValue(gsEventType
, gsStarBasic
),
90 comphelper::makePropertyValue(gsLibrary
, sLibraryVal
),
91 comphelper::makePropertyValue(gsMacroName
, sMacroNameVal
)
94 // add values for event now
95 rEvents
->AddEventValues(rApiEventName
, aValues
);
97 // return dummy context
98 return new SvXMLImportContext(rImport
);
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */