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 "XMLScriptContextFactory.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 XMLScriptContextFactory::XMLScriptContextFactory() : 45 sEventType(RTL_CONSTASCII_USTRINGPARAM("EventType")), 46 sScript(RTL_CONSTASCII_USTRINGPARAM("Script")), 47 sURL(RTL_CONSTASCII_USTRINGPARAM("Script")) 48 { 49 } 50 51 XMLScriptContextFactory::~XMLScriptContextFactory() 52 { 53 } 54 55 SvXMLImportContext * XMLScriptContextFactory::CreateContext 56 (SvXMLImport & rImport, 57 sal_uInt16 p_nPrefix, 58 const OUString & rLocalName, 59 const Reference<XAttributeList> & xAttrList, 60 XMLEventsImportContext * rEvents, 61 const OUString & rApiEventName, 62 const OUString & /*rApiLanguage*/) 63 { 64 OUString sURLVal; 65 66 sal_Int16 nCount = xAttrList->getLength(); 67 for (sal_Int16 nAttr = 0; nAttr < nCount; nAttr++) 68 { 69 OUString sLocalName; 70 sal_uInt16 nPrefix = rImport.GetNamespaceMap(). 71 GetKeyByAttrName(xAttrList->getNameByIndex(nAttr), &sLocalName); 72 73 if (XML_NAMESPACE_XLINK == nPrefix) 74 { 75 if (IsXMLToken(sLocalName, XML_HREF)) 76 sURLVal = xAttrList->getValueByIndex(nAttr); 77 // else: ignore 78 } 79 // else ignore 80 } 81 82 Sequence<PropertyValue> aValues(2); 83 84 // EventType 85 aValues[0].Name = sEventType; 86 aValues[0].Value <<= sScript; 87 88 // URL 89 aValues[1].Name = sURL; 90 aValues[1].Value <<= sURLVal; 91 92 // add values for event now 93 rEvents->AddEventValues(rApiEventName, aValues); 94 95 // return dummy context 96 return new SvXMLImportContext(rImport, p_nPrefix, rLocalName); 97 } 98 99