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 
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_forms.hxx"
31 #include <stdio.h>
32 #include <com/sun/star/xml/xpath/Libxml2ExtensionHandle.hpp>
33 #include <com/sun/star/beans/NamedValue.hpp>
34 #include "extension.hxx"
35 #include "xpathlib.hxx"
36 #include "frm_module.hxx"
37 
38 using namespace com::sun::star::uno;
39 using namespace com::sun::star::lang;
40 using namespace com::sun::star::xforms;
41 using namespace com::sun::star::xml::xpath;
42 using namespace com::sun::star::beans;
43 using com::sun::star::xml::dom::XNode;
44 
45 Reference< XInterface > SAL_CALL CLibxml2XFormsExtension::Create(
46     const Reference< XMultiServiceFactory >& /*aFactory*/)
47 {
48     // printf("_create_\n");
49     Reference< XInterface > aInstance(static_cast< XXPathExtension* >(new CLibxml2XFormsExtension(/*aFactory*/)));
50     return aInstance;
51 }
52 
53 ::rtl::OUString SAL_CALL CLibxml2XFormsExtension::getImplementationName_Static()
54 {
55     // printf("_implname_\n");
56     return ::rtl::OUString::createFromAscii("com.sun.star.comp.xml.xpath.XFormsExtension");
57 }
58 
59 Sequence< ::rtl::OUString > SAL_CALL CLibxml2XFormsExtension::getSupportedServiceNames_Static()
60 {
61     // printf("_services_\n");
62     Sequence< ::rtl::OUString > aSequence(1);
63     aSequence[0] = ::rtl::OUString::createFromAscii("com.sun.star.xml.xpath.XPathExtension");
64     return aSequence;
65 }
66 
67 Libxml2ExtensionHandle SAL_CALL CLibxml2XFormsExtension::getLibxml2ExtensionHandle() throw (RuntimeException)
68 {
69     Libxml2ExtensionHandle aHandle;
70     aHandle.functionLookupFunction = reinterpret_cast< sal_Int64 >( &xforms_lookupFunc );
71     aHandle.functionData = reinterpret_cast< sal_Int64 >( this );
72     aHandle.variableLookupFunction = (sal_Int64)0;
73     aHandle.variableData = (sal_Int64)0;
74     return aHandle;
75 }
76 
77 void SAL_CALL CLibxml2XFormsExtension::initialize(const Sequence< Any >& aSequence) throw (RuntimeException)
78 {
79     NamedValue aValue;
80     for (sal_Int32 i = 0; i < aSequence.getLength(); i++)
81     {
82         if (! (aSequence[i] >>= aValue))
83             throw RuntimeException();
84         if (aValue.Name.equalsAscii("Model"))
85             aValue.Value >>= m_aModel;
86         else if (aValue.Name.equalsAscii("ContextNode"))
87             aValue.Value >>= m_aContextNode;
88     }
89 }
90 
91 Reference< XModel > CLibxml2XFormsExtension::getModel()
92 {
93     return m_aModel;
94 }
95 
96 Reference< XNode > CLibxml2XFormsExtension::getContextNode()
97 {
98     return m_aContextNode;
99 }
100 
101 extern "C" void SAL_CALL createRegistryInfo_CLibxml2XFormsExtension()
102 {
103     static frm::OMultiInstanceAutoRegistration< CLibxml2XFormsExtension >   aRegistration;
104 }
105