| 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 |
|
| 20 |
#include <comphelper/propertyvalue.hxx> |
| 21 |
#include <XMLStarBasicContextFactory.hxx> |
| 22 |
#include <xmloff/XMLEventsImportContext.hxx> |
| 23 |
#include <xmloff/xmlimp.hxx> |
| 24 |
#include <xmloff/xmlnamespace.hxx> |
| 25 |
#include <xmloff/xmltoken.hxx> |
| 26 |
#include <o3tl/string_view.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 OUString gsEventType(u"EventType"_ustr); |
| 38 |
constexpr OUString gsLibrary(u"Library"_ustr); |
| 39 |
constexpr OUString gsMacroName(u"MacroName"_ustr); |
| 40 |
constexpr OUString gsStarBasic(u"StarBasic"_ustr); |
| 41 |
|
| 42 |
XMLStarBasicContextFactory::XMLStarBasicContextFactory() |
| 43 |
{ |
| 44 |
} |
| 45 |
|
| 46 |
XMLStarBasicContextFactory::~XMLStarBasicContextFactory() |
| 47 |
{ |
| 48 |
} |
| 49 |
|
| 50 |
SvXMLImportContext* XMLStarBasicContextFactory::CreateContext( |
| 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 |
o3tl::equalsIgnoreAsciiCase(sMacroNameVal.subView(0,rApp.getLength()), 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 |
o3tl::equalsIgnoreAsciiCase(sMacroNameVal.subView(0,rDoc.getLength()), rDoc ) && |
| 77 |
':' == sMacroNameVal[rDoc.getLength()] ) |
| 78 |
{ |
| 79 |
sLibraryVal = rDoc; |
| 80 |
sMacroNameVal = sMacroNameVal.copy( rDoc.getLength()+1 ); |
| 81 |
} |
| 82 |
|
| 83 |
if (!sMacroNameVal.isEmpty()) |
| 84 |
rImport.NotifyMacroEventRead(); |
| 85 |
|
| 86 |
Sequence<PropertyValue> aValues |
| 87 |
{ |
| 88 |
comphelper::makePropertyValue(gsEventType, gsStarBasic), |
| 89 |
comphelper::makePropertyValue(gsLibrary, sLibraryVal), |
| 90 |
comphelper::makePropertyValue(gsMacroName, sMacroNameVal) |
| 91 |
}; |
| 92 |
|
| 93 |
// add values for event now |
| 94 |
rEvents->AddEventValues(rApiEventName, aValues); |
| 95 |
|
| 96 |
// return dummy context |
| 97 |
return new SvXMLImportContext(rImport); |
| 98 |
} |
| 99 |
|
| 100 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |