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 
22 #include <xmloff/xmlimp.hxx>
23 #include <xmloff/namespacemap.hxx>
24 #include <xmloff/xmlnamespace.hxx>
25 #include <xmloff/xmltoken.hxx>
26 
27 
28 using namespace ::xmloff::token;
29 
30 using ::com::sun::star::xml::sax::XFastAttributeList;
31 using ::com::sun::star::beans::PropertyValue;
32 using ::com::sun::star::uno::Reference;
33 using ::com::sun::star::uno::Sequence;
34 
35 
36 constexpr OUStringLiteral gsEventType(u"EventType");
37 constexpr OUStringLiteral gsLibrary(u"Library");
38 constexpr OUStringLiteral gsMacroName(u"MacroName");
39 constexpr OUStringLiteral gsStarBasic(u"StarBasic");
40 
42 {
43 }
44 
46 {
47 }
48 
50  SvXMLImport& rImport,
51  const Reference<XFastAttributeList> & xAttrList,
52  XMLEventsImportContext* rEvents,
53  const OUString& rApiEventName)
54 {
55  OUString sLibraryVal;
56  OUString sMacroNameVal;
57 
58  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
59  {
60  if (aIter.getToken() == XML_ELEMENT(SCRIPT, XML_MACRO_NAME))
61  sMacroNameVal = aIter.toString();
62  // else: ignore
63  }
64 
65  const OUString& rApp = GetXMLToken( XML_APPLICATION );
66  const OUString& rDoc = GetXMLToken( XML_DOCUMENT );
67  if( sMacroNameVal.getLength() > rApp.getLength()+1 &&
68  sMacroNameVal.copy(0,rApp.getLength()).equalsIgnoreAsciiCase( rApp ) &&
69  ':' == sMacroNameVal[rApp.getLength()] )
70  {
71  sLibraryVal = "StarOffice";
72  sMacroNameVal = sMacroNameVal.copy( rApp.getLength()+1 );
73  }
74  else if( sMacroNameVal.getLength() > rDoc.getLength()+1 &&
75  sMacroNameVal.copy(0,rDoc.getLength()).equalsIgnoreAsciiCase( rDoc ) &&
76  ':' == sMacroNameVal[rDoc.getLength()] )
77  {
78  sLibraryVal = rDoc;
79  sMacroNameVal = sMacroNameVal.copy( rDoc.getLength()+1 );
80  }
81 
82  Sequence<PropertyValue> aValues(3);
83 
84  // EventType
85  aValues[0].Name = gsEventType;
86  aValues[0].Value <<= OUString(gsStarBasic);
87 
88  // library name
89  aValues[1].Name = gsLibrary;
90  aValues[1].Value <<= sLibraryVal;
91 
92  // macro name
93  aValues[2].Name = gsMacroName;
94  aValues[2].Value <<= sMacroNameVal;
95 
96  // add values for event now
97  rEvents->AddEventValues(rApiEventName, aValues);
98 
99  // return dummy context
100  return new SvXMLImportContext(rImport);
101 }
102 
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral gsMacroName(u"MacroName")
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
void AddEventValues(const OUString &rEventName, const css::uno::Sequence< css::beans::PropertyValue > &rValues)
constexpr OUStringLiteral gsLibrary(u"Library")
virtual SvXMLImportContext * CreateContext(SvXMLImport &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, XMLEventsImportContext *rEvents, const OUString &rApiEventName) override
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:45
constexpr OUStringLiteral gsEventType(u"EventType")
bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3406
Handling of tokens in XML:
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:96
constexpr OUStringLiteral gsStarBasic(u"StarBasic")