Debian Codegraph @

xmloff/source/script/XMLScriptContextFactory.cxx

raw
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
20 #include <comphelper/propertyvalue.hxx>
21 #include <XMLScriptContextFactory.hxx>
22 #include <xmloff/XMLEventsImportContext.hxx>
23 #include <xmloff/xmlimp.hxx>
24 #include <xmloff/xmlnamespace.hxx>
25 #include <xmloff/xmltoken.hxx>
26
27 using namespace ::xmloff::token;
28
29 using ::com::sun::star::xml::sax::XFastAttributeList;
30 using ::com::sun::star::beans::PropertyValue;
31 using ::com::sun::star::uno::Reference;
32 using ::com::sun::star::uno::Sequence;
33
34 constexpr OUString gsEventType(u"EventType"_ustr);
35 constexpr OUString gsScript(u"Script"_ustr);
36 constexpr OUString gsURL(u"Script"_ustr);
37
38 XMLScriptContextFactory::XMLScriptContextFactory() {}
39
40 XMLScriptContextFactory::~XMLScriptContextFactory() {}
41
42 SvXMLImportContext* XMLScriptContextFactory::CreateContext(
43 SvXMLImport& rImport, const Reference<XFastAttributeList>& xAttrList,
44 XMLEventsImportContext* rEvents, const OUString& rApiEventName)
45 {
46 OUString sURLVal;
47
48 for (auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList))
49 {
50 if (aIter.getToken() == XML_ELEMENT(XLINK, XML_HREF))
51 sURLVal = aIter.toString();
52 // else: ignore
53 }
54
55 if (!sURLVal.isEmpty())
56 rImport.NotifyMacroEventRead();
57
58 Sequence<PropertyValue> aValues{ comphelper::makePropertyValue(gsEventType, gsScript),
59 comphelper::makePropertyValue(gsURL, sURLVal) };
60
61 // add values for event now
62 rEvents->AddEventValues(rApiEventName, aValues);
63
64 // return dummy context
65 return new SvXMLImportContext(rImport);
66 }
67
68 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */