Branch data Line data Source code
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 "XMLStarBasicContextFactory.hxx"
21 : : #include <xmloff/XMLEventsImportContext.hxx>
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 ::rtl::OUString;
31 : : using ::com::sun::star::xml::sax::XAttributeList;
32 : : using ::com::sun::star::beans::PropertyValue;
33 : : using ::com::sun::star::uno::Reference;
34 : : using ::com::sun::star::uno::Sequence;
35 : : using ::com::sun::star::uno::Any;
36 : :
37 : :
38 : 24 : XMLStarBasicContextFactory::XMLStarBasicContextFactory() :
39 : : sEventType("EventType"),
40 : : sLibrary("Library"),
41 : : sMacroName("MacroName"),
42 : 24 : sStarBasic("StarBasic")
43 : : {
44 : 24 : }
45 : :
46 : 24 : XMLStarBasicContextFactory::~XMLStarBasicContextFactory()
47 : : {
48 [ - + ]: 48 : }
49 : :
50 : 6 : SvXMLImportContext* XMLStarBasicContextFactory::CreateContext(
51 : : SvXMLImport& rImport,
52 : : sal_uInt16 p_nPrefix,
53 : : const OUString& rLocalName,
54 : : const Reference<XAttributeList> & xAttrList,
55 : : XMLEventsImportContext* rEvents,
56 : : const OUString& rApiEventName,
57 : : const OUString& /*rApiLanguage*/)
58 : : {
59 : 6 : OUString sLibraryVal;
60 : 6 : OUString sMacroNameVal;
61 : :
62 [ + - ][ + - ]: 6 : sal_Int16 nCount = xAttrList->getLength();
63 [ + + ]: 24 : for(sal_Int16 nAttr = 0; nAttr < nCount; nAttr++)
64 : : {
65 : 18 : OUString sLocalName;
66 : 18 : sal_uInt16 nPrefix = rImport.GetNamespaceMap().
67 [ + - + - ]: 36 : GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), &sLocalName );
[ + - ]
68 : :
69 [ + - ]: 18 : if (XML_NAMESPACE_SCRIPT == nPrefix)
70 : : {
71 [ + - ][ + + ]: 18 : if (IsXMLToken(sLocalName, XML_MACRO_NAME))
72 : : {
73 [ + - ][ + - ]: 6 : sMacroNameVal = xAttrList->getValueByIndex(nAttr);
74 : : }
75 : : // else: ingore
76 : : }
77 : : // else: ignore
78 : 18 : }
79 : :
80 [ + - ]: 6 : const OUString& rApp = GetXMLToken( XML_APPLICATION );
81 [ + - ]: 6 : const OUString& rDoc = GetXMLToken( XML_DOCUMENT );
82 [ + - - + : 18 : if( sMacroNameVal.getLength() > rApp.getLength()+1 &&
# # ][ - + ]
83 [ + - ]: 12 : sMacroNameVal.copy(0,rApp.getLength()).equalsIgnoreAsciiCase( rApp ) &&
84 : 0 : ':' == sMacroNameVal[rApp.getLength()] )
85 : : {
86 : 0 : sLibraryVal = "StarOffice";
87 : 0 : sMacroNameVal = sMacroNameVal.copy( rApp.getLength()+1 );
88 : : }
89 [ + - + - : 24 : else if( sMacroNameVal.getLength() > rDoc.getLength()+1 &&
+ - ][ + - ]
90 [ + - ]: 12 : sMacroNameVal.copy(0,rDoc.getLength()).equalsIgnoreAsciiCase( rDoc ) &&
91 : 6 : ':' == sMacroNameVal[rDoc.getLength()] )
92 : : {
93 : 6 : sLibraryVal = rDoc;
94 : 6 : sMacroNameVal = sMacroNameVal.copy( rDoc.getLength()+1 );
95 : : }
96 : :
97 [ + - ]: 6 : Sequence<PropertyValue> aValues(3);
98 : :
99 : : // EventType
100 [ + - ]: 6 : aValues[0].Name = sEventType;
101 [ + - ][ + - ]: 6 : aValues[0].Value <<= sStarBasic;
102 : :
103 : : // library name
104 [ + - ]: 6 : aValues[1].Name = sLibrary;
105 [ + - ][ + - ]: 6 : aValues[1].Value <<= sLibraryVal;
106 : :
107 : : // macro name
108 [ + - ]: 6 : aValues[2].Name = sMacroName;
109 [ + - ][ + - ]: 6 : aValues[2].Value <<= sMacroNameVal;
110 : :
111 : : // add values for event now
112 [ + - ]: 6 : rEvents->AddEventValues(rApiEventName, aValues);
113 : :
114 : : // return dummy context
115 [ + - ][ + - ]: 6 : return new SvXMLImportContext(rImport, p_nPrefix, rLocalName);
[ + - ]
116 : : }
117 : :
118 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|