1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 #include "XMLScriptContextFactory.hxx"
31 #include <xmloff/XMLEventsImportContext.hxx>
32 #include <tools/debug.hxx>
33 #include <xmloff/xmlimp.hxx>
34 #include <xmloff/nmspmap.hxx>
35 #include "xmloff/xmlnmspe.hxx"
36 #include <xmloff/xmltoken.hxx>
37 
38 
39 using namespace ::xmloff::token;
40 
41 using ::rtl::OUString;
42 using ::com::sun::star::xml::sax::XAttributeList;
43 using ::com::sun::star::beans::PropertyValue;
44 using ::com::sun::star::uno::Reference;
45 using ::com::sun::star::uno::Sequence;
46 using ::com::sun::star::uno::Any;
47 
48 XMLScriptContextFactory::XMLScriptContextFactory() :
49     sEventType(RTL_CONSTASCII_USTRINGPARAM("EventType")),
50     sScript(RTL_CONSTASCII_USTRINGPARAM("Script")),
51     sURL(RTL_CONSTASCII_USTRINGPARAM("Script"))
52 {
53 }
54 
55 XMLScriptContextFactory::~XMLScriptContextFactory()
56 {
57 }
58 
59 SvXMLImportContext * XMLScriptContextFactory::CreateContext
60 (SvXMLImport & rImport,
61  sal_uInt16 p_nPrefix,
62  const OUString & rLocalName,
63  const Reference<XAttributeList> & xAttrList,
64  XMLEventsImportContext * rEvents,
65  const OUString & rApiEventName,
66  const OUString & /*rApiLanguage*/)
67 {
68     OUString sURLVal;
69 
70     sal_Int16 nCount = xAttrList->getLength();
71     for (sal_Int16 nAttr = 0; nAttr < nCount; nAttr++)
72     {
73         OUString sLocalName;
74         sal_uInt16 nPrefix = rImport.GetNamespaceMap().
75             GetKeyByAttrName(xAttrList->getNameByIndex(nAttr), &sLocalName);
76 
77         if (XML_NAMESPACE_XLINK == nPrefix)
78         {
79             if (IsXMLToken(sLocalName, XML_HREF))
80                 sURLVal = xAttrList->getValueByIndex(nAttr);
81             // else: ignore
82         }
83         // else ignore
84     }
85 
86     Sequence<PropertyValue> aValues(2);
87 
88 	// EventType
89 	aValues[0].Name = sEventType;
90 	aValues[0].Value <<= sScript;
91 
92 	// URL
93 	aValues[1].Name = sURL;
94 	aValues[1].Value <<= sURLVal;
95 
96 	// add values for event now
97 	rEvents->AddEventValues(rApiEventName, aValues);
98 
99 	// return dummy context
100 	return new SvXMLImportContext(rImport, p_nPrefix, rLocalName);
101 }
102 
103