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>
24 #include <xmloff/namespacemap.hxx>
25 #include <xmloff/xmlnamespace.hxx>
26 #include <xmloff/xmltoken.hxx>
27 
28 
29 using namespace ::xmloff::token;
30 
31 using ::com::sun::star::xml::sax::XFastAttributeList;
32 using ::com::sun::star::beans::PropertyValue;
33 using ::com::sun::star::uno::Reference;
34 using ::com::sun::star::uno::Sequence;
35 
36 
37 constexpr OUStringLiteral gsEventType(u"EventType");
38 constexpr OUStringLiteral gsLibrary(u"Library");
39 constexpr OUStringLiteral gsMacroName(u"MacroName");
40 constexpr OUStringLiteral gsStarBasic(u"StarBasic");
41 
43 {
44 }
45 
47 {
48 }
49 
51  SvXMLImport& rImport,
52  const Reference<XFastAttributeList> & xAttrList,
53  XMLEventsImportContext* rEvents,
54  const OUString& rApiEventName)
55 {
56  OUString sLibraryVal;
57  OUString sMacroNameVal;
58 
59  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
60  {
61  if (aIter.getToken() == XML_ELEMENT(SCRIPT, XML_MACRO_NAME))
62  sMacroNameVal = aIter.toString();
63  // else: ignore
64  }
65 
66  const OUString& rApp = GetXMLToken( XML_APPLICATION );
67  const OUString& rDoc = GetXMLToken( XML_DOCUMENT );
68  if( sMacroNameVal.getLength() > rApp.getLength()+1 &&
69  sMacroNameVal.copy(0,rApp.getLength()).equalsIgnoreAsciiCase( rApp ) &&
70  ':' == sMacroNameVal[rApp.getLength()] )
71  {
72  sLibraryVal = "StarOffice";
73  sMacroNameVal = sMacroNameVal.copy( rApp.getLength()+1 );
74  }
75  else if( sMacroNameVal.getLength() > rDoc.getLength()+1 &&
76  sMacroNameVal.copy(0,rDoc.getLength()).equalsIgnoreAsciiCase( rDoc ) &&
77  ':' == sMacroNameVal[rDoc.getLength()] )
78  {
79  sLibraryVal = rDoc;
80  sMacroNameVal = sMacroNameVal.copy( rDoc.getLength()+1 );
81  }
82 
83  Sequence<PropertyValue> aValues
84  {
88  };
89 
90  // add values for event now
91  rEvents->AddEventValues(rApiEventName, aValues);
92 
93  // return dummy context
94  return new SvXMLImportContext(rImport);
95 }
96 
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral gsMacroName(u"MacroName")
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
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:3472
Handling of tokens in XML:
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97
constexpr OUStringLiteral gsStarBasic(u"StarBasic")