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/nmspmap.hxx>
24 #include <xmloff/xmlnmspe.hxx>
25 #include <xmloff/xmltoken.hxx>
26 
27 
28 using namespace ::xmloff::token;
29 
30 using ::com::sun::star::xml::sax::XAttributeList;
31 using ::com::sun::star::beans::PropertyValue;
32 using ::com::sun::star::uno::Reference;
33 using ::com::sun::star::uno::Sequence;
34 
35 static const OUStringLiteral gsEventType("EventType");
36 static const OUStringLiteral gsScript("Script");
37 static const OUStringLiteral gsURL("Script");
38 
40 {
41 }
42 
44 {
45 }
46 
48 (SvXMLImport & rImport,
49  const Reference<XAttributeList> & xAttrList,
50  XMLEventsImportContext * rEvents,
51  const OUString & rApiEventName)
52 {
53  OUString sURLVal;
54 
55  sal_Int16 nCount = xAttrList->getLength();
56  for (sal_Int16 nAttr = 0; nAttr < nCount; nAttr++)
57  {
58  OUString sLocalName;
59  sal_uInt16 nPrefix = rImport.GetNamespaceMap().
60  GetKeyByAttrName(xAttrList->getNameByIndex(nAttr), &sLocalName);
61 
62  if (XML_NAMESPACE_XLINK == nPrefix)
63  {
64  if (IsXMLToken(sLocalName, XML_HREF))
65  sURLVal = xAttrList->getValueByIndex(nAttr);
66  // else: ignore
67  }
68  // else ignore
69  }
70 
71  Sequence<PropertyValue> aValues(2);
72 
73  // EventType
74  aValues[0].Name = gsEventType;
75  aValues[0].Value <<= OUString(gsScript);
76 
77  // URL
78  aValues[1].Name = gsURL;
79  aValues[1].Value <<= sURLVal;
80 
81  // add values for event now
82  rEvents->AddEventValues(rApiEventName, aValues);
83 
84  // return dummy context
85  return new SvXMLImportContext(rImport);
86 }
87 
88 
89 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3422
static const OUStringLiteral gsURL("Script")
SvXMLNamespaceMap & GetNamespaceMap()
Definition: xmlimp.hxx:397
static const OUStringLiteral gsEventType("EventType")
void AddEventValues(const OUString &rEventName, const css::uno::Sequence< css::beans::PropertyValue > &rValues)
int nCount
virtual ~XMLScriptContextFactory() override
virtual SvXMLImportContext * CreateContext(SvXMLImport &rImport, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList, XMLEventsImportContext *rEvents, const OUString &rApiEventName) override
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
constexpr sal_uInt16 XML_NAMESPACE_XLINK
Definition: xmlnmspe.hxx:35
static const OUStringLiteral gsScript("Script")
Handling of tokens in XML: