LibreOffice Module xmloff (master)  1
XMLScriptContextFactory.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 
22 #include <xmloff/xmlimp.hxx>
23 #include <xmloff/namespacemap.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 OUStringLiteral gsEventType(u"EventType");
35 constexpr OUStringLiteral gsScript(u"Script");
36 constexpr OUStringLiteral gsURL(u"Script");
37 
39 
41 
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  Sequence<PropertyValue> aValues(2);
56 
57  // EventType
58  aValues[0].Name = gsEventType;
59  aValues[0].Value <<= OUString(gsScript);
60 
61  // URL
62  aValues[1].Name = gsURL;
63  aValues[1].Value <<= sURLVal;
64 
65  // add values for event now
66  rEvents->AddEventValues(rApiEventName, aValues);
67 
68  // return dummy context
69  return new SvXMLImportContext(rImport);
70 }
71 
72 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
constexpr OUStringLiteral gsScript(u"Script")
void AddEventValues(const OUString &rEventName, const css::uno::Sequence< css::beans::PropertyValue > &rValues)
virtual ~XMLScriptContextFactory() override
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
Handling of tokens in XML:
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97
virtual SvXMLImportContext * CreateContext(SvXMLImport &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, XMLEventsImportContext *rEvents, const OUString &rApiEventName) override
constexpr OUStringLiteral gsEventType(u"EventType")
constexpr OUStringLiteral gsURL(u"Script")