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/xmlnamespace.hxx>
25 #include <xmloff/xmltoken.hxx>
26 #include <o3tl/string_view.hxx>
29 using namespace ::xmloff::token
;
31 using ::com::sun::star::xml::sax::XFastAttributeList
;
32 using ::com::sun::star::beans::PropertyValue
;
33 using ::com::sun::star::uno::Reference
;
34 using ::com::sun::star::uno::Sequence
;
37 constexpr OUString
gsEventType(u
"EventType"_ustr
);
38 constexpr OUString
gsLibrary(u
"Library"_ustr
);
39 constexpr OUString
gsMacroName(u
"MacroName"_ustr
);
40 constexpr OUString
gsStarBasic(u
"StarBasic"_ustr
);
42 XMLStarBasicContextFactory::XMLStarBasicContextFactory()
46 XMLStarBasicContextFactory::~XMLStarBasicContextFactory()
50 SvXMLImportContext
* XMLStarBasicContextFactory::CreateContext(
52 const Reference
<XFastAttributeList
> & xAttrList
,
53 XMLEventsImportContext
* rEvents
,
54 const OUString
& rApiEventName
)
57 OUString sMacroNameVal
;
59 for( auto& aIter
: sax_fastparser::castToFastAttributeList(xAttrList
) )
61 if (aIter
.getToken() == XML_ELEMENT(SCRIPT
, XML_MACRO_NAME
))
62 sMacroNameVal
= aIter
.toString();
66 const OUString
& rApp
= GetXMLToken( XML_APPLICATION
);
67 const OUString
& rDoc
= GetXMLToken( XML_DOCUMENT
);
68 if( sMacroNameVal
.getLength() > rApp
.getLength()+1 &&
69 o3tl::equalsIgnoreAsciiCase(sMacroNameVal
.subView(0,rApp
.getLength()), rApp
) &&
70 ':' == sMacroNameVal
[rApp
.getLength()] )
72 sLibraryVal
= "StarOffice";
73 sMacroNameVal
= sMacroNameVal
.copy( rApp
.getLength()+1 );
75 else if( sMacroNameVal
.getLength() > rDoc
.getLength()+1 &&
76 o3tl::equalsIgnoreAsciiCase(sMacroNameVal
.subView(0,rDoc
.getLength()), rDoc
) &&
77 ':' == sMacroNameVal
[rDoc
.getLength()] )
80 sMacroNameVal
= sMacroNameVal
.copy( rDoc
.getLength()+1 );
83 if (!sMacroNameVal
.isEmpty())
84 rImport
.NotifyMacroEventRead();
86 Sequence
<PropertyValue
> aValues
88 comphelper::makePropertyValue(gsEventType
, gsStarBasic
),
89 comphelper::makePropertyValue(gsLibrary
, sLibraryVal
),
90 comphelper::makePropertyValue(gsMacroName
, sMacroNameVal
)
93 // add values for event now
94 rEvents
->AddEventValues(rApiEventName
, aValues
);
96 // return dummy context
97 return new SvXMLImportContext(rImport
);
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */