diff options
author | Cédric Bosdonnat <cedric.bosdonnat@free.fr> | 2013-04-04 10:15:32 +0200 |
---|---|---|
committer | Cédric Bosdonnat <cedric.bosdonnat@free.fr> | 2013-04-04 10:20:44 +0200 |
commit | ef84858cbf77100bb524055c652535d8ea66be3f (patch) | |
tree | 0c521aaabdd1c0b61c8166af0a94113b8ba2246d | |
parent | 966fb2685d954daa3ae1cbc6684a55a7a6204e03 (diff) |
Java client wizard: copy jodconnector into the created project
Several major changes around jodconnector:
* The created project now has the jar in it to build more easily
without Eclipse
* The jodconnector source code is now in the source tree instead of a
jar. The means that the jar is created at build time.
* Removed the SLF4J dependencies from the jodconnector
* Removed the JODContainer as it's now useless
22 files changed, 539 insertions, 462 deletions
@@ -2,3 +2,4 @@ /site /*.zip /core/doc/help/html/api/ +/java/jodconnector.jar diff --git a/java/.classpath b/java/.classpath index 55be196..b8d8d6c 100644 --- a/java/.classpath +++ b/java/.classpath @@ -5,5 +5,6 @@ <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> <classpathentry kind="src" path="source"/> <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/ANT"/> + <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/OOo Classes"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/java/build.xml b/java/build.xml index d85291a..ff49f19 100644 --- a/java/build.xml +++ b/java/build.xml @@ -58,6 +58,7 @@ <property name="java.out.path" value="${java.basedir}/bin/ant" /> <property name="java.out.classes" value="${java.out.path}/classes"/> <property name="java.sources" value="${java.basedir}/source"/> + <property name="jodconnector.classes" value="${java.out.path}/jodconnector"/> <path id="java.dependencies.path"> <pathelement location="${packager.out.classes}"/> @@ -83,17 +84,36 @@ <target name="purge" depends="init-env"> <property name="java.out.path" value="${java.basedir}/bin/ant" /> <delete dir="${java.out.path}" /> + <delete file="${java.basedir}/jodconnector.jar" /> </target> + <target name="jodconnector.compile"> + <mkdir dir="${jodconnector.classes}"/> + <javac srcdir="${java.sources}" destdir="${jodconnector.classes}" + target="1.5" source="1.5" + debug="true" + classpathref="office.class.path" + includes="com/artofsolving/**" defaultexcludes="true"> + </javac> + </target> + + <target name="jodconnector.package" depends="jodconnector.compile"> + <jar destfile="${java.basedir}/jodconnector.jar"> + <zipfileset prefix="" dir="${jodconnector.classes}"/> + <zipfileset prefix="" dir="${java.sources}" defaultexcludes="true" includes="com/artofsolving/**"/> + </jar> + </target> + <target name="java.compile" depends="init-env" unless="java.nobuild"> <javac srcdir="${java.sources}" destdir="${java.out.classes}" target="1.5" source="1.5" debug="${debug}" classpathref="java.dependencies.path" - excludes="**/*Test.*"/> + excludes="**/*Test.*,com/artofsolving/**"> + </javac> </target> - <target name="java.plugin" depends="java.version, java.compile" unless="java.nobuild"> + <target name="java.plugin" depends="java.version, java.compile, jodconnector.package" unless="java.nobuild"> <jar destfile="${java.out.path}/plugins/${package.prefix}.java_${java.Bundle-Version}.jar" manifest="${java.basedir}/META-INF/MANIFEST.MF"> <zipfileset prefix="" dir="${java.sources}"> diff --git a/java/lib/jodconnector.jar b/java/lib/jodconnector.jar Binary files differdeleted file mode 100644 index 904f470..0000000 --- a/java/lib/jodconnector.jar +++ /dev/null diff --git a/java/lib/slf4j-api-1.5.6.jar b/java/lib/slf4j-api-1.5.6.jar Binary files differdeleted file mode 100644 index d794252..0000000 --- a/java/lib/slf4j-api-1.5.6.jar +++ /dev/null diff --git a/java/lib/slf4j-jdk14-1.5.6.jar b/java/lib/slf4j-jdk14-1.5.6.jar Binary files differdeleted file mode 100644 index 1ce0a28..0000000 --- a/java/lib/slf4j-jdk14-1.5.6.jar +++ /dev/null diff --git a/java/plugin.xml b/java/plugin.xml index d50406b..979aee5 100644 --- a/java/plugin.xml +++ b/java/plugin.xml @@ -33,10 +33,6 @@ class="org.openoffice.ide.eclipse.java.build.OooClasspathContainerInitializer" id="org.openoffice.ide.eclipse.java.OOO_CONTAINER"> </classpathContainerInitializer> - <classpathContainerInitializer - class="org.openoffice.ide.eclipse.java.client.JODContainer" - id="org.openoffice.ide.eclipse.java.JOD_CONTAINER"> - </classpathContainerInitializer> </extension> <extension point="org.eclipse.jdt.ui.classpathContainerPage"> @@ -45,11 +41,6 @@ id="org.openoffice.ide.eclipse.java.OOO_CONTAINER" name="LibreOffice Libraries"> </classpathContainerPage> - <classpathContainerPage - class="org.openoffice.ide.eclipse.java.client.JODContainerPage" - id="org.openoffice.ide.eclipse.java.JOD_CONTAINER" - name="LibreOffice UNO connector"> - </classpathContainerPage> </extension> <extension point="org.eclipse.ui.newWizards"> diff --git a/java/source/com/artofsolving/jodconverter/openoffice/connection/AbstractOpenOfficeConnection.java b/java/source/com/artofsolving/jodconverter/openoffice/connection/AbstractOpenOfficeConnection.java new file mode 100644 index 0000000..68c114e --- /dev/null +++ b/java/source/com/artofsolving/jodconverter/openoffice/connection/AbstractOpenOfficeConnection.java @@ -0,0 +1,134 @@ +// +// JODConverter - Java OpenDocument Converter +// Copyright (C) 2004-2007 - Mirko Nasato <mirko@artofsolving.com> +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// 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. +// http://www.gnu.org/copyleft/lesser.html +// +// Contributor: +// Laurent Godard <lgodard@nuxeo.com> +// +package com.artofsolving.jodconverter.openoffice.connection; + +import java.net.ConnectException; + +import com.sun.star.beans.XPropertySet; +import com.sun.star.bridge.XBridge; +import com.sun.star.bridge.XBridgeFactory; +import com.sun.star.comp.helper.Bootstrap; +import com.sun.star.connection.NoConnectException; +import com.sun.star.connection.XConnection; +import com.sun.star.connection.XConnector; +import com.sun.star.frame.XComponentLoader; +import com.sun.star.lang.EventObject; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XEventListener; +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.ucb.XFileIdentifierConverter; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; + +public abstract class AbstractOpenOfficeConnection implements OpenOfficeConnection, XEventListener { + + private String connectionString; + private XComponent bridgeComponent; + private XMultiComponentFactory serviceManager; + private XComponentContext componentContext; + private XBridge bridge; + private boolean connected = false; + private boolean expectingDisconnection = false; + + protected AbstractOpenOfficeConnection(String connectionString) { + this.connectionString = connectionString; + } + + public synchronized void connect() throws ConnectException { + try { + XComponentContext localContext = Bootstrap.createInitialComponentContext(null); + XMultiComponentFactory localServiceManager = localContext.getServiceManager(); + XConnector connector = (XConnector) UnoRuntime.queryInterface(XConnector.class, + localServiceManager.createInstanceWithContext("com.sun.star.connection.Connector", localContext)); + XConnection connection = connector.connect(connectionString); + XBridgeFactory bridgeFactory = (XBridgeFactory) UnoRuntime.queryInterface(XBridgeFactory.class, + localServiceManager.createInstanceWithContext("com.sun.star.bridge.BridgeFactory", localContext)); + bridge = bridgeFactory.createBridge("", "urp", connection, null); + bridgeComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, bridge); + bridgeComponent.addEventListener(this); + serviceManager = (XMultiComponentFactory) UnoRuntime.queryInterface(XMultiComponentFactory.class, + bridge.getInstance("StarOffice.ServiceManager")); + XPropertySet properties = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, serviceManager); + componentContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, + properties.getPropertyValue("DefaultContext")); + connected = true; + } catch (NoConnectException connectException) { + throw new ConnectException("connection failed: "+ connectionString +": " + connectException.getMessage()); + } catch (Exception exception) { + throw new OpenOfficeException("connection failed: "+ connectionString, exception); + } + } + + public synchronized void disconnect() { + expectingDisconnection = true; + bridgeComponent.dispose(); + } + + public boolean isConnected() { + return connected; + } + + public void disposing(EventObject event) { + connected = false; + if (!expectingDisconnection) { + throw new OpenOfficeException("disconnected unexpectedly"); + } + expectingDisconnection = false; + } + + // for unit tests only + void simulateUnexpectedDisconnection() { + disposing(null); + bridgeComponent.dispose(); + } + + private Object getService(String className) { + try { + if (!connected) { + connect(); + } + return serviceManager.createInstanceWithContext(className, componentContext); + } catch (Exception exception) { + throw new OpenOfficeException("could not obtain service: " + className, exception); + } + } + + public XComponentLoader getDesktop() { + return (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, + getService("com.sun.star.frame.Desktop")); + } + + public XFileIdentifierConverter getFileContentProvider() { + return (XFileIdentifierConverter) UnoRuntime.queryInterface(XFileIdentifierConverter.class, + getService("com.sun.star.ucb.FileContentProvider")); + } + + public XBridge getBridge() { + return bridge; + } + + public XMultiComponentFactory getRemoteServiceManager() { + return serviceManager; + } + + public XComponentContext getComponentContext() { + return componentContext; + } + +} diff --git a/java/source/com/artofsolving/jodconverter/openoffice/connection/OpenOfficeConfiguration.java b/java/source/com/artofsolving/jodconverter/openoffice/connection/OpenOfficeConfiguration.java new file mode 100644 index 0000000..b34e050 --- /dev/null +++ b/java/source/com/artofsolving/jodconverter/openoffice/connection/OpenOfficeConfiguration.java @@ -0,0 +1,92 @@ +// +// JODConverter - Java OpenDocument Converter +// OpenOffice.org Configuration checker +// Copyright (C) 2007 - Laurent Godard <lgodard@nuxeo.com> +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// 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. +// http://www.gnu.org/copyleft/lesser.html +// +// Contributor: +// Mirko Nasato <mirko@artofsolving.com> +// + +package com.artofsolving.jodconverter.openoffice.connection; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.container.XNameAccess; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; + +/** + * Utility class to access OpenOffice.org configuration properties at runtime + */ +public class OpenOfficeConfiguration { + + public static final String NODE_L10N = "org.openoffice.Setup/L10N"; + public static final String NODE_PRODUCT = "org.openoffice.Setup/Product"; + + private OpenOfficeConnection connection; + + public OpenOfficeConfiguration(OpenOfficeConnection connection){ + this.connection = connection; + } + + public String getOpenOfficeProperty(String nodePath, String node){ + if (!nodePath.startsWith("/")){ + nodePath = "/" + nodePath; + } + String property = ""; + // create the provider and remember it as a XMultiServiceFactory + try { + final String sProviderService = "com.sun.star.configuration.ConfigurationProvider"; + Object configProvider = connection.getRemoteServiceManager().createInstanceWithContext( + sProviderService, connection.getComponentContext()); + XMultiServiceFactory xConfigProvider = (XMultiServiceFactory) UnoRuntime.queryInterface( + com.sun.star.lang.XMultiServiceFactory.class, configProvider); + + // The service name: Need only read access: + final String sReadOnlyView = "com.sun.star.configuration.ConfigurationAccess"; + // creation arguments: nodepath + PropertyValue aPathArgument = new PropertyValue(); + aPathArgument.Name = "nodepath"; + aPathArgument.Value = nodePath; + Object[] aArguments = new Object[1]; + aArguments[0] = aPathArgument; + + // create the view + XInterface xElement = (XInterface) xConfigProvider.createInstanceWithArguments(sReadOnlyView, aArguments); + XNameAccess xChildAccess = + (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, xElement); + + // get the value + property = (String) xChildAccess.getByName(node); + } catch (Exception exception){ + throw new OpenOfficeException("Could not retrieve property", exception); + } + return property; + } + + public String getOpenOfficeVersion(){ + try { + // OOo >= 2.2 returns major.minor.micro + return getOpenOfficeProperty(NODE_PRODUCT, "ooSetupVersionAboutBox"); + } catch (OpenOfficeException noSuchElementException) { + // OOo < 2.2 only returns major.minor + return getOpenOfficeProperty(NODE_PRODUCT, "ooSetupVersion"); + } + } + + public String getOpenOfficeLocale(){ + return getOpenOfficeProperty(NODE_L10N, "ooLocale"); + } + +} diff --git a/java/source/com/artofsolving/jodconverter/openoffice/connection/OpenOfficeConnection.java b/java/source/com/artofsolving/jodconverter/openoffice/connection/OpenOfficeConnection.java new file mode 100644 index 0000000..84b644d --- /dev/null +++ b/java/source/com/artofsolving/jodconverter/openoffice/connection/OpenOfficeConnection.java @@ -0,0 +1,53 @@ +// +// JODConverter - Java OpenDocument Converter +// Copyright (C) 2004-2007 - Mirko Nasato <mirko@artofsolving.com> +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// 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. +// http://www.gnu.org/copyleft/lesser.html +// +package com.artofsolving.jodconverter.openoffice.connection; + +import java.net.ConnectException; + +import com.sun.star.bridge.XBridge; +import com.sun.star.frame.XComponentLoader; +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.ucb.XFileIdentifierConverter; +import com.sun.star.uno.XComponentContext; + +/** + * A UNO remote protocol connection to a listening OpenOffice.org instance + */ +public interface OpenOfficeConnection { + + public void connect() throws ConnectException; + + public void disconnect(); + + public boolean isConnected(); + + /** + * @return the com.sun.star.frame.Desktop service + */ + public XComponentLoader getDesktop(); + + /** + * @return the com.sun.star.ucb.FileContentProvider service + */ + public XFileIdentifierConverter getFileContentProvider(); + + public XBridge getBridge(); + + public XMultiComponentFactory getRemoteServiceManager(); + + public XComponentContext getComponentContext(); + +} diff --git a/java/source/com/artofsolving/jodconverter/openoffice/connection/OpenOfficeException.java b/java/source/com/artofsolving/jodconverter/openoffice/connection/OpenOfficeException.java new file mode 100644 index 0000000..05915f5 --- /dev/null +++ b/java/source/com/artofsolving/jodconverter/openoffice/connection/OpenOfficeException.java @@ -0,0 +1,29 @@ +// +// JODConverter - Java OpenDocument Converter +// Copyright (C) 2004-2007 - Mirko Nasato <mirko@artofsolving.com> +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// 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. +// http://www.gnu.org/copyleft/lesser.html +// +package com.artofsolving.jodconverter.openoffice.connection; + +public class OpenOfficeException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + public OpenOfficeException(String message) { + super(message); + } + + public OpenOfficeException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/java/source/com/artofsolving/jodconverter/openoffice/connection/PipeOpenOfficeConnection.java b/java/source/com/artofsolving/jodconverter/openoffice/connection/PipeOpenOfficeConnection.java new file mode 100644 index 0000000..20c8719 --- /dev/null +++ b/java/source/com/artofsolving/jodconverter/openoffice/connection/PipeOpenOfficeConnection.java @@ -0,0 +1,38 @@ +// +// JODConverter - Java OpenDocument Converter +// Copyright (C) 2004-2007 - Mirko Nasato <mirko@artofsolving.com> +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// 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. +// http://www.gnu.org/copyleft/lesser.html +// +package com.artofsolving.jodconverter.openoffice.connection; + +/** + * OpenOffice connection using a named pipe + * <p> + * <b>Warning!</b> This requires the <i>sal3</i> native library shipped with OpenOffice.org; + * it must be made available via the <i>java.library.path</i> parameter, e.g. + * <pre> + * java -Djava.library.path=/opt/openoffice.org/program my.App + * </pre> + */ +public class PipeOpenOfficeConnection extends AbstractOpenOfficeConnection { + + public static final String DEFAULT_PIPE_NAME = "jodconverter"; + + public PipeOpenOfficeConnection() { + this(DEFAULT_PIPE_NAME); + } + + public PipeOpenOfficeConnection(String pipeName) { + super("pipe,name="+ pipeName); + } +} diff --git a/java/source/com/artofsolving/jodconverter/openoffice/connection/SocketOpenOfficeConnection.java b/java/source/com/artofsolving/jodconverter/openoffice/connection/SocketOpenOfficeConnection.java new file mode 100644 index 0000000..cab093b --- /dev/null +++ b/java/source/com/artofsolving/jodconverter/openoffice/connection/SocketOpenOfficeConnection.java @@ -0,0 +1,34 @@ +// +// JODConverter - Java OpenDocument Converter +// Copyright (C) 2004-2007 - Mirko Nasato <mirko@artofsolving.com> +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// 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. +// http://www.gnu.org/copyleft/lesser.html +// +package com.artofsolving.jodconverter.openoffice.connection; + +public class SocketOpenOfficeConnection extends AbstractOpenOfficeConnection { + + public static final String DEFAULT_HOST = "localhost"; + public static final int DEFAULT_PORT = 8100; + + public SocketOpenOfficeConnection() { + this(DEFAULT_HOST, DEFAULT_PORT); + } + + public SocketOpenOfficeConnection(int port) { + this(DEFAULT_HOST, port); + } + + public SocketOpenOfficeConnection(String host, int port) { + super("socket,host=" + host + ",port=" + port + ",tcpNoDelay=1"); + } +} diff --git a/java/source/org/openoffice/ide/eclipse/java/client/ClientWizard.java b/java/source/org/openoffice/ide/eclipse/java/client/ClientWizard.java index f2e388e..dbdd4f4 100644 --- a/java/source/org/openoffice/ide/eclipse/java/client/ClientWizard.java +++ b/java/source/org/openoffice/ide/eclipse/java/client/ClientWizard.java @@ -59,13 +59,12 @@ import org.openoffice.ide.eclipse.java.utils.TemplatesHelper; */ public class ClientWizard extends BasicNewResourceWizard { + public static final String JODCONNECTOR_LIBNAME = "jodconnector.jar"; //$NON-NLS-1$ private static final String DEST_PACKAGE = "org.openoffice.client"; //$NON-NLS-1$ private static final String CLIENT_CLASS = "UnoClient"; //$NON-NLS-1$ private static final String LICENSE_DIR = "third-party licenses"; //$NON-NLS-1$ private static final String[] LICENSE_FILES = new String[] { "license-jodconnector.txt", //$NON-NLS-1$ - "license-openoffice.org.txt", //$NON-NLS-1$ - "license-slf4j.txt", //$NON-NLS-1$ }; private IWorkbenchPage mActivePage; @@ -84,6 +83,13 @@ public class ClientWizard extends BasicNewResourceWizard { } @Override + public boolean performCancel() { + boolean ret = super.performCancel(); + mThirdPage.performCancel(); + return ret; + } + + @Override public boolean performFinish() { boolean res = true; @@ -110,7 +116,7 @@ public class ClientWizard extends BasicNewResourceWizard { return res; } - + /** * Configure the Java project in order to have a Java UNO client project. * @@ -123,6 +129,7 @@ public class ClientWizard extends BasicNewResourceWizard { // Generate the sample classes in org.openoffice.connection IProject prj = pJavaProject.getProject(); + IClasspathEntry[] srcEntries = mFirstPage.getSourceClasspathEntries(); IFolder srcFolder = ResourcesPlugin.getWorkspace().getRoot().getFolder( srcEntries[0].getPath() ); @@ -157,12 +164,12 @@ public class ClientWizard extends BasicNewResourceWizard { public void addPages() { mCnxPage = new UnoConnectionPage(); - mFirstPage = new ClientWizardPageOne( mCnxPage ); + mFirstPage = new NewJavaProjectWizardPageOne( ); addPage( mFirstPage ); addPage( mCnxPage ); - mThirdPage = new NewJavaProjectWizardPageTwo( mFirstPage ); + mThirdPage = new ClientWizardPageTwo( mFirstPage, mCnxPage ); addPage( mThirdPage ); } } diff --git a/java/source/org/openoffice/ide/eclipse/java/client/ClientWizardPageOne.java b/java/source/org/openoffice/ide/eclipse/java/client/ClientWizardPageOne.java deleted file mode 100644 index 666eb8e..0000000 --- a/java/source/org/openoffice/ide/eclipse/java/client/ClientWizardPageOne.java +++ /dev/null @@ -1,85 +0,0 @@ -/************************************************************************* - * - * The Contents of this file are made available subject to the terms of - * the GNU Lesser General Public License Version 2.1 - * - * GNU Lesser General Public License Version 2.1 - * ============================================= - * Copyright 2009 by Cédric Bosdonnat - * - * 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: Cédric Bosdonnat. - * - * Copyright: 2009 by Cédric Bosdonnat - * - * All Rights Reserved. - * - ************************************************************************/ -package org.openoffice.ide.eclipse.java.client; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.ui.wizards.NewJavaProjectWizardPageOne; -import org.openoffice.ide.eclipse.core.model.config.IOOo; -import org.openoffice.ide.eclipse.java.build.OOoClasspathContainer; - -/** - * The first page of the UNO Java client wizard overrides the default - * New Java project first page to add the OOo libraries as default dependencies. - * - * <p><strong>Many thanks to Karl Weber for pointing that and providing - * sample code.</strong></p> - * - * @author cbosdonnat - * - */ -public class ClientWizardPageOne extends NewJavaProjectWizardPageOne { - - private UnoConnectionPage mCnxPage; - - /** - * Constructor. - * - * @param pCnxPage the connection page of the wizard - */ - public ClientWizardPageOne( UnoConnectionPage pCnxPage ) { - super(); - mCnxPage = pCnxPage; - } - - @Override - public IClasspathEntry[] getDefaultClasspathEntries() { - IClasspathEntry[] oldEntries = super.getDefaultClasspathEntries(); - - IOOo ooo = mCnxPage.getOoo(); - IPath path = new Path(OOoClasspathContainer.ID + IPath.SEPARATOR + ooo.getName()); - IClasspathEntry oooEntry = JavaCore.newContainerEntry(path); - - IClasspathEntry[] newEntries = new IClasspathEntry[] { - oooEntry, - JODContainer.createClasspathEntry( true ) - }; - - IClasspathEntry[] entries = new IClasspathEntry[ oldEntries.length + newEntries.length ]; - - System.arraycopy( oldEntries, 0, entries, 0, oldEntries.length ); - System.arraycopy( newEntries, 0, entries, oldEntries.length, newEntries.length ); - - return entries; - } -} diff --git a/java/source/org/openoffice/ide/eclipse/java/client/ClientWizardPageTwo.java b/java/source/org/openoffice/ide/eclipse/java/client/ClientWizardPageTwo.java new file mode 100644 index 0000000..906973f --- /dev/null +++ b/java/source/org/openoffice/ide/eclipse/java/client/ClientWizardPageTwo.java @@ -0,0 +1,118 @@ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the GNU Lesser General Public License Version 2.1 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2009 by Cédric Bosdonnat + * + * 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: Cédric Bosdonnat. + * + * Copyright: 2013 by SUSE + * + * All Rights Reserved. + * + ************************************************************************/ +package org.openoffice.ide.eclipse.java.client; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.net.URL; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.ui.wizards.NewJavaProjectWizardPageOne; +import org.eclipse.jdt.ui.wizards.NewJavaProjectWizardPageTwo; +import org.openoffice.ide.eclipse.core.model.config.IOOo; +import org.openoffice.ide.eclipse.java.OOoJavaPlugin; +import org.openoffice.ide.eclipse.java.build.OOoClasspathContainer; + +/** + * Overrides NewJavaProjectWizardPageTwo to add jodconnector.jar to the temporary project. + * + * @author Cedric Bosdonnat + * + */ +public class ClientWizardPageTwo extends NewJavaProjectWizardPageTwo { + + private UnoConnectionPage mCnxPage; + + public ClientWizardPageTwo(NewJavaProjectWizardPageOne mainPage, UnoConnectionPage cnxPage ) { + super(mainPage); + mCnxPage = cnxPage; + } + + @Override + public void setVisible(boolean visible) { + super.setVisible(visible); + + if (getContainer().getCurrentPage() == mCnxPage) + removeProvisonalProject(); + } + + @Override + public void init(IJavaProject jproject, IPath defaultOutputLocation, IClasspathEntry[] defaultEntries, + boolean defaultsOverrideExistingClasspath) { + + IProject project = jproject.getProject(); + + // Copy the jodconnector.jar file to the new project + try { + URL libUrl = OOoJavaPlugin.getDefault().getBundle().getResource( ClientWizard.JODCONNECTOR_LIBNAME ); + URL libFileUrl = FileLocator.toFileURL( libUrl ); + File libFile = new File( libFileUrl.toURI() ); + InputStream in = new FileInputStream( libFile ); + IFile destLib = project.getFile( ClientWizard.JODCONNECTOR_LIBNAME ); + destLib.create( in, true, null ); + } catch ( Exception e ) { + } + + // Refresh the project + try { + project.refreshLocal( IResource.DEPTH_INFINITE, null); + } catch (Exception e ) { + } + + // Update the classpath + IOOo ooo = mCnxPage.getOoo(); + IPath path = new Path(OOoClasspathContainer.ID + IPath.SEPARATOR + ooo.getName()); + IClasspathEntry oooEntry = JavaCore.newContainerEntry(path); + + IPath jodPath = project.getFolder( ClientWizard.JODCONNECTOR_LIBNAME ).getFullPath(); + + IClasspathEntry[] newEntries = new IClasspathEntry[] { + oooEntry, + JavaCore.newLibraryEntry(jodPath, jodPath, jodPath) + }; + + IClasspathEntry[] entries = new IClasspathEntry[ defaultEntries.length + newEntries.length ]; + + System.arraycopy( defaultEntries, 0, entries, 0, defaultEntries.length ); + System.arraycopy( newEntries, 0, entries, defaultEntries.length, newEntries.length ); + + super.init(jproject, defaultOutputLocation, entries, defaultsOverrideExistingClasspath); + } +} diff --git a/java/source/org/openoffice/ide/eclipse/java/client/JODContainer.java b/java/source/org/openoffice/ide/eclipse/java/client/JODContainer.java deleted file mode 100644 index dd0c0d0..0000000 --- a/java/source/org/openoffice/ide/eclipse/java/client/JODContainer.java +++ /dev/null @@ -1,203 +0,0 @@ -/************************************************************************* - * - * The Contents of this file are made available subject to the terms of - * the GNU Lesser General Public License Version 2.1 - * - * GNU Lesser General Public License Version 2.1 - * ============================================= - * Copyright 2009 by Cédric Bosdonnat - * - * 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: Cédric Bosdonnat. - * - * Copyright: 2009 by Cédric Bosdonnat. - * - * All Rights Reserved. - * - ************************************************************************/ -package org.openoffice.ide.eclipse.java.client; - -import java.io.File; -import java.net.URL; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jdt.core.ClasspathContainerInitializer; -import org.eclipse.jdt.core.IClasspathContainer; -import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaCore; -import org.openoffice.ide.eclipse.core.PluginLogger; -import org.openoffice.ide.eclipse.java.OOoJavaPlugin; - -/** - * Provides JODConnector and its dependencies as a library container. - * - * @author cbosdonnat - * - */ -public class JODContainer extends ClasspathContainerInitializer { - - public static final String ID = "org.openoffice.ide.eclipse.java.JOD_CONTAINER"; //$NON-NLS-1$ - public static final String WITH_SLF4J_IMPL = "slf4j-impl"; //$NON-NLS-1$ - - private static final String SLF4J_IMPL_LIBNAME = "slf4j-jdk14-1.5.6.jar"; //$NON-NLS-1$ - private static final String JODCONNECTOR_LIBNAME = "jodconnector.jar"; //$NON-NLS-1$ - - private static final String[] LIBS = new String[] { - JODCONNECTOR_LIBNAME, - "slf4j-api-1.5.6.jar" //$NON-NLS-1$ - }; - - /** - * Default constructor. - */ - public JODContainer( ) { - } - - @Override - public void initialize(IPath pContainerPath, IJavaProject pProject) - throws CoreException { - - boolean withSlf4jImpl = checkSlf4jImpl( pContainerPath ); - - JODClasspathContainer container = new JODClasspathContainer( withSlf4jImpl ); - - IJavaProject[] projects = new IJavaProject[]{pProject}; - IClasspathContainer[] containers = new IClasspathContainer[]{container}; - - JavaCore.setClasspathContainer(pContainerPath, projects, containers, null); - } - - /** - * Check if the container path needs to include SLF4J implementation. - * - * @param pContainerPath the path to check - * - * @return <code>true</code> if SLF4J has to be included - */ - public static boolean checkSlf4jImpl(IPath pContainerPath) { - return pContainerPath.segmentCount() > 1 && pContainerPath.segment( 1 ).equals( WITH_SLF4J_IMPL ); - } - - /** - * Utility method to get the container entry. - * - * @param pWithSlf4jImpl <code>true</code> to add the SLF4J jdk14 implementation - * - * @return the container entry - */ - public static IClasspathEntry createClasspathEntry( boolean pWithSlf4jImpl ) { - IPath path = new Path( JODContainer.ID ); - if ( pWithSlf4jImpl ) { - path = path.append( WITH_SLF4J_IMPL ); - } - - return JavaCore.newContainerEntry( path ); - } - - /** - * Class implementing the JOD libraries container. - * - * @author cbosdonnat - * - */ - public class JODClasspathContainer implements IClasspathContainer { - - private boolean mSlf4jImpl; - - /** - * Constructor. - * - * @param pWithSlf4jImpl <code>true</code> to add the SLF4J jdk14 implementation - */ - public JODClasspathContainer( boolean pWithSlf4jImpl ) { - mSlf4jImpl = pWithSlf4jImpl; - } - - /** - * {@inheritDoc} - */ - public IClasspathEntry[] getClasspathEntries() { - - String[] libsNames = getLibs( ); - - IClasspathEntry[] libs = new IClasspathEntry[ libsNames.length ]; - for ( int i = 0; i < libsNames.length; i++ ) { - String lib = libsNames[i]; - try { - URL libUrl = OOoJavaPlugin.getDefault().getBundle().getResource( - OOoJavaPlugin.LIBS_DIR + lib ); - URL libFileUrl = FileLocator.toFileURL( libUrl ); - File libFile = new File( libFileUrl.toURI() ); - IPath libPath = Path.fromOSString( libFile.toString() ); - - IPath srcPath = null; - if ( lib.equals( JODCONNECTOR_LIBNAME ) ) { - srcPath = libPath; - } - - libs[i] = JavaCore.newLibraryEntry( libPath, srcPath, null ); - } catch ( Exception e ) { - PluginLogger.error( Messages.getString("JODContainer.GetLibraryError") + lib, e ); //$NON-NLS-1$ - } - } - - return libs; - } - - /** - * {@inheritDoc} - */ - public String getDescription() { - return Messages.getString("JODContainer.Description"); //$NON-NLS-1$ - } - - /** - * {@inheritDoc} - */ - public int getKind() { - return K_APPLICATION; - } - - /** - * {@inheritDoc} - */ - public IPath getPath() { - return new Path( ID ); - } - - /** - * @return the libraries names to add to the container. - */ - private String[] getLibs( ) { - int libsCount = LIBS.length; - if ( mSlf4jImpl ) { - libsCount++; - } - - String[] allLibs = new String[ libsCount ]; - System.arraycopy( LIBS, 0, allLibs, 0, LIBS.length ); - - if ( mSlf4jImpl ) { - allLibs[ allLibs.length - 1 ] = SLF4J_IMPL_LIBNAME; - } - return allLibs; - } - } -} diff --git a/java/source/org/openoffice/ide/eclipse/java/client/JODContainerPage.java b/java/source/org/openoffice/ide/eclipse/java/client/JODContainerPage.java deleted file mode 100644 index 0023394..0000000 --- a/java/source/org/openoffice/ide/eclipse/java/client/JODContainerPage.java +++ /dev/null @@ -1,120 +0,0 @@ -/************************************************************************* - * - * The Contents of this file are made available subject to the terms of - * the GNU Lesser General Public License Version 2.1 - * - * GNU Lesser General Public License Version 2.1 - * ============================================= - * Copyright 2009 by Cédric Bosdonnat - * - * 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: Cédric Bosdonnat. - * - * Copyright: 2009 by Cédric Bosdonnat. - * - * All Rights Reserved. - * - ************************************************************************/ -package org.openoffice.ide.eclipse.java.client; - -import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.ui.wizards.IClasspathContainerPage; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.openoffice.ide.eclipse.core.gui.rows.BooleanRow; -import org.openoffice.ide.eclipse.core.gui.rows.FieldEvent; -import org.openoffice.ide.eclipse.core.gui.rows.IFieldChangedListener; -import org.openoffice.ide.eclipse.java.OOoJavaPlugin; -import org.openoffice.ide.eclipse.java.build.Messages; - -/** - * JOD Connector configuration page. - * - * @author cbosdonnat - * - */ -public class JODContainerPage extends WizardPage implements - IClasspathContainerPage { - - private static final int LAYOUT_COLS = 2; - - private BooleanRow mSlf4jRow; - - private boolean mSlf4j; - - /** - * Needed default constructor. - */ - public JODContainerPage( ) { - super( "jodcontainer" ); //$NON-NLS-1$ - - setTitle( Messages.getString("JODContainerPage.Title") ); //$NON-NLS-1$ - ImageDescriptor image = OOoJavaPlugin.getImageDescriptor( - Messages.getString("OOoContainerPage.DialogImage")); //$NON-NLS-1$ - setImageDescriptor(image); - } - - /** - * {@inheritDoc} - */ - public boolean finish() { - // Nothing to do - return true; - } - - /** - * {@inheritDoc} - */ - public IClasspathEntry getSelection() { - return JODContainer.createClasspathEntry( mSlf4j ); - } - - /** - * {@inheritDoc} - */ - public void setSelection(IClasspathEntry pContainerEntry) { - if ( pContainerEntry != null ) { - mSlf4j = JODContainer.checkSlf4jImpl( pContainerEntry.getPath() ); - } else { - mSlf4j = true; - } - } - - /** - * {@inheritDoc} - */ - public void createControl( Composite pParent ) { - Composite body = new Composite( pParent, SWT.NONE ); - body.setLayout( new GridLayout( LAYOUT_COLS, false ) ); - - // SLF4J boolean row - mSlf4jRow = new BooleanRow( body, new String(), - Messages.getString("JODContainerPage.SLF4JLabel") ); //$NON-NLS-1$ - mSlf4jRow.setValue( mSlf4j ); - mSlf4jRow.setFieldChangedListener( new IFieldChangedListener() { - - public void fieldChanged(FieldEvent pEvent) { - mSlf4j = mSlf4jRow.getBooleanValue(); - } - }); - - setControl( body ); - } - -} diff --git a/java/source/org/openoffice/ide/eclipse/java/client/UnoClient.java.tpl b/java/source/org/openoffice/ide/eclipse/java/client/UnoClient.java.tpl index e4143b4..79bf86e 100644 --- a/java/source/org/openoffice/ide/eclipse/java/client/UnoClient.java.tpl +++ b/java/source/org/openoffice/ide/eclipse/java/client/UnoClient.java.tpl @@ -6,6 +6,10 @@ import com.artofsolving.jodconverter.openoffice.connection.PipeOpenOfficeConnect import com.sun.star.uno.XComponentContext; +// Make sure LibreOffice is started with the proper arguments to have it listen before +// running this client application. Use one of the following commands to start it: +// * For socket connection: soffice --accept="socket,host=localhost,port=8100,tcpNoDelay=1;urp;" +// * For pipe connection: soffice --accept="pipe,name=yourpipename;urp;" public class UnoClient '{' public static void main(String[] args) '{' diff --git a/java/source/org/openoffice/ide/eclipse/java/client/license-openoffice.org.txt.tpl b/java/source/org/openoffice/ide/eclipse/java/client/license-openoffice.org.txt.tpl deleted file mode 100644 index 199b041..0000000 --- a/java/source/org/openoffice/ide/eclipse/java/client/license-openoffice.org.txt.tpl +++ /dev/null @@ -1,13 +0,0 @@ -You may only copy and distribute this program consistent with the requirements and distribute this -Program consistent with the requirements of either the GNU General Public License (GPL) and -GNU Lesser General Public License (LGPL), respectively, depending on whether you elected to obtain -access to this program via the GPL/LGPL Option. Copies of the GPL and LGPL licenses can be found -http://www.openoffice.org/project/www/license.html - ------------------------------------- -Third Party Code. Additional copyright notices and license terms applicable to portions of the -Software are set forth in the THIRDPARTYLICENSEREADME.html file. - ------------------------------------- -Copyright 2002,2005 Sun Microsystems, Inc. - diff --git a/java/source/org/openoffice/ide/eclipse/java/client/license-slf4j.txt.tpl b/java/source/org/openoffice/ide/eclipse/java/client/license-slf4j.txt.tpl deleted file mode 100644 index f6e2f31..0000000 --- a/java/source/org/openoffice/ide/eclipse/java/client/license-slf4j.txt.tpl +++ /dev/null @@ -1,24 +0,0 @@ -Copyright (c) 2004-2007 QOS.ch
-All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-
-
diff --git a/java/source/org/openoffice/ide/eclipse/java/utils/messages.properties b/java/source/org/openoffice/ide/eclipse/java/utils/messages.properties index 23b1150..7c1ae23 100644 --- a/java/source/org/openoffice/ide/eclipse/java/utils/messages.properties +++ b/java/source/org/openoffice/ide/eclipse/java/utils/messages.properties @@ -1,3 +1,3 @@ TemplatesHelper.ErrorPattern=Error during {0} creation [{1}] -TemplatesHelper.ReadError=reading template +TemplatesHelper.ReadError=reading file ZipContentHelper.NotDirectoryError=Not a directory: |