summaryrefslogtreecommitdiffstats
path: root/odk/examples/java/DocumentHandling
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
commit940b4d1848e8c70ab7642901a68594e8016caffc (patch)
treeeb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /odk/examples/java/DocumentHandling
parentInitial commit. (diff)
downloadlibreoffice-upstream.tar.xz
libreoffice-upstream.zip
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'odk/examples/java/DocumentHandling')
-rw-r--r--odk/examples/java/DocumentHandling/DocumentConverter.java226
-rw-r--r--odk/examples/java/DocumentHandling/DocumentLoader.java94
-rw-r--r--odk/examples/java/DocumentHandling/DocumentPrinter.java111
-rw-r--r--odk/examples/java/DocumentHandling/DocumentSaver.java131
-rw-r--r--odk/examples/java/DocumentHandling/Makefile144
-rw-r--r--odk/examples/java/DocumentHandling/test/test1.odtbin0 -> 397817 bytes
6 files changed, 706 insertions, 0 deletions
diff --git a/odk/examples/java/DocumentHandling/DocumentConverter.java b/odk/examples/java/DocumentHandling/DocumentConverter.java
new file mode 100644
index 000000000..386af9f1f
--- /dev/null
+++ b/odk/examples/java/DocumentHandling/DocumentConverter.java
@@ -0,0 +1,226 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.uno.UnoRuntime;
+
+import java.io.File;
+
+
+/** The class <CODE>DocumentConverter</CODE> allows you to convert all documents
+ * in a given directory and in its subdirectories to a given type. A converted
+ * document will be created in the same directory as the origin document.
+ *
+ */
+public class DocumentConverter {
+ /** Containing the loaded documents
+ */
+ static com.sun.star.frame.XComponentLoader xCompLoader = null;
+ /** Containing the given type to convert to
+ */
+ static String sConvertType = "";
+ /** Containing the given extension
+ */
+ static String sExtension = "";
+ /** Containing the current file or directory
+ */
+ static String sIndent = "";
+ /** Containing the directory where the converted files are saved
+ */
+ static String sOutputDir = "";
+
+ /** Traversing the given directory recursively and converting their files to
+ * the favoured type if possible
+ * @param fileDirectory Containing the directory
+ */
+ static void traverse( File fileDirectory ) {
+ // Testing, if the file is a directory, and if so, it throws an exception
+ if ( !fileDirectory.isDirectory() ) {
+ throw new IllegalArgumentException(
+ "not a directory: " + fileDirectory.getName()
+ );
+ }
+
+ // Prepare Url for the output directory
+ File outdir = new File(DocumentConverter.sOutputDir);
+ String sOutUrl = "file:///" + outdir.getAbsolutePath().replace( '\\', '/' );
+
+ System.out.println("\nThe converted documents will stored in \""
+ + outdir.getPath() + "!");
+
+ System.out.println(sIndent + "[" + fileDirectory.getName() + "]");
+ sIndent += " ";
+
+ // Getting all files and directories in the current directory
+ File[] entries = fileDirectory.listFiles();
+
+
+ // Iterating for each file and directory
+ for ( int i = 0; i < entries.length; ++i ) {
+ // Testing, if the entry in the list is a directory
+ if ( entries[ i ].isDirectory() ) {
+ // Recursive call for the new directory
+ traverse( entries[ i ] );
+ } else {
+ // Converting the document to the favoured type
+ try {
+ // Composing the URL by replacing all backslashes
+ String sUrl = "file:///"
+ + entries[ i ].getAbsolutePath().replace( '\\', '/' );
+
+ // Loading the wanted document
+ com.sun.star.beans.PropertyValue propertyValues[] =
+ new com.sun.star.beans.PropertyValue[1];
+ propertyValues[0] = new com.sun.star.beans.PropertyValue();
+ propertyValues[0].Name = "Hidden";
+ propertyValues[0].Value = Boolean.TRUE;
+
+ Object oDocToStore =
+ DocumentConverter.xCompLoader.loadComponentFromURL(
+ sUrl, "_blank", 0, propertyValues);
+
+ // Getting an object that will offer a simple way to store
+ // a document to a URL.
+ com.sun.star.frame.XStorable xStorable =
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XStorable.class, oDocToStore );
+
+ // Preparing properties for converting the document
+ propertyValues = new com.sun.star.beans.PropertyValue[2];
+ // Setting the flag for overwriting
+ propertyValues[0] = new com.sun.star.beans.PropertyValue();
+ propertyValues[0].Name = "Overwrite";
+ propertyValues[0].Value = Boolean.TRUE;
+ // Setting the filter name
+ propertyValues[1] = new com.sun.star.beans.PropertyValue();
+ propertyValues[1].Name = "FilterName";
+ propertyValues[1].Value = DocumentConverter.sConvertType;
+
+ // Appending the favoured extension to the origin document name
+ int index1 = sUrl.lastIndexOf('/');
+ int index2 = sUrl.lastIndexOf('.');
+ String sStoreUrl = sOutUrl + sUrl.substring(index1, index2 + 1)
+ + DocumentConverter.sExtension;
+
+ // Storing and converting the document
+ xStorable.storeAsURL(sStoreUrl, propertyValues);
+
+ // Closing the converted document. Use XCloseable.close if the
+ // interface is supported, otherwise use XComponent.dispose
+ com.sun.star.util.XCloseable xCloseable =
+ UnoRuntime.queryInterface(
+ com.sun.star.util.XCloseable.class, xStorable);
+
+ if ( xCloseable != null ) {
+ xCloseable.close(false);
+ } else {
+ com.sun.star.lang.XComponent xComp =
+ UnoRuntime.queryInterface(
+ com.sun.star.lang.XComponent.class, xStorable);
+
+ xComp.dispose();
+ }
+ }
+ catch( Exception e ) {
+ e.printStackTrace(System.err);
+ }
+
+ System.out.println(sIndent + entries[ i ].getName());
+ }
+ }
+
+ sIndent = sIndent.substring(2);
+ }
+
+ /** Bootstrap UNO, getting the remote component context, getting a new instance
+ * of the desktop (used interface XComponentLoader) and calling the
+ * static method traverse
+ * @param args The array of the type String contains the directory, in which
+ * all files should be converted, the favoured converting type
+ * and the wanted extension
+ */
+ public static void main( String args[] ) {
+ if ( args.length < 3 ) {
+ System.out.println("usage: java -jar DocumentConverter.jar " +
+ "\"<directory to convert>\" \"<type to convert to>\" " +
+ "\"<extension>\" \"<output_directory>\"");
+ System.out.println("\ne.g.:");
+ System.out.println("usage: java -jar DocumentConverter.jar " +
+ "\"c:/myoffice\" \"swriter: MS Word 97\" \"doc\"");
+ System.exit(1);
+ }
+
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ try {
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+
+ // get the remote office service manager
+ com.sun.star.lang.XMultiComponentFactory xMCF =
+ xContext.getServiceManager();
+
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext);
+
+ xCompLoader = UnoRuntime.queryInterface(com.sun.star.frame.XComponentLoader.class,
+ oDesktop);
+
+ // Getting the given starting directory
+ File file = new File(args[0]);
+
+ // Getting the given type to convert to
+ sConvertType = args[1];
+
+ // Getting the given extension that should be appended to the
+ // origin document
+ sExtension = args[2];
+
+ // Getting the given type to convert to
+ sOutputDir = args[3];
+
+ // Starting the conversion of documents in the given directory
+ // and subdirectories
+ traverse(file);
+
+ System.exit(0);
+ } catch( Exception e ) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/DocumentHandling/DocumentLoader.java b/odk/examples/java/DocumentHandling/DocumentLoader.java
new file mode 100644
index 000000000..63d8dc66e
--- /dev/null
+++ b/odk/examples/java/DocumentHandling/DocumentLoader.java
@@ -0,0 +1,94 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.uno.UnoRuntime;
+
+
+/** This class opens a new or an existing office document.
+ */
+public class DocumentLoader {
+ public static void main(String args[]) {
+ if ( args.length < 1 ) {
+ System.out.println(
+ "usage: java -jar DocumentLoader.jar \"<URL|path>\"" );
+ System.out.println( "\ne.g.:" );
+ System.out.println(
+ "java -jar DocumentLoader.jar \"private:factory/swriter\"" );
+ System.exit(1);
+ }
+
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ try {
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+
+ // get the remote office service manager
+ com.sun.star.lang.XMultiComponentFactory xMCF =
+ xContext.getServiceManager();
+
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext);
+
+ com.sun.star.frame.XComponentLoader xCompLoader =
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class, oDesktop);
+
+ String sUrl = args[0];
+ if ( sUrl.indexOf("private:") != 0) {
+ java.io.File sourceFile = new java.io.File(args[0]);
+ StringBuffer sbTmp = new StringBuffer("file:///");
+ sbTmp.append(sourceFile.getCanonicalPath().replace('\\', '/'));
+ sUrl = sbTmp.toString();
+ }
+
+ // Load a Writer document, which will be automatically displayed
+ com.sun.star.lang.XComponent xComp = xCompLoader.loadComponentFromURL(
+ sUrl, "_blank", 0, new com.sun.star.beans.PropertyValue[0]);
+
+ if ( xComp != null )
+ System.exit(0);
+ else
+ System.exit(1);
+ }
+ catch( Exception e ) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/DocumentHandling/DocumentPrinter.java b/odk/examples/java/DocumentHandling/DocumentPrinter.java
new file mode 100644
index 000000000..dfa35aedd
--- /dev/null
+++ b/odk/examples/java/DocumentHandling/DocumentPrinter.java
@@ -0,0 +1,111 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.uno.UnoRuntime;
+
+
+public class DocumentPrinter {
+ public static void main(String args[]) {
+ if ( args.length < 3 ) {
+ System.out.println("usage: java -jar DocumentLoader.jar " +
+ "\"<Favoured printer>\" \"<URL|path>\" \"<Pages>\"");
+ System.out.println( "\ne.g.:" );
+ System.out.println("java -jar DocumentLoader.jar \"amadeus\" " +
+ "\"file:///f:/TestPrint.odt\" \"1-3;7;9\"");
+ System.exit(1);
+ }
+
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ try {
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+
+ // get the remote office service manager
+ com.sun.star.lang.XMultiComponentFactory xMCF =
+ xContext.getServiceManager();
+
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext);
+
+ com.sun.star.frame.XComponentLoader xCompLoader =
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class, oDesktop);
+
+ java.io.File sourceFile = new java.io.File(args[1]);
+ StringBuffer sUrl = new StringBuffer("file:///");
+ sUrl.append(sourceFile.getCanonicalPath().replace('\\', '/'));
+
+ // Load a Writer document, which will be automatically displayed
+ com.sun.star.lang.XComponent xComp = xCompLoader.loadComponentFromURL(
+ sUrl.toString(), "_blank", 0,
+ new com.sun.star.beans.PropertyValue[0] );
+
+ // Querying for the interface XPrintable on the loaded document
+ com.sun.star.view.XPrintable xPrintable =
+ UnoRuntime.queryInterface(
+ com.sun.star.view.XPrintable.class, xComp);
+
+ // Setting the property "Name" for the favoured printer (name of
+ // IP address)
+ com.sun.star.beans.PropertyValue propertyValue[] =
+ new com.sun.star.beans.PropertyValue[1];
+ propertyValue[0] = new com.sun.star.beans.PropertyValue();
+ propertyValue[0].Name = "Name";
+ propertyValue[0].Value = args[ 0 ];
+
+ // Setting the name of the printer
+ xPrintable.setPrinter( propertyValue );
+
+ // Setting the property "Pages" so that only the desired pages
+ // will be printed.
+ propertyValue[0] = new com.sun.star.beans.PropertyValue();
+ propertyValue[0].Name = "Pages";
+ propertyValue[0].Value = args[ 2 ];
+
+ // Printing the loaded document
+ xPrintable.print( propertyValue );
+
+ System.exit(0);
+ }
+ catch( Exception e ) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/DocumentHandling/DocumentSaver.java b/odk/examples/java/DocumentHandling/DocumentSaver.java
new file mode 100644
index 000000000..ec1ce9242
--- /dev/null
+++ b/odk/examples/java/DocumentHandling/DocumentSaver.java
@@ -0,0 +1,131 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.uno.UnoRuntime;
+
+
+/** The purpose of this class is to open a specified text document and save this
+ * file to a specified URL. The type of the saved file is
+ * "swriter: StarOffice XML (Writer)".
+ */
+public class DocumentSaver {
+ /** The main method of the application.
+ * @param args The program needs two arguments:
+ * - full file name to open,
+ * - full file name to save.
+ */
+ public static void main(String args[]) {
+ if ( args.length < 2 ) {
+ System.out.println("usage: java -jar DocumentSaver.jar" +
+ "\"<URL|path to load>\" \"<URL|path to save>\"");
+ System.out.println("\ne.g.:");
+ System.out.println("java -jar DocumentSaver " +
+ "\"file:///f:/TestPrint.doc\"" +
+ "\"file:///f:/TestPrint.odt\"");
+ System.exit(1);
+ }
+
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ try {
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+
+ // get the remote office service manager
+ com.sun.star.lang.XMultiComponentFactory xMCF =
+ xContext.getServiceManager();
+
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext);
+
+ com.sun.star.frame.XComponentLoader xCompLoader =
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class, oDesktop);
+
+ java.io.File sourceFile = new java.io.File(args[0]);
+ StringBuffer sLoadUrl = new StringBuffer("file:///");
+ sLoadUrl.append(sourceFile.getCanonicalPath().replace('\\', '/'));
+
+ sourceFile = new java.io.File(args[1]);
+ StringBuffer sSaveUrl = new StringBuffer("file:///");
+ sSaveUrl.append(sourceFile.getCanonicalPath().replace('\\', '/'));
+
+ com.sun.star.beans.PropertyValue[] propertyValue =
+ new com.sun.star.beans.PropertyValue[1];
+ propertyValue[0] = new com.sun.star.beans.PropertyValue();
+ propertyValue[0].Name = "Hidden";
+ propertyValue[0].Value = Boolean.TRUE;
+
+ Object oDocToStore = xCompLoader.loadComponentFromURL(
+ sLoadUrl.toString(), "_blank", 0, propertyValue );
+ com.sun.star.frame.XStorable xStorable =
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XStorable.class, oDocToStore );
+
+ propertyValue = new com.sun.star.beans.PropertyValue[ 2 ];
+ propertyValue[0] = new com.sun.star.beans.PropertyValue();
+ propertyValue[0].Name = "Overwrite";
+ propertyValue[0].Value = Boolean.TRUE;
+ propertyValue[1] = new com.sun.star.beans.PropertyValue();
+ propertyValue[1].Name = "FilterName";
+ propertyValue[1].Value = "StarOffice XML (Writer)";
+ xStorable.storeAsURL( sSaveUrl.toString(), propertyValue );
+
+ System.out.println("\nDocument \"" + sLoadUrl + "\" saved under \"" +
+ sSaveUrl + "\"\n");
+
+ com.sun.star.util.XCloseable xCloseable = UnoRuntime.queryInterface(com.sun.star.util.XCloseable.class,
+ oDocToStore );
+
+ if (xCloseable != null ) {
+ xCloseable.close(false);
+ } else
+ {
+ com.sun.star.lang.XComponent xComp = UnoRuntime.queryInterface(
+ com.sun.star.lang.XComponent.class, oDocToStore );
+ xComp.dispose();
+ }
+ System.out.println("document closed!");
+ System.exit(0);
+ }
+ catch( Exception e ) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/DocumentHandling/Makefile b/odk/examples/java/DocumentHandling/Makefile
new file mode 100644
index 000000000..d8eff760d
--- /dev/null
+++ b/odk/examples/java/DocumentHandling/Makefile
@@ -0,0 +1,144 @@
+#*************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# the BSD license.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#**************************************************************************
+
+# Builds the Java DocumentHandling examples of the SDK.
+
+PRJ=../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+
+# Define non-platform/compiler specific settings
+SAMPLE_NAME=JavaDocumentHandlingExamples
+SAMPLE_CLASS_OUT = $(OUT_CLASS)/$(SAMPLE_NAME)
+SAMPLE_GEN_OUT = $(OUT_MISC)/$(SAMPLE_NAME)
+
+DIRFLAG=$(OUT_MISC)/$(SAMPLE_NAME)_directory.flag
+
+APP1_NAME=DocumentConverter
+APP1_JAR=$(SAMPLE_CLASS_OUT)/$(APP1_NAME).jar
+APP2_NAME=DocumentLoader
+APP2_JAR=$(SAMPLE_CLASS_OUT)/$(APP2_NAME).jar
+APP3_NAME=DocumentPrinter
+APP3_JAR=$(SAMPLE_CLASS_OUT)/$(APP3_NAME).jar
+APP4_NAME=DocumentSaver
+APP4_JAR=$(SAMPLE_CLASS_OUT)/$(APP4_NAME).jar
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(SAMPLE_CLASS_OUT))
+
+
+# Targets
+.PHONY: ALL
+ALL : \
+ $(SAMPLE_NAME)
+
+include $(SETTINGS)/stdtarget.mk
+
+$(SAMPLE_CLASS_OUT)/%.class : %.java
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(SAMPLE_CLASS_OUT) $<
+
+$(SAMPLE_CLASS_OUT)/%.mf :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo Main-Class: com.sun.star.lib.loader.Loader> $@
+ $(ECHOLINE)>> $@
+ @echo Name: com/sun/star/lib/loader/Loader.class>> $@
+ @echo Application-Class: $*>> $@
+
+$(SAMPLE_CLASS_OUT)/%.jar : $(SAMPLE_CLASS_OUT)/%.mf $(SAMPLE_CLASS_OUT)/%.class
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ +cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_JAR) cvfm $(@F) $*.mf $*.class
+ +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
+
+$(APP1_JAR) : $(SAMPLE_CLASS_OUT)/$(APP1_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP1_NAME).class
+$(APP2_JAR) : $(SAMPLE_CLASS_OUT)/$(APP2_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP2_NAME).class
+$(APP3_JAR) : $(SAMPLE_CLASS_OUT)/$(APP3_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP3_NAME).class
+$(APP4_JAR) : $(SAMPLE_CLASS_OUT)/$(APP4_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP4_NAME).class
+
+$(SAMPLE_NAME) : $(APP1_JAR) $(APP2_JAR) $(APP3_JAR) $(APP4_JAR)
+ @echo --------------------------------------------------------------------------------
+ @echo The $(APP1_NAME) search the "$(QM)./test$(QM)" directory for documents, convert
+ @echo them using the "$(QM)MS Word 97$(QM)" filter and the extension "$(QM).doc$(QM)".
+ @echo The converted files are store in "$(QM)$(SAMPLE_GEN_OUT)/converted_files$(QM)".
+ @echo The list of possible filter names can change. Normally an updated list can be found
+ @echo on "$(QM)http://www.openoffice.org/files/documents/25/111/filter_description.html$(QM)".
+ @echo -
+ @echo The $(APP2_NAME) loads the document "$(QM)./test/test1.odt$(QM)".
+ @echo -
+ @echo The $(APP3_NAME) prints the document "$(QM)./test/test1.odt$(QM)" using the
+ @echo the specified printer. If the printer is unknown, the default printer is used.
+ @echo -
+ @echo The $(APP5_NAME) loads the document "$(QM)./test/test1.odt$(QM)" and saves it
+ @echo under "$(QM)$(SAMPLE_GEN_OUT)/savetest/testsave.odt$(QM)".
+ @echo -
+ @echo Please use one of the following commands to execute the examples!
+ @echo -
+ @echo $(MAKE) $(APP1_NAME).run
+ @echo $(MAKE) $(APP2_NAME).run
+ @echo $(MAKE) $(APP3_NAME).run
+ @echo $(MAKE) $(APP4_NAME).run
+ @echo --------
+ @echo The examples need parameters. Please use one the following commands to
+ @echo start the demo if you do not want the default parameters specified in the
+ @echo this makefile. Starting without parameters print a command line help:
+ @echo --- $(APP1_NAME) ---
+ @echo java -jar $(APP1_NAME).jar "$(QM)directory$(QM)" "$(QM)filter name$(QM)" "$(QM)extension$(QM)" "$(QM)output_directory$(QM)"
+ @echo --- $(APP2_NAME) ---
+ @echo java -jar $(APP2_NAME).jar "$(QM)Url|path$(QM)"
+ @echo --- $(APP3_NAME) ---
+ @echo java -jar $(APP3_NAME).jar "$(QM)printername$(QM)" "$(QM)filename$(QM)" "$(QM)pages$(QM)"
+ @echo --- $(APP4_NAME) ---
+ @echo java -jar $(APP4_NAME).jar "$(QM)load Url|path$(QM)" "$(QM)save Url|path$(QM)"
+ @echo --------------------------------------------------------------------------------
+
+$(APP1_NAME).run: $(APP1_JAR)
+ -$(MKDIR) $(subst /,$(PS),$(SAMPLE_GEN_OUT)/converted_files)
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $< "./test" "MS Word 97" "doc" "$(SAMPLE_GEN_OUT)/converted_files"
+
+$(APP2_NAME).run: $(APP2_JAR)
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $< "./test/test1.odt"
+
+$(APP3_NAME).run: $(APP3_JAR)
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $< "my_printer" "./test/test1.odt" 1
+
+$(APP4_NAME).run: $(APP4_JAR)
+ -$(MKDIR) $(subst /,$(PS),$(SAMPLE_GEN_OUT)/savetest)
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $< "./test/test1.odt" "$(SAMPLE_GEN_OUT)/savetest/testsave.odt"
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_CLASS_OUT))
+ -$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_GEN_OUT))
diff --git a/odk/examples/java/DocumentHandling/test/test1.odt b/odk/examples/java/DocumentHandling/test/test1.odt
new file mode 100644
index 000000000..6a3c769ee
--- /dev/null
+++ b/odk/examples/java/DocumentHandling/test/test1.odt
Binary files differ