From 61bc58aa6e55a0e41973948a17faacd07b1ec32f Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Tue, 5 Apr 2016 16:47:58 +0200 Subject: [PATCH] Add generated extension --- .classpath | 8 + .gitignore | 3 + .project | 23 +++ .unoproject | 12 ++ description.xml | 7 + idl/org/libreoffice/example/.idl | 5 + .../libreoffice/example/StarterProject.idl | 12 ++ package.properties | 0 .../example/comp/RegistrationHandler.classes | 1 + .../example/comp/RegistrationHandler.java | 175 ++++++++++++++++++ .../example/comp/StarterProjectImpl.java | 64 +++++++ 11 files changed, 310 insertions(+) create mode 100644 .classpath create mode 100644 .gitignore create mode 100644 .project create mode 100644 .unoproject create mode 100644 description.xml create mode 100644 idl/org/libreoffice/example/.idl create mode 100644 idl/org/libreoffice/example/StarterProject.idl create mode 100644 package.properties create mode 100644 source/org/libreoffice/example/comp/RegistrationHandler.classes create mode 100644 source/org/libreoffice/example/comp/RegistrationHandler.java create mode 100644 source/org/libreoffice/example/comp/StarterProjectImpl.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..6e6fd97 --- /dev/null +++ b/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..627052d --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +bin/ +build/ +types.rdb diff --git a/.project b/.project new file mode 100644 index 0000000..605dc2d --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + StarterProject + + + + + + org.libreoffice.ide.eclipse.core.types + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.libreoffice.ide.eclipse.core.unonature + org.eclipse.jdt.core.javanature + + diff --git a/.unoproject b/.unoproject new file mode 100644 index 0000000..aa6d445 --- /dev/null +++ b/.unoproject @@ -0,0 +1,12 @@ +#UNO project configuration file +#Tue Apr 05 16:35:24 CEST 2016 +project.srcdir=/source +regclassname=org.libreoffice.example.comp.RegistrationHandler +javaversion=java5 +project.sdk=5.0.5.2 +project.ooo=LibreOffice 5.0 +project.implementation=comp +project.build=build +project.language=Java +project.prefix=org.libreoffice.example +project.idl=/idl diff --git a/description.xml b/description.xml new file mode 100644 index 0000000..da4917a --- /dev/null +++ b/description.xml @@ -0,0 +1,7 @@ + + + + + StarterProject + + diff --git a/idl/org/libreoffice/example/.idl b/idl/org/libreoffice/example/.idl new file mode 100644 index 0000000..cc5c49a --- /dev/null +++ b/idl/org/libreoffice/example/.idl @@ -0,0 +1,5 @@ +#ifndef __org_libreoffice_example__idl__ +#define __org_libreoffice_example__idl__ + +module org { module libreoffice { module example { }; }; }; +#endif diff --git a/idl/org/libreoffice/example/StarterProject.idl b/idl/org/libreoffice/example/StarterProject.idl new file mode 100644 index 0000000..fc34ddb --- /dev/null +++ b/idl/org/libreoffice/example/StarterProject.idl @@ -0,0 +1,12 @@ +#ifndef __org_libreoffice_example_starterproject_idl__ +#define __org_libreoffice_example_starterproject_idl__ + +#include +module org { module libreoffice { module example { + + service StarterProject : com::sun::star::task::XJobExecutor { + + }; + + }; }; }; +#endif diff --git a/package.properties b/package.properties new file mode 100644 index 0000000..e69de29 diff --git a/source/org/libreoffice/example/comp/RegistrationHandler.classes b/source/org/libreoffice/example/comp/RegistrationHandler.classes new file mode 100644 index 0000000..c145ca0 --- /dev/null +++ b/source/org/libreoffice/example/comp/RegistrationHandler.classes @@ -0,0 +1 @@ +org.libreoffice.example.comp.StarterProjectImpl diff --git a/source/org/libreoffice/example/comp/RegistrationHandler.java b/source/org/libreoffice/example/comp/RegistrationHandler.java new file mode 100644 index 0000000..3819b73 --- /dev/null +++ b/source/org/libreoffice/example/comp/RegistrationHandler.java @@ -0,0 +1,175 @@ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * either of the GNU Lesser General Public License Version 2.1 + * + * Sun Microsystems Inc., October, 2000 + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc.. + * + * Copyright: 2002 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): Cedric Bosdonnat + * + * + ************************************************************************/ +package org.libreoffice.example.comp; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.LineNumberReader; +import java.lang.reflect.Method; +import java.util.ArrayList; + +import com.sun.star.lang.XSingleComponentFactory; +import com.sun.star.registry.XRegistryKey; + +/** + * Component main registration class. + * + *

This class should not be modified.

+ * + * @author Cedric Bosdonnat aka. cedricbosdo + * + */ +public class RegistrationHandler { + + /** + * Get a component factory for the implementations handled by this class. + * + *

This method calls all the methods of the same name from the classes listed + * in the RegistrationHandler.classes file. This method + * should not be modified.

+ * + * @param pImplementationName the name of the implementation to create. + * + * @return the factory which can create the implementation. + */ + public static XSingleComponentFactory __getComponentFactory(String sImplementationName ) { + XSingleComponentFactory xFactory = null; + + Class[] classes = findServicesImplementationClasses(); + + int i = 0; + while (i < classes.length && xFactory == null) { + Class clazz = classes[i]; + if ( sImplementationName.equals( clazz.getCanonicalName() ) ) { + try { + Class[] getTypes = new Class[]{String.class}; + Method getFactoryMethod = clazz.getMethod("__getComponentFactory", getTypes); + Object o = getFactoryMethod.invoke(null, sImplementationName); + xFactory = (XSingleComponentFactory)o; + } catch (Exception e) { + // Nothing to do: skip + System.err.println("Error happened"); + e.printStackTrace(); + } + } + i++; + } + return xFactory; + } + + /** + * Writes the services implementation informations to the UNO registry. + * + *

This method calls all the methods of the same name from the classes listed + * in the RegistrationHandler.classes file. This method + * should not be modified.

+ * + * @param pRegistryKey the root registry key where to write the informations. + * + * @return true if the informations have been successfully written + * to the registry key, false otherwise. + */ + public static boolean __writeRegistryServiceInfo(XRegistryKey xRegistryKey ) { + + Class[] classes = findServicesImplementationClasses(); + + boolean success = true; + int i = 0; + while (i < classes.length && success) { + Class clazz = classes[i]; + try { + Class[] writeTypes = new Class[]{XRegistryKey.class}; + Method getFactoryMethod = clazz.getMethod("__writeRegistryServiceInfo", writeTypes); + Object o = getFactoryMethod.invoke(null, xRegistryKey); + success = success && ((Boolean)o).booleanValue(); + } catch (Exception e) { + success = false; + e.printStackTrace(); + } + i++; + } + return success; + } + + /** + * @return all the UNO implementation classes. + */ + private static Class[] findServicesImplementationClasses() { + + ArrayList classes = new ArrayList(); + + InputStream in = RegistrationHandler.class.getResourceAsStream("RegistrationHandler.classes"); + LineNumberReader reader = new LineNumberReader(new InputStreamReader(in)); + + try { + String line = reader.readLine(); + while (line != null) { + if (!line.equals("")) { + line = line.trim(); + try { + Class clazz = Class.forName(line); + + Class[] writeTypes = new Class[]{XRegistryKey.class}; + Class[] getTypes = new Class[]{String.class}; + + Method writeRegMethod = clazz.getMethod("__writeRegistryServiceInfo", writeTypes); + Method getFactoryMethod = clazz.getMethod("__getComponentFactory", getTypes); + + if (writeRegMethod != null && getFactoryMethod != null) { + classes.add(clazz); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + line = reader.readLine(); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + reader.close(); + in.close(); + } catch (Exception e) {}; + } + + return classes.toArray(new Class[classes.size()]); + } +} diff --git a/source/org/libreoffice/example/comp/StarterProjectImpl.java b/source/org/libreoffice/example/comp/StarterProjectImpl.java new file mode 100644 index 0000000..b6edecc --- /dev/null +++ b/source/org/libreoffice/example/comp/StarterProjectImpl.java @@ -0,0 +1,64 @@ +package org.libreoffice.example.comp; + +import com.sun.star.uno.XComponentContext; +import com.sun.star.lib.uno.helper.Factory; +import com.sun.star.lang.XSingleComponentFactory; +import com.sun.star.registry.XRegistryKey; +import com.sun.star.lib.uno.helper.WeakBase; + + +public final class StarterProjectImpl extends WeakBase + implements com.sun.star.lang.XServiceInfo, + com.sun.star.task.XJobExecutor +{ + private final XComponentContext m_xContext; + private static final String m_implementationName = StarterProjectImpl.class.getName(); + private static final String[] m_serviceNames = { + "org.libreoffice.example.StarterProject" }; + + + public StarterProjectImpl( XComponentContext context ) + { + m_xContext = context; + }; + + public static XSingleComponentFactory __getComponentFactory( String sImplementationName ) { + XSingleComponentFactory xFactory = null; + + if ( sImplementationName.equals( m_implementationName ) ) + xFactory = Factory.createComponentFactory(StarterProjectImpl.class, m_serviceNames); + return xFactory; + } + + public static boolean __writeRegistryServiceInfo( XRegistryKey xRegistryKey ) { + return Factory.writeRegistryServiceInfo(m_implementationName, + m_serviceNames, + xRegistryKey); + } + + // com.sun.star.lang.XServiceInfo: + public String getImplementationName() { + return m_implementationName; + } + + public boolean supportsService( String sService ) { + int len = m_serviceNames.length; + + for( int i=0; i < len; i++) { + if (sService.equals(m_serviceNames[i])) + return true; + } + return false; + } + + public String[] getSupportedServiceNames() { + return m_serviceNames; + } + + // com.sun.star.task.XJobExecutor: + public void trigger(String Event) + { + // TODO: Insert your implementation for "trigger" here. + } + +}