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::XAttributeList;
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<XAttributeList> & xAttrList,
52  XMLEventsImportContext* rEvents,
53  const OUString& rApiEventName)
54 {
55  OUString sLibraryVal;
56  OUString sMacroNameVal;
57 
58  sal_Int16 nCount = xAttrList->getLength();
59  for(sal_Int16 nAttr = 0; nAttr < nCount; nAttr++)
60  {
61  OUString sLocalName;
62  sal_uInt16 nPrefix = rImport.GetNamespaceMap().
63  GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), &sLocalName );
64 
65  if (XML_NAMESPACE_SCRIPT == nPrefix)
66  {
67  if (IsXMLToken(sLocalName, XML_MACRO_NAME))
68  {
69  sMacroNameVal = xAttrList->getValueByIndex(nAttr);
70  }
71  // else: ignore
72  }
73  // else: ignore
74  }
75 
76  const OUString& rApp = GetXMLToken( XML_APPLICATION );
77  const OUString& rDoc = GetXMLToken( XML_DOCUMENT );
78  if( sMacroNameVal.getLength() > rApp.getLength()+1 &&
79  sMacroNameVal.copy(0,rApp.getLength()).equalsIgnoreAsciiCase( rApp ) &&
80  ':' == sMacroNameVal[rApp.getLength()] )
81  {
82  sLibraryVal = "StarOffice";
83  sMacroNameVal = sMacroNameVal.copy( rApp.getLength()+1 );
84  }
85  else if( sMacroNameVal.getLength() > rDoc.getLength()+1 &&
86  sMacroNameVal.copy(0,rDoc.getLength()).equalsIgnoreAsciiCase( rDoc ) &&
87  ':' == sMacroNameVal[rDoc.getLength()] )
88  {
89  sLibraryVal = rDoc;
90  sMacroNameVal = sMacroNameVal.copy( rDoc.getLength()+1 );
91  }
92 
93  Sequence<PropertyValue> aValues(3);
94 
95  // EventType
96  aValues[0].Name = gsEventType;
97  aValues[0].Value <<= OUString(gsStarBasic);
98 
99  // library name
100  aValues[1].Name = gsLibrary;
101  aValues[1].Value <<= sLibraryVal;
102 
103  // macro name
104  aValues[2].Name = gsMacroName;
105  aValues[2].Value <<= sMacroNameVal;
106 
107  // add values for event now
108  rEvents->AddEventValues(rApiEventName, aValues);
109 
110  // return dummy context
111  return new SvXMLImportContext(rImport);
112 }
113 
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3434
virtual SvXMLImportContext * CreateContext(SvXMLImport &rImport, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList, XMLEventsImportContext *rEvents, const OUString &rApiEventName) override
constexpr OUStringLiteral gsMacroName(u"MacroName")
constexpr sal_uInt16 XML_NAMESPACE_SCRIPT
SvXMLNamespaceMap & GetNamespaceMap()
Definition: xmlimp.hxx:402
void AddEventValues(const OUString &rEventName, const css::uno::Sequence< css::beans::PropertyValue > &rValues)
int nCount
constexpr OUStringLiteral gsLibrary(u"Library")
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
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:3378
Handling of tokens in XML:
constexpr OUStringLiteral gsStarBasic(u"StarBasic")