Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "EventOASISTContext.hxx"
30 : : #include "EventMap.hxx"
31 : : #include "MutableAttrList.hxx"
32 : : #include "xmloff/xmlnmspe.hxx"
33 : : #include "ActionMapTypesOASIS.hxx"
34 : : #include "AttrTransformerAction.hxx"
35 : : #include "TransformerActions.hxx"
36 : : #include "TransformerBase.hxx"
37 : :
38 : : #ifndef OASIS_FILTER_OOO_1X
39 : : // Used to parse Scripting Framework URLs
40 : : #include <com/sun/star/uri/XUriReferenceFactory.hpp>
41 : : #include <com/sun/star/uri/XVndSunStarScriptUrl.hpp>
42 : : #include <comphelper/processfactory.hxx>
43 : : #endif
44 : :
45 : : #include <boost/unordered_map.hpp>
46 : :
47 : : using ::rtl::OUString;
48 : :
49 : : using namespace ::com::sun::star::uno;
50 : : using namespace ::com::sun::star::xml::sax;
51 : : using namespace ::xmloff::token;
52 : :
53 : : class XMLTransformerOASISEventMap_Impl:
54 : : public ::boost::unordered_map< NameKey_Impl, ::rtl::OUString,
55 : : NameHash_Impl, NameHash_Impl >
56 : : {
57 : : public:
58 : : XMLTransformerOASISEventMap_Impl( XMLTransformerEventMapEntry *pInit );
59 : : ~XMLTransformerOASISEventMap_Impl();
60 : : };
61 : :
62 [ # # ]: 0 : XMLTransformerOASISEventMap_Impl::XMLTransformerOASISEventMap_Impl( XMLTransformerEventMapEntry *pInit )
63 : : {
64 [ # # ]: 0 : if( pInit )
65 : : {
66 : 0 : XMLTransformerOASISEventMap_Impl::key_type aKey;
67 : 0 : XMLTransformerOASISEventMap_Impl::mapped_type aData;
68 [ # # ]: 0 : while( pInit->m_pOASISName )
69 : : {
70 : 0 : aKey.m_nPrefix = pInit->m_nOASISPrefix;
71 : 0 : aKey.m_aLocalName = OUString::createFromAscii(pInit->m_pOASISName);
72 : :
73 : : OSL_ENSURE( find( aKey ) == end(), "duplicate event map entry" );
74 : :
75 : 0 : aData = OUString::createFromAscii(pInit->m_pOOoName);
76 : :
77 : 0 : XMLTransformerOASISEventMap_Impl::value_type aVal( aKey, aData );
78 : :
79 [ # # ]: 0 : insert( aVal );
80 : 0 : ++pInit;
81 : 0 : }
82 : : }
83 : 0 : }
84 : :
85 : 0 : XMLTransformerOASISEventMap_Impl::~XMLTransformerOASISEventMap_Impl()
86 : : {
87 : 0 : }
88 : :
89 : : // -----------------------------------------------------------------------------
90 : :
91 [ # # ][ # # ]: 0 : TYPEINIT1( XMLEventOASISTransformerContext, XMLRenameElemTransformerContext);
92 : :
93 : 0 : XMLEventOASISTransformerContext::XMLEventOASISTransformerContext(
94 : : XMLTransformerBase& rImp,
95 : : const OUString& rQName ) :
96 : : XMLRenameElemTransformerContext( rImp, rQName,
97 : 0 : rImp.GetNamespaceMap().GetKeyByAttrName( rQName ), XML_EVENT )
98 : : {
99 : 0 : }
100 : :
101 : 0 : XMLEventOASISTransformerContext::~XMLEventOASISTransformerContext()
102 : : {
103 [ # # ]: 0 : }
104 : :
105 : : XMLTransformerOASISEventMap_Impl
106 : 0 : *XMLEventOASISTransformerContext::CreateEventMap()
107 : : {
108 [ # # ]: 0 : return new XMLTransformerOASISEventMap_Impl( aTransformerEventMap );
109 : : }
110 : :
111 : : XMLTransformerOASISEventMap_Impl
112 : 0 : *XMLEventOASISTransformerContext::CreateFormEventMap()
113 : : {
114 [ # # ]: 0 : return new XMLTransformerOASISEventMap_Impl( aFormTransformerEventMap );
115 : : }
116 : :
117 : 88 : void XMLEventOASISTransformerContext::FlushEventMap(
118 : : XMLTransformerOASISEventMap_Impl *p )
119 : : {
120 [ - + ]: 88 : delete p;
121 : 88 : }
122 : :
123 : 0 : OUString XMLEventOASISTransformerContext::GetEventName(
124 : : sal_uInt16 nPrefix,
125 : : const OUString& rName,
126 : : XMLTransformerOASISEventMap_Impl& rMap,
127 : : XMLTransformerOASISEventMap_Impl *pMap2)
128 : : {
129 : 0 : XMLTransformerOASISEventMap_Impl::key_type aKey( nPrefix, rName );
130 [ # # ]: 0 : if( pMap2 )
131 : : {
132 : : XMLTransformerOASISEventMap_Impl::const_iterator aIter =
133 [ # # ]: 0 : pMap2->find( aKey );
134 [ # # ][ # # ]: 0 : if( !(aIter == pMap2->end()) )
135 [ # # ]: 0 : return (*aIter).second;
136 : : }
137 : :
138 [ # # ]: 0 : XMLTransformerOASISEventMap_Impl::const_iterator aIter = rMap.find( aKey );
139 [ # # ][ # # ]: 0 : if( aIter == rMap.end() )
140 : 0 : return rName;
141 : : else
142 [ # # ]: 0 : return (*aIter).second;
143 : : }
144 : :
145 : 0 : bool ParseURLAsString(
146 : : const OUString& rAttrValue,
147 : : OUString* pName, OUString* pLocation )
148 : : {
149 : 0 : OUString SCHEME( "vnd.sun.star.script:" );
150 : :
151 : 0 : sal_Int32 params = rAttrValue.indexOf( '?' );
152 [ # # ][ # # ]: 0 : if ( rAttrValue.indexOf( SCHEME ) != 0 || params < 0 )
[ # # ]
153 : : {
154 : 0 : return sal_False;
155 : : }
156 : :
157 : 0 : sal_Int32 start = SCHEME.getLength();
158 : 0 : *pName = rAttrValue.copy( start, params - start );
159 : :
160 : 0 : OUString aToken;
161 : 0 : OUString aLanguage;
162 : 0 : params++;
163 [ # # ]: 0 : do
164 : : {
165 : 0 : aToken = rAttrValue.getToken( 0, '&', params );
166 : 0 : sal_Int32 dummy = 0;
167 : :
168 [ # # ][ # # ]: 0 : if ( aToken.match( GetXMLToken( XML_LANGUAGE ) ) )
169 : : {
170 : 0 : aLanguage = aToken.getToken( 1, '=', dummy );
171 : : }
172 [ # # ][ # # ]: 0 : else if ( aToken.match( GetXMLToken( XML_LOCATION ) ) )
173 : : {
174 : 0 : OUString tmp = aToken.getToken( 1, '=', dummy );
175 [ # # ][ # # ]: 0 : if ( tmp.equalsIgnoreAsciiCase( GetXMLToken( XML_DOCUMENT ) ) )
176 : : {
177 [ # # ]: 0 : *pLocation = GetXMLToken( XML_DOCUMENT );
178 : : }
179 : : else
180 : : {
181 [ # # ]: 0 : *pLocation = GetXMLToken( XML_APPLICATION );
182 : 0 : }
183 : : }
184 : : } while ( params >= 0 );
185 : :
186 [ # # ]: 0 : if ( aLanguage.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("basic")) )
187 : : {
188 : 0 : return sal_True;
189 : : }
190 : 0 : return sal_False;
191 : : }
192 : :
193 : 0 : bool ParseURL(
194 : : const OUString& rAttrValue,
195 : : OUString* pName, OUString* pLocation )
196 : : {
197 : : #ifdef OASIS_FILTER_OOO_1X
198 : : return ParseURLAsString( rAttrValue, pName, pLocation );
199 : : #else
200 : : Reference< com::sun::star::lang::XMultiServiceFactory >
201 [ # # ]: 0 : xSMgr = ::comphelper::getProcessServiceFactory();
202 : :
203 : : Reference< com::sun::star::uri::XUriReferenceFactory >
204 [ # # ]: 0 : xFactory( xSMgr->createInstance( OUString(
205 [ # # ][ # # ]: 0 : "com.sun.star.uri.UriReferenceFactory" ) ), UNO_QUERY );
206 : :
207 [ # # ]: 0 : if ( xFactory.is() )
208 : : {
209 : : Reference< com::sun::star::uri::XVndSunStarScriptUrl > xUrl (
210 [ # # ][ # # ]: 0 : xFactory->parse( rAttrValue ), UNO_QUERY );
[ # # ]
211 : :
212 [ # # ]: 0 : if ( xUrl.is() )
213 : : {
214 [ # # ]: 0 : OUString aLanguageKey = GetXMLToken( XML_LANGUAGE );
215 [ # # ][ # # ]: 0 : if ( xUrl.is() && xUrl->hasParameter( aLanguageKey ) )
[ # # ][ # # ]
[ # # ]
216 : : {
217 [ # # ][ # # ]: 0 : OUString aLanguage = xUrl->getParameter( aLanguageKey );
218 : :
219 [ # # ]: 0 : if ( aLanguage.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("basic")) )
220 : : {
221 [ # # ][ # # ]: 0 : *pName = xUrl->getName();
222 : :
223 : : OUString tmp =
224 [ # # ][ # # ]: 0 : xUrl->getParameter( GetXMLToken( XML_LOCATION ) );
[ # # ]
225 : :
226 [ # # ]: 0 : OUString doc = GetXMLToken( XML_DOCUMENT );
227 : :
228 [ # # ]: 0 : if ( tmp.equalsIgnoreAsciiCase( doc ) )
229 : : {
230 : 0 : *pLocation = doc;
231 : : }
232 : : else
233 : : {
234 [ # # ]: 0 : *pLocation = GetXMLToken( XML_APPLICATION );
235 : : }
236 : 0 : return sal_True;
237 [ # # ]: 0 : }
238 [ # # ]: 0 : }
239 : : }
240 : 0 : return sal_False;
241 : : }
242 : : else
243 : : {
244 [ # # ]: 0 : return ParseURLAsString( rAttrValue, pName, pLocation );
245 : 0 : }
246 : : #endif
247 : : }
248 : :
249 : 0 : void XMLEventOASISTransformerContext::StartElement(
250 : : const Reference< XAttributeList >& rAttrList )
251 : : {
252 : : OSL_TRACE("XMLEventOASISTransformerContext::StartElement");
253 : :
254 : : XMLTransformerActions *pActions =
255 [ # # ]: 0 : GetTransformer().GetUserDefinedActions( OASIS_EVENT_ACTIONS );
256 : : OSL_ENSURE( pActions, "go no actions" );
257 : :
258 : 0 : Reference< XAttributeList > xAttrList( rAttrList );
259 : 0 : XMLMutableAttributeList *pMutableAttrList = 0;
260 [ # # ][ # # ]: 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
[ # # ]
261 [ # # ]: 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
262 : : {
263 [ # # ][ # # ]: 0 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
264 : 0 : OUString aLocalName;
265 : : sal_uInt16 nPrefix =
266 : 0 : GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
267 [ # # ]: 0 : &aLocalName );
268 : 0 : XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
269 : : XMLTransformerActions::const_iterator aIter =
270 [ # # ]: 0 : pActions->find( aKey );
271 [ # # ][ # # ]: 0 : if( !(aIter == pActions->end() ) )
272 : : {
273 [ # # ]: 0 : if( !pMutableAttrList )
274 : : {
275 : : pMutableAttrList =
276 [ # # ]: 0 : new XMLMutableAttributeList( xAttrList );
277 [ # # ][ # # ]: 0 : xAttrList = pMutableAttrList;
278 : : }
279 [ # # ][ # # ]: 0 : const OUString& rAttrValue = xAttrList->getValueByIndex( i );
280 [ # # ][ # # : 0 : switch( (*aIter).second.m_nActionType )
# # # # ]
281 : : {
282 : : case XML_ATACTION_HREF:
283 : : {
284 : 0 : OUString aAttrValue( rAttrValue );
285 : 0 : OUString aName, aLocation;
286 : :
287 : : bool bNeedsTransform =
288 [ # # ]: 0 : ParseURL( rAttrValue, &aName, &aLocation );
289 : :
290 [ # # ]: 0 : if ( bNeedsTransform )
291 : : {
292 [ # # ]: 0 : pMutableAttrList->RemoveAttributeByIndex( i );
293 : :
294 : : OUString aAttrQName(
295 : 0 : GetTransformer().GetNamespaceMap().GetQNameByKey(
296 : : XML_NAMESPACE_SCRIPT,
297 [ # # # # ]: 0 : ::xmloff::token::GetXMLToken( XML_MACRO_NAME ) ) );
298 : :
299 [ # # ]: 0 : pMutableAttrList->AddAttribute( aAttrQName, aName );
300 : :
301 : : sal_Int16 idx = pMutableAttrList->GetIndexByName(
302 : 0 : GetTransformer().GetNamespaceMap().GetQNameByKey(
303 : : XML_NAMESPACE_SCRIPT,
304 [ # # # # ]: 0 : GetXMLToken( XML_LANGUAGE ) ) );
[ # # ]
305 : :
306 : : pMutableAttrList->SetValueByIndex( idx,
307 [ # # ]: 0 : OUString("StarBasic") );
308 : :
309 : : OUString aLocQName(
310 : 0 : GetTransformer().GetNamespaceMap().GetQNameByKey(
311 : : XML_NAMESPACE_SCRIPT,
312 [ # # # # ]: 0 : GetXMLToken( XML_LOCATION ) ) );
313 : :
314 [ # # ]: 0 : pMutableAttrList->AddAttribute( aLocQName, aLocation );
315 : 0 : }
316 : : }
317 : 0 : break;
318 : : case XML_ATACTION_EVENT_NAME:
319 : : {
320 : : // Check if the event belongs to a form or control by
321 : : // cehcking the 2nd ancestor element, f.i.:
322 : : // <form:button><form:event-listeners><form:event-listener>
323 : : const XMLTransformerContext *pObjContext =
324 [ # # ]: 0 : GetTransformer().GetAncestorContext( 1 );
325 : : sal_Bool bForm = pObjContext &&
326 : :
327 [ # # ][ # # ]: 0 : pObjContext->HasNamespace(XML_NAMESPACE_FORM );
[ # # ]
328 : : pMutableAttrList->SetValueByIndex( i,
329 : 0 : GetTransformer().GetEventName( rAttrValue,
330 [ # # ][ # # ]: 0 : bForm ) );
331 : : }
332 : 0 : break;
333 : : case XML_ATACTION_REMOVE_NAMESPACE_PREFIX:
334 : : {
335 : 0 : OUString aAttrValue( rAttrValue );
336 : : sal_uInt16 nValPrefix =
337 [ # # ]: 0 : static_cast<sal_uInt16>((*aIter).second.m_nParam1);
338 [ # # ]: 0 : if( GetTransformer().RemoveNamespacePrefix(
339 [ # # ]: 0 : aAttrValue, nValPrefix ) )
340 [ # # ]: 0 : pMutableAttrList->SetValueByIndex( i, aAttrValue );
341 : : }
342 : 0 : break;
343 : : case XML_ATACTION_MACRO_NAME:
344 : : {
345 : 0 : OUString aName, aLocation;
346 : : bool bNeedsTransform =
347 [ # # ]: 0 : ParseURL( rAttrValue, &aName, &aLocation );
348 : :
349 [ # # ]: 0 : if ( bNeedsTransform )
350 : : {
351 [ # # ]: 0 : pMutableAttrList->SetValueByIndex( i, aName );
352 : :
353 : : sal_Int16 idx = pMutableAttrList->GetIndexByName(
354 : 0 : GetTransformer().GetNamespaceMap().GetQNameByKey(
355 : : XML_NAMESPACE_SCRIPT,
356 [ # # # # ]: 0 : GetXMLToken( XML_LANGUAGE ) ) );
[ # # ]
357 : :
358 : : pMutableAttrList->SetValueByIndex( idx,
359 [ # # ]: 0 : OUString("StarBasic") );
360 : :
361 : : OUString aLocQName(
362 : 0 : GetTransformer().GetNamespaceMap().GetQNameByKey(
363 : : XML_NAMESPACE_SCRIPT,
364 [ # # # # ]: 0 : GetXMLToken( XML_LOCATION ) ) );
365 : :
366 [ # # ]: 0 : pMutableAttrList->AddAttribute( aLocQName, aLocation );
367 : : }
368 : : else
369 : : {
370 [ # # ]: 0 : const OUString& rApp = GetXMLToken( XML_APPLICATION );
371 [ # # ]: 0 : const OUString& rDoc = GetXMLToken( XML_DOCUMENT );
372 : 0 : OUString aAttrValue;
373 [ # # ][ # # : 0 : if( rAttrValue.getLength() > rApp.getLength()+1 &&
# # # # ]
374 : : rAttrValue.copy(0,rApp.getLength()).
375 [ # # ]: 0 : equalsIgnoreAsciiCase( rApp ) &&
376 : 0 : ':' == rAttrValue[rApp.getLength()] )
377 : : {
378 : 0 : aLocation = rApp;
379 : 0 : aAttrValue = rAttrValue.copy( rApp.getLength()+1 );
380 : : }
381 [ # # # # : 0 : else if( rAttrValue.getLength() > rDoc.getLength()+1 &&
# # ][ # # ]
382 : : rAttrValue.copy(0,rDoc.getLength()).
383 [ # # ]: 0 : equalsIgnoreAsciiCase( rDoc ) &&
384 : 0 : ':' == rAttrValue[rDoc.getLength()] )
385 : : {
386 : 0 : aLocation= rDoc;
387 : 0 : aAttrValue = rAttrValue.copy( rDoc.getLength()+1 );
388 : : }
389 [ # # ]: 0 : if( !aAttrValue.isEmpty() )
390 : : pMutableAttrList->SetValueByIndex( i,
391 [ # # ]: 0 : aAttrValue );
392 [ # # ]: 0 : if( !aLocation.isEmpty() )
393 : : {
394 : 0 : OUString aAttrQName( GetTransformer().GetNamespaceMap().
395 : : GetQNameByKey( XML_NAMESPACE_SCRIPT,
396 [ # # # # ]: 0 : ::xmloff::token::GetXMLToken( XML_LOCATION ) ) );
397 [ # # ]: 0 : pMutableAttrList->AddAttribute( aAttrQName, aLocation );
398 : : // draw bug
399 : 0 : aAttrQName = GetTransformer().GetNamespaceMap().
400 : : GetQNameByKey( XML_NAMESPACE_SCRIPT,
401 [ # # # # ]: 0 : ::xmloff::token::GetXMLToken( XML_LIBRARY ) );
402 [ # # ]: 0 : pMutableAttrList->AddAttribute( aAttrQName, aLocation );
403 : 0 : }
404 : 0 : }
405 : : }
406 : 0 : break;
407 : : case XML_ATACTION_COPY:
408 : 0 : break;
409 : : default:
410 : : OSL_ENSURE( !this, "unknown action" );
411 : 0 : break;
412 : 0 : }
413 : : }
414 : 0 : }
415 : :
416 [ # # ]: 0 : XMLRenameElemTransformerContext::StartElement( xAttrList );
417 : 0 : }
418 : :
419 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|