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 "XMLScriptExportHandler.hxx" 27 28 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP 29 #include <com/sun/star/beans/PropertyValue.hpp> 30 #endif 31 #include <tools/debug.hxx> 32 #include <xmloff/xmlexp.hxx> 33 #include <xmloff/xmltoken.hxx> 34 #include <xmloff/nmspmap.hxx> 35 #include "xmloff/xmlnmspe.hxx" 36 37 38 using namespace ::com::sun::star::uno; 39 using namespace ::xmloff::token; 40 41 using ::rtl::OUString; 42 using ::com::sun::star::beans::PropertyValue; 43 44 45 XMLScriptExportHandler::XMLScriptExportHandler() : 46 sURL(RTL_CONSTASCII_USTRINGPARAM("Script")) 47 { 48 } 49 50 XMLScriptExportHandler::~XMLScriptExportHandler() 51 { 52 } 53 54 void XMLScriptExportHandler::Export( 55 SvXMLExport& rExport, 56 const OUString& rEventQName, 57 Sequence<PropertyValue> & rValues, 58 sal_Bool bUseWhitespace) 59 { 60 // without the property the listener would lack the required xlink:href and xlink:type 61 sal_Bool bHasScript = sal_False; 62 sal_Int32 nCount = rValues.getLength(); 63 for(sal_Int32 i = 0; i < nCount; i++) 64 { 65 if (sURL.equals(rValues[i].Name)) 66 bHasScript = sal_True; 67 } 68 if (!bHasScript) 69 return; 70 71 rExport.AddAttribute(XML_NAMESPACE_SCRIPT, XML_LANGUAGE, 72 rExport.GetNamespaceMap().GetQNameByKey( 73 XML_NAMESPACE_OOO, GetXMLToken(XML_SCRIPT) ) ); 74 rExport.AddAttribute(XML_NAMESPACE_SCRIPT, XML_EVENT_NAME, rEventQName); 75 76 for(sal_Int32 i = 0; i < nCount; i++) 77 { 78 if (sURL.equals(rValues[i].Name)) 79 { 80 OUString sTmp; 81 rValues[i].Value >>= sTmp; 82 rExport.AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, sTmp); 83 84 // #i110911# xlink:type="simple" is required 85 rExport.AddAttribute(XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE); 86 } 87 // else: disregard 88 } 89 90 SvXMLElementExport aEventElemt(rExport, XML_NAMESPACE_SCRIPT, 91 XML_EVENT_LISTENER, 92 bUseWhitespace, sal_False); 93 } 94