Renamings
This commit is contained in:
parent
79c0051ee5
commit
620425f43d
19 changed files with 163 additions and 367 deletions
|
@ -6,7 +6,6 @@ import java.util.Arrays;
|
|||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.libreoffice.example.comp.MetadataInaccessableException;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.NEW;
|
||||
import com.sun.star.beans.IllegalTypeException;
|
||||
|
|
|
@ -0,0 +1,98 @@
|
|||
package pro.litvinovg.libreoffice.metadata;
|
||||
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
import pro.litvinovg.libreoffice.metadata.views.EditorGUI;
|
||||
|
||||
import com.sun.star.lib.uno.helper.Factory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
|
||||
import com.sun.star.beans.Property;
|
||||
import com.sun.star.beans.XPropertyContainer;
|
||||
import com.sun.star.beans.XPropertySet;
|
||||
import com.sun.star.beans.XPropertySetInfo;
|
||||
import com.sun.star.document.XDocumentProperties;
|
||||
import com.sun.star.document.XDocumentPropertiesSupplier;
|
||||
import com.sun.star.frame.XDesktop;
|
||||
import com.sun.star.lang.XComponent;
|
||||
import com.sun.star.lang.XMultiComponentFactory;
|
||||
import com.sun.star.lang.XMultiServiceFactory;
|
||||
import com.sun.star.lang.XSingleComponentFactory;
|
||||
import com.sun.star.registry.XRegistryKey;
|
||||
import com.sun.star.lib.uno.helper.WeakBase;
|
||||
|
||||
|
||||
public final class MetadataExtensionImpl extends WeakBase
|
||||
implements com.sun.star.lang.XServiceInfo,
|
||||
com.sun.star.task.XJobExecutor
|
||||
{
|
||||
private final XComponentContext context;
|
||||
private XDesktop xDesktop;
|
||||
private XMultiComponentFactory multiComponentFactory;
|
||||
private XComponent currentDocument;
|
||||
private XDocumentProperties documentProperties;
|
||||
private XDocumentPropertiesSupplier documentPropertiesSupplier;
|
||||
private static final String m_implementationName = MetadataExtensionImpl.class.getName();
|
||||
private static final String[] m_serviceNames = { "pro.litvinovg.libreoffice.MetadataEditor" };
|
||||
|
||||
|
||||
public MetadataExtensionImpl(XComponentContext componentContext) {
|
||||
context = componentContext;
|
||||
|
||||
};
|
||||
|
||||
public static XSingleComponentFactory __getComponentFactory( String sImplementationName ) {
|
||||
XSingleComponentFactory xFactory = null;
|
||||
|
||||
if ( sImplementationName.equals( m_implementationName ) )
|
||||
xFactory = Factory.createComponentFactory(MetadataExtensionImpl.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 action)
|
||||
{
|
||||
switch (action) {
|
||||
case "openGUI":
|
||||
Document doc = new Document(context);
|
||||
EditorGUI.runGUI(doc);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package pro.litvinovg.libreoffice.metadata;
|
||||
|
||||
public class MetadataInaccessableException extends Exception {
|
||||
public MetadataInaccessableException(String errorMessage) {
|
||||
super(errorMessage);
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
pro.litvinovg.libreoffice.metadata.MetadataExtensionImpl
|
|
@ -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 pro.litvinovg.libreoffice.metadata;
|
||||
|
||||
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.
|
||||
*
|
||||
* <p><strong>This class should not be modified.</strong></p>
|
||||
*
|
||||
* @author Cedric Bosdonnat aka. cedricbosdo
|
||||
*
|
||||
*/
|
||||
public class RegistrationHandler {
|
||||
|
||||
/**
|
||||
* Get a component factory for the implementations handled by this class.
|
||||
*
|
||||
* <p>This method calls all the methods of the same name from the classes listed
|
||||
* in the <code>RegistrationHandler.classes</code> file. <strong>This method
|
||||
* should not be modified.</strong></p>
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* <p>This method calls all the methods of the same name from the classes listed
|
||||
* in the <code>RegistrationHandler.classes</code> file. <strong>This method
|
||||
* should not be modified.</strong></p>
|
||||
*
|
||||
* @param pRegistryKey the root registry key where to write the informations.
|
||||
*
|
||||
* @return <code>true</code> if the informations have been successfully written
|
||||
* to the registry key, <code>false</code> 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<Class> classes = new ArrayList<Class>();
|
||||
|
||||
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()]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package pro.litvinovg.libreoffice.metadata.tests;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
import pro.litvinovg.libreoffice.metadata.tests.uno.WriterTest;
|
||||
|
||||
import pro.litvinovg.libreoffice.metadata.tests.base.UnoSuite;
|
||||
|
||||
@RunWith(UnoSuite.class)
|
||||
@SuiteClasses({WriterTest.class})
|
||||
public class UnoTests {
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package pro.litvinovg.libreoffice.metadata.tests.base;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.runner.Runner;
|
||||
import org.junit.runner.notification.RunNotifier;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.model.InitializationError;
|
||||
import org.junit.runners.model.RunnerBuilder;
|
||||
|
||||
import com.sun.star.frame.XDesktop;
|
||||
import com.sun.star.lang.XMultiComponentFactory;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
public class UnoSuite extends Suite {
|
||||
|
||||
private static XComponentContext componentContext;
|
||||
|
||||
public UnoSuite(Class<?> klass, RunnerBuilder builder) throws InitializationError {
|
||||
super(klass, builder);
|
||||
}
|
||||
|
||||
public UnoSuite(RunnerBuilder builder, Class<?>[] classes) throws InitializationError {
|
||||
super(builder, classes);
|
||||
}
|
||||
|
||||
public UnoSuite(Class<?> klass, Class<?>[] suiteClasses) throws InitializationError {
|
||||
super(klass, suiteClasses);
|
||||
}
|
||||
|
||||
public UnoSuite(Class<?> klass, List<Runner> runners) throws InitializationError {
|
||||
super(klass, runners);
|
||||
}
|
||||
|
||||
public UnoSuite(RunnerBuilder builder, Class<?> klass, Class<?>[] suiteClasses) throws InitializationError {
|
||||
super(builder, klass, suiteClasses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(RunNotifier arg0) {
|
||||
try {
|
||||
startOffice();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
super.run(arg0);
|
||||
|
||||
stopOffice();
|
||||
}
|
||||
|
||||
private void startOffice() throws Exception {
|
||||
componentContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
|
||||
}
|
||||
|
||||
private void stopOffice() {
|
||||
try {
|
||||
if (componentContext != null) {
|
||||
// Only the uno test suite which started the office can stop it
|
||||
XMultiComponentFactory xMngr = componentContext.getServiceManager();
|
||||
Object oDesktop = xMngr.createInstanceWithContext("com.sun.star.frame.Desktop", componentContext);
|
||||
XDesktop xDesktop = (XDesktop)UnoRuntime.queryInterface(XDesktop.class, oDesktop);
|
||||
|
||||
xDesktop.terminate();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static XComponentContext getComponentContext() {
|
||||
return componentContext;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package pro.litvinovg.libreoffice.metadata.tests.helper;
|
||||
|
||||
import com.sun.star.beans.PropertyValue;
|
||||
import com.sun.star.frame.FrameSearchFlag;
|
||||
import com.sun.star.frame.XComponentLoader;
|
||||
import com.sun.star.lang.XComponent;
|
||||
import com.sun.star.lang.XMultiComponentFactory;
|
||||
import com.sun.star.text.XTextDocument;
|
||||
import com.sun.star.uno.Exception;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
|
||||
import pro.litvinovg.libreoffice.metadata.tests.base.UnoSuite;
|
||||
|
||||
public class UnoHelper {
|
||||
|
||||
public static XTextDocument getWriterDocument() throws Exception {
|
||||
XMultiComponentFactory xMngr = UnoSuite.getComponentContext().getServiceManager();
|
||||
Object oDesktop = xMngr.createInstanceWithContext("com.sun.star.frame.Desktop", UnoSuite.getComponentContext());
|
||||
XComponentLoader xLoader = (XComponentLoader)UnoRuntime.queryInterface(
|
||||
XComponentLoader.class, oDesktop);
|
||||
|
||||
XComponent xDoc = xLoader.loadComponentFromURL("private:factory/swriter", "_default",
|
||||
FrameSearchFlag.ALL, new PropertyValue[0]);
|
||||
|
||||
return (XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, xDoc);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package pro.litvinovg.libreoffice.metadata.tests.uno;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.sun.star.text.XTextDocument;
|
||||
|
||||
import pro.litvinovg.libreoffice.metadata.tests.helper.UnoHelper;
|
||||
|
||||
public class WriterTest {
|
||||
|
||||
private XTextDocument xTextDocument;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
xTextDocument = UnoHelper.getWriterDocument();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
assertNotNull(xTextDocument);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue