LibreOffice Module xmloff (master) 1
XMLStarBasicContextFactory.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
23#include <xmloff/xmlimp.hxx>
26#include <xmloff/xmltoken.hxx>
27#include <o3tl/string_view.hxx>
28
29
30using namespace ::xmloff::token;
31
32using ::com::sun::star::xml::sax::XFastAttributeList;
33using ::com::sun::star::beans::PropertyValue;
34using ::com::sun::star::uno::Reference;
35using ::com::sun::star::uno::Sequence;
36
37
38constexpr OUStringLiteral gsEventType(u"EventType");
39constexpr OUStringLiteral gsLibrary(u"Library");
40constexpr OUStringLiteral gsMacroName(u"MacroName");
41constexpr OUStringLiteral gsStarBasic(u"StarBasic");
42
44{
45}
46
48{
49}
50
52 SvXMLImport& rImport,
53 const Reference<XFastAttributeList> & xAttrList,
55 const OUString& rApiEventName)
56{
57 OUString sLibraryVal;
58 OUString sMacroNameVal;
59
60 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
61 {
62 if (aIter.getToken() == XML_ELEMENT(SCRIPT, XML_MACRO_NAME))
63 sMacroNameVal = aIter.toString();
64 // else: ignore
65 }
66
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()] )
72 {
73 sLibraryVal = "StarOffice";
74 sMacroNameVal = sMacroNameVal.copy( rApp.getLength()+1 );
75 }
76 else if( sMacroNameVal.getLength() > rDoc.getLength()+1 &&
77 o3tl::equalsIgnoreAsciiCase(sMacroNameVal.subView(0,rDoc.getLength()), rDoc ) &&
78 ':' == sMacroNameVal[rDoc.getLength()] )
79 {
80 sLibraryVal = rDoc;
81 sMacroNameVal = sMacroNameVal.copy( rDoc.getLength()+1 );
82 }
83
84 if (!sMacroNameVal.isEmpty())
85 rImport.NotifyMacroEventRead();
86
87 Sequence<PropertyValue> aValues
88 {
92 };
93
94 // add values for event now
95 rEvents->AddEventValues(rApiEventName, aValues);
96
97 // return dummy context
98 return new SvXMLImportContext(rImport);
99}
100
101/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral gsLibrary(u"Library")
constexpr OUStringLiteral gsMacroName(u"MacroName")
constexpr OUStringLiteral gsStarBasic(u"StarBasic")
constexpr OUStringLiteral gsEventType(u"EventType")
This class deliberately does not support XWeak, to improve performance when loading large documents.
Definition: xmlictxt.hxx:48
Import <script:events> element.
void AddEventValues(const OUString &rEventName, const css::uno::Sequence< css::beans::PropertyValue > &rValues)
virtual SvXMLImportContext * CreateContext(SvXMLImport &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, XMLEventsImportContext *rEvents, const OUString &rApiEventName) override
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
Handling of tokens in XML:
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3541
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97