1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include "XMLStarBasicContextFactory.hxx"
27 #include <xmloff/XMLEventsImportContext.hxx>
28 #include <tools/debug.hxx>
29 #include <xmloff/xmlimp.hxx>
30 #include <xmloff/nmspmap.hxx>
31 #include "xmloff/xmlnmspe.hxx"
32 #include <xmloff/xmltoken.hxx>
33 
34 
35 using namespace ::xmloff::token;
36 
37 using ::rtl::OUString;
38 using ::com::sun::star::xml::sax::XAttributeList;
39 using ::com::sun::star::beans::PropertyValue;
40 using ::com::sun::star::uno::Reference;
41 using ::com::sun::star::uno::Sequence;
42 using ::com::sun::star::uno::Any;
43 
44 
XMLStarBasicContextFactory()45 XMLStarBasicContextFactory::XMLStarBasicContextFactory() :
46 	sEventType(RTL_CONSTASCII_USTRINGPARAM("EventType")),
47 	sLibrary(RTL_CONSTASCII_USTRINGPARAM("Library")),
48 	sMacroName(RTL_CONSTASCII_USTRINGPARAM("MacroName")),
49 	sStarBasic(RTL_CONSTASCII_USTRINGPARAM("StarBasic"))
50 {
51 }
52 
~XMLStarBasicContextFactory()53 XMLStarBasicContextFactory::~XMLStarBasicContextFactory()
54 {
55 }
56 
CreateContext(SvXMLImport & rImport,sal_uInt16 p_nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList,XMLEventsImportContext * rEvents,const OUString & rApiEventName,const OUString &)57 SvXMLImportContext* XMLStarBasicContextFactory::CreateContext(
58 	SvXMLImport& rImport,
59 	sal_uInt16 p_nPrefix,
60 	const OUString& rLocalName,
61 	const Reference<XAttributeList> & xAttrList,
62 	XMLEventsImportContext* rEvents,
63 	const OUString& rApiEventName,
64 	const OUString& /*rApiLanguage*/)
65 {
66 	OUString sLibraryVal;
67 	OUString sMacroNameVal;
68 
69 	sal_Int16 nCount = xAttrList->getLength();
70 	for(sal_Int16 nAttr = 0; nAttr < nCount; nAttr++)
71 	{
72 		OUString sLocalName;
73 		sal_uInt16 nPrefix = rImport.GetNamespaceMap().
74 			GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), &sLocalName );
75 
76 		if (XML_NAMESPACE_SCRIPT == nPrefix)
77 		{
78 //			if (IsXMLToken(sLocalName, XML_LIBRARY))
79 //			{
80 //				sLibraryVal = xAttrList->getValueByIndex(nAttr);
81 //			}
82 //			if (IsXMLToken(sLocalName, XML_LOCATION))
83 //			{
84 //				sLibraryVal = xAttrList->getValueByIndex(nAttr);
85 //                if ( IsXMLToken( sLibraryVal, XML_APPLICATION ) )
86 //                    sLibraryVal =
87 //                        OUString(RTL_CONSTASCII_USTRINGPARAM("StarOffice"));
88 //			}
89 //			else
90 			if (IsXMLToken(sLocalName, XML_MACRO_NAME))
91 			{
92 				sMacroNameVal = xAttrList->getValueByIndex(nAttr);
93 			}
94 			// else: ingore
95 		}
96 		// else: ignore
97 	}
98 
99 	const OUString& rApp = GetXMLToken( XML_APPLICATION );
100 	const OUString& rDoc = GetXMLToken( XML_DOCUMENT );
101 	if( sMacroNameVal.getLength() > rApp.getLength()+1 &&
102 		sMacroNameVal.copy(0,rApp.getLength()).equalsIgnoreAsciiCase( rApp ) &&
103 		':' == sMacroNameVal[rApp.getLength()] )
104 	{
105 		sLibraryVal = OUString(RTL_CONSTASCII_USTRINGPARAM("StarOffice"));
106 		sMacroNameVal = sMacroNameVal.copy( rApp.getLength()+1 );
107 	}
108 	else if( sMacroNameVal.getLength() > rDoc.getLength()+1 &&
109 		sMacroNameVal.copy(0,rDoc.getLength()).equalsIgnoreAsciiCase( rDoc ) &&
110 		':' == sMacroNameVal[rDoc.getLength()] )
111 	{
112 		sLibraryVal = rDoc;
113 		sMacroNameVal = sMacroNameVal.copy( rDoc.getLength()+1 );
114 	}
115 
116 	Sequence<PropertyValue> aValues(3);
117 
118 	// EventType
119 	aValues[0].Name = sEventType;
120 	aValues[0].Value <<= sStarBasic;
121 
122 	// library name
123 	aValues[1].Name = sLibrary;
124 	aValues[1].Value <<= sLibraryVal;
125 
126 	// macro name
127 	aValues[2].Name = sMacroName;
128 	aValues[2].Value <<= sMacroNameVal;
129 
130 	// add values for event now
131 	rEvents->AddEventValues(rApiEventName, aValues);
132 
133 	// return dummy context
134 	return new SvXMLImportContext(rImport, p_nPrefix, rLocalName);
135 }
136