summaryrefslogtreecommitdiff
path: root/odk/examples/java
diff options
context:
space:
mode:
Diffstat (limited to 'odk/examples/java')
-rw-r--r--odk/examples/java/ConverterServlet/ConverterServlet.html46
-rw-r--r--odk/examples/java/ConverterServlet/ConverterServlet.java336
-rw-r--r--odk/examples/java/ConverterServlet/Makefile94
-rw-r--r--odk/examples/java/ConverterServlet/README38
-rw-r--r--odk/examples/java/ConverterServlet/web.xml23
-rw-r--r--odk/examples/java/DocumentHandling/DocumentConverter.java225
-rw-r--r--odk/examples/java/DocumentHandling/DocumentLoader.java92
-rw-r--r--odk/examples/java/DocumentHandling/DocumentPrinter.java109
-rw-r--r--odk/examples/java/DocumentHandling/DocumentSaver.java131
-rw-r--r--odk/examples/java/DocumentHandling/Makefile145
-rw-r--r--odk/examples/java/DocumentHandling/test/test1.odtbin0 -> 7999 bytes
-rw-r--r--odk/examples/java/Drawing/Makefile92
-rw-r--r--odk/examples/java/Drawing/SDraw.java272
-rw-r--r--odk/examples/java/EmbedDocument/Container1/EmbedContApp.java1024
-rw-r--r--odk/examples/java/EmbedDocument/Container1/EmbedContFrame.java108
-rw-r--r--odk/examples/java/EmbedDocument/Container1/Makefile48
-rwxr-xr-xodk/examples/java/EmbedDocument/EmbeddedObject/EditorFrame.java121
-rw-r--r--odk/examples/java/EmbedDocument/EmbeddedObject/EmbeddedObject.odtbin0 -> 9975 bytes
-rwxr-xr-xodk/examples/java/EmbedDocument/EmbeddedObject/EmbeddedObject.xcu28
-rw-r--r--odk/examples/java/EmbedDocument/EmbeddedObject/Makefile147
-rwxr-xr-xodk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObject.java1124
-rwxr-xr-xodk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObjectFactory.java101
-rwxr-xr-xodk/examples/java/Inspector/Addon.xcu28
-rwxr-xr-xodk/examples/java/Inspector/Addons.xcu23
-rw-r--r--odk/examples/java/Inspector/HideableMutableTreeNode.java88
-rw-r--r--odk/examples/java/Inspector/HideableTreeModel.java298
-rw-r--r--odk/examples/java/Inspector/Inspector.java461
-rw-r--r--odk/examples/java/Inspector/InspectorAddon.java228
-rw-r--r--odk/examples/java/Inspector/InspectorPane.java629
-rw-r--r--odk/examples/java/Inspector/InstanceInspector.idl52
-rw-r--r--odk/examples/java/Inspector/InstanceInspectorTest.odtbin0 -> 12272 bytes
-rw-r--r--odk/examples/java/Inspector/Introspector.java667
-rw-r--r--odk/examples/java/Inspector/Makefile195
-rw-r--r--odk/examples/java/Inspector/MethodParametersDialog.java353
-rwxr-xr-xodk/examples/java/Inspector/ObjectInspector.xcs18
-rwxr-xr-xodk/examples/java/Inspector/ObjectInspector.xcu18
-rwxr-xr-xodk/examples/java/Inspector/ProtocolHandler.xcu11
-rw-r--r--odk/examples/java/Inspector/ProtocolHandlerAddon.java283
-rw-r--r--odk/examples/java/Inspector/SourceCodeGenerator.java1766
-rw-r--r--odk/examples/java/Inspector/SwingDialogProvider.java442
-rw-r--r--odk/examples/java/Inspector/SwingTreeControlProvider.java427
-rw-r--r--odk/examples/java/Inspector/SwingTreePathProvider.java40
-rw-r--r--odk/examples/java/Inspector/SwingUnoFacetteNode.java84
-rw-r--r--odk/examples/java/Inspector/SwingUnoMethodNode.java138
-rw-r--r--odk/examples/java/Inspector/SwingUnoNode.java156
-rw-r--r--odk/examples/java/Inspector/SwingUnoPropertyNode.java96
-rw-r--r--odk/examples/java/Inspector/TDocSupplier.java168
-rw-r--r--odk/examples/java/Inspector/TestInspector.java88
-rw-r--r--odk/examples/java/Inspector/UnoFacetteNode.java85
-rw-r--r--odk/examples/java/Inspector/UnoMethodNode.java228
-rw-r--r--odk/examples/java/Inspector/UnoNode.java437
-rw-r--r--odk/examples/java/Inspector/UnoPropertyNode.java225
-rw-r--r--odk/examples/java/Inspector/UnoTreeRenderer.java135
-rw-r--r--odk/examples/java/Inspector/XDialogProvider.java65
-rw-r--r--odk/examples/java/Inspector/XInstanceInspector.idl56
-rw-r--r--odk/examples/java/Inspector/XLanguageSourceCodeGenerator.java106
-rw-r--r--odk/examples/java/Inspector/XMethodParametersDialog.java37
-rw-r--r--odk/examples/java/Inspector/XTreeControlProvider.java93
-rw-r--r--odk/examples/java/Inspector/XTreePathProvider.java25
-rw-r--r--odk/examples/java/Inspector/XUnoFacetteNode.java63
-rw-r--r--odk/examples/java/Inspector/XUnoMethodNode.java68
-rw-r--r--odk/examples/java/Inspector/XUnoNode.java84
-rw-r--r--odk/examples/java/Inspector/XUnoPropertyNode.java51
-rwxr-xr-xodk/examples/java/Inspector/images/containers_16.pngbin0 -> 233 bytes
-rwxr-xr-xodk/examples/java/Inspector/images/content_16.pngbin0 -> 370 bytes
-rwxr-xr-xodk/examples/java/Inspector/images/interfaces_16.pngbin0 -> 433 bytes
-rwxr-xr-xodk/examples/java/Inspector/images/methods_16.pngbin0 -> 380 bytes
-rwxr-xr-xodk/examples/java/Inspector/images/properties_16.pngbin0 -> 242 bytes
-rwxr-xr-xodk/examples/java/Inspector/images/services_16.pngbin0 -> 258 bytes
-rwxr-xr-xodk/examples/java/Inspector/manifest.mf3
-rw-r--r--odk/examples/java/MinimalComponent/BuildMinimalComponent.xml64
-rw-r--r--odk/examples/java/MinimalComponent/Makefile203
-rw-r--r--odk/examples/java/MinimalComponent/MinimalComponent.idl52
-rw-r--r--odk/examples/java/MinimalComponent/MinimalComponent.java171
-rw-r--r--odk/examples/java/MinimalComponent/TestMinimalComponent.java69
-rw-r--r--odk/examples/java/NotesAccess/Makefile113
-rw-r--r--odk/examples/java/NotesAccess/NotesAccess.java288
-rw-r--r--odk/examples/java/NotesAccess/Stocks.nsfbin0 -> 262144 bytes
-rw-r--r--odk/examples/java/PropertySet/Makefile134
-rw-r--r--odk/examples/java/PropertySet/PropTest.java265
-rw-r--r--odk/examples/java/PropertySet/PropertySet.odtbin0 -> 8391 bytes
-rw-r--r--odk/examples/java/Spreadsheet/CalcAddins.java304
-rw-r--r--odk/examples/java/Spreadsheet/CalcAddins.odsbin0 -> 8653 bytes
-rw-r--r--odk/examples/java/Spreadsheet/ChartTypeChange.java355
-rw-r--r--odk/examples/java/Spreadsheet/EuroAdaption.java389
-rw-r--r--odk/examples/java/Spreadsheet/Makefile213
-rw-r--r--odk/examples/java/Spreadsheet/SCalc.java412
-rw-r--r--odk/examples/java/Spreadsheet/XCalcAddins.idl100
-rw-r--r--odk/examples/java/Storage/Makefile58
-rw-r--r--odk/examples/java/Storage/StorageFunctionality.java147
-rw-r--r--odk/examples/java/Storage/StorageTest.java7
-rw-r--r--odk/examples/java/Storage/Test01.java158
-rw-r--r--odk/examples/java/Storage/Test02.java152
-rw-r--r--odk/examples/java/Storage/Test03.java209
-rw-r--r--odk/examples/java/Storage/Test04.java273
-rw-r--r--odk/examples/java/Storage/Test05.java268
-rw-r--r--odk/examples/java/Storage/Test06.java278
-rw-r--r--odk/examples/java/Storage/Test07.java137
-rw-r--r--odk/examples/java/Storage/Test08.java213
-rw-r--r--odk/examples/java/Storage/Test09.java123
-rw-r--r--odk/examples/java/Storage/TestHelper.java864
-rw-r--r--odk/examples/java/Text/BookmarkInsertion.java284
-rw-r--r--odk/examples/java/Text/GraphicsInserter.java179
-rw-r--r--odk/examples/java/Text/HardFormatting.java286
-rw-r--r--odk/examples/java/Text/Makefile136
-rw-r--r--odk/examples/java/Text/SWriter.java397
-rw-r--r--odk/examples/java/Text/StyleCreation.java226
-rw-r--r--odk/examples/java/Text/StyleInitialization.java320
-rw-r--r--odk/examples/java/Text/TextDocumentStructure.java205
-rw-r--r--odk/examples/java/Text/TextReplace.java231
-rw-r--r--odk/examples/java/Text/WriterSelector.java162
-rw-r--r--odk/examples/java/Text/oo_smiley.gifbin0 -> 46109 bytes
-rw-r--r--odk/examples/java/ToDo/Makefile166
-rw-r--r--odk/examples/java/ToDo/ToDo.idl50
-rw-r--r--odk/examples/java/ToDo/ToDo.java965
-rw-r--r--odk/examples/java/ToDo/ToDo.odsbin0 -> 13276 bytes
-rw-r--r--odk/examples/java/ToDo/XToDo.idl50
-rw-r--r--odk/examples/java/makefile.mk155
118 files changed, 22653 insertions, 0 deletions
diff --git a/odk/examples/java/ConverterServlet/ConverterServlet.html b/odk/examples/java/ConverterServlet/ConverterServlet.html
new file mode 100644
index 000000000000..7c68ce8ba15e
--- /dev/null
+++ b/odk/examples/java/ConverterServlet/ConverterServlet.html
@@ -0,0 +1,46 @@
+<html><head><title>Document Converter
+</title></head><body>
+<h1>Document Converter</h1>
+<p>Converting documents with a remote running OpenOffice.org.</p>
+<form action="http://localhost:8080/conversion/servlet/ConverterServlet" method=post enctype="multipart/form-data">
+ <table width="510" border="0">
+ <tr>
+ <td>Local document</td>
+ <td>
+ <input type=file size=50 maxlength=100000 name="DocumentToBeConverted">
+ </td>
+ </tr>
+ <tr>
+ <td>Target document type</td>
+ <td>
+ <select name="converttype">
+ <option selected>swriter: StarOffice XML (Writer)</option>
+ <option>swriter: HTML (StarWriter)</option>
+ <option>swriter: MS Word 97</option>
+ <option>swriter: Text</option>
+ <option>scalc: StarOffice XML (Calc)</option>
+ <option>scalc: HTML (StarCalc)</option>
+ <option>scalc: MS Excel 97</option>
+ <option>sdraw: StarOffice XML (Draw)</option>
+ <option>simpress: StarOffice XML (Impress)</option>
+ <option>simpress: MS PowerPoint 97</option>
+ </select>
+ </td>
+ </tr>
+ <tr>
+ <td>Extension</td>
+ <td>
+ <input type=text name="extension">
+ </td>
+ </tr>
+ </table>
+ <p>The converted document will be returned by the server. If you selected the
+ target document type &quot;swriter: HTML (StarWriter)&quot; or &quot;scalc:
+ HTML (StarCalc)&quot;, the document will be shown in the browser. If have an application
+ registered in your browser for the selected document type (mime type) the application will be started.
+ Otherwise, a dialog will be opened, which allows you to open or save the converted document.</p>
+ <p>
+ <input type=submit value="Convert">
+ </p>
+</form>
+</body></html>
diff --git a/odk/examples/java/ConverterServlet/ConverterServlet.java b/odk/examples/java/ConverterServlet/ConverterServlet.java
new file mode 100644
index 000000000000..281b47db370c
--- /dev/null
+++ b/odk/examples/java/ConverterServlet/ConverterServlet.java
@@ -0,0 +1,336 @@
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+
+// JDK API
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.BufferedInputStream;
+import java.util.Enumeration;
+
+// Servlet API
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletOutputStream;
+
+// Helper API
+import com.oreilly.servlet.MultipartRequest;
+import com.oreilly.servlet.MultipartResponse;
+import com.oreilly.servlet.ServletUtils;
+
+// UNO API
+import com.sun.star.bridge.XUnoUrlResolver;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.frame.XComponentLoader;
+import com.sun.star.frame.XStorable;
+import com.sun.star.util.XCloseable;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiComponentFactory;
+
+
+/** This class implements a http servlet in order to convert an incoming document
+ * with help of a running OpenOffice.org and to push the converted file back
+ * to the client.
+ */
+public class ConverterServlet extends HttpServlet {
+ /** Specifies the temporary directory on the web server.
+ */
+ private String stringWorkingDirectory =
+ System.getProperty( "java.io.tmpdir" ).replace( '\\', '/' );
+
+ /** Specifies the host for the office server.
+ */
+ private String stringHost = "localhost";
+
+ /** Specifies the port for the office server.
+ */
+ private String stringPort = "2083";
+
+ /** Called by the server (via the service method) to allow a servlet to handle
+ * a POST request. The file from the client will be uploaded to the web server
+ * and converted on the web server and after all pushed to the client.
+ * @param request Object that contains the request the client has made of the servlet.
+ * @param response Object that contains the response the servlet sends to the client.
+ * @throws ServletException If the request for the POST could not be handled.
+ * @throws IOException If an input or output error is detected when the servlet handles the request.
+ */
+ protected void doPost( HttpServletRequest request,
+ HttpServletResponse response) throws ServletException, java.io.IOException {
+ try {
+ // If necessary, add a slash to the end of the string.
+ if ( !stringWorkingDirectory.endsWith( "/" ) ) {
+ stringWorkingDirectory += "/";
+ }
+
+ // Construct a MultipartRequest to help read the information.
+ // Pass in the request, a directory to save files to, and the
+ // maximum POST size we should attempt to handle.
+ MultipartRequest multipartrequest =
+ new MultipartRequest( request, stringWorkingDirectory, 5 * 1024 * 1024 );
+
+ // Getting all file names from the request
+ Enumeration files = multipartrequest.getFileNames();
+
+ // Every received file will be converted to the specified type
+ while (files.hasMoreElements()) {
+ // Getting the name from the element
+ String stringName = (String)files.nextElement();
+
+ // Getting the filename from the request
+ String stringFilename =
+ multipartrequest.getFilesystemName( stringName );
+
+ // Converting the given file on the server to the specified type and
+ // append a special extension
+ File cleanupFile = null;
+ String stringSourceFile = stringWorkingDirectory + stringFilename;
+
+ try {
+ String stringConvertedFile = convertDocument(stringSourceFile,
+ multipartrequest.getParameter( "converttype" ),
+ multipartrequest.getParameter( "extension" ));
+
+ String shortFileName = stringConvertedFile.substring(
+ stringConvertedFile.lastIndexOf('/') + 1);
+
+ // Set the response header
+ // Set the filename, is used when the file will be saved (problem with mozilla)
+ response.addHeader( "Content-Disposition",
+ "attachment; filename=" + shortFileName);
+
+ // Constructing the multi part response to the client
+ MultipartResponse multipartresponse = new MultipartResponse(response);
+
+ // Is the convert type HTML?
+ if ( ( multipartrequest.getParameter( "converttype" ).equals(
+ "swriter: HTML (StarWriter)" ) )
+ || ( multipartrequest.getParameter( "converttype" ).equals(
+ "scalc: HTML (StarCalc)" ) ) ) {
+ // Setting the content type of the response being sent to the client
+ // to text
+ multipartresponse.startResponse( "text/html" );
+ } else {
+ // Setting the content type of the response being sent to the client
+ // to application/octet-stream so that file will open a dialog box
+ // at the client in order to save the converted file
+ multipartresponse.startResponse( "application/octet-stream" );
+ }
+
+ // Pushing the converted file to the client
+ ServletUtils.returnFile( stringConvertedFile,
+ response.getOutputStream() );
+
+ // Finishing the multi part response
+ multipartresponse.finish();
+
+ // clean up the working directory
+ cleanupFile = new File(stringConvertedFile);
+ if ( cleanupFile.exists() )
+ cleanupFile.delete();
+
+ } catch (Exception exc) {
+ response.setContentType( "text/html;charset=8859-1" );
+ PrintWriter out = response.getWriter();
+
+ exc.printStackTrace();
+
+ out.println( "<html><head>" );
+ out.println( " <title>" + "SDK Converter Servlet" + "</title>" );
+ out.println( "</head>" );
+ out.println( "<body><br><p>");
+ out.println( "<b>Sorry, the conversion failed!</b></p>");
+ out.println( "<p><b>Error Mesage:</b><br>" + exc.getMessage() + "<br>");
+ exc.printStackTrace(out);
+ out.println( "</p></body><html>");
+ }
+
+ // clean up the working directory
+ cleanupFile = new File(stringSourceFile);
+ if ( cleanupFile.exists() )
+ cleanupFile.delete();
+ }
+ }
+ catch (Exception exception) {
+ System.err.println( exception.toString() );
+ }
+ }
+
+ /** This method converts a document to a given type by using a running
+ * OpenOffice.org and saves the converted document to the specified
+ * working directory.
+ * @param stringDocumentName The full path name of the file on the server to be converted.
+ * @param stringConvertType Type to convert to.
+ * @param stringExtension This string will be appended to the file name of the converted file.
+ * @return The full path name of the converted file will be returned.
+ * @see stringWorkingDirectory
+ */
+ private String convertDocument( String stringDocumentName,
+ String stringConvertType,
+ String stringExtension)
+ throws Exception
+ {
+ String stringConvertedFile = "";
+
+ // Converting the document to the favoured type
+// try {
+ // Composing the URL
+ String stringUrl = "file:///" + stringDocumentName;
+
+ /* Bootstraps a component context with the jurt base components
+ registered. Component context to be granted to a component for running.
+ Arbitrary values can be retrieved from the context. */
+ XComponentContext xcomponentcontext =
+ com.sun.star.comp.helper.Bootstrap.createInitialComponentContext( null );
+
+ /* Gets the service manager instance to be used (or null). This method has
+ been added for convenience, because the service manager is a often used
+ object. */
+ XMultiComponentFactory xmulticomponentfactory =
+ xcomponentcontext.getServiceManager();
+
+ /* Creates an instance of the component UnoUrlResolver which
+ supports the services specified by the factory. */
+ Object objectUrlResolver =
+ xmulticomponentfactory.createInstanceWithContext(
+ "com.sun.star.bridge.UnoUrlResolver", xcomponentcontext );
+
+ // Create a new url resolver
+ XUnoUrlResolver xurlresolver = ( XUnoUrlResolver )
+ UnoRuntime.queryInterface( XUnoUrlResolver.class,
+ objectUrlResolver );
+
+ // Resolves an object that is specified as follow:
+ // uno:<connection description>;<protocol description>;<initial object name>
+ Object objectInitial = xurlresolver.resolve(
+ "uno:socket,host=" + stringHost + ",port=" + stringPort +
+ ";urp;StarOffice.ServiceManager" );
+
+ // Create a service manager from the initial object
+ xmulticomponentfactory = ( XMultiComponentFactory )
+ UnoRuntime.queryInterface( XMultiComponentFactory.class, objectInitial );
+
+ // Query for the XPropertySet interface.
+ XPropertySet xpropertysetMultiComponentFactory = ( XPropertySet )
+ UnoRuntime.queryInterface( XPropertySet.class, xmulticomponentfactory );
+
+ // Get the default context from the office server.
+ Object objectDefaultContext =
+ xpropertysetMultiComponentFactory.getPropertyValue( "DefaultContext" );
+
+ // Query for the interface XComponentContext.
+ xcomponentcontext = ( XComponentContext ) UnoRuntime.queryInterface(
+ XComponentContext.class, objectDefaultContext );
+
+ /* A desktop environment contains tasks with one or more
+ frames in which components can be loaded. Desktop is the
+ environment for components which can instanciate within
+ frames. */
+ XComponentLoader xcomponentloader = ( XComponentLoader )
+ UnoRuntime.queryInterface( XComponentLoader.class,
+ xmulticomponentfactory.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xcomponentcontext ) );
+
+ // Preparing properties for loading the document
+ PropertyValue propertyvalue[] = new PropertyValue[ 1 ];
+ // Setting the flag for hidding the open document
+ propertyvalue[ 0 ] = new PropertyValue();
+ propertyvalue[ 0 ].Name = "Hidden";
+ propertyvalue[ 0 ].Value = new Boolean(true);
+
+ // Loading the wanted document
+ Object objectDocumentToStore =
+ xcomponentloader.loadComponentFromURL(
+ stringUrl, "_blank", 0, propertyvalue );
+
+ // Getting an object that will offer a simple way to store a document to a URL.
+ XStorable xstorable =
+ ( XStorable ) UnoRuntime.queryInterface( XStorable.class,
+ objectDocumentToStore );
+
+ // Preparing properties for converting the document
+ propertyvalue = new PropertyValue[ 2 ];
+ // Setting the flag for overwriting
+ propertyvalue[ 0 ] = new PropertyValue();
+ propertyvalue[ 0 ].Name = "Overwrite";
+ propertyvalue[ 0 ].Value = new Boolean(true);
+ // Setting the filter name
+ propertyvalue[ 1 ] = new PropertyValue();
+ propertyvalue[ 1 ].Name = "FilterName";
+ propertyvalue[ 1 ].Value = stringConvertType;
+
+ // Appending the favoured extension to the origin document name
+ int index = stringUrl.lastIndexOf('.');
+ if ( index >= 0 ) {
+ stringConvertedFile = stringUrl.substring(0, index) + "." + stringExtension;
+ } else {
+ stringConvertedFile = stringUrl + "." + stringExtension;
+ }
+
+ // Storing and converting the document
+ xstorable.storeAsURL( stringConvertedFile, propertyvalue );
+
+ XCloseable xcloseable = (XCloseable)UnoRuntime.queryInterface( XCloseable.class,xstorable );
+
+ // Closing the converted document
+ if ( xcloseable != null )
+ xcloseable.close(false);
+ else {
+ // If Xcloseable is not supported (older versions,
+ // use dispose() for closing the document
+ XComponent xComponent = ( XComponent ) UnoRuntime.queryInterface(
+ XComponent.class, xstorable );
+ xComponent.dispose();
+ }
+
+// }
+// catch( Exception exception ) {
+// exception.printStackTrace();
+// return( "" );
+// }
+
+ if ( stringConvertedFile.startsWith( "file:///" ) ) {
+ // Truncating the beginning of the file name
+ stringConvertedFile = stringConvertedFile.substring( 8 );
+ }
+
+ // Returning the name of the converted file
+ return stringConvertedFile;
+ }
+}
diff --git a/odk/examples/java/ConverterServlet/Makefile b/odk/examples/java/ConverterServlet/Makefile
new file mode 100644
index 000000000000..8c1828cea7b2
--- /dev/null
+++ b/odk/examples/java/ConverterServlet/Makefile
@@ -0,0 +1,94 @@
+#*************************************************************************
+#
+# 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 ConverterServlet example of the SDK.
+
+PRJ=../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+COMPONENT_NAME=ConverterServletExample
+OUT_COMP_CLASS=$(OUT_CLASS)/$(COMPONENT_NAME)
+
+JAVAFILES = \
+ ConverterServlet.java
+
+CLASSFILES = $(patsubst %.java,$(OUT_COMP_CLASS)/%.class,$(JAVAFILES))
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(OFFICE_CLASSES_DIR)/cos.jar\
+ $(PATH_SEPARATOR)$(OFFICE_CLASSES_DIR)/servlet.jar\
+ $(PATH_SEPARATOR)$(OUT_COMP_CLASS))
+
+# Targets
+.PHONY: ALL
+ALL : \
+ ConverterServletExample
+
+include $(SETTINGS)/stdtarget.mk
+
+$(OFFICE_CLASSES_DIR)/cos.jar :
+ @echo --------------------------------------------------------------------------------
+ @echo You need the servlet support Java archive "$(QM)cos.jar$(QM)" for this example.
+ @echo You can download it from "$(QM)http://www.servlets.com/cos/index.html$(QM)"
+ @echo and then please copy it into your "$(QM)$(OFFICE_CLASSES_DIR)$(QM)" directory.
+ @echo --------------------------------------------------------------------------------
+
+$(OFFICE_CLASSES_DIR)/servlet.jar :
+ @echo --------------------------------------------------------------------------------
+ @echo You need the servlet API "$(QM)servlet.jar$(QM)" for this example.
+ @echo You can download it from "$(QM)http://java.sun.com/products/servlet/index.html$(QM)"
+ @echo and then please copy it into your "$(QM)$(OFFICE_CLASSES_DIR)$(QM)" directory.
+ @echo --------------------------------------------------------------------------------
+
+$(CLASSFILES) : $(JAVAFILES) $(OFFICE_CLASSES_DIR)/cos.jar $(OFFICE_CLASSES_DIR)/servlet.jar
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_COMP_CLASS) $(JAVAFILES)
+
+ConverterServletExample : $(CLASSFILES)
+ @echo --------------------------------------------------------------------------------
+ @echo Please see the README file for more information how to use the converter
+ @echo servlet.
+ @echo --------------------------------------------------------------------------------
+
+%.run: $(OUT_COMP_CLASS)/%.class
+ $(JAVA) -classpath "$(SDK_CLASSPATH)" $(basename $@)
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_CLASS))
diff --git a/odk/examples/java/ConverterServlet/README b/odk/examples/java/ConverterServlet/README
new file mode 100644
index 000000000000..ea59b80b43c0
--- /dev/null
+++ b/odk/examples/java/ConverterServlet/README
@@ -0,0 +1,38 @@
+Servlet for converting documents
+================================
+
+Build preparation:
+==================
+In the file "ConverterServlet.html", search for the following line:
+<form action="http://localhost:8080/conversion/servlet/ConverterServlet" method=post enctype="multipart/form-data">
+Replace the existing IP address (localhost) with your intended IP address.
+
+Installation instructions:
+==========================
+1. If no web server is available you should install your favourite web server.
+ The example was tested with a Tomcat 4.1 server (http://jakarta.apache.org/tomcat/)
+2. Download the servlet support Java archive (cos.jar) from
+ http://www.servlets.com/cos/index.html and copy the file to the directory
+ <OFFICE_HOME>/program/classes. If you don't use the created WAR (WAR = simple web archive file, it
+ is similar to a normal Jar file) file, please make these classes also known to your web server.
+3. You need also the Servlet API (servlet.jar). The Tomcat server comes with this Servlet API. Please
+ copy the file "servlet.jar" to the directory <OFFICE_HOME>/program/classes.
+ If you don't use the Tomcat server, make sure that the Servlet API is in the classpath of your web
+ server. You can download the Servlet API from http://java.sun.com/products/servlet/index.html .
+4. Use your GNU make (http://www.gnu.org) to build the servlet class.
+5. Make the servlet class known to your web server.
+ The example creates also a WAR file which can be easy deployed in a Tomcat server.
+ 5.1 Browse the 'Tomcat Web Application Manager'
+ 5.2 Navigate into the section 'Upload a WAR file to install'
+ 5.3 Browse to your generated WAR file and select it
+ 5.4 install it
+
+
+Converting documents with the servlet:
+======================================
+1. Browse your web server "http://<your_ip>/conversion/ConverterServlet.html" or
+ open the file "ConverterServlet.html" in your web browser and select a file.
+2. Select a type to convert the file to, and the extension for the converted file.
+3. Press the button. The document will be uploaded to the server, converted and
+ pushed back to the client. Your browser will open a dialog for saving the
+ converted document.
diff --git a/odk/examples/java/ConverterServlet/web.xml b/odk/examples/java/ConverterServlet/web.xml
new file mode 100644
index 000000000000..9bef5ff964b9
--- /dev/null
+++ b/odk/examples/java/ConverterServlet/web.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<!DOCTYPE web-app
+ PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd">
+
+<web-app>
+ <display-name>Conversion</display-name>
+ <description>
+ Converter servlet demo of the SDK.
+ </description>
+
+ <servlet>
+ <servlet-name>ConverterServlet</servlet-name>
+ <servlet-class>ConverterServlet</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>ConverterServlet</servlet-name>
+ <url-pattern>/servlet/*</url-pattern>
+ </servlet-mapping>
+
+</web-app>
diff --git a/odk/examples/java/DocumentHandling/DocumentConverter.java b/odk/examples/java/DocumentHandling/DocumentConverter.java
new file mode 100644
index 000000000000..97d407935501
--- /dev/null
+++ b/odk/examples/java/DocumentHandling/DocumentConverter.java
@@ -0,0 +1,225 @@
+/*************************************************************************
+ *
+ * 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;
+import java.io.FileFilter;
+
+
+/** 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 backslashs
+ 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 = new 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 =
+ (com.sun.star.frame.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 = new 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.clsoe if the
+ // interface is supported, otherwise use XComponent.dispose
+ com.sun.star.util.XCloseable xCloseable =
+ (com.sun.star.util.XCloseable)UnoRuntime.queryInterface(
+ com.sun.star.util.XCloseable.class, xStorable);
+
+ if ( xCloseable != null ) {
+ xCloseable.close(false);
+ } else {
+ com.sun.star.lang.XComponent xComp =
+ (com.sun.star.lang.XComponent)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 = (com.sun.star.frame.XComponentLoader)
+ 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);
+ }
+ }
+}
diff --git a/odk/examples/java/DocumentHandling/DocumentLoader.java b/odk/examples/java/DocumentHandling/DocumentLoader.java
new file mode 100644
index 000000000000..a5a7fb5fc730
--- /dev/null
+++ b/odk/examples/java/DocumentHandling/DocumentLoader.java
@@ -0,0 +1,92 @@
+/*************************************************************************
+ *
+ * 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 =
+ (com.sun.star.frame.XComponentLoader)
+ 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 automaticly 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);
+ }
+ }
+}
diff --git a/odk/examples/java/DocumentHandling/DocumentPrinter.java b/odk/examples/java/DocumentHandling/DocumentPrinter.java
new file mode 100644
index 000000000000..3331f43f809a
--- /dev/null
+++ b/odk/examples/java/DocumentHandling/DocumentPrinter.java
@@ -0,0 +1,109 @@
+/*************************************************************************
+ *
+ * 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 =
+ (com.sun.star.frame.XComponentLoader)
+ 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 automaticly 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 =
+ (com.sun.star.view.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);
+ }
+ }
+}
diff --git a/odk/examples/java/DocumentHandling/DocumentSaver.java b/odk/examples/java/DocumentHandling/DocumentSaver.java
new file mode 100644
index 000000000000..93d6231a4b44
--- /dev/null
+++ b/odk/examples/java/DocumentHandling/DocumentSaver.java
@@ -0,0 +1,131 @@
+/*************************************************************************
+ *
+ * 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 =
+ (com.sun.star.frame.XComponentLoader)
+ 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 = new Boolean(true);
+
+ Object oDocToStore = xCompLoader.loadComponentFromURL(
+ sLoadUrl.toString(), "_blank", 0, propertyValue );
+ com.sun.star.frame.XStorable xStorable =
+ (com.sun.star.frame.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 = new 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 = (com.sun.star.util.XCloseable)
+ UnoRuntime.queryInterface(com.sun.star.util.XCloseable.class,
+ oDocToStore );
+
+ if (xCloseable != null ) {
+ xCloseable.close(false);
+ } else
+ {
+ com.sun.star.lang.XComponent xComp = (com.sun.star.lang.XComponent)
+ 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);
+ }
+ }
+}
diff --git a/odk/examples/java/DocumentHandling/Makefile b/odk/examples/java/DocumentHandling/Makefile
new file mode 100644
index 000000000000..0cf208330bfd
--- /dev/null
+++ b/odk/examples/java/DocumentHandling/Makefile
@@ -0,0 +1,145 @@
+#*************************************************************************
+#
+# 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
+include $(SETTINGS)/dk.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 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 000000000000..66db1c56df6f
--- /dev/null
+++ b/odk/examples/java/DocumentHandling/test/test1.odt
Binary files differ
diff --git a/odk/examples/java/Drawing/Makefile b/odk/examples/java/Drawing/Makefile
new file mode 100644
index 000000000000..6281c2462a16
--- /dev/null
+++ b/odk/examples/java/Drawing/Makefile
@@ -0,0 +1,92 @@
+#*************************************************************************
+#
+# 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 Drawing example of the SDK.
+
+PRJ=../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+EXAMPLE_NAME=JavaDrawingExample
+OUT_APP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME)
+
+APP1_NAME=SDraw
+APP1_JAR=$(OUT_APP_CLASS)/$(APP1_NAME).jar
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(OUT_APP_CLASS))
+
+# Targets
+.PHONY: ALL
+ALL : \
+ $(EXAMPLE_NAME)
+
+include $(SETTINGS)/stdtarget.mk
+
+$(OUT_APP_CLASS)/%.class : %.java
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_APP_CLASS) $<
+
+$(OUT_APP_CLASS)/%.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: $*>> $@
+
+$(OUT_APP_CLASS)/%.jar : $(OUT_APP_CLASS)/%.mf $(OUT_APP_CLASS)/%.class
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ +cd $(subst /,$(PS),$(OUT_APP_CLASS)) && $(SDK_JAR) cvfm $(@F) $*.mf $*.class
+ +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
+
+$(APP1_JAR) : $(OUT_APP_CLASS)/$(APP1_NAME).mf $(OUT_APP_CLASS)/$(APP1_NAME).class
+
+$(EXAMPLE_NAME) : $(APP1_JAR)
+ @echo --------------------------------------------------------------------------------
+ @echo Please use the following command to execute the example!
+ @echo -
+ @echo $(MAKE) SDraw.run
+ @echo --------------------------------------------------------------------------------
+
+%.run: $(OUT_APP_CLASS)/%.jar
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $<
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_CLASS))
diff --git a/odk/examples/java/Drawing/SDraw.java b/odk/examples/java/Drawing/SDraw.java
new file mode 100644
index 000000000000..551689c5626b
--- /dev/null
+++ b/odk/examples/java/Drawing/SDraw.java
@@ -0,0 +1,272 @@
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+
+//***************************************************************************
+// comment: Step 1: bootstrap UNO and get the remote component context
+// Step 2: open an empty text document
+// Step 3: get the drawpage an insert some shapes
+//***************************************************************************
+
+
+import java.lang.Math;
+
+import com.sun.star.uno.UnoRuntime;
+
+public class SDraw {
+
+
+ public static void main(String args[]) {
+
+ //oooooooooooooooooooooooooooStep 1oooooooooooooooooooooooooooooooooooooooo
+ // bootstrap UNO and get the remote component context. The context can
+ // be used to get the service manager
+ //*************************************************************************
+ 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 ...");
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+ com.sun.star.lang.XComponent xDrawDoc = null;
+ com.sun.star.drawing.XDrawPage xDrawPage = null;
+
+ //oooooooooooooooooooooooooooStep 2oooooooooooooooooooooooooooooooooooooooo
+ // open an empty document. In this case it's a draw document.
+ // For this purpose an instance of com.sun.star.frame.Desktop
+ // is created. It's interface XDesktop provides the XComponentLoader,
+ // which is used to open the document via loadComponentFromURL
+ //*************************************************************************
+
+ //Open document
+ //Draw
+ System.out.println("Opening an empty Draw document ...");
+ xDrawDoc = openDraw(xContext);
+
+ //oooooooooooooooooooooooooooStep 3oooooooooooooooooooooooooooooooooooooooo
+ // get the drawpage an insert some shapes.
+ // the documents DrawPageSupplier supplies the DrawPage vi IndexAccess
+ // To add a shape get the MultiServiceFaktory of the document, create an
+ // instance of the ShapeType and add it to the Shapes-container
+ // provided by the drawpage
+ //*************************************************************************
+
+
+ // get the drawpage of drawing here
+ try {
+ System.out.println( "getting Drawpage" );
+ com.sun.star.drawing.XDrawPagesSupplier xDPS =
+ (com.sun.star.drawing.XDrawPagesSupplier)UnoRuntime.queryInterface(
+ com.sun.star.drawing.XDrawPagesSupplier.class, xDrawDoc);
+ com.sun.star.drawing.XDrawPages xDPn = xDPS.getDrawPages();
+ com.sun.star.container.XIndexAccess xDPi =
+ (com.sun.star.container.XIndexAccess)UnoRuntime.queryInterface(
+ com.sun.star.container.XIndexAccess.class, xDPn);
+ xDrawPage = (com.sun.star.drawing.XDrawPage)UnoRuntime.queryInterface(
+ com.sun.star.drawing.XDrawPage.class, xDPi.getByIndex(0));
+ } catch ( Exception e ) {
+ System.err.println( "Couldn't create document"+ e );
+ e.printStackTrace(System.err);
+ }
+
+ createSequence(xDrawDoc, xDrawPage);
+
+ //put something on the drawpage
+ System.out.println( "inserting some Shapes" );
+ com.sun.star.drawing.XShapes xShapes = (com.sun.star.drawing.XShapes)
+ UnoRuntime.queryInterface(
+ com.sun.star.drawing.XShapes.class, xDrawPage);
+ xShapes.add(createShape(xDrawDoc,2000,1500,1000,1000,"Line",0));
+ xShapes.add(createShape(xDrawDoc,3000,4500,15000,1000,"Ellipse",16711680));
+ xShapes.add(createShape(xDrawDoc,5000,3500,7500,5000,"Rectangle",6710932));
+
+ //*************************************************************************
+ System.out.println("done");
+ System.exit(0);
+ }
+
+ public static com.sun.star.lang.XComponent openDraw(
+ com.sun.star.uno.XComponentContext xContext)
+ {
+ com.sun.star.frame.XComponentLoader xCLoader;
+ com.sun.star.text.XTextDocument xDoc = null;
+ com.sun.star.lang.XComponent xComp = null;
+
+ try {
+ // get the remote office service manager
+ com.sun.star.lang.XMultiComponentFactory xMCF =
+ xContext.getServiceManager();
+
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext);
+
+ xCLoader = (com.sun.star.frame.XComponentLoader)
+ UnoRuntime.queryInterface(com.sun.star.frame.XComponentLoader.class,
+ oDesktop);
+ com.sun.star.beans.PropertyValue szEmptyArgs[] =
+ new com.sun.star.beans.PropertyValue[0];
+ String strDoc = "private:factory/sdraw";
+ xComp = xCLoader.loadComponentFromURL(strDoc, "_blank", 0, szEmptyArgs);
+
+ } catch(Exception e){
+ System.err.println(" Exception " + e);
+ e.printStackTrace(System.err);
+ }
+
+ return xComp;
+ }
+
+ public static com.sun.star.drawing.XShape createShape(
+ com.sun.star.lang.XComponent xDocComp, int height, int width, int x,
+ int y, String kind, int col)
+ {
+ //possible values for kind are 'Ellipse', 'Line' and 'Rectangle'
+ com.sun.star.awt.Size size = new com.sun.star.awt.Size();
+ com.sun.star.awt.Point position = new com.sun.star.awt.Point();
+ com.sun.star.drawing.XShape xShape = null;
+
+ //get MSF
+ com.sun.star.lang.XMultiServiceFactory xDocMSF =
+ (com.sun.star.lang.XMultiServiceFactory) UnoRuntime.queryInterface(
+ com.sun.star.lang.XMultiServiceFactory.class, xDocComp );
+
+ try {
+ Object oInt = xDocMSF.createInstance("com.sun.star.drawing."
+ +kind + "Shape");
+ xShape = (com.sun.star.drawing.XShape)UnoRuntime.queryInterface(
+ com.sun.star.drawing.XShape.class, oInt);
+ size.Height = height;
+ size.Width = width;
+ position.X = x;
+ position.Y = y;
+ xShape.setSize(size);
+ xShape.setPosition(position);
+
+ } catch ( Exception e ) {
+ System.err.println( "Couldn't create instance "+ e );
+ e.printStackTrace(System.err);
+ }
+
+ com.sun.star.beans.XPropertySet xSPS = (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xShape);
+
+ try {
+ xSPS.setPropertyValue("FillColor", new Integer(col));
+ } catch (Exception e) {
+ System.err.println("Can't change colors " + e);
+ e.printStackTrace(System.err);
+ }
+
+ return xShape;
+ }
+
+ public static com.sun.star.drawing.XShape createSequence(
+ com.sun.star.lang.XComponent xDocComp, com.sun.star.drawing.XDrawPage xDP)
+ {
+ com.sun.star.awt.Size size = new com.sun.star.awt.Size();
+ com.sun.star.awt.Point position = new com.sun.star.awt.Point();
+ com.sun.star.drawing.XShape xShape = null;
+ com.sun.star.drawing.XShapes xShapes = (com.sun.star.drawing.XShapes)
+ UnoRuntime.queryInterface(com.sun.star.drawing.XShapes.class, xDP);
+ int height = 3000;
+ int width = 3500;
+ int x = 1900;
+ int y = 20000;
+ Object oInt = null;
+ int r = 40;
+ int g = 0;
+ int b = 80;
+
+ //get MSF
+ com.sun.star.lang.XMultiServiceFactory xDocMSF =
+ (com.sun.star.lang.XMultiServiceFactory)UnoRuntime.queryInterface(
+ com.sun.star.lang.XMultiServiceFactory.class, xDocComp );
+
+ for (int i=0; i<370; i=i+25) {
+ try{
+ oInt = xDocMSF.createInstance("com.sun.star.drawing.EllipseShape");
+ xShape = (com.sun.star.drawing.XShape)UnoRuntime.queryInterface(
+ com.sun.star.drawing.XShape.class, oInt);
+ size.Height = height;
+ size.Width = width;
+ position.X = (x+(i*40));
+ position.Y =
+ (new Float(y+(Math.sin((i*Math.PI)/180))*5000)).intValue();
+ xShape.setSize(size);
+ xShape.setPosition(position);
+
+ } catch ( Exception e ) {
+ // Some exception occures.FAILED
+ System.err.println( "Couldn't get Shape "+ e );
+ e.printStackTrace(System.err);
+ }
+
+ b=b+8;
+
+ com.sun.star.beans.XPropertySet xSPS = (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,
+ xShape);
+
+ try {
+ xSPS.setPropertyValue("FillColor", new Integer(getCol(r,g,b)));
+ xSPS.setPropertyValue("Shadow", new Boolean(true));
+ } catch (Exception e) {
+ System.err.println("Can't change colors " + e);
+ e.printStackTrace(System.err);
+ }
+ xShapes.add(xShape);
+ }
+
+ com.sun.star.drawing.XShapeGrouper xSGrouper =
+ (com.sun.star.drawing.XShapeGrouper)UnoRuntime.queryInterface(
+ com.sun.star.drawing.XShapeGrouper.class, xDP);
+
+ xShape = xSGrouper.group(xShapes);
+
+ return xShape;
+ }
+
+ public static int getCol(int r, int g, int b) {
+ return r*65536+g*256+b;
+ }
+}
+
+
+
diff --git a/odk/examples/java/EmbedDocument/Container1/EmbedContApp.java b/odk/examples/java/EmbedDocument/Container1/EmbedContApp.java
new file mode 100644
index 000000000000..9e2ff4bdf113
--- /dev/null
+++ b/odk/examples/java/EmbedDocument/Container1/EmbedContApp.java
@@ -0,0 +1,1024 @@
+import java.awt.*;
+import java.applet.*;
+import java.awt.event.*;
+import java.net.*;
+import java.io.*;
+
+import javax.swing.JOptionPane;
+
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XInterface;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.uno.Type;
+
+import com.sun.star.lang.XComponent;
+
+import com.sun.star.beans.PropertyValue;
+
+import com.sun.star.datatransfer.DataFlavor;
+import com.sun.star.datatransfer.XTransferable;
+
+import com.sun.star.container.XNameAccess;
+
+import com.sun.star.io.XStream;
+import com.sun.star.io.XInputStream;
+import com.sun.star.io.XOutputStream;
+import com.sun.star.io.XTruncate;
+
+import com.sun.star.embed.*;
+
+public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClient
+{
+ private XMultiServiceFactory m_xServiceFactory;
+
+ private XEmbeddedObject m_xEmbedObj;
+ private XStorage m_xStorage;
+
+ private Frame m_aFrame;
+ private Menu m_aFileMenu;
+ private Menu m_aObjectMenu;
+ private Toolkit m_aToolkit;
+ private Image m_aImage;
+
+ private boolean m_bOwnFile = false;
+
+ private boolean m_bLinkObj = false;
+ private String m_aLinkURI;
+
+ public EmbedContApp( Frame aFrame, XMultiServiceFactory xServiceFactory )
+ {
+ m_aFrame = aFrame;
+ m_xServiceFactory = xServiceFactory;
+ }
+
+ public void init()
+ {
+ resize( 640, 480 );
+ setBackground( Color.gray );
+
+ m_aToolkit = Toolkit.getDefaultToolkit();
+
+ // Get a menu bar.
+ MenuBar aMenuBar = m_aFrame.getMenuBar();
+ if( aMenuBar == null )
+ {
+ aMenuBar = new MenuBar();
+ m_aFrame.setMenuBar( aMenuBar );
+ }
+
+ // Create menus for the menu bar.
+
+ // File menu
+ m_aFileMenu = new Menu( "File", true );
+ aMenuBar.add( m_aFileMenu );
+
+ MenuItem aItem = new NewMenuItem();
+ m_aFileMenu.add( aItem );
+
+ aItem = new OpenFileMenuItem();
+ m_aFileMenu.add( aItem );
+
+ aItem = new SaveMenuItem();
+ m_aFileMenu.add( aItem );
+
+ aItem = new SaveAsMenuItem();
+ m_aFileMenu.add( aItem );
+
+ // Object menu
+ m_aObjectMenu = new Menu( "Object", true );
+ aMenuBar.add( m_aObjectMenu );
+
+ aItem = new NewObjectMenuItem();
+ m_aObjectMenu.add( aItem );
+
+ aItem = new LoadObjectMenuItem();
+ m_aObjectMenu.add( aItem );
+
+ aItem = new LinkObjectMenuItem();
+ m_aObjectMenu.add( aItem );
+
+ aItem = new ConvertLinkToEmbedMenuItem();
+ m_aObjectMenu.add( aItem );
+
+ // Handle mouse clicks in our window.
+// addMouseListener( new MouseWatcher() );
+ addMouseListener( this );
+ }
+
+ public void update( Graphics g )
+ {
+ paint( g );
+ }
+
+ public void paint( Graphics g )
+ {
+ super.paint( g );
+
+ if ( m_xEmbedObj != null )
+ {
+ synchronized( this )
+ {
+ if ( m_aImage != null )
+ g.drawImage( m_aImage, 0, 0, EmbedContApp.this );
+ }
+ }
+ }
+
+ public void generateNewImage()
+ {
+ if ( m_xEmbedObj != null )
+ {
+ try {
+ int nOldState = m_xEmbedObj.getCurrentState();
+ int nState = nOldState;
+ if ( nOldState == EmbedStates.EMBED_LOADED )
+ {
+ m_xEmbedObj.changeState( EmbedStates.EMBED_RUNNING );
+ nState = EmbedStates.EMBED_RUNNING;
+ }
+
+ if ( nState == EmbedStates.EMBED_ACTIVE || nState == EmbedStates.EMBED_RUNNING )
+ {
+ XComponentSupplier xCompProv = (XComponentSupplier)UnoRuntime.queryInterface(
+ XComponentSupplier.class,
+ m_xEmbedObj );
+ if ( xCompProv != null )
+ {
+ XComponent xComp = xCompProv.getComponent();
+ XTransferable xTransfer = (XTransferable)UnoRuntime.queryInterface(
+ XTransferable.class,
+ xComp );
+ if ( xTransfer != null )
+ {
+ DataFlavor aFlavor = new DataFlavor();
+ aFlavor.MimeType = "image/png";
+ aFlavor.HumanPresentableName = "Portable Network Graphics";
+ aFlavor.DataType = new Type( byte[].class );
+
+ byte[] aPNGData = (byte[])AnyConverter.toArray( xTransfer.getTransferData( aFlavor ) );
+ if ( aPNGData != null && aPNGData.length != 0 )
+ {
+ synchronized( this )
+ {
+ m_aImage = m_aToolkit.createImage( aPNGData );
+ }
+ }
+ }
+ else
+ System.out.println( "paint() : can not get XTransferable for the component!\n" );
+ }
+ else
+ System.out.println( "paint() : XComponentSupplier is not implemented!\n" );
+ }
+ }
+ catch( com.sun.star.uno.Exception e )
+ {
+ // dialogs should not be used in paint()
+ System.out.println( "Exception in paint(): " + e );
+ }
+ }
+ }
+
+ public void mouseClicked( MouseEvent e )
+ {
+ if( e.getModifiers() == InputEvent.BUTTON1_MASK )
+ {
+ // activate object if exists and not active
+ if ( m_xEmbedObj != null )
+ {
+ try {
+ m_xEmbedObj.changeState( EmbedStates.EMBED_ACTIVE );
+ }
+ catch( Exception ex )
+ {
+ JOptionPane.showMessageDialog( m_aFrame, ex, "Exception on mouse click", JOptionPane.ERROR_MESSAGE );
+ }
+ }
+ }
+ }
+
+ public void mousePressed( MouseEvent e ){};
+ public void mouseEntered( MouseEvent e ){};
+ public void mouseExited( MouseEvent e ){};
+ public void mouseReleased( MouseEvent e ){};
+
+ // XEmbeddedClient
+ public void saveObject()
+ throws com.sun.star.uno.Exception
+ {
+ if ( m_xEmbedObj != null )
+ {
+ try {
+ XEmbedPersist xPersist = (XEmbedPersist)UnoRuntime.queryInterface( XEmbedPersist.class, m_xEmbedObj );
+ if ( xPersist != null )
+ {
+ xPersist.storeOwn();
+ generateNewImage();
+ }
+ else
+ JOptionPane.showMessageDialog( m_aFrame, "No XEmbedPersist!", "Error:", JOptionPane.ERROR_MESSAGE );
+ }
+ catch( Exception e )
+ {
+ JOptionPane.showMessageDialog( m_aFrame, e, "Exception in saveObject:", JOptionPane.ERROR_MESSAGE );
+ }
+ }
+
+ generateNewImage();
+ repaint();
+ }
+
+ public void onShowWindow( boolean bVisible )
+ {
+ // for now nothing to do
+ }
+
+ // classes
+ class NewMenuItem extends MenuItem implements ActionListener // Menu New
+ {
+ public NewMenuItem()
+ {
+ super( "New", new MenuShortcut( KeyEvent.VK_A ));
+ addActionListener( this );
+ }
+
+ public void actionPerformed( ActionEvent e )
+ {
+ // clear everything
+ clearObjectAndStorage();
+
+ repaint();
+ }
+ }
+
+ class SaveAsMenuItem extends MenuItem implements ActionListener // Menu SaveAs...
+ {
+ public SaveAsMenuItem()
+ {
+ super( "SaveAs..." );
+ addActionListener( this );
+ }
+
+ public void actionPerformed( ActionEvent e )
+ {
+ // open SaveAs dialog and store
+
+ if ( m_xStorage != null && m_xEmbedObj != null )
+ {
+ FileDialog aFileDialog = new FileDialog( m_aFrame, "SaveAs", FileDialog.SAVE );
+ aFileDialog.show();
+ if ( aFileDialog.getFile() != null )
+ {
+ String aFileName = aFileDialog.getDirectory() + aFileDialog.getFile();
+ File aFile = new File( aFileName );
+ if ( aFile != null )
+ {
+ // create object from specified file
+ String aFileURI = aFile.toURI().toASCIIString();
+ try {
+ saveObject();
+
+ if ( m_bLinkObj )
+ storeLinkToStorage();
+
+ saveStorageAsFileURI( aFileURI );
+ }
+ catch( Exception ex )
+ {
+ JOptionPane.showMessageDialog( m_aFrame,
+ ex,
+ "Exception in SaveAsMenuItem:",
+ JOptionPane.ERROR_MESSAGE );
+ }
+ }
+ }
+ }
+ else
+ JOptionPane.showMessageDialog( m_aFrame, "No document is embedded!", "Error:", JOptionPane.ERROR_MESSAGE );
+ }
+ }
+
+ class OpenFileMenuItem extends MenuItem implements ActionListener // Menu Open
+ {
+ public OpenFileMenuItem()
+ {
+ super( "Open", new MenuShortcut( KeyEvent.VK_C ));
+ addActionListener( this );
+ }
+
+ public void actionPerformed( ActionEvent e )
+ {
+ // clear everything
+ clearObjectAndStorage();
+
+ // open OpenFile dialog and load doc
+ FileDialog aFileDialog = new FileDialog( m_aFrame, "Open" );
+ aFileDialog.show();
+ if ( aFileDialog.getFile() != null )
+ {
+ String aFileName = aFileDialog.getDirectory() + aFileDialog.getFile();
+ File aFile = new File( aFileName );
+ if ( aFile != null )
+ {
+ // create object from specified file
+ String aFileURI = aFile.toURI().toASCIIString();
+
+ // load from specified file
+ loadFileURI( aFileURI );
+
+ if ( m_xEmbedObj != null )
+ {
+ try {
+ m_xEmbedObj.setClientSite( EmbedContApp.this );
+ }
+ catch( Exception ex )
+ {
+ JOptionPane.showMessageDialog( m_aFrame,
+ ex,
+ "Exception in OpenFileMenuItem:",
+ JOptionPane.ERROR_MESSAGE );
+ }
+ }
+ }
+ }
+
+ generateNewImage();
+ repaint();
+ }
+ }
+
+ class SaveMenuItem extends MenuItem implements ActionListener // Menu Save
+ {
+ public SaveMenuItem()
+ {
+ super( "Save", new MenuShortcut( KeyEvent.VK_D ));
+ addActionListener( this );
+ }
+
+ public void actionPerformed( ActionEvent e )
+ {
+ // if has persistance store there
+ // if not open SaveAs dialog and store
+ if ( m_xStorage != null && m_xEmbedObj != null )
+ {
+ if ( m_bOwnFile )
+ {
+ if ( m_xStorage == null )
+ {
+ JOptionPane.showMessageDialog( m_aFrame,
+ "No storage for oned file!",
+ "Error:",
+ JOptionPane.ERROR_MESSAGE );
+ return;
+ }
+
+ try {
+ saveObject();
+
+ if ( m_bLinkObj )
+ storeLinkToStorage();
+
+ XTransactedObject xTransact = (XTransactedObject)UnoRuntime.queryInterface( XTransactedObject.class,
+ m_xStorage );
+ if ( xTransact != null )
+ xTransact.commit();
+ }
+ catch( Exception ex )
+ {
+ JOptionPane.showMessageDialog( m_aFrame,
+ ex,
+ "Exception during save operation in SaveMenuItem:",
+ JOptionPane.ERROR_MESSAGE );
+ }
+ }
+ else
+ {
+ FileDialog aFileDialog = new FileDialog( m_aFrame, "SaveAs", FileDialog.SAVE );
+ aFileDialog.show();
+ if ( aFileDialog.getFile() != null )
+ {
+ String aFileName = aFileDialog.getDirectory() + aFileDialog.getFile();
+ File aFile = new File( aFileName );
+ if ( aFile != null )
+ {
+ // create object from specified file
+ String aFileURI = aFile.toURI().toASCIIString();
+ try {
+ saveObject();
+
+ if ( m_bLinkObj )
+ storeLinkToStorage();
+
+ saveStorageAsFileURI( aFileURI );
+ }
+ catch( Exception ex )
+ {
+ JOptionPane.showMessageDialog( m_aFrame,
+ ex,
+ "Exception during 'save as' operation in SaveMenuItem:",
+ JOptionPane.ERROR_MESSAGE );
+ }
+ }
+ }
+ }
+ }
+ else
+ JOptionPane.showMessageDialog( m_aFrame, "No document is embedded!", "Error:", JOptionPane.ERROR_MESSAGE );
+ }
+ }
+
+ class NewObjectMenuItem extends MenuItem implements ActionListener // Menu NewObject
+ {
+ public NewObjectMenuItem()
+ {
+ super( "Create", new MenuShortcut( KeyEvent.VK_N ));
+ addActionListener( this );
+ }
+
+ public void actionPerformed( ActionEvent e )
+ {
+ // remove current object an init a new one
+ clearObjectAndStorage();
+
+ Object[] possibleValues = { "com.sun.star.comp.Writer.TextDocument",
+ "com.sun.star.comp.Writer.GlobalDocument",
+ "com.sun.star.comp.Writer.WebDocument",
+ "com.sun.star.comp.Calc.SpreadsheetDocument",
+ "com.sun.star.comp.Draw.PresentationDocument",
+ "com.sun.star.comp.Draw.DrawingDocument",
+ "com.sun.star.comp.Math.FormulaDocument" };
+
+ String selectedValue = (String)JOptionPane.showInputDialog( null, "DocumentType", "Select",
+ JOptionPane.INFORMATION_MESSAGE, null,
+ possibleValues, possibleValues[0] );
+
+ if ( selectedValue != null )
+ {
+ m_xStorage = createTempStorage();
+
+ if ( m_xStorage != null )
+ m_xEmbedObj = createEmbedObject( selectedValue );
+ else
+ JOptionPane.showMessageDialog( m_aFrame,
+ "Can't create temporary storage!",
+ "Error:",
+ JOptionPane.ERROR_MESSAGE );
+
+
+ if ( m_xEmbedObj != null )
+ {
+ try {
+ m_xEmbedObj.setClientSite( EmbedContApp.this );
+ }
+ catch( Exception ex )
+ {
+ JOptionPane.showMessageDialog( m_aFrame,
+ ex,
+ "Exception in NewObjectMenuItem:",
+ JOptionPane.ERROR_MESSAGE );
+ }
+ }
+ }
+
+ generateNewImage();
+ repaint();
+ }
+ }
+
+ class LoadObjectMenuItem extends MenuItem implements ActionListener // Menu LoadObject
+ {
+ public LoadObjectMenuItem()
+ {
+ super( "Load from file", new MenuShortcut( KeyEvent.VK_L ));
+ addActionListener( this );
+ }
+
+ public void actionPerformed( ActionEvent e )
+ {
+ // first remove current object
+ clearObjectAndStorage();
+
+ // open OpenFile dialog and load doc
+ FileDialog aFileDialog = new FileDialog( m_aFrame, "Select sources to use for object init" );
+ aFileDialog.show();
+ if ( aFileDialog.getFile() != null )
+ {
+ String aFileName = aFileDialog.getDirectory() + aFileDialog.getFile();
+ File aFile = new File( aFileName );
+ if ( aFile != null )
+ {
+ // create object from specified file
+ String aFileURI = aFile.toURI().toASCIIString();
+ m_xStorage = createTempStorage();
+
+ if ( m_xStorage != null )
+ m_xEmbedObj = loadEmbedObject( aFileURI );
+
+ if ( m_xEmbedObj != null )
+ {
+ try {
+ m_xEmbedObj.setClientSite( EmbedContApp.this );
+ }
+ catch( Exception ex )
+ {
+ JOptionPane.showMessageDialog( m_aFrame,
+ ex,
+ "Exception in LoadObjectMenuItem:",
+ JOptionPane.ERROR_MESSAGE );
+ }
+ }
+ }
+ }
+
+ generateNewImage();
+ repaint();
+ }
+ }
+
+ class LinkObjectMenuItem extends MenuItem implements ActionListener // Menu LinkObject
+ {
+ public LinkObjectMenuItem()
+ {
+ super( "Create link", new MenuShortcut( KeyEvent.VK_M ));
+ addActionListener( this );
+ }
+
+ public void actionPerformed( ActionEvent e )
+ {
+ // first remove current object
+ clearObjectAndStorage();
+
+ // open OpenFile dialog and load doc
+ FileDialog aFileDialog = new FileDialog( m_aFrame, "Select sources to use for object init" );
+ aFileDialog.show();
+ if ( aFileDialog.getFile() != null )
+ {
+ m_xStorage = createTempStorage();
+
+ String aFileName = aFileDialog.getDirectory() + aFileDialog.getFile();
+ File aFile = new File( aFileName );
+ if ( aFile != null )
+ {
+ // create object from specified file
+ String aFileURI = aFile.toURI().toASCIIString();
+
+ m_xEmbedObj = createLinkObject( aFileURI );
+
+ if ( m_xEmbedObj != null )
+ {
+ m_aLinkURI = aFileURI;
+ m_bLinkObj = true;
+
+ try {
+ m_xEmbedObj.setClientSite( EmbedContApp.this );
+ }
+ catch( Exception ex )
+ {
+ JOptionPane.showMessageDialog( m_aFrame,
+ ex,
+ "Exception in LinkObjectMenuItem:",
+ JOptionPane.ERROR_MESSAGE );
+ }
+ }
+ }
+ }
+
+ generateNewImage();
+ repaint();
+ }
+ }
+
+ class ConvertLinkToEmbedMenuItem extends MenuItem implements ActionListener // Menu LinkObject
+ {
+ public ConvertLinkToEmbedMenuItem()
+ {
+ super( "Convert link to embed", new MenuShortcut( KeyEvent.VK_M ));
+ addActionListener( this );
+ }
+
+ public void actionPerformed( ActionEvent e )
+ {
+ if ( !m_bLinkObj )
+ {
+ JOptionPane.showMessageDialog( m_aFrame, "The object is not a link!", "Error:", JOptionPane.ERROR_MESSAGE );
+ return;
+ }
+
+ if ( m_xEmbedObj != null )
+ {
+ if ( m_xStorage != null )
+ {
+ try {
+ XNameAccess xNameAccess = (XNameAccess)UnoRuntime.queryInterface( XNameAccess.class,
+ m_xStorage );
+ if ( xNameAccess != null && xNameAccess.hasByName( "LinkName" ) )
+ m_xStorage.removeElement( "LinkName" );
+
+ XEmbedPersist xPersist = (XEmbedPersist)UnoRuntime.queryInterface( XEmbedPersist.class,
+ m_xEmbedObj );
+ if ( xPersist != null )
+ {
+ PropertyValue[] pEmp = new PropertyValue[0];
+ xPersist.setPersistentEntry( m_xStorage, "EmbedSub", EntryInitModes.ENTRY_NO_INIT, pEmp );
+ m_bLinkObj = false;
+ m_aLinkURI = null;
+ }
+ else
+ JOptionPane.showMessageDialog( m_aFrame,
+ "No XEmbedPersist in ConvertLink... !",
+ "Error:",
+ JOptionPane.ERROR_MESSAGE );
+ }
+ catch( Exception e1 )
+ {
+ JOptionPane.showMessageDialog( m_aFrame,
+ e1,
+ "Exception in ConvertLinkToEmbed:try 1 :",
+ JOptionPane.ERROR_MESSAGE );
+ }
+ }
+ }
+ }
+ }
+
+ // Helper methods
+ public XEmbeddedObject createEmbedObject( String aServiceName )
+ {
+ XEmbeddedObject xEmbObj = null;
+ byte[] pClassID = new byte[16];
+
+ if ( aServiceName.equals( "com.sun.star.comp.Writer.TextDocument" ) )
+ {
+ int[] pTempClassID = { 0x8B, 0xC6, 0xB1, 0x65, 0xB1, 0xB2, 0x4E, 0xDD,
+ 0xAA, 0x47, 0xDA, 0xE2, 0xEE, 0x68, 0x9D, 0xD6 };
+ for ( int ind = 0; ind < 16; ind++ )
+ pClassID[ind] = (byte)pTempClassID[ind];
+ }
+ else if ( aServiceName.equals( "com.sun.star.comp.Writer.GlobalDocument" ) )
+ {
+ int[] pTempClassID = { 0xB2, 0x1A, 0x0A, 0x7C, 0xE4, 0x03, 0x41, 0xFE,
+ 0x95, 0x62, 0xBD, 0x13, 0xEA, 0x6F, 0x15, 0xA0 };
+ for ( int ind = 0; ind < 16; ind++ )
+ pClassID[ind] = (byte)pTempClassID[ind];
+ }
+ else if ( aServiceName.equals( "com.sun.star.comp.Writer.WebDocument" ) )
+ {
+ int[] pTempClassID = { 0xA8, 0xBB, 0xA6, 0x0C, 0x7C, 0x60, 0x45, 0x50,
+ 0x91, 0xCE, 0x39, 0xC3, 0x90, 0x3F, 0xAC, 0x5E };
+ for ( int ind = 0; ind < 16; ind++ )
+ pClassID[ind] = (byte)pTempClassID[ind];
+ }
+ else if ( aServiceName.equals( "com.sun.star.comp.Calc.SpreadsheetDocument" ) )
+ {
+ int[] pTempClassID = { 0x47, 0xBB, 0xB4, 0xCB, 0xCE, 0x4C, 0x4E, 0x80,
+ 0xA5, 0x91, 0x42, 0xD9, 0xAE, 0x74, 0x95, 0x0F };
+ for ( int ind = 0; ind < 16; ind++ )
+ pClassID[ind] = (byte)pTempClassID[ind];
+ }
+ else if ( aServiceName.equals( "com.sun.star.comp.Draw.PresentationDocument" ) )
+ {
+ int[] pTempClassID = { 0x91, 0x76, 0xE4, 0x8A, 0x63, 0x7A, 0x4D, 0x1F,
+ 0x80, 0x3B, 0x99, 0xD9, 0xBF, 0xAC, 0x10, 0x47 };
+ for ( int ind = 0; ind < 16; ind++ )
+ pClassID[ind] = (byte)pTempClassID[ind];
+ }
+ else if ( aServiceName.equals( "com.sun.star.comp.Draw.DrawingDocument" ) )
+ {
+ int[] pTempClassID = { 0x4B, 0xAB, 0x89, 0x70, 0x8A, 0x3B, 0x45, 0xB3,
+ 0x99, 0x1C, 0xCB, 0xEE, 0xAC, 0x6B, 0xD5, 0xE3 };
+ for ( int ind = 0; ind < 16; ind++ )
+ pClassID[ind] = (byte)pTempClassID[ind];
+ }
+ else if ( aServiceName.equals( "com.sun.star.comp.Math.FormulaDocument" ) )
+ {
+ int[] pTempClassID = { 0x07, 0x8B, 0x7A, 0xBA, 0x54, 0xFC, 0x45, 0x7F,
+ 0x85, 0x51, 0x61, 0x47, 0xE7, 0x76, 0xA9, 0x97 };
+ for ( int ind = 0; ind < 16; ind++ )
+ pClassID[ind] = (byte)pTempClassID[ind];
+ }
+
+ if ( pClassID != null )
+ {
+ // create embedded object based on the class ID
+ try {
+ Object oEmbedFactory = m_xServiceFactory.createInstance( "com.sun.star.embed.EmbeddedObjectFactory" );
+ XEmbedObjectFactory xEmbedFactory = (XEmbedObjectFactory)UnoRuntime.queryInterface(
+ XEmbedObjectFactory.class,
+ oEmbedFactory );
+ if ( xEmbedFactory != null )
+ {
+ Object oEmbObj = xEmbedFactory.createInstanceInitNew( pClassID,
+ "Dummy name",
+ m_xStorage,
+ "EmbedSub" );
+ xEmbObj = (XEmbeddedObject)UnoRuntime.queryInterface( XEmbeddedObject.class, oEmbObj );
+ }
+ else
+ JOptionPane.showMessageDialog( m_aFrame,
+ "Can't create EmbedFactory!",
+ "Error:",
+ JOptionPane.ERROR_MESSAGE );
+ }
+ catch( Exception e )
+ {
+ JOptionPane.showMessageDialog( m_aFrame, e, "Exception in createInstanceInitNew():", JOptionPane.ERROR_MESSAGE );
+ }
+ }
+ else
+ JOptionPane.showMessageDialog( m_aFrame, "Can't retrieve class ID!", "Error:", JOptionPane.ERROR_MESSAGE );
+
+ return xEmbObj;
+ }
+
+ public XEmbeddedObject createLinkObject( String aLinkURL )
+ {
+ XEmbeddedObject xEmbObj = null;
+
+ try {
+ Object oEmbedFactory = m_xServiceFactory.createInstance( "com.sun.star.embed.EmbeddedObjectFactory" );
+ XEmbedObjectFactory xEmbedFactory = (XEmbedObjectFactory)UnoRuntime.queryInterface(
+ XEmbedObjectFactory.class,
+ oEmbedFactory );
+ if ( xEmbedFactory != null )
+ {
+ Object oEmbObj = xEmbedFactory.createInstanceLink( aLinkURL );
+ xEmbObj = (XEmbeddedObject)UnoRuntime.queryInterface( XEmbeddedObject.class, oEmbObj );
+ }
+ else
+ JOptionPane.showMessageDialog( m_aFrame,
+ "Can't create EmbedFactory!",
+ "Error:",
+ JOptionPane.ERROR_MESSAGE );
+ }
+ catch( Exception e )
+ {
+ JOptionPane.showMessageDialog( m_aFrame, e, "Exception in createLinkObject():", JOptionPane.ERROR_MESSAGE );
+ }
+
+
+ return xEmbObj;
+ }
+
+
+ public XEmbeddedObject loadEmbedObject( String aFileURI )
+ {
+ XEmbeddedObject xEmbObj = null;
+ try {
+ Object oEmbedFactory = m_xServiceFactory.createInstance( "com.sun.star.embed.EmbeddedObjectFactory" );
+ XEmbedObjectFactory xEmbedFactory = (XEmbedObjectFactory)UnoRuntime.queryInterface(
+ XEmbedObjectFactory.class,
+ oEmbedFactory );
+ if ( xEmbedFactory != null )
+ {
+ PropertyValue[] aMedDescr = { new PropertyValue(), new PropertyValue() };
+ aMedDescr[0].Name = "URL";
+ aMedDescr[0].Value = (Object) aFileURI;
+ aMedDescr[1].Name = "ReadOnly";
+ aMedDescr[1].Value = (Object) new Boolean( false );
+ Object oEmbObj = xEmbedFactory.createInstanceInitFromMediaDescriptor( m_xStorage,
+ "EmbedSub",
+ aMedDescr );
+ xEmbObj = (XEmbeddedObject)UnoRuntime.queryInterface( XEmbeddedObject.class, oEmbObj );
+ }
+ else
+ JOptionPane.showMessageDialog( m_aFrame,
+ "Can't create EmbedFactory!",
+ "Error:",
+ JOptionPane.ERROR_MESSAGE );
+ }
+ catch( Exception e )
+ {
+ JOptionPane.showMessageDialog( m_aFrame, e, "Exception in loadEmbedObject():", JOptionPane.ERROR_MESSAGE );
+ }
+
+ return xEmbObj;
+ }
+
+ public void clearObjectAndStorage()
+ {
+ synchronized( this )
+ {
+ m_aImage = null;
+ }
+
+ m_bOwnFile = false;
+
+ m_aLinkURI = null;
+ m_bLinkObj = false;
+
+ if ( m_xEmbedObj != null )
+ {
+ try {
+ XComponent xComponent = (XComponent)UnoRuntime.queryInterface( XComponent.class, m_xEmbedObj );
+ if ( xComponent != null )
+ xComponent.dispose();
+ }
+ catch ( Exception ex )
+ {}
+ m_xEmbedObj = null;
+ }
+
+ if ( m_xStorage != null )
+ {
+ try {
+ XComponent xComponent = (XComponent)UnoRuntime.queryInterface( XComponent.class, m_xStorage );
+ if ( xComponent != null )
+ xComponent.dispose();
+ }
+ catch ( Exception ex )
+ {}
+ m_xStorage = null;
+ }
+ }
+
+ public XStorage createTempStorage()
+ {
+ XStorage xTempStorage = null;
+
+ try {
+ Object oStorageFactory = m_xServiceFactory.createInstance( "com.sun.star.embed.StorageFactory" );
+ XSingleServiceFactory xStorageFactory = (XSingleServiceFactory)UnoRuntime.queryInterface(
+ XSingleServiceFactory.class,
+ oStorageFactory );
+ if ( xStorageFactory != null )
+ {
+ Object oStorage = xStorageFactory.createInstance();
+ xTempStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oStorage );
+ }
+ else
+ JOptionPane.showMessageDialog( m_aFrame,
+ "Can't create StorageFactory!",
+ "Error:",
+ JOptionPane.ERROR_MESSAGE );
+ }
+ catch( Exception e )
+ {
+ JOptionPane.showMessageDialog( m_aFrame, e, "Exception in createTempStorage():", JOptionPane.ERROR_MESSAGE );
+ }
+
+ return xTempStorage;
+ }
+
+ public void saveStorageAsFileURI( String aFileURI )
+ {
+ try {
+ Object oStorageFactory = m_xServiceFactory.createInstance( "com.sun.star.embed.StorageFactory" );
+ XSingleServiceFactory xStorageFactory = (XSingleServiceFactory)UnoRuntime.queryInterface(
+ XSingleServiceFactory.class,
+ oStorageFactory );
+ if ( xStorageFactory != null )
+ {
+ Object aArgs[] = new Object[2];
+ aArgs[0] = aFileURI;
+ aArgs[1] = new Integer( ElementModes.ELEMENT_READWRITE );
+
+ Object oStorage = xStorageFactory.createInstanceWithArguments( aArgs );
+ XStorage xTargetStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oStorage );
+ m_xStorage.copyToStorage( xTargetStorage );
+
+ XComponent xComponent = (XComponent)UnoRuntime.queryInterface( XComponent.class, m_xStorage );
+ xComponent.dispose();
+
+ m_xStorage = xTargetStorage;
+ m_bOwnFile = true;
+ }
+ else
+ JOptionPane.showMessageDialog( m_aFrame,
+ "Can't create StorageFactory!",
+ "Error:",
+ JOptionPane.ERROR_MESSAGE );
+ }
+ catch( Exception e )
+ {
+ JOptionPane.showMessageDialog( m_aFrame, e, "Exception in saveStorageToFileURI():", JOptionPane.ERROR_MESSAGE );
+ }
+
+ }
+
+ public void loadFileURI( String aFileURI )
+ {
+ try
+ {
+ Object oStorageFactory = m_xServiceFactory.createInstance( "com.sun.star.embed.StorageFactory" );
+ XSingleServiceFactory xStorageFactory = (XSingleServiceFactory)UnoRuntime.queryInterface(
+ XSingleServiceFactory.class,
+ oStorageFactory );
+ Object aArgs[] = new Object[2];
+ aArgs[0] = aFileURI;
+ aArgs[1] = new Integer( ElementModes.ELEMENT_READWRITE );
+
+ Object oStorage = xStorageFactory.createInstanceWithArguments( aArgs );
+ XStorage xTargetStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oStorage );
+
+ Object oEmbedFactory = m_xServiceFactory.createInstance( "com.sun.star.embed.EmbeddedObjectFactory" );
+ XEmbedObjectFactory xEmbedFactory = (XEmbedObjectFactory)UnoRuntime.queryInterface(
+ XEmbedObjectFactory.class,
+ oEmbedFactory );
+
+ XNameAccess xNameAccess = (XNameAccess)UnoRuntime.queryInterface( XNameAccess.class,
+ xTargetStorage );
+ if ( xNameAccess == null )
+ {
+ JOptionPane.showMessageDialog( m_aFrame, "No XNameAccess!", "Error:", JOptionPane.ERROR_MESSAGE );
+ return;
+ }
+
+ Object oEmbObj = null;
+ if ( xNameAccess.hasByName( "LinkName" ) && xTargetStorage.isStreamElement( "LinkName" ) )
+ {
+ XStream xLinkStream = xTargetStorage.openStreamElement( "LinkName", ElementModes.ELEMENT_READ );
+ if ( xLinkStream != null )
+ {
+ XInputStream xInStream = xLinkStream.getInputStream();
+ if ( xInStream != null )
+ {
+ byte[][] pBuff = new byte[1][0];
+ int nRead = xInStream.readBytes( pBuff, 1000 );
+ m_aLinkURI = new String( pBuff[0] );
+ xInStream.closeInput();
+ oEmbObj = xEmbedFactory.createInstanceLink( m_aLinkURI );
+ m_bLinkObj = true;
+ }
+ }
+ }
+ else
+ oEmbObj = xEmbedFactory.createInstanceInitFromEntry( xTargetStorage,
+ "EmbedSub",
+ false );
+
+ m_xEmbedObj = (XEmbeddedObject)UnoRuntime.queryInterface( XEmbeddedObject.class, oEmbObj );
+
+ if ( m_xEmbedObj != null )
+ {
+ m_xStorage = xTargetStorage;
+ m_bOwnFile = true;
+ }
+ else
+ JOptionPane.showMessageDialog( m_aFrame,
+ "Can't create EmbedObject from storage!",
+ "Error:",
+ JOptionPane.ERROR_MESSAGE );
+ }
+ catch( Exception e )
+ {
+ JOptionPane.showMessageDialog( m_aFrame, e, "Exception in loadFileURI():", JOptionPane.ERROR_MESSAGE );
+ }
+ }
+
+ public void storeLinkToStorage()
+ {
+ if ( m_xStorage != null && m_bLinkObj )
+ {
+ try {
+ XStream xLinkStream = m_xStorage.openStreamElement( "LinkName", ElementModes.ELEMENT_WRITE );
+
+ if ( xLinkStream != null )
+ {
+ XOutputStream xLinkOutStream = xLinkStream.getOutputStream();
+ XTruncate xTruncate = (XTruncate) UnoRuntime.queryInterface( XTruncate.class,
+ xLinkOutStream );
+ if ( xLinkOutStream != null && xTruncate != null )
+ {
+ xTruncate.truncate();
+
+ char[] aLinkChar = m_aLinkURI.toCharArray();
+ byte[] aLinkBytes = new byte[ aLinkChar.length ];
+ for ( int ind = 0; ind < aLinkChar.length; ind++ )
+ aLinkBytes[ind] = (byte)aLinkChar[ind];
+
+ xLinkOutStream.writeBytes( aLinkBytes );
+ xLinkOutStream.closeOutput();
+
+ XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class,
+ xLinkStream );
+ if ( xComponent != null )
+ xComponent.dispose();
+ }
+ else
+ JOptionPane.showMessageDialog( m_aFrame,
+ "The substream can not be truncated or written!",
+ "Error:",
+ JOptionPane.ERROR_MESSAGE );
+
+ }
+ else
+ JOptionPane.showMessageDialog( m_aFrame,
+ "Can't create/open substream!",
+ "Error:",
+ JOptionPane.ERROR_MESSAGE );
+ }
+ catch( Exception e )
+ {
+ JOptionPane.showMessageDialog( m_aFrame,
+ e,
+ "Exception in storeLinkToStorage:",
+ JOptionPane.ERROR_MESSAGE );
+
+ }
+ }
+ }
+}
+
diff --git a/odk/examples/java/EmbedDocument/Container1/EmbedContFrame.java b/odk/examples/java/EmbedDocument/Container1/EmbedContFrame.java
new file mode 100644
index 000000000000..2a29ff4cc026
--- /dev/null
+++ b/odk/examples/java/EmbedDocument/Container1/EmbedContFrame.java
@@ -0,0 +1,108 @@
+import java.awt.*;
+import java.awt.event.*;
+
+import com.sun.star.comp.servicemanager.ServiceManager;
+
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.connection.XConnector;
+import com.sun.star.connection.XConnection;
+
+import com.sun.star.bridge.XUnoUrlResolver;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XInterface;
+import com.sun.star.uno.XNamingService;
+import com.sun.star.uno.XComponentContext;
+
+import com.sun.star.container.*;
+import com.sun.star.beans.*;
+import com.sun.star.lang.*;
+
+
+public class EmbedContFrame extends Frame
+{
+ WindowListener m_aCloser = new WindowAdapter()
+ {
+ public void windowClosing( WindowEvent e )
+ {
+ dispose();
+ System.exit( 0 );
+ }
+ };
+
+ public EmbedContFrame( String sName )
+ {
+ super( sName );
+ addWindowListener( m_aCloser );
+ }
+
+ public static void start()
+ {
+ EmbedContFrame aFrame = new EmbedContFrame( "Testing container." );
+
+ // connect to the office
+ XMultiServiceFactory aServiceFactory = null;
+ try {
+ aServiceFactory = connectOfficeGetServiceFactory();
+ }
+ catch( Exception e )
+ {}
+
+ if ( aServiceFactory == null )
+ {
+ System.out.println( "Can't get service manager!\n" );
+ System.exit( 1 );
+ }
+
+ EmbedContApp aApp = new EmbedContApp( aFrame, aServiceFactory );
+ aApp.init();
+ aApp.start();
+
+ Dimension aSize = aApp.getSize();
+
+ aFrame.add( "Center", aApp );
+ aFrame.pack();
+ aFrame.setSize( aSize );
+
+ aFrame.setVisible( true );
+ }
+
+ public static void main( String args[] )
+ {
+ EmbedContFrame.start();
+ }
+
+ public static XMultiServiceFactory connectOfficeGetServiceFactory()
+ throws com.sun.star.uno.Exception,
+ com.sun.star.uno.RuntimeException,
+ Exception
+ {
+ String sConnectionString = "uno:socket,host=localhost,port=8100;urp;StarOffice.NamingService";
+
+ // Get component context
+ XComponentContext xComponentContext =
+ com.sun.star.comp.helper.Bootstrap.createInitialComponentContext( null );
+
+ // initial serviceManager
+ XMultiComponentFactory xLocalServiceManager = xComponentContext.getServiceManager();
+
+ // create a connector, so that it can contact the office
+ Object oUrlResolver = xLocalServiceManager.createInstanceWithContext( "com.sun.star.bridge.UnoUrlResolver",
+ xComponentContext );
+ XUnoUrlResolver xUrlResolver = (XUnoUrlResolver)UnoRuntime.queryInterface( XUnoUrlResolver.class, oUrlResolver );
+
+ Object oInitialObject = xUrlResolver.resolve( sConnectionString );
+ XNamingService xName = (XNamingService)UnoRuntime.queryInterface( XNamingService.class, oInitialObject );
+
+ XMultiServiceFactory xMSF = null;
+ if( xName != null ) {
+ Object oMSF = xName.getRegisteredObject( "StarOffice.ServiceManager" );
+ xMSF = (XMultiServiceFactory)UnoRuntime.queryInterface( XMultiServiceFactory.class, oMSF );
+ }
+ else
+ System.out.println( "Error: Can't get XNamingService interface from url resolver!" );
+
+ return xMSF;
+ }
+}
+
diff --git a/odk/examples/java/EmbedDocument/Container1/Makefile b/odk/examples/java/EmbedDocument/Container1/Makefile
new file mode 100644
index 000000000000..be1f5299f773
--- /dev/null
+++ b/odk/examples/java/EmbedDocument/Container1/Makefile
@@ -0,0 +1,48 @@
+# Builds the Java Storage test example of the SDK.
+
+PRJ=../../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+COMPONENT_NAME=EmbedDocument.Container1
+OUT_COMP_CLASS = $(OUT_CLASS)/$(COMPONENT_NAME)
+
+JAVAFILES = \
+ EmbedContApp.java\
+ EmbedContFrame.java
+
+CLASSFILES = $(patsubst %.java,$(OUT_COMP_CLASS)/%.class,$(JAVAFILES))
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(OUT_COMP_CLASS))
+
+
+# Targets
+.PHONY: ALL
+ALL : \
+ JavaStorageTestExample
+
+include $(SETTINGS)/stdtarget.mk
+
+$(CLASSFILES) : $(JAVAFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_COMP_CLASS) $(JAVAFILES)
+
+JavaStorageTestExample : $(CLASSFILES)
+ @echo --------------------------------------------------------------------------------
+ @echo Please use following command to execute the example!
+ @echo ------
+ @echo $(MAKE) EmbedContFrame.run
+ @echo --------------------------------------------------------------------------------
+
+%.run: $(OUT_COMP_CLASS)/%.class
+ $(SDK_JAVA) -classpath "$(SDK_CLASSPATH)" $(basename $@)
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_CLASS))
+
diff --git a/odk/examples/java/EmbedDocument/EmbeddedObject/EditorFrame.java b/odk/examples/java/EmbedDocument/EmbeddedObject/EditorFrame.java
new file mode 100755
index 000000000000..0be57999755a
--- /dev/null
+++ b/odk/examples/java/EmbedDocument/EmbeddedObject/EditorFrame.java
@@ -0,0 +1,121 @@
+package org.openoffice.examples.embedding;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.image.*;
+import javax.swing.JTextArea;
+import javax.swing.JFrame;
+import java.io.*;
+import javax.imageio.ImageIO;
+
+import org.openoffice.examples.embedding.OwnEmbeddedObject;
+
+public class EditorFrame extends JFrame
+{
+ OwnEmbeddedObject m_aEmbObj;
+ JTextArea m_aTextArea;
+ BufferedImage m_aBufImage;
+
+ WindowListener m_aCloser = new WindowAdapter()
+ {
+ public void windowClosing( WindowEvent e )
+ {
+ // m_aBufImage = m_aTextArea.getGraphicsConfiguration().createCompatibleImage( m_aTextArea.getWidth(), m_aTextArea.getHeight() );
+ m_aBufImage = new BufferedImage( m_aTextArea.getWidth(), m_aTextArea.getHeight(), BufferedImage.TYPE_INT_RGB );
+ Graphics2D aGr = m_aBufImage.createGraphics();
+ m_aTextArea.paintAll( aGr );
+ aGr.dispose();
+
+ hide();
+ m_aEmbObj.CloseFrameRequest();
+ }
+ };
+
+ public EditorFrame( String sName, OwnEmbeddedObject aEmbObj, int nWidth, int nHeight )
+ {
+ super( sName );
+ m_aEmbObj = aEmbObj;
+ addWindowListener( m_aCloser );
+ m_aTextArea = new JTextArea( "", nWidth, nHeight );
+
+ add( "Center", m_aTextArea );
+ pack();
+ // setResizable( false );
+ }
+
+ public String getText()
+ {
+ return m_aTextArea.getText();
+ }
+
+ public void setText( String aText )
+ {
+ m_aTextArea.setText( aText );
+ }
+
+ public Dimension getAppSize()
+ {
+ return m_aTextArea.getSize();
+ }
+
+ public void setAppSize( Dimension aSize )
+ {
+ Dimension aOwnSize = getSize();
+ Dimension aAppSize = m_aTextArea.getSize();
+ Dimension aToSet =
+ new Dimension( (int)( aSize.getWidth() + aOwnSize.getWidth() - aAppSize.getWidth() ),
+ (int)(aSize.getHeight() + aOwnSize.getHeight() - aAppSize.getHeight() ) );
+
+ setSize( aToSet );
+ validate();
+
+ // pack();
+ }
+
+ public byte[] getReplacementImage()
+ {
+ Dimension aDim = m_aTextArea.getSize();
+ BufferedImage aBufImage = null;
+
+ if ( m_aBufImage != null )
+ aBufImage = m_aBufImage;
+ else
+ {
+ try
+ {
+ int nWidth = (int)aDim.getWidth();
+ int nHeight = (int)aDim.getHeight();
+ aBufImage = new BufferedImage( nWidth, nHeight, BufferedImage.TYPE_INT_RGB );
+ Graphics2D aGr = aBufImage.createGraphics();
+ aGr.setBackground( Color.WHITE );
+ aGr.clearRect( 0, 0, nWidth, nHeight );
+ aGr.dispose();
+ }
+ catch ( java.lang.Exception e )
+ {}
+ }
+
+ if ( aBufImage != null )
+ {
+ try
+ {
+ File aTmpFile = File.createTempFile( "temp", ".png" );
+ ImageIO.write( aBufImage, "png", aTmpFile );
+
+ int nLen = (int)aTmpFile.length();
+ byte[] aResult = new byte[nLen];
+ FileInputStream aTmpStream = new FileInputStream( aTmpFile );
+ aTmpStream.read( aResult );
+ aTmpStream.close();
+ aTmpFile.delete();
+
+ return aResult;
+ }
+ catch ( java.lang.Exception e )
+ {}
+ }
+
+ return new byte[0];
+ }
+}
+
diff --git a/odk/examples/java/EmbedDocument/EmbeddedObject/EmbeddedObject.odt b/odk/examples/java/EmbedDocument/EmbeddedObject/EmbeddedObject.odt
new file mode 100644
index 000000000000..dde408bd337f
--- /dev/null
+++ b/odk/examples/java/EmbedDocument/EmbeddedObject/EmbeddedObject.odt
Binary files differ
diff --git a/odk/examples/java/EmbedDocument/EmbeddedObject/EmbeddedObject.xcu b/odk/examples/java/EmbedDocument/EmbeddedObject/EmbeddedObject.xcu
new file mode 100755
index 000000000000..fd6f76745192
--- /dev/null
+++ b/odk/examples/java/EmbedDocument/EmbeddedObject/EmbeddedObject.xcu
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE oor:component-data SYSTEM "../../../../component-update.dtd">
+<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:package="org.openoffice.Office" oor:name="Embedding">
+ <node oor:name="Objects">
+ <node oor:name="69474366-FD6F-4806-8374-8EDD1B6E771D" oor:op="replace">
+ <prop oor:name="ObjectFactory"><value>org.openoffice.examples.embedding.Factory69474366FD6F480683748EDD1B6E771D</value></prop>
+ <prop oor:name="ObjectDocumentServiceName"><value></value></prop>
+ <prop oor:name="ObjectMiscStatus"/>
+ <prop oor:name="ObjectVerbs"><value>PRIMARY SHOW OPEN HIDE</value></prop>
+ </node>
+ </node>
+ <node oor:name="MimeTypeClassIDRelations">
+ <prop oor:name="application/x-openoffice-embedded-69474366-FD6F-4806-8374-8EDD1B6E771D" oor:op="replace" oor:type="xs:string">
+ <value>69474366-FD6F-4806-8374-8EDD1B6E771D</value>
+ </prop>
+ </node>
+ <node oor:name="ObjectNames">
+ <node oor:name="Object69474366-FD6F-4806-8374-8EDD1B6E771D" oor:op="replace">
+ <prop oor:name="ObjectUIName">
+ <value xml:lang="en-US">Example of a simple outplace text object</value>
+ </prop>
+ <prop oor:name="ClassID">
+ <value>69474366-FD6F-4806-8374-8EDD1B6E771D</value>
+ </prop>
+ </node>
+ </node>
+</oor:component-data>
+
diff --git a/odk/examples/java/EmbedDocument/EmbeddedObject/Makefile b/odk/examples/java/EmbedDocument/EmbeddedObject/Makefile
new file mode 100644
index 000000000000..6b75f4ed72ac
--- /dev/null
+++ b/odk/examples/java/EmbedDocument/EmbeddedObject/Makefile
@@ -0,0 +1,147 @@
+#*************************************************************************
+#
+# 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.
+#
+#**************************************************************************
+
+PRJ=../../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+# include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+
+# we use the sample directory name for separating this example
+# from others in the output directory
+SAMPLE_NAME=EmbeddedObject
+SAMPLE_CLASS_OUT=$(OUT_CLASS)/$(SAMPLE_NAME)
+SAMPLE_GEN_OUT=$(OUT_MISC)/$(SAMPLE_NAME)
+
+COMP_NAME=OwnEmbeddedObject
+COMP_CLASS_OUT=$(SAMPLE_CLASS_OUT)/$(COMP_NAME)
+COMP_GEN_OUT=$(SAMPLE_GEN_OUT)/$(COMP_NAME)
+COMP_PACKAGE=$(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT)
+COMP_PACKAGE_URL=$(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)")
+COMP_JAR_NAME=$(COMP_NAME).uno.jar
+COMP_JAR=$(SAMPLE_CLASS_OUT)/$(COMP_JAR_NAME)
+COMP_JAR_MANIFEST=$(COMP_GEN_OUT)/$(COMP_NAME).Manifest
+COMP_UNOPKG_MANIFEST = $(COMP_GEN_OUT)/META-INF/manifest.xml
+COMP_REGISTERFLAG=$(COMP_GEN_OUT)$(PS)java_$(COMP_NAME)_register_component.flag
+
+PACKAGE = org/openoffice/examples/embedding
+
+COMP_JAVAFILES =\
+ OwnEmbeddedObject.java\
+ OwnEmbeddedObjectFactory.java\
+ EditorFrame.java
+
+COMP_CLASSFILES = $(patsubst %.java,$(COMP_CLASS_OUT)/%.class,$(COMP_JAVAFILES))
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(SAMPLE_CLASS_OUT)\
+ $(PATH_SEPARATOR)$(COMP_CLASS_OUT))
+
+
+# Targets
+.PHONY: ALL
+ALL : $(COMP_NAME)
+
+include $(SETTINGS)/stdtarget.mk
+
+$(COMP_GEN_OUT)/%.Manifest :
+ -$(MKDIR) $(subst \\,\,$(subst /,$(PS),$(@D)))
+ @echo RegistrationClassName: $(subst /,.,$(PACKAGE)).$(COMP_NAME)Factory> $@
+
+# component as well as application are dependent from the generated types
+# rule for component class files
+$(COMP_CLASS_OUT)/%.class : $(COMP_JAVAFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(COMP_CLASS_OUT) $(COMP_JAVAFILES)
+
+# rule for component jar file
+$(COMP_JAR) : $(COMP_JAR_MANIFEST) $(COMP_CLASSFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAR) cvfm $@ $< -C $(COMP_CLASS_OUT) .
+
+# rule for component package manifest
+$(COMP_GEN_OUT)/%/manifest.xml :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
+ @echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-component;type=Java$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(COMP_NAME).uno.jar$(QM)"/$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(SAMPLE_NAME).xcu$(QM)"/$(CSEP) >> $@
+ @echo $(OSEP)/manifest:manifest$(CSEP) >> $@
+
+# rule for component package file
+$(COMP_PACKAGE) : $(COMP_JAR) $(COMP_UNOPKG_MANIFEST)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_ZIP) $@ $(COMP_JAR_NAME) $(SAMPLE_NAME).xcu
+ cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_ZIP) $@ $(COMP_JAR_NAME)
+ cd $(subst /,$(PS),$(COMP_GEN_OUT)) && $(SDK_ZIP) -u $@ META-INF/manifest.xml
+
+$(COMP_REGISTERFLAG) : $(COMP_PACKAGE)
+ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES"
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst \\,\,$(subst /,$(PS),$(@D)))
+ $(DEPLOYTOOL) $(COMP_PACKAGE_URL)
+ @echo flagged > $(subst /,$(PS),$@)
+else
+ @echo --------------------------------------------------------------------------------
+ @echo If you want to install your component automatically, please set the environment
+ @echo variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only
+ @echo possible if no office instance is running.
+ @echo --------------------------------------------------------------------------------
+endif
+
+$(COMP_NAME) : $(COMP_REGISTERFLAG)
+ @echo ------
+ @echo The $(COMP_NAME) component was installed if SDK_AUTO_DEPLOYMENT = YES.
+ @echo Load the "$(QM)$(SAMPLE_NAME).odt$(QM)" document to see how this component works.
+ @echo You can use this component inside your office installation, see the example
+ @echo description.
+ @echo -
+ @echo $(MAKE) $(SAMPLE_NAME).odt.load
+ @echo --------------------------------------------------------------------------------
+
+$(SAMPLE_NAME).odt.load : $(COMP_REGISTERFLAG)
+ "$(OFFICE_PROGRAM_PATH)$(PS)soffice" $(basename $@)
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_CLASS_OUT))
+ -$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_GEN_OUT))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL)))
diff --git a/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObject.java b/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObject.java
new file mode 100755
index 000000000000..df2da9f0ebea
--- /dev/null
+++ b/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObject.java
@@ -0,0 +1,1124 @@
+package org.openoffice.examples.embedding;
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.lib.uno.helper.WeakBase;
+import com.sun.star.io.XStream;
+import com.sun.star.io.XOutputStream;
+import com.sun.star.io.XInputStream;
+import com.sun.star.io.XTruncate;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.lang.XComponent;
+import com.sun.star.document.EventObject;
+import com.sun.star.embed.VisualRepresentation;
+import com.sun.star.container.XNameAccess;
+
+
+import com.sun.star.embed.*;
+
+import java.util.Vector;
+import java.awt.Dimension;
+import java.lang.Integer;
+import org.omg.CORBA.COMM_FAILURE;
+
+import org.openoffice.examples.embedding.EditorFrame;
+
+public final class OwnEmbeddedObject extends WeakBase
+ implements com.sun.star.embed.XEmbedPersist,
+ com.sun.star.embed.XEmbeddedObject
+{
+ protected final XComponentContext m_xContext;
+ protected final byte[] m_aClassID;
+
+ protected boolean m_bDisposed = false;
+ protected int m_nObjectState = -1;
+
+ protected com.sun.star.embed.XStorage m_xParentStorage;
+ protected com.sun.star.embed.XStorage m_xOwnStorage;
+ protected String m_aEntryName;
+
+ protected com.sun.star.embed.XStorage m_xNewParentStorage;
+ protected com.sun.star.embed.XStorage m_xNewOwnStorage;
+ protected String m_aNewEntryName;
+ protected boolean m_bWaitSaveCompleted = false;
+
+ protected EditorFrame m_aEditorFrame;
+
+ protected Vector m_aListeners;
+
+ com.sun.star.embed.VerbDescriptor[] m_pOwnVerbs;
+
+ com.sun.star.embed.XEmbeddedClient m_xClient;
+
+ Dimension m_aObjSize;
+
+ // -------------------------------------------------------------
+ protected Vector GetListeners()
+ {
+ if ( m_aListeners == null )
+ m_aListeners = new Vector<Object>( 10, 10 );
+
+ return m_aListeners;
+ }
+
+ // -------------------------------------------------------------
+ protected Dimension UpdateSizeAndGetFromActive()
+ {
+ if ( m_nObjectState == com.sun.star.embed.EmbedStates.ACTIVE )
+ m_aObjSize = m_aEditorFrame.getAppSize();
+
+ if ( m_aObjSize != null )
+ return m_aObjSize;
+ else
+ return new Dimension();
+ }
+
+ // -------------------------------------------------------------
+ protected void SwitchOwnPersistence( XStorage xParentStorage, XStorage xOwnStorage, String aEntryName )
+ {
+ if ( xOwnStorage != m_xOwnStorage )
+ {
+ if ( m_xOwnStorage != null )
+ m_xOwnStorage.dispose();
+ m_xParentStorage = xParentStorage;
+ m_xOwnStorage = xOwnStorage;
+ m_aEntryName = aEntryName;
+ }
+ }
+
+ // -------------------------------------------------------------
+ protected void SwitchOwnPersistence( XStorage xParentStorage, String aEntryName ) throws com.sun.star.io.IOException
+ {
+ if ( xParentStorage != m_xParentStorage || !aEntryName.equals( m_aEntryName ) )
+ {
+ try
+ {
+ XStorage xOwnStorage = xParentStorage.openStorageElement( aEntryName, com.sun.star.embed.ElementModes.READWRITE );
+ SwitchOwnPersistence( xParentStorage, xOwnStorage, aEntryName );
+ }
+ catch( com.sun.star.uno.RuntimeException e )
+ {
+ throw e;
+ }
+ catch( com.sun.star.io.IOException e )
+ {
+ throw e;
+ }
+ catch( com.sun.star.uno.Exception e )
+ {
+ throw new com.sun.star.io.IOException( "Error while switching object storage!" );
+ }
+ }
+ }
+
+ // -------------------------------------------------------------
+ protected static void SaveDataToStorage( XStorage xStorage, String aString, Dimension aDimension ) throws com.sun.star.io.IOException
+ {
+ try
+ {
+ // save the text
+ XStream xStream = xStorage.openStreamElement( "content.txt", com.sun.star.embed.ElementModes.READWRITE );
+ XComponent xStreamComp = ( XComponent ) UnoRuntime.queryInterface( XComponent.class, xStream );
+ if ( xStreamComp == null )
+ throw new com.sun.star.uno.RuntimeException();
+
+ XOutputStream xOutStream = xStream.getOutputStream();
+ XTruncate xTruncate = ( XTruncate ) UnoRuntime.queryInterface( XTruncate.class, xOutStream );
+ if ( xTruncate == null )
+ throw new com.sun.star.io.IOException();
+
+ xTruncate.truncate();
+ xOutStream.writeBytes( aString.getBytes() );
+
+ // save the size
+ xStream = xStorage.openStreamElement( "properties.txt", com.sun.star.embed.ElementModes.READWRITE );
+ xStreamComp = ( XComponent ) UnoRuntime.queryInterface( XComponent.class, xStream );
+ if ( xStreamComp == null )
+ throw new com.sun.star.uno.RuntimeException();
+
+ xOutStream = xStream.getOutputStream();
+ xTruncate = ( XTruncate ) UnoRuntime.queryInterface( XTruncate.class, xOutStream );
+ if ( xTruncate == null )
+ throw new com.sun.star.io.IOException();
+
+ xTruncate.truncate();
+ String aProps = Integer.toString( (int)aDimension.getWidth() ) + "|" + Integer.toString( (int)aDimension.getHeight() );
+ xOutStream.writeBytes( aProps.getBytes() );
+
+ // set the media type
+ XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, xStorage );
+ if ( xPropSet == null )
+ throw new com.sun.star.uno.RuntimeException();
+ xPropSet.setPropertyValue( "MediaType", "application/x-openoffice-embedded-69474366-FD6F-4806-8374-8EDD1B6E771D" );
+
+ XTransactedObject xTransact = ( XTransactedObject ) UnoRuntime.queryInterface( XTransactedObject.class, xStorage );
+ if ( xTransact != null )
+ xTransact.commit();
+
+ xStreamComp.dispose();
+ }
+ catch( com.sun.star.uno.RuntimeException e )
+ {
+ throw e;
+ }
+ catch( com.sun.star.io.IOException e )
+ {
+ throw e;
+ }
+ catch( com.sun.star.uno.Exception e )
+ {
+ throw new com.sun.star.io.IOException( "Error while switching object storage!" );
+ }
+ }
+
+ // -------------------------------------------------------------
+ protected void PostEvent( String aEvEntryName )
+ {
+ if ( m_aListeners != null )
+ {
+ com.sun.star.document.EventObject aEventObject = new com.sun.star.document.EventObject( this, aEvEntryName );
+ for ( int nInd = 0; nInd < m_aListeners.size(); nInd++ )
+ {
+ try
+ {
+ com.sun.star.document.XEventListener xListener = ( com.sun.star.document.XEventListener )
+ UnoRuntime.queryInterface( com.sun.star.document.XEventListener.class, m_aListeners.get( nInd ) );
+
+ if ( xListener != null )
+ xListener.notifyEvent( aEventObject );
+ }
+ catch( java.lang.Exception e )
+ {
+ m_aListeners.remove( nInd );
+ }
+ }
+ }
+ }
+
+ // -------------------------------------------------------------
+ protected void StateChangeNotification( boolean bBeforeChange, int nOldState, int nNewState )
+ {
+ if ( m_aListeners != null )
+ {
+ com.sun.star.lang.EventObject aEventObject = new com.sun.star.lang.EventObject( this );
+ for ( int nInd = 0; nInd < m_aListeners.size(); nInd++ )
+ {
+ try
+ {
+ com.sun.star.embed.XStateChangeListener xListener = ( com.sun.star.embed.XStateChangeListener )
+ UnoRuntime.queryInterface( com.sun.star.embed.XStateChangeListener.class, m_aListeners.get( nInd ) );
+
+ if ( xListener != null )
+ {
+ if ( bBeforeChange )
+ xListener.changingState( aEventObject, nOldState, nNewState );
+ else
+ xListener.stateChanged( aEventObject, nOldState, nNewState );
+ }
+ }
+ catch( java.lang.Exception e )
+ {
+ m_aListeners.remove( nInd );
+ }
+ }
+ }
+ }
+
+ // -------------------------------------------------------------
+ protected String ReadStringFromStream( XStorage xStorage, String aStreamName ) throws com.sun.star.io.IOException
+ {
+ if ( xStorage == null )
+ throw new com.sun.star.uno.RuntimeException();
+
+ try
+ {
+ XStream xStream = xStorage.openStreamElement( aStreamName, com.sun.star.embed.ElementModes.READWRITE );
+ XComponent xStreamComp = ( XComponent ) UnoRuntime.queryInterface( XComponent.class, xStream );
+ if ( xStreamComp == null )
+ throw new com.sun.star.uno.RuntimeException();
+
+ XInputStream xInStream = xStream.getInputStream();
+ byte[][] aData = new byte[1][];
+ aData[0] = new byte[0];
+ String aResult = new String();
+
+ int nLen = 0;
+ do
+ {
+ nLen = xInStream.readBytes( aData, 10 );
+ if ( aData.length == 0 || aData[0] == null )
+ throw new com.sun.star.io.IOException();
+ aResult += new String( aData[0] );
+ } while( nLen > 0 );
+
+ xStreamComp.dispose();
+
+ return aResult;
+ }
+ catch( com.sun.star.uno.RuntimeException e )
+ {
+ throw e;
+ }
+ catch( com.sun.star.io.IOException e )
+ {
+ throw e;
+ }
+ catch( com.sun.star.uno.Exception e )
+ {
+ throw new com.sun.star.io.IOException( "Error while reading one of object streams!" );
+ }
+ }
+
+ // -------------------------------------------------------------
+ protected void ReadSizeFromOwnStorage() throws com.sun.star.io.IOException
+ {
+ String aSize = ReadStringFromStream( m_xOwnStorage, "properties.txt" );
+
+ int nSeparator = aSize.indexOf( '|' );
+ if ( nSeparator > 0 && nSeparator < aSize.length() - 1 )
+ {
+ int nWidth = Integer.parseInt( aSize.substring( 0, nSeparator ) );
+ int nHeight = Integer.parseInt( aSize.substring( nSeparator + 1, aSize.length() ) );
+ m_aObjSize = new Dimension( nWidth, nHeight );
+ }
+ }
+
+ // -------------------------------------------------------------
+ public OwnEmbeddedObject( XComponentContext context, byte[] aClassID )
+ {
+ m_xContext = context;
+ m_aClassID = aClassID;
+ };
+
+ // -------------------------------------------------------------
+ public void CloseFrameRequest()
+ {
+ com.sun.star.embed.XEmbeddedClient xClient = m_xClient;
+ if ( xClient == null )
+ return;
+
+ UpdateSizeAndGetFromActive();
+ StateChangeNotification( true, com.sun.star.embed.EmbedStates.ACTIVE, com.sun.star.embed.EmbedStates.RUNNING );
+
+ try{
+ xClient.visibilityChanged( false );
+ } catch( com.sun.star.uno.Exception e ){}
+
+ try{
+ xClient.saveObject();
+ } catch( com.sun.star.uno.Exception e ){}
+
+ m_nObjectState = com.sun.star.embed.EmbedStates.RUNNING;
+ StateChangeNotification( false, com.sun.star.embed.EmbedStates.ACTIVE, m_nObjectState );
+
+ PostEvent( "OnVisAreaChanged" );
+ }
+
+ // com.sun.star.embed.XCommonEmbedPersist:
+ // -------------------------------------------------------------
+ public void storeOwn() throws com.sun.star.embed.WrongStateException, com.sun.star.io.IOException, com.sun.star.uno.Exception
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ if ( m_nObjectState == -1 || m_bWaitSaveCompleted )
+ throw new com.sun.star.embed.WrongStateException();
+
+ // nothing to do, if the object is in loaded state
+ if ( m_nObjectState == com.sun.star.embed.EmbedStates.LOADED )
+ return;
+
+ if ( m_xOwnStorage == null )
+ throw new com.sun.star.io.IOException();
+
+ PostEvent( "OnSave" );
+
+ if ( m_aEditorFrame == null )
+ throw new com.sun.star.uno.RuntimeException();
+
+ SaveDataToStorage( m_xOwnStorage, m_aEditorFrame.getText(), UpdateSizeAndGetFromActive() );
+
+ PostEvent( "OnSaveDone" );
+ }
+
+ // -------------------------------------------------------------
+ public boolean isReadonly() throws com.sun.star.embed.WrongStateException
+ {
+ return false;
+ }
+
+ // -------------------------------------------------------------
+ public void reload(com.sun.star.beans.PropertyValue[] aMediaArgs, com.sun.star.beans.PropertyValue[] aObjectArgs) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.embed.WrongStateException, com.sun.star.io.IOException, com.sun.star.uno.Exception
+ {
+ // not implemented currently
+ return;
+ }
+
+ // com.sun.star.embed.XEmbedPersist:
+ // -------------------------------------------------------------
+ public void setPersistentEntry(com.sun.star.embed.XStorage xStorage, String aEntryName, int nEntryConnectionMode, com.sun.star.beans.PropertyValue[] aMediaArgs, com.sun.star.beans.PropertyValue[] aObjectArgs) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.embed.WrongStateException, com.sun.star.io.IOException, com.sun.star.uno.Exception
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ if ( xStorage == null || aEntryName.length() == 0 )
+ throw new com.sun.star.lang.IllegalArgumentException();
+
+ if ( ( m_nObjectState != -1 || nEntryConnectionMode == com.sun.star.embed.EntryInitModes.NO_INIT )
+ && ( m_nObjectState == -1 || nEntryConnectionMode != com.sun.star.embed.EntryInitModes.NO_INIT ) )
+ {
+ // if the object is not loaded
+ // it can not get persistant representation without initialization
+
+ // if the object is loaded
+ // it can switch persistant representation only without initialization
+
+ throw new com.sun.star.embed.WrongStateException();
+ }
+
+ if ( m_bWaitSaveCompleted )
+ {
+ if ( nEntryConnectionMode == com.sun.star.embed.EntryInitModes.NO_INIT )
+ {
+ if ( m_xParentStorage == xStorage && m_aEntryName.equals( aEntryName ) )
+ saveCompleted( false );
+ else if ( m_xNewParentStorage == xStorage && m_aNewEntryName.equals( aEntryName ) )
+ saveCompleted( true );
+ else
+ throw new com.sun.star.embed.WrongStateException();
+ }
+ else
+ throw new com.sun.star.embed.WrongStateException();
+
+ return;
+ }
+
+ boolean bElExists = xStorage.hasByName( aEntryName );
+
+ if ( nEntryConnectionMode == com.sun.star.embed.EntryInitModes.DEFAULT_INIT )
+ {
+ SwitchOwnPersistence( xStorage, aEntryName );
+ if ( bElExists )
+ {
+ XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, m_xOwnStorage );
+ if ( xPropSet == null )
+ throw new com.sun.star.uno.RuntimeException();
+
+ String aMediaType = AnyConverter.toString( xPropSet.getPropertyValue( "MediaType" ) );
+ if ( !aMediaType.equals( "application/x-openoffice-embedded-69474366-FD6F-4806-8374-8EDD1B6E771D" ) )
+ throw new com.sun.star.lang.IllegalArgumentException();
+
+ m_nObjectState = com.sun.star.embed.EmbedStates.LOADED;
+ }
+ else
+ {
+ m_aEditorFrame = new EditorFrame( m_aEntryName, this, 5, 20 );
+ m_nObjectState = com.sun.star.embed.EmbedStates.RUNNING;
+ m_aObjSize = m_aEditorFrame.getAppSize();
+ }
+ }
+ else if ( nEntryConnectionMode == com.sun.star.embed.EntryInitModes.TRUNCATE_INIT )
+ {
+ SwitchOwnPersistence( xStorage, aEntryName );
+ m_aEditorFrame = new EditorFrame( m_aEntryName, this, 5, 20 );
+ m_nObjectState = com.sun.star.embed.EmbedStates.RUNNING;
+ m_aObjSize = m_aEditorFrame.getAppSize();
+ }
+ else
+ throw new com.sun.star.lang.IllegalArgumentException();
+ }
+
+ // -------------------------------------------------------------
+ public void storeToEntry(com.sun.star.embed.XStorage xStorage, String aEntryName, com.sun.star.beans.PropertyValue[] aMediaArgs, com.sun.star.beans.PropertyValue[] aObjectArgs) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.embed.WrongStateException, com.sun.star.io.IOException, com.sun.star.uno.Exception
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ if ( m_nObjectState == -1 || m_bWaitSaveCompleted )
+ throw new com.sun.star.embed.WrongStateException();
+
+ if ( m_nObjectState == com.sun.star.embed.EmbedStates.LOADED )
+ {
+ m_xParentStorage.copyElementTo( m_aEntryName, xStorage, aEntryName );
+ }
+ else
+ {
+ com.sun.star.embed.XStorage xSubStorage =
+ xStorage.openStorageElement( aEntryName,
+ com.sun.star.embed.ElementModes.READWRITE | com.sun.star.embed.ElementModes.TRUNCATE );
+
+ String aContents = m_aEditorFrame.getText();
+
+ SaveDataToStorage( xSubStorage, m_aEditorFrame.getText(), UpdateSizeAndGetFromActive() );
+ }
+ }
+
+ // -------------------------------------------------------------
+ public void storeAsEntry(com.sun.star.embed.XStorage xStorage, String aEntryName, com.sun.star.beans.PropertyValue[] aMediaArgs, com.sun.star.beans.PropertyValue[] aObjectArgs) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.embed.WrongStateException, com.sun.star.io.IOException, com.sun.star.uno.Exception
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ if ( m_nObjectState == -1 || m_bWaitSaveCompleted )
+ throw new com.sun.star.embed.WrongStateException();
+
+ com.sun.star.embed.XStorage xSubStorage = null;
+
+ if ( m_nObjectState == com.sun.star.embed.EmbedStates.LOADED )
+ {
+ xSubStorage =
+ xStorage.openStorageElement( aEntryName,
+ com.sun.star.embed.ElementModes.READWRITE | com.sun.star.embed.ElementModes.NOCREATE );
+
+ m_xOwnStorage.copyToStorage( xSubStorage );
+ }
+ else
+ {
+ xSubStorage =
+ xStorage.openStorageElement( aEntryName,
+ com.sun.star.embed.ElementModes.READWRITE | com.sun.star.embed.ElementModes.TRUNCATE );
+
+ SaveDataToStorage( xSubStorage, m_aEditorFrame.getText(), UpdateSizeAndGetFromActive() );
+ }
+
+ m_bWaitSaveCompleted = true;
+ m_xNewOwnStorage = xSubStorage;
+ m_xNewParentStorage = xStorage;
+ m_aNewEntryName = aEntryName;
+
+ }
+
+ // -------------------------------------------------------------
+ public void saveCompleted(boolean bUseNew) throws com.sun.star.embed.WrongStateException, com.sun.star.uno.Exception
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ if ( m_nObjectState == -1 )
+ throw new com.sun.star.embed.WrongStateException();
+
+ // it is allowed to call saveCompleted( false ) for nonstored objects
+ if ( !m_bWaitSaveCompleted && !bUseNew )
+ return;
+
+ if ( !m_bWaitSaveCompleted )
+ throw new com.sun.star.io.IOException();
+
+ if ( bUseNew )
+ {
+ SwitchOwnPersistence( m_xNewParentStorage, m_xNewOwnStorage, m_aNewEntryName );
+ PostEvent( "OnSaveAsDone" );
+ }
+ else
+ {
+ try
+ {
+ m_xNewOwnStorage.dispose();
+ }
+ catch( com.sun.star.uno.RuntimeException e )
+ {}
+ }
+
+ m_xNewOwnStorage = null;
+ m_xNewParentStorage = null;
+ m_aNewEntryName = null;
+ m_bWaitSaveCompleted = false;
+ }
+
+ // -------------------------------------------------------------
+ public boolean hasEntry() throws com.sun.star.embed.WrongStateException
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ if ( m_bWaitSaveCompleted )
+ throw new com.sun.star.embed.WrongStateException();
+
+ if ( m_xOwnStorage != null )
+ return true;
+
+ return false;
+ }
+
+ // -------------------------------------------------------------
+ public String getEntryName() throws com.sun.star.embed.WrongStateException
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ if ( m_nObjectState == -1 || m_bWaitSaveCompleted )
+ throw new com.sun.star.embed.WrongStateException();
+
+ return m_aEntryName;
+ }
+
+ // com.sun.star.embed.XVisualObject:
+ // -------------------------------------------------------------
+ public void setVisualAreaSize(long nAspect, com.sun.star.awt.Size aSize) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.embed.WrongStateException, com.sun.star.uno.Exception
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ if ( m_nObjectState == -1 )
+ throw new com.sun.star.embed.WrongStateException();
+
+ if ( nAspect == com.sun.star.embed.Aspects.MSOLE_ICON )
+ // the ICON aspect should be handled by the container
+ throw new com.sun.star.embed.WrongStateException();
+
+ if ( m_nObjectState == com.sun.star.embed.EmbedStates.LOADED )
+ changeState( com.sun.star.embed.EmbedStates.RUNNING );
+
+ if ( m_aEditorFrame == null )
+ throw new com.sun.star.uno.RuntimeException();
+
+ m_aObjSize.setSize( aSize.Width, aSize.Height );
+ m_aEditorFrame.setAppSize( m_aObjSize );
+ }
+
+ // -------------------------------------------------------------
+ public com.sun.star.awt.Size getVisualAreaSize(long nAspect) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.embed.WrongStateException, com.sun.star.uno.Exception
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ if ( m_nObjectState == -1 )
+ throw new com.sun.star.embed.WrongStateException();
+
+ if ( nAspect == com.sun.star.embed.Aspects.MSOLE_ICON )
+ // the ICON aspect should be handled by the container
+ throw new com.sun.star.embed.WrongStateException();
+
+ if ( m_nObjectState == com.sun.star.embed.EmbedStates.LOADED )
+ changeState( com.sun.star.embed.EmbedStates.RUNNING );
+
+ UpdateSizeAndGetFromActive();
+
+ return new com.sun.star.awt.Size( (int)m_aObjSize.getWidth(), (int)m_aObjSize.getHeight() );
+ }
+
+ // -------------------------------------------------------------
+ public VisualRepresentation getPreferredVisualRepresentation(long nAspect) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.embed.WrongStateException, com.sun.star.uno.Exception
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ if ( m_nObjectState == -1 )
+ throw new com.sun.star.embed.WrongStateException();
+
+ if ( nAspect == com.sun.star.embed.Aspects.MSOLE_ICON )
+ // the ICON aspect should be handled by the container
+ throw new com.sun.star.embed.WrongStateException();
+
+ if ( m_nObjectState == com.sun.star.embed.EmbedStates.LOADED )
+ changeState( com.sun.star.embed.EmbedStates.RUNNING );
+
+ byte[] aData = m_aEditorFrame.getReplacementImage();
+ VisualRepresentation aVisRep = new VisualRepresentation();
+ aVisRep.Data = aData;
+ aVisRep.Flavor = new com.sun.star.datatransfer.DataFlavor( "image/png", "png", new com.sun.star.uno.Type( byte[].class ) );
+ return aVisRep;
+ }
+
+ // -------------------------------------------------------------
+ public int getMapUnit(long nAspect) throws com.sun.star.uno.Exception
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ if ( m_nObjectState == -1 )
+ throw new com.sun.star.embed.WrongStateException();
+
+ if ( nAspect == com.sun.star.embed.Aspects.MSOLE_ICON )
+ // the ICON aspect should be handled by the container
+ throw new com.sun.star.embed.WrongStateException();
+
+ return com.sun.star.embed.EmbedMapUnits.PIXEL;
+ }
+
+ // com.sun.star.embed.XClassifiedObject:
+ // -------------------------------------------------------------
+ public byte[] getClassID()
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ return m_aClassID;
+ }
+
+ // -------------------------------------------------------------
+ public String getClassName()
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ return new String();
+ }
+
+ // -------------------------------------------------------------
+ public void setClassInfo(byte[] aClassID, String sClassName) throws com.sun.star.lang.NoSupportException
+ {
+ throw new com.sun.star.lang.NoSupportException();
+ }
+
+ // com.sun.star.embed.XComponentSupplier:
+ // -------------------------------------------------------------
+ public com.sun.star.util.XCloseable getComponent()
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ // allows no access to the component, this simple example just has no
+ return null;
+ }
+
+ // com.sun.star.embed.XStateChangeBroadcaster:
+ // -------------------------------------------------------------
+ public void addStateChangeListener(com.sun.star.embed.XStateChangeListener xListener)
+ {
+ if ( m_bDisposed )
+ return;
+
+ GetListeners().add( xListener );
+ }
+
+ // -------------------------------------------------------------
+ public void removeStateChangeListener(com.sun.star.embed.XStateChangeListener xListener)
+ {
+ if ( m_bDisposed )
+ return;
+
+ if ( m_aListeners != null )
+ m_aListeners.remove( xListener );
+ }
+
+ // com.sun.star.document.XEventBroadcaster:
+ // -------------------------------------------------------------
+ public void addEventListener(com.sun.star.document.XEventListener xListener)
+ {
+ if ( m_bDisposed )
+ return;
+
+ GetListeners().add( xListener );
+ }
+
+ // -------------------------------------------------------------
+ public void removeEventListener(com.sun.star.document.XEventListener xListener)
+ {
+ if ( m_bDisposed )
+ return;
+
+ if ( m_aListeners != null )
+ m_aListeners.remove( xListener );
+ }
+
+ // com.sun.star.util.XCloseBroadcaster:
+ // -------------------------------------------------------------
+ public void addCloseListener(com.sun.star.util.XCloseListener xListener)
+ {
+ if ( m_bDisposed )
+ return;
+
+ GetListeners().add( xListener );
+ }
+
+ // -------------------------------------------------------------
+ public void removeCloseListener(com.sun.star.util.XCloseListener xListener)
+ {
+ if ( m_bDisposed )
+ return;
+
+ if ( m_aListeners != null )
+ m_aListeners.remove( xListener );
+ }
+
+ // com.sun.star.util.XCloseable:
+ // -------------------------------------------------------------
+ public void close(boolean bDeliverOwnership) throws com.sun.star.util.CloseVetoException
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ com.sun.star.lang.EventObject aEventObject = new com.sun.star.lang.EventObject( this );
+
+ if ( m_aListeners != null )
+ {
+ for ( int nInd = 0; nInd < m_aListeners.size(); nInd++ )
+ {
+ try
+ {
+ com.sun.star.util.XCloseListener xListener = ( com.sun.star.util.XCloseListener )
+ UnoRuntime.queryInterface( com.sun.star.document.XEventListener.class, m_aListeners.get( nInd ) );
+
+ if ( xListener != null )
+ xListener.queryClosing( aEventObject, bDeliverOwnership );
+ }
+ catch( com.sun.star.util.CloseVetoException e )
+ {
+ throw e;
+ }
+ catch( java.lang.Exception e )
+ {
+ m_aListeners.remove( nInd );
+ }
+ }
+
+ m_bDisposed = true;
+
+ for ( int nInd = 0; nInd < m_aListeners.size(); nInd++ )
+ {
+ try
+ {
+ com.sun.star.util.XCloseListener xListener = ( com.sun.star.util.XCloseListener )
+ UnoRuntime.queryInterface( com.sun.star.document.XEventListener.class, m_aListeners.get( nInd ) );
+
+ if ( xListener != null )
+ xListener.notifyClosing( aEventObject );
+ }
+ catch( java.lang.Exception e )
+ {
+ m_aListeners.remove( nInd );
+ }
+ }
+
+ m_aListeners.clear();
+ }
+
+ m_bDisposed = true;
+
+ if ( m_aEditorFrame != null )
+ {
+ m_aEditorFrame.dispose();
+ m_aEditorFrame = null;
+ }
+
+ if ( m_xOwnStorage != null )
+ {
+ try {
+ m_xOwnStorage.dispose();
+ } catch( java.lang.Exception e ) {}
+ m_xOwnStorage = null;
+ }
+ }
+
+ // com.sun.star.embed.XEmbeddedObject:
+ // -------------------------------------------------------------
+ public void changeState(int nNewState) throws com.sun.star.embed.UnreachableStateException, com.sun.star.embed.WrongStateException, com.sun.star.uno.Exception
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ if ( m_nObjectState == -1 )
+ throw new com.sun.star.embed.WrongStateException();
+
+ int nOldState = m_nObjectState;
+
+ if ( nOldState == nNewState )
+ {
+ if ( nOldState == com.sun.star.embed.EmbedStates.ACTIVE )
+ {
+ if ( m_aEditorFrame == null )
+ throw new com.sun.star.uno.RuntimeException();
+ m_aEditorFrame.toFront();
+ }
+
+ return;
+ }
+
+ if ( nNewState != com.sun.star.embed.EmbedStates.LOADED
+ && nNewState != com.sun.star.embed.EmbedStates.RUNNING
+ && nNewState != com.sun.star.embed.EmbedStates.ACTIVE )
+ throw new com.sun.star.embed.UnreachableStateException();
+
+ StateChangeNotification( true, nOldState, nNewState );
+
+ try
+ {
+ if ( nOldState == com.sun.star.embed.EmbedStates.LOADED )
+ {
+ // switch to the RUNNING state first
+ String aText = ReadStringFromStream( m_xOwnStorage, "content.txt" );
+
+ EditorFrame aEditorFrame = new EditorFrame( m_aEntryName, this, 5, 20 );
+ aEditorFrame.setText( aText );
+
+ ReadSizeFromOwnStorage();
+
+ m_aEditorFrame = aEditorFrame;
+ m_nObjectState = com.sun.star.embed.EmbedStates.RUNNING;
+
+ if ( nNewState == com.sun.star.embed.EmbedStates.ACTIVE )
+ {
+ if ( m_xClient == null )
+ throw new com.sun.star.embed.WrongStateException();
+
+ m_aEditorFrame.show();
+ m_aEditorFrame.toFront();
+
+ if ( m_aObjSize != null )
+ aEditorFrame.setAppSize( m_aObjSize );
+
+ m_xClient.visibilityChanged( true );
+ m_nObjectState = com.sun.star.embed.EmbedStates.ACTIVE;
+ }
+ }
+ else if ( nOldState == com.sun.star.embed.EmbedStates.RUNNING )
+ {
+ if ( nNewState == com.sun.star.embed.EmbedStates.LOADED )
+ {
+ EditorFrame aFrame = m_aEditorFrame;
+ m_aEditorFrame = null;
+ aFrame.dispose();
+ m_nObjectState = nNewState;
+ }
+ else // nNewState == ACTIVE
+ {
+ if ( m_aEditorFrame == null )
+ throw new com.sun.star.uno.RuntimeException();
+
+ if ( m_xClient == null )
+ throw new com.sun.star.embed.WrongStateException();
+
+ m_aEditorFrame.show();
+ m_aEditorFrame.toFront();
+
+ if ( m_aObjSize != null )
+ m_aEditorFrame.setAppSize( m_aObjSize );
+
+ m_xClient.visibilityChanged( true );
+
+ m_nObjectState = nNewState;
+ }
+ }
+ else // nOldState == ACTIVE
+ {
+ UpdateSizeAndGetFromActive();
+ if ( nNewState == com.sun.star.embed.EmbedStates.RUNNING )
+ {
+ m_aEditorFrame.hide();
+ m_nObjectState = nNewState;
+ }
+ else // nNewState == LOADED
+ {
+ EditorFrame aFrame = m_aEditorFrame;
+ m_aEditorFrame = null;
+ aFrame.dispose();
+ m_nObjectState = nNewState;
+ }
+ }
+ }
+ catch( com.sun.star.uno.Exception e )
+ {
+ if ( nOldState != m_nObjectState )
+ StateChangeNotification( false, nOldState, m_nObjectState );
+ throw e;
+ }
+
+ StateChangeNotification( true, nOldState, nNewState );
+ }
+
+ // -------------------------------------------------------------
+ public int[] getReachableStates() throws com.sun.star.embed.NeedsRunningStateException, com.sun.star.embed.WrongStateException
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ if ( m_nObjectState == -1 )
+ throw new com.sun.star.embed.WrongStateException();
+
+ int[] pStates = new int[3];
+ pStates[0] = com.sun.star.embed.EmbedStates.LOADED;
+ pStates[1] = com.sun.star.embed.EmbedStates.RUNNING;
+ pStates[2] = com.sun.star.embed.EmbedStates.ACTIVE;
+
+ return pStates;
+ }
+
+ // -------------------------------------------------------------
+ public int getCurrentState() throws com.sun.star.embed.WrongStateException
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ if ( m_nObjectState == -1 )
+ throw new com.sun.star.embed.WrongStateException();
+
+ return m_nObjectState;
+ }
+
+ // -------------------------------------------------------------
+ public void doVerb(int nVerbID) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.embed.WrongStateException, com.sun.star.embed.UnreachableStateException, com.sun.star.uno.Exception
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ if ( m_nObjectState == -1 )
+ throw new com.sun.star.embed.WrongStateException();
+
+ if ( nVerbID == com.sun.star.embed.EmbedVerbs.MS_OLEVERB_PRIMARY
+ || nVerbID == com.sun.star.embed.EmbedVerbs.MS_OLEVERB_SHOW
+ || nVerbID == com.sun.star.embed.EmbedVerbs.MS_OLEVERB_OPEN )
+ changeState( com.sun.star.embed.EmbedStates.ACTIVE );
+ else if ( nVerbID == com.sun.star.embed.EmbedVerbs.MS_OLEVERB_HIDE )
+ changeState( com.sun.star.embed.EmbedStates.RUNNING );
+ }
+
+ // -------------------------------------------------------------
+ public com.sun.star.embed.VerbDescriptor[] getSupportedVerbs() throws com.sun.star.embed.NeedsRunningStateException, com.sun.star.embed.WrongStateException
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ if ( m_nObjectState == -1 )
+ throw new com.sun.star.embed.WrongStateException();
+
+ if ( m_pOwnVerbs == null )
+ {
+ try
+ {
+ XMultiComponentFactory xFactory = m_xContext.getServiceManager();
+ Object obj = xFactory.createInstanceWithContext( "com.sun.star.configuration.ConfigurationProvider", m_xContext );
+ XMultiServiceFactory xConfProvider = (XMultiServiceFactory) UnoRuntime.queryInterface( XMultiServiceFactory.class, obj );
+ if ( xConfProvider == null )
+ throw new com.sun.star.uno.RuntimeException();
+
+ Object[] aArgs = new Object[1];
+ aArgs[0] = "/org.openoffice.Office.Embedding/Objects";
+ Object oSettings = xConfProvider.createInstanceWithArguments( "com.sun.star.configuration.ConfigurationAccess", aArgs );
+ XNameAccess xObjConfNA = ( XNameAccess ) UnoRuntime.queryInterface( XNameAccess.class, oSettings );
+ if ( xObjConfNA == null )
+ throw new com.sun.star.uno.RuntimeException();
+
+ Object oEmbObj = xObjConfNA.getByName( "69474366-FD6F-4806-8374-8EDD1B6E771D" );
+ XNameAccess xEmbObjNA = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, oEmbObj );
+ if ( xEmbObjNA == null )
+ throw new com.sun.star.uno.RuntimeException();
+
+ String[] pVerbShortcuts = (String[]) AnyConverter.toArray( xEmbObjNA.getByName( "ObjectVerbs" ) );
+ if ( pVerbShortcuts != null && pVerbShortcuts.length != 0 )
+ {
+ com.sun.star.embed.VerbDescriptor[] pVerbs = new com.sun.star.embed.VerbDescriptor[pVerbShortcuts.length];
+ aArgs[0] = "/org.openoffice.Office.Embedding/Verbs";
+ Object oVerbs = xConfProvider.createInstanceWithArguments( "com.sun.star.configuration.ConfigurationAccess", aArgs );
+ XNameAccess xVerbsConfNA = ( XNameAccess ) UnoRuntime.queryInterface( XNameAccess.class, oVerbs );
+ if ( xVerbsConfNA == null )
+ throw new com.sun.star.uno.RuntimeException();
+
+ for ( int nInd = 0; nInd < pVerbShortcuts.length; nInd++ )
+ {
+ try
+ {
+ XNameAccess xVerbNA = (XNameAccess) UnoRuntime.queryInterface(
+ XNameAccess.class,
+ xVerbsConfNA.getByName( pVerbShortcuts[nInd] ) );
+ if ( xVerbNA != null )
+ {
+ com.sun.star.embed.VerbDescriptor aVerb = new com.sun.star.embed.VerbDescriptor();
+ aVerb.VerbID = AnyConverter.toInt( xVerbNA.getByName( "VerbID" ) );
+ aVerb.VerbName = AnyConverter.toString( xVerbNA.getByName( "VerbUIName" ) );
+ aVerb.VerbFlags = AnyConverter.toInt( xVerbNA.getByName( "VerbFlags" ) );
+ aVerb.VerbAttributes = AnyConverter.toInt( xVerbNA.getByName( "VerbAttributes" ) );
+ pVerbs[nInd] = aVerb;
+ }
+ }
+ catch( java.lang.Exception e )
+ {
+ }
+
+ if ( pVerbs[nInd] == null )
+ {
+ // let the error be visible
+ pVerbs[nInd] = new com.sun.star.embed.VerbDescriptor();
+ pVerbs[nInd].VerbID = com.sun.star.embed.EmbedVerbs.MS_OLEVERB_PRIMARY;
+ pVerbs[nInd].VerbName = "ERROR!";
+ pVerbs[nInd].VerbFlags = 0;
+ pVerbs[nInd].VerbAttributes = com.sun.star.embed.VerbAttributes.MS_VERBATTR_ONCONTAINERMENU;
+ }
+ }
+
+ m_pOwnVerbs = pVerbs;
+ }
+ }
+ catch( com.sun.star.uno.Exception e )
+ {}
+ }
+
+ if ( m_pOwnVerbs != null )
+ return m_pOwnVerbs;
+
+ return new com.sun.star.embed.VerbDescriptor[0];
+ }
+
+ // -------------------------------------------------------------
+ public void setClientSite(com.sun.star.embed.XEmbeddedClient xClient) throws com.sun.star.embed.WrongStateException
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ if ( m_nObjectState == -1 )
+ throw new com.sun.star.embed.WrongStateException();
+
+ m_xClient = xClient;
+ }
+
+ // -------------------------------------------------------------
+ public com.sun.star.embed.XEmbeddedClient getClientSite() throws com.sun.star.embed.WrongStateException
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ if ( m_nObjectState == -1 )
+ throw new com.sun.star.embed.WrongStateException();
+
+ return m_xClient;
+ }
+
+ // -------------------------------------------------------------
+ public void update() throws com.sun.star.embed.WrongStateException, com.sun.star.uno.Exception
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ if ( m_nObjectState == -1 )
+ throw new com.sun.star.embed.WrongStateException();
+
+ // not implemented
+ }
+
+ // -------------------------------------------------------------
+ public void setUpdateMode(int nMode) throws com.sun.star.embed.WrongStateException
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ if ( m_nObjectState == -1 )
+ throw new com.sun.star.embed.WrongStateException();
+
+ // not implemented
+ }
+
+ // -------------------------------------------------------------
+ public long getStatus(long nAspect) throws com.sun.star.embed.WrongStateException
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ if ( m_nObjectState == -1 )
+ throw new com.sun.star.embed.WrongStateException();
+
+ return 0;
+ }
+
+ // -------------------------------------------------------------
+ public void setContainerName(String sName)
+ {
+ if ( m_bDisposed )
+ throw new com.sun.star.lang.DisposedException();
+
+ // not implemented
+ }
+}
+
diff --git a/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObjectFactory.java b/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObjectFactory.java
new file mode 100755
index 000000000000..525d13e63eef
--- /dev/null
+++ b/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObjectFactory.java
@@ -0,0 +1,101 @@
+package org.openoffice.examples.embedding;
+
+import com.sun.star.uno.UnoRuntime;
+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;
+import com.sun.star.uno.Exception;
+import com.sun.star.lang.IllegalArgumentException;
+
+import com.sun.star.embed.*;
+
+import org.openoffice.examples.embedding.OwnEmbeddedObject;
+
+public final class OwnEmbeddedObjectFactory extends WeakBase
+ implements com.sun.star.lang.XServiceInfo,
+ com.sun.star.embed.XEmbedObjectFactory
+{
+ private final XComponentContext m_xContext;
+ private static final String m_implementationName = OwnEmbeddedObjectFactory.class.getName();
+ private static final String[] m_serviceNames = {
+ "org.openoffice.examples.embedding.Factory69474366FD6F480683748EDD1B6E771D" };
+ private static final byte[] m_classID = { 0x69, 0x47, 0x43, 0x66, (byte)0xFD, 0x6F, 0x48, 0x06, (byte)0x83, 0x74, (byte)0x8E, (byte)0xDD, 0x1B, 0x6E, 0x77, 0x1D };
+
+
+ public OwnEmbeddedObjectFactory( XComponentContext context )
+ {
+ m_xContext = context;
+ };
+
+ public static XSingleComponentFactory __getComponentFactory( String sImplementationName ) {
+ XSingleComponentFactory xFactory = null;
+
+ if ( sImplementationName.equals( m_implementationName ) )
+ xFactory = Factory.createComponentFactory(OwnEmbeddedObjectFactory.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.embed.XEmbedObjectFactory:
+ public Object createInstanceUserInit(byte[] aClassID, String sClassName, com.sun.star.embed.XStorage xStorage, String sEntName, int nEntryConnectionMode, com.sun.star.beans.PropertyValue[] aArgs, com.sun.star.beans.PropertyValue[] aObjectArgs) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.io.IOException, com.sun.star.uno.Exception
+ {
+ if ( xStorage == null || sEntName == null || sEntName.length() == 0 )
+ throw new com.sun.star.lang.IllegalArgumentException();
+
+ if ( nEntryConnectionMode == com.sun.star.embed.EntryInitModes.DEFAULT_INIT )
+ {
+ if ( aClassID != null && aClassID.length != 0 )
+ {
+ if ( aClassID.length != m_classID.length )
+ throw new com.sun.star.lang.IllegalArgumentException();
+
+ for ( int i = 0; i < aClassID.length; i++ )
+ if ( aClassID[i] != m_classID[i] )
+ throw new com.sun.star.lang.IllegalArgumentException();
+ }
+ else if ( !xStorage.hasByName( sEntName ) )
+ throw new com.sun.star.lang.IllegalArgumentException();
+ }
+ else if ( nEntryConnectionMode == com.sun.star.embed.EntryInitModes.TRUNCATE_INIT )
+ {
+ if ( aClassID.length != m_classID.length )
+ throw new com.sun.star.lang.IllegalArgumentException();
+
+ for ( int i = 0; i < m_classID.length; i++ )
+ if ( aClassID[i] != m_classID[i] )
+ throw new com.sun.star.lang.IllegalArgumentException();
+ }
+
+ OwnEmbeddedObject aObject = new OwnEmbeddedObject( m_xContext, m_classID );
+ aObject.setPersistentEntry( xStorage, sEntName, nEntryConnectionMode, aArgs, aObjectArgs );
+
+ return aObject;
+ }
+
+}
diff --git a/odk/examples/java/Inspector/Addon.xcu b/odk/examples/java/Inspector/Addon.xcu
new file mode 100755
index 000000000000..7989e35db35f
--- /dev/null
+++ b/odk/examples/java/Inspector/Addon.xcu
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<oor:node xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="Addon" oor:package="org.openoffice.Office">
+ <node oor:name="AddonUI">
+ <node oor:name="OfficeToolBar">
+ <node oor:name="org.openoffice.Object-Inspector" oor:op="replace">
+ <prop oor:name="Title" oor:type="xs:string">
+ <value xml:lang="en-US">Object Inspector</value>
+ </prop>
+ <node oor:name="m1" oor:op="replace">
+ <prop oor:name="URL" oor:type="xs:string">
+ <value>vnd.org.openoffice.inspector:post</value>
+ </prop>
+ <prop oor:name="Title" oor:type="xs:string">
+ <value/>
+ <value xml:lang="en-US">~Start Inspector...</value>
+ </prop>
+ <prop oor:name="Target" oor:type="xs:string">
+ <value>_self</value>
+ </prop>
+ <prop oor:name="Context" oor:type="xs:string">
+ <value></value>
+ </prop>
+ </node>
+ </node>
+ </node>
+ </node>
+ </oor:node>
+
diff --git a/odk/examples/java/Inspector/Addons.xcu b/odk/examples/java/Inspector/Addons.xcu
new file mode 100755
index 000000000000..ee44a8d68773
--- /dev/null
+++ b/odk/examples/java/Inspector/Addons.xcu
@@ -0,0 +1,23 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="Addons" oor:package="org.openoffice.Office">
+ <node oor:name="AddonUI">
+ <node oor:name="OfficeToolBar">
+ <node oor:name="org.openoffice.Office.addon.Inspector" oor:op="replace">
+ <node oor:name="toolBar_Inspector" oor:op="replace">
+ <prop oor:name="URL" oor:type="xs:string">
+ <value>org.openoffice.Office.addon.Inspector:inspect</value>
+ </prop>
+ <prop oor:name="Title" oor:type="xs:string">
+ <value xml:lang="en-US">Object Inspector</value>
+ </prop>
+ <prop oor:name="Target" oor:type="xs:string">
+ <value>_self</value>
+ </prop>
+ <prop oor:name="Context" oor:type="xs:string">
+ <value></value>
+ </prop>
+ </node>
+ </node>
+ </node>
+ </node>
+</oor:component-data>
diff --git a/odk/examples/java/Inspector/HideableMutableTreeNode.java b/odk/examples/java/Inspector/HideableMutableTreeNode.java
new file mode 100644
index 000000000000..37ac35f116b1
--- /dev/null
+++ b/odk/examples/java/Inspector/HideableMutableTreeNode.java
@@ -0,0 +1,88 @@
+// *** HideableMutableTreeNode ***
+import javax.swing.*;
+import javax.swing.tree.*;
+
+/**
+ * <code>HideableMutableTreeNode</code> is a <code>DefaultMutableTreeNode</code>
+ * implementation that works with <code>HideableTreeModel</code>.
+ */
+public class HideableMutableTreeNode extends DefaultMutableTreeNode {
+ /**
+ * The node is visible flag.
+ */
+ public boolean bIsvisible = true;
+ private static final String SDUMMY = "Dummy";
+
+
+ /**
+ * Creates a tree node that has no parent and no children, but which
+ * allows children.
+ */
+ public HideableMutableTreeNode() {
+ super();
+ }
+
+ /**
+ * Creates a tree node with no parent, no children, but which allows
+ * children, and initializes it with the specified user object.
+ *
+ * @param userObject - an Object provided by the user that
+ * constitutes the node's data
+ */
+ public HideableMutableTreeNode(Object _userObject) {
+ super(_userObject);
+ }
+
+ /**
+ * Creates a tree node with no parent, no children, initialized with the
+ * specified user object, and that allows children only if specified.
+ *
+ * @param _userObject - an Object provided by the user that describes the node's data
+ * @param _ballowsChildren - if true, the node is allowed to have childnodes -- otherwise, it is always a leaf node
+ */
+ public HideableMutableTreeNode(Object _userObject, boolean _ballowsChildren) {
+ super(_userObject, _ballowsChildren);
+ }
+
+ /**
+ * Checks if the node is visible.
+ *
+ * @return true if the node is visible, else false
+ */
+ public boolean isVisible() {
+ return this.bIsvisible;
+ }
+
+ /**
+ * Sets if the node is visible.
+ *
+ * @param returns true if the node is visible, else false
+ */
+ public void setVisible(boolean _bIsVisible) {
+ this.bIsvisible = _bIsVisible;
+ }
+
+
+ public void addDummyNode(){
+ removeDummyNode();
+ DefaultMutableTreeNode oDefaultMutableTreeNode = new DefaultMutableTreeNode(SDUMMY);
+ add(oDefaultMutableTreeNode);
+
+ }
+
+
+ public boolean removeDummyNode(){
+ boolean breturn = false;
+ if (getChildCount() == 1){
+ DefaultMutableTreeNode oDefaultMutableTreeNode = (DefaultMutableTreeNode) getChildAt(0);
+ if (oDefaultMutableTreeNode != null){
+ if (oDefaultMutableTreeNode.getUserObject().equals(SDUMMY)){
+ remove(0);
+ breturn = true;
+ }
+ }
+ }
+ return breturn;
+ }
+
+} \ No newline at end of file
diff --git a/odk/examples/java/Inspector/HideableTreeModel.java b/odk/examples/java/Inspector/HideableTreeModel.java
new file mode 100644
index 000000000000..91444d1478a8
--- /dev/null
+++ b/odk/examples/java/Inspector/HideableTreeModel.java
@@ -0,0 +1,298 @@
+
+// *** HideableTreeModel ***
+import java.awt.*;
+import java.awt.event.*;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Vector;
+import javax.swing.*;
+import javax.swing.event.*;
+import javax.swing.tree.*;
+
+
+public class HideableTreeModel implements TreeModel {
+
+ private Vector modelListeners = new Vector();
+ private Object root = null;
+
+
+ public HideableTreeModel(TreeNode _root) {
+ super();
+ setRoot(_root);
+ }
+
+
+ public Object getRoot() {
+ return this.root;
+ }
+
+
+ protected void setRoot(Object r) {
+ this.root = r;
+ }
+
+
+ public Object[] getPathToRoot(Object node) {
+ return getPathToRoot(node, 0);
+ }
+
+
+ private Object[] getPathToRoot(Object node, int i) {
+ Object anode[];
+ if(node == null) {
+ if(i == 0) {
+ return null;
+ }
+ anode = new Object[i];
+ } else {
+ i++;
+ if(node == getRoot()) {
+ anode = new Object[i];
+ } else {
+ anode = getPathToRoot(getParent(node), i);
+ }
+ anode[anode.length - i] = node;
+ }
+ return anode;
+ }
+
+
+ public void addTreeModelListener(TreeModelListener l) {
+ modelListeners.addElement(l);
+ }
+
+
+ public void removeTreeModelListener(TreeModelListener l) {
+ modelListeners.removeElement(l);
+ }
+
+
+ public void reload() {
+ reload(getRoot());
+ }
+
+
+ public void reload(Object node) {
+ if(node != null) {
+ TreePath tp = new TreePath(getPathToRoot(node));
+ fireTreeStructureChanged(new TreeModelEvent(this, tp));
+ }
+ }
+
+
+ public void valueForPathChanged(TreePath path, Object newValue) {
+ nodeChanged(path.getLastPathComponent());
+ }
+
+ public void nodeInserted(Object node, Object child) {
+ nodeInserted(node, child, -1);
+ }
+
+
+ public void nodeInserted(Object node, Object child, int index) {
+ if(index < 0) {
+ index = getIndexOfChild(node, child);
+ }
+ if(node != null && child != null && index >= 0) {
+ TreePath tp = new TreePath(getPathToRoot(node));
+ int[] ai = { index };
+ Object[] ac = { child };
+ fireTreeNodesInserted(new TreeModelEvent(this, tp, ai, ac));
+ }
+ }
+
+
+ public void nodeRemoved(Object node, Object child, int index) {
+ if(node != null && child != null && index >= 0) {
+ TreePath tp = new TreePath(getPathToRoot(node));
+ int[] ai = { index };
+ Object[] ac = { child };
+ fireTreeNodesRemoved(new TreeModelEvent(this, tp, ai, ac));
+ }
+ }
+
+
+ public void nodeChanged(Object node) {
+ if(node != null) {
+ TreePath tp = new TreePath(getPathToRoot(node));
+ fireTreeNodesChanged(new TreeModelEvent(this, tp, null, null));
+ }
+ }
+
+
+ protected void fireTreeNodesChanged(TreeModelEvent event) {
+ for(int i = 0; i < modelListeners.size(); i++) {
+ ((TreeModelListener)modelListeners.elementAt(i)).treeNodesChanged(event);
+ }
+ }
+
+
+ protected void fireTreeNodesInserted(TreeModelEvent event) {
+ for(int i = 0; i < modelListeners.size(); i++) {
+ ((TreeModelListener)modelListeners.elementAt(i)).treeNodesInserted(event);
+ }
+ }
+
+
+ protected void fireTreeNodesRemoved(TreeModelEvent event) {
+ for(int i = 0; i < modelListeners.size(); i++) {
+ ((TreeModelListener)modelListeners.elementAt(i)).treeNodesRemoved(event);
+ }
+ }
+
+ protected void fireTreeStructureChanged(TreeModelEvent event) {
+ for(int i = 0; i < modelListeners.size(); i++) {
+ ((TreeModelListener)modelListeners.elementAt(i)).treeStructureChanged(event);
+ }
+ }
+
+
+ public ArrayList getExpandedPaths(JTree tree) {
+ ArrayList expandedPaths = new ArrayList();
+ addExpandedPaths(tree, tree.getPathForRow(0), expandedPaths);
+ return expandedPaths;
+ }
+
+
+ private void addExpandedPaths(JTree tree, TreePath path, ArrayList pathlist) {
+ Enumeration aEnum = tree.getExpandedDescendants(path);
+ while(aEnum.hasMoreElements()) {
+ TreePath tp = (TreePath) aEnum.nextElement();
+ pathlist.add(tp);
+ addExpandedPaths(tree, tp, pathlist);
+ }
+ }
+
+
+ public void expandPaths(JTree tree, ArrayList pathlist) {
+ for(int i = 0; i < pathlist.size(); i++) {
+ tree.expandPath((TreePath)pathlist.get(i));
+ }
+ }
+
+
+ public boolean isLeaf(Object _oNode) {
+ if(_oNode instanceof TreeNode) {
+ return ((TreeNode) _oNode).isLeaf();
+ }
+ return true;
+ }
+
+
+
+ public Object getParent(Object node) {
+ if(node != getRoot() && (node instanceof TreeNode)) {
+ return ((TreeNode)node).getParent();
+ }
+ return null;
+ }
+
+
+ public boolean isNodeVisible(Object node) {
+ if(node != getRoot()) {
+ if(node instanceof HideableMutableTreeNode) {
+ return ((HideableMutableTreeNode)node).isVisible();
+ }
+ }
+ return true;
+ }
+
+
+ public boolean setNodeVisible(Object node, boolean v) {
+ // can't hide root
+ if(node != getRoot()) {
+ if(node instanceof HideableMutableTreeNode) {
+ HideableMutableTreeNode n = (HideableMutableTreeNode)node;
+ if(v != n.isVisible()) {
+ TreeNode parent = n.getParent();
+ if(v) {
+ // need to get index after showing...
+ n.setVisible(v);
+ int index = getIndexOfChild(parent, n);
+ nodeInserted(parent, n, index);
+ } else {
+ // need to get index before hiding...
+ int index = getIndexOfChild(parent, n);
+ n.setVisible(v);
+ nodeRemoved(parent, n, index);
+ }
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ public boolean isPathToNodeVisible(Object node) {
+ Object[] path = getPathToRoot(node);
+ for(int i = 0; i < path.length; i++) {
+ if(!isNodeVisible(path[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+
+ public void ensurePathToNodeVisible(Object node) {
+ Object[] path = getPathToRoot(node);
+ for(int i = 0; i < path.length; i++) {
+ setNodeVisible(path[i], true);
+ }
+ }
+
+
+ public Object getChild(Object parent, int index) {
+ if(parent instanceof TreeNode) {
+ TreeNode p = (TreeNode) parent;
+ for(int i = 0, j = -1; i < p.getChildCount(); i++) {
+ TreeNode pc = (TreeNode)p.getChildAt(i);
+ if(isNodeVisible(pc)) {
+ j++;
+ }
+ if(j == index) {
+ return pc;
+ }
+ }
+ }
+ return null;
+ }
+
+
+ public int getChildCount(Object parent) {
+ int count = 0;
+ if(parent instanceof TreeNode) {
+ TreeNode p = (TreeNode) parent;
+ for(int i = 0; i < p.getChildCount(); i++) {
+ TreeNode pc = (TreeNode)p.getChildAt(i);
+ if(isNodeVisible(pc)) {
+ count++;
+ }
+ }
+ }
+ return count;
+ }
+
+
+ public int getIndexOfChild(Object parent, Object child) {
+ int index = -1;
+ if(parent instanceof TreeNode && child instanceof TreeNode) {
+ TreeNode p = (TreeNode)parent;
+ TreeNode c = (TreeNode)child;
+ if(isNodeVisible(c)) {
+ index = 0;
+ for(int i = 0; i < p.getChildCount(); i++) {
+ TreeNode pc = (TreeNode)p.getChildAt(i);
+ if(pc.equals(c)) {
+ return index;
+ }
+ if(isNodeVisible(pc)) {
+ index++;
+ }
+ }
+ }
+ }
+ return index;
+ }
+} \ No newline at end of file
diff --git a/odk/examples/java/Inspector/Inspector.java b/odk/examples/java/Inspector/Inspector.java
new file mode 100644
index 000000000000..78f5cc182ee4
--- /dev/null
+++ b/odk/examples/java/Inspector/Inspector.java
@@ -0,0 +1,461 @@
+/*************************************************************************
+ *
+ * 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.awt.Rectangle;
+import com.sun.star.awt.XMessageBox;
+import com.sun.star.awt.XMessageBoxFactory;
+import com.sun.star.awt.XWindowPeer;
+import com.sun.star.beans.NamedValue;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.container.XNameAccess;
+import com.sun.star.frame.XModel;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.lang.XSingleComponentFactory;
+import com.sun.star.lib.uno.helper.Factory;
+import com.sun.star.lib.uno.helper.WeakBase;
+import com.sun.star.registry.XRegistryKey;
+import com.sun.star.ui.dialogs.XExecutableDialog;
+import com.sun.star.ui.dialogs.XFolderPicker;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.util.CloseVetoException;
+import com.sun.star.util.XChangesBatch;
+import com.sun.star.util.XCloseable;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.Vector;
+import org.openoffice.XInstanceInspector;
+
+
+/** The purpose of this class is to provide a factory for creating the service
+ * (<CODE>__getServiceFactory</CODE>) and writes the information into the given
+ * registry key (<CODE>__writeRegistryServiceInfo</CODE>).
+ */
+public class Inspector{
+ public static final String sIDLDOCUMENTSUBFOLDER = "docs/common/ref/";
+
+
+ /** This class implements the method of the interface XInstanceInspector.
+ * Also the class implements the interfaces XServiceInfo, and XTypeProvider.
+ */
+ static public class _Inspector extends WeakBase implements XInstanceInspector, XServiceInfo{
+
+ static private final String __serviceName = "org.openoffice.InstanceInspector";
+ private HashMap aApplicationHashMap = new HashMap();
+ private String sTitle = "Object Inspector";
+ private Vector aHiddenDocuments = new Vector();
+// private String[] sApplicationDocUrls = new String[]{"private:factory/swriter", "private:factory/scalc", "private:factory/simpress", "private:factory/sdraw", "private:factory/sbase"};
+// private String[] sApplicationDocNames = new String[]{"Text Document", "Spreadsheet", "Presentation", "Drawing", "Database"};
+ private XComponentContext m_xComponentContext;
+ private HashMap aInspectorPanes = new HashMap();
+ private XDialogProvider m_oSwingDialogProvider;
+ private TDocSupplier oTDocSupplier;
+ private Introspector m_oIntrospector = null;
+ // TODO: improve these strings:
+ private static final String sWRONGINSTALLATIONPATH = "Your selected path does not refer to an SDK-Installation!";
+ /** Creates a new instance of Dialog */
+ public _Inspector(XComponentContext _xComponentContext) {
+ m_xComponentContext = _xComponentContext;
+ m_oIntrospector = Introspector.getIntrospector(m_xComponentContext);
+ aApplicationHashMap.put("private:factory/swriter", "Text Document");
+ aApplicationHashMap.put("private:factory/scalc", "Spreadsheet");
+ aApplicationHashMap.put("private:factory/simpress", "Presentation");
+ aApplicationHashMap.put("private:factory/sdraw", "Drawing");
+ aApplicationHashMap.put("private:factory/smath", "Formula");
+ m_oSwingDialogProvider = new SwingDialogProvider(this, sTitle);
+// aApplicationHashMap.put("private:factory/sbase", "Database");
+ }
+
+
+ public XComponentContext getXComponentContext(){
+ return m_xComponentContext;
+ }
+
+
+ public HashMap getInspectorPages(){
+ return aInspectorPanes;
+ }
+
+
+ protected String getSDKPath(){
+ String sRetPath = "";
+ try{
+ XNameAccess xNameAccess = getConfigurationAccess("org.openoffice.inspector.ObjectInspector", true);
+ XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xNameAccess);
+ sRetPath = (String) xPropertySet.getPropertyValue("SDKPath");
+ }catch( Exception exception ) {
+ exception.printStackTrace(System.out);
+ }
+ return sRetPath;
+ }
+
+
+ public String getIDLPath(){
+ String sRetPath = getSDKPath();
+ if (m_oIntrospector.isValidSDKInstallationPath(sRetPath)){
+ sRetPath = m_oIntrospector.addToPath(sRetPath, sIDLDOCUMENTSUBFOLDER);
+ }
+ else{
+ sRetPath = "";
+ }
+ return sRetPath;
+ }
+
+
+ public void openIdlFileforSelectedNode(){
+ InspectorPane oInspectorPane = m_oSwingDialogProvider.getSelectedInspectorPage();
+ if (oInspectorPane != null){
+ XUnoNode oUnoNode = oInspectorPane.getSelectedNode();
+ if (oUnoNode != null){
+ String sPath = getIDLPath();
+ oUnoNode.openIdlDescription(sPath);
+ }
+ }
+ }
+
+
+ public void assignSDKPath() {
+ try {
+ String sInstallationFolder = "";
+ Object oFolderPicker = m_xComponentContext.getServiceManager().createInstanceWithContext("com.sun.star.ui.dialogs.FolderPicker", m_xComponentContext);
+ XFolderPicker xFolderPicker = (XFolderPicker) UnoRuntime.queryInterface(XFolderPicker.class, oFolderPicker);
+ XExecutableDialog xExecutable = (XExecutableDialog) UnoRuntime.queryInterface(XExecutableDialog.class, oFolderPicker);
+ XComponent xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, oFolderPicker);
+ String sPath = getSDKPath();
+ if (!sPath.equals("")){
+ xFolderPicker.setDisplayDirectory(sPath);
+ }
+ xFolderPicker.setTitle("Add the Path to your SDK installation");
+ short nResult = xExecutable.execute();
+ if (nResult == com.sun.star.ui.dialogs.ExecutableDialogResults.OK){
+ sInstallationFolder = xFolderPicker.getDirectory();
+ if (m_oIntrospector.isValidSDKInstallationPath(sInstallationFolder)){
+ XNameAccess xNameAccess = getConfigurationAccess(true);
+ XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xNameAccess);
+ xPropertySet.setPropertyValue("SDKPath", sInstallationFolder);
+ XChangesBatch xBatch = (XChangesBatch) UnoRuntime.queryInterface(XChangesBatch.class, xNameAccess);
+ xBatch.commitChanges();
+ }
+ else{
+ XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xFolderPicker);
+ Object oWindow = xPropertySet.getPropertyValue("Window");
+ XWindowPeer xWindowPeer = (XWindowPeer) UnoRuntime.queryInterface(XWindowPeer.class, oWindow);
+ showErrorMessageBox(xWindowPeer, sTitle, sWRONGINSTALLATIONPATH);
+ assignSDKPath();
+ }
+ }
+ xComponent.dispose();
+ }catch( Exception exception ) {
+ exception.printStackTrace(System.out);
+ }}
+
+
+ public void showErrorMessageBox(XWindowPeer _xWindowPeer, String _sTitle, String _sMessage){
+ try {
+ Object oToolkit = m_xComponentContext.getServiceManager().createInstanceWithContext("com.sun.star.awt.Toolkit", m_xComponentContext);
+ XMessageBoxFactory xMessageBoxFactory = (XMessageBoxFactory) UnoRuntime.queryInterface(XMessageBoxFactory.class, oToolkit);
+ Rectangle aRectangle = new Rectangle();
+ XMessageBox xMessageBox = xMessageBoxFactory.createMessageBox(_xWindowPeer, aRectangle, "errorbox", com.sun.star.awt.MessageBoxButtons.BUTTONS_OK, _sTitle, _sMessage);
+ XComponent xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, xMessageBox);
+ if (xMessageBox != null){
+ short nResult = xMessageBox.execute();
+ xComponent.dispose();
+ }
+ } catch (com.sun.star.uno.Exception ex) {
+ ex.printStackTrace(System.out);
+ }}
+
+
+ public void inspect(java.lang.Object _oUserDefinedObject, String _sTitle) throws com.sun.star.uno.RuntimeException {
+ try {
+ int nPageIndex = m_oSwingDialogProvider.getInspectorPageCount();
+ SwingTreeControlProvider oSwingTreeControlProvider = new SwingTreeControlProvider(m_oSwingDialogProvider);
+ InspectorPane oInspectorPane = new InspectorPane(getXComponentContext(), m_oSwingDialogProvider, oSwingTreeControlProvider, getSourceCodeLanguage());
+ oInspectorPane.inspect(_oUserDefinedObject, _sTitle);
+ getInspectorPages().put(_sTitle, oInspectorPane);
+ m_oSwingDialogProvider.show(nPageIndex);
+ }catch( Exception exception ) {
+ exception.printStackTrace(System.out);
+ }}
+
+
+ public void inspectOpenEmptyDocument(String _sApplicationDocUrl){
+ XComponent xComponent = getTDocSupplier().openEmptyDocument(_sApplicationDocUrl);
+ String sRootTitle = (String) aApplicationHashMap.get(_sApplicationDocUrl);
+ inspect(xComponent, sRootTitle);
+ aHiddenDocuments.add(xComponent);
+ }
+
+
+ public void inspectOpenDocument(String _sTDocUrl){
+ String sTreeNodeName = getTDocSupplier().getTitleByTDocUrl(_sTDocUrl);
+ XModel xTDocModel = getTDocSupplier().getXModelByTDocUrl(_sTDocUrl);
+ inspect(xTDocModel, sTreeNodeName);
+ }
+
+
+ public void inspectSelectedNode(){
+ InspectorPane oInspectorPane = m_oSwingDialogProvider.getSelectedInspectorPage();
+ if (oInspectorPane != null){
+ XUnoNode oUnoNode = oInspectorPane.getSelectedNode();
+ Object oUnoObject = oUnoNode.getUnoObject();
+ if (oUnoObject != null){
+ String sNodeDescription = UnoNode.getNodeDescription(oUnoObject);
+ inspect(oUnoObject, sNodeDescription);
+ }
+ }
+ }
+
+
+ public void addSourceCodeOfSelectedNode(){
+ InspectorPane oInspectorPane = m_oSwingDialogProvider.getSelectedInspectorPage();
+ if (oInspectorPane != null){
+ oInspectorPane.addSourceCodeOfSelectedNode();
+ }
+ }
+
+
+ public void invokeSelectedMethod(){
+ InspectorPane oInspectorPane = m_oSwingDialogProvider.getSelectedInspectorPage();
+ if (oInspectorPane != null){
+ oInspectorPane.invokeSelectedMethodNode();
+ }
+ }
+
+
+ public void setSourceCodeLanguage(final int _nLanguage){
+ try{
+ String sLanguage = "Java";
+ XNameAccess xNameAccess = getConfigurationAccess("org.openoffice.inspector.ObjectInspector", true);
+ XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xNameAccess);
+ switch (_nLanguage){
+ case XLanguageSourceCodeGenerator.nJAVA:
+ sLanguage = "Java";
+ break;
+ case XLanguageSourceCodeGenerator.nCPLUSPLUS:
+ sLanguage = "CPlusPlus";
+ break;
+ case XLanguageSourceCodeGenerator.nBASIC:
+ sLanguage = "Basic";
+ break;
+ default:
+ System.out.println("Warning: Sourcecode language is not defined!");
+ }
+ xPropertySet.setPropertyValue("Language", sLanguage);
+ XChangesBatch xBatch = (XChangesBatch) UnoRuntime.queryInterface(XChangesBatch.class, xNameAccess);
+ xBatch.commitChanges();
+ for (int i = 0; i < m_oSwingDialogProvider.getInspectorPageCount(); i++){
+ m_oSwingDialogProvider.getInspectorPage(i).convertCompleteSourceCode(_nLanguage);
+ }
+ }catch( Exception exception ) {
+ exception.printStackTrace(System.out);
+ }}
+
+
+ private TDocSupplier getTDocSupplier(){
+ if (oTDocSupplier == null){
+ oTDocSupplier = new TDocSupplier(m_xComponentContext);
+ }
+ return oTDocSupplier;
+ }
+
+ public String[] getTDocUrls(){
+ return getTDocSupplier().getTDocUrls();
+ }
+
+
+ public String[] getTDocTitles(String[] _sTDocUrls){
+ return getTDocSupplier().getTDocTitles(_sTDocUrls);
+ }
+
+
+ public String[][] getApplicationUrls(){
+ Set aSet = aApplicationHashMap.keySet();
+ String[][] sReturnList = new String[aSet.size()][];
+ int n= 0;
+ for ( Iterator i = aSet.iterator(); i.hasNext(); ){
+ String[] sSingleApplication = new String[2];
+ sSingleApplication[0] = (String) i.next();
+ // assign the title in the second index
+ sSingleApplication[1] = (String) aApplicationHashMap.get(sSingleApplication[0]);
+ sReturnList[n++] = sSingleApplication;
+ }
+ return sReturnList;
+ }
+
+
+ public void disposeHiddenDocuments(){
+ int nHiddenCount = aHiddenDocuments.size();
+ if (nHiddenCount > 0){
+ for (int i = nHiddenCount - 1; i >= 0; i--){
+ XComponent xComponent = (XComponent) aHiddenDocuments.get(i);
+ if (xComponent != null){
+ try {
+ XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, xComponent);
+ xCloseable.close(true);
+ aHiddenDocuments.remove(i);
+ } catch (CloseVetoException ex) {
+ ex.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
+
+ public static String[] getServiceNames() {
+ String[] sSupportedServiceNames = { __serviceName };
+ return sSupportedServiceNames;
+ }
+
+ // Implement the interface XServiceInfo
+ /** Get all supported service names.
+ * @return Supported service names.
+ */
+ public String[] getSupportedServiceNames() {
+ return getServiceNames();
+ }
+
+ // Implement the interface XServiceInfo
+ /** Test, if the given service will be supported.
+ * @param sService Service name.
+ * @return Return true, if the service will be supported.
+ */
+ public boolean supportsService( String sServiceName ) {
+ return sServiceName.equals( __serviceName );
+ }
+
+ // Implement the interface XServiceInfo
+ /** Get the implementation name of the component.
+ * @return Implementation name of the component.
+ */
+ public String getImplementationName() {
+ return _Inspector.class.getName();
+ }
+
+
+ private int getSourceCodeLanguage(){
+ int nLanguage = XLanguageSourceCodeGenerator.nJAVA;
+ try{
+ XNameAccess xNameAccess = getConfigurationAccess("org.openoffice.inspector.ObjectInspector", false);
+ String sLanguage = (String) xNameAccess.getByName("Language");
+ if (sLanguage.toUpperCase().equals("JAVA")){
+ nLanguage = XLanguageSourceCodeGenerator.nJAVA;
+ }
+ else if (sLanguage.toUpperCase().equals("BASIC")){
+ nLanguage = XLanguageSourceCodeGenerator.nBASIC;
+ }
+ else if (sLanguage.toUpperCase().equals("CPLUSPLUS")){
+ nLanguage = XLanguageSourceCodeGenerator.nCPLUSPLUS;
+ }
+ else{
+ System.out.println("Warning: Sourcecode language " + sLanguage + " is not defined!");
+ }
+ m_oSwingDialogProvider.selectSourceCodeLanguage(nLanguage);
+ }catch( Exception exception ) {
+ exception.printStackTrace(System.out);
+ }
+ return nLanguage;
+ }
+
+
+ public XNameAccess getConfigurationAccess(boolean _bUpdate){
+ return getConfigurationAccess("org.openoffice.inspector.ObjectInspector", _bUpdate);
+ }
+
+
+ public XNameAccess getConfigurationAccess(String _sNodePath, boolean update) {
+ XNameAccess xNameAccess = null;
+ try {
+ String sAccess = "";
+ if (update) {
+ sAccess = "com.sun.star.configuration.ConfigurationUpdateAccess";
+ }
+ else{
+ sAccess = "com.sun.star.configuration.ConfigurationAccess";
+ }
+ XMultiComponentFactory xMCF = m_xComponentContext.getServiceManager();
+ Object oDefaultProvider = xMCF.createInstanceWithContext("com.sun.star.configuration.DefaultProvider", this.getXComponentContext());
+ XMultiServiceFactory xMSFCfg = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, oDefaultProvider);
+ Object oAccess = xMSFCfg.createInstanceWithArguments(sAccess, new Object[]{new NamedValue("nodepath", _sNodePath)});
+ xNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, oAccess);
+ } catch (com.sun.star.uno.Exception e) {
+ }
+ return xNameAccess;
+ }
+
+
+ }
+
+// end of inner class
+
+
+ /**
+ * Gives a factory for creating the service.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return returns a <code>XSingleComponentFactory</code> for creating
+ * the component
+ * @param sImplName the name of the implementation for which a
+ * service is desired
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static XSingleComponentFactory __getComponentFactory( String sImplName )
+ {
+ XSingleComponentFactory xFactory = null;
+ if ( sImplName.equals( _Inspector.class.getName() ) )
+ xFactory = Factory.createComponentFactory(_Inspector.class, _Inspector.getServiceNames());
+ if ( xFactory == null )
+ xFactory = InspectorAddon.__getComponentFactory(sImplName);
+ return xFactory;
+ }
+
+ /**
+ * Writes the service information into the given registry key.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return returns true if the operation succeeded
+ * @param regKey the registryKey
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
+ return (Factory.writeRegistryServiceInfo(_Inspector.class.getName(), _Inspector.getServiceNames(), regKey)
+ && InspectorAddon.__writeRegistryServiceInfo(regKey));
+ }
+}
+
diff --git a/odk/examples/java/Inspector/InspectorAddon.java b/odk/examples/java/Inspector/InspectorAddon.java
new file mode 100644
index 000000000000..92c8ab5c43fa
--- /dev/null
+++ b/odk/examples/java/Inspector/InspectorAddon.java
@@ -0,0 +1,228 @@
+/*************************************************************************
+ *
+ * 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.beans.XPropertySet;
+import com.sun.star.frame.DispatchDescriptor;
+import com.sun.star.frame.FrameSearchFlag;
+import com.sun.star.frame.XController;
+import com.sun.star.frame.XDesktop;
+import com.sun.star.frame.XDispatch;
+import com.sun.star.frame.XDispatchProvider;
+import com.sun.star.frame.XFrame;
+import com.sun.star.frame.XModel;
+import com.sun.star.frame.XStatusListener;
+import com.sun.star.lang.XInitialization;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.lang.XSingleComponentFactory;
+import com.sun.star.lib.uno.helper.WeakBase;
+import com.sun.star.registry.XRegistryKey;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.lib.uno.helper.Factory;
+
+
+public class InspectorAddon {
+ /** This class implements the component. At least the interfaces XServiceInfo,
+ * XTypeProvider, and XInitialization should be provided by the service.
+ */
+ public static class InspectorAddonImpl extends WeakBase implements XDispatchProvider, XInitialization, XServiceInfo {
+ private static XModel xModel = null;
+ org.openoffice.XInstanceInspector xInstInspector = null;
+// Dispatcher oDispatcher = null;
+ XFrame m_xFrame = null;
+
+ private static final String[] m_serviceNames = {
+ "org.openoffice.InstanceInspectorAddon",
+ "com.sun.star.frame.ProtocolHandler" };
+ ;
+ private XComponentContext m_xContext = null;
+
+ /** Creates a new instance of InspectorAddon */
+ public InspectorAddonImpl(XComponentContext _xContext) {
+ m_xContext = _xContext;
+ }
+
+ public XDispatch queryDispatch( /*IN*/com.sun.star.util.URL aURL, /*IN*/String sTargetFrameName, /*IN*/int iSearchFlags ) {
+ XDispatch xRet = null;
+ if ( aURL.Protocol.compareTo("org.openoffice.Office.addon.Inspector:") == 0 ) {
+ if ( aURL.Path.compareTo( "inspect" ) == 0 ){
+ // Todo: Check if the frame is already administered (use hashtable)
+ xRet = new Dispatcher(m_xFrame);
+ }
+ }
+ return xRet;
+ }
+
+
+ public XDispatch[] queryDispatches( /*IN*/DispatchDescriptor[] seqDescripts ) {
+ int nCount = seqDescripts.length;
+ XDispatch[] lDispatcher = new XDispatch[nCount];
+ for( int i=0; i<nCount; ++i )
+ lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL, seqDescripts[i].FrameName, seqDescripts[i].SearchFlags );
+ return lDispatcher;
+ }
+
+
+ public void initialize( Object[] object ) throws com.sun.star.uno.Exception {
+ if ( object.length > 0 ){
+ m_xFrame = ( XFrame ) UnoRuntime.queryInterface(XFrame.class, object[ 0 ] );
+ }
+ }
+
+ public class Dispatcher implements XDispatch{
+ private XFrame m_xFrame = null;
+ private XModel xModel = null;
+
+ public Dispatcher(XFrame _xFrame){
+ m_xFrame = _xFrame;
+ if (m_xFrame != null){
+ XController xController = m_xFrame.getController();
+ if (xController != null){
+ xModel = xController.getModel();
+ }
+ }
+ }
+
+ // XDispatch
+ public void dispatch( /*IN*/com.sun.star.util.URL _aURL, /*IN*/com.sun.star.beans.PropertyValue[] aArguments ) {
+ try{
+ if ( _aURL.Protocol.compareTo("org.openoffice.Office.addon.Inspector:") == 0 ){
+ if ( _aURL.Path.equals("inspect")){
+ Object oUnoInspectObject = xModel;
+ com.sun.star.lang.XMultiComponentFactory xMCF = m_xContext.getServiceManager();
+ if (xInstInspector == null){
+ Object obj= xMCF.createInstanceWithContext("org.openoffice.InstanceInspector", m_xContext);
+ xInstInspector = (org.openoffice.XInstanceInspector)UnoRuntime.queryInterface(org.openoffice.XInstanceInspector.class, obj);
+ }
+ if ((m_xFrame == null) || (xModel == null)){
+ Object oDesktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", m_xContext);
+ m_xFrame = (XFrame) UnoRuntime.queryInterface(XFrame.class, oDesktop);
+ oUnoInspectObject = m_xFrame;
+ }
+ XPropertySet xFramePropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, m_xFrame);
+ String sTitle = (String) xFramePropertySet.getPropertyValue("Title");
+ String[] sTitleList = sTitle.split(" - ");
+ if (sTitleList.length > 0){
+ sTitle = sTitleList[0];
+ }
+ xInstInspector.inspect(oUnoInspectObject, sTitle);
+ }
+ }
+ } catch( Exception e ) {
+ System.err.println( e + e.getMessage());
+ e.printStackTrace(System.out);
+ }}
+
+ public void addStatusListener( /*IN*/XStatusListener xControl, /*IN*/com.sun.star.util.URL aURL ) {
+ }
+
+ public void removeStatusListener( /*IN*/XStatusListener xControl, /*IN*/com.sun.star.util.URL aURL ) {
+ }
+
+
+ }
+
+
+ public static String[] getServiceNames() {
+ return m_serviceNames;
+ }
+
+ // Implement the interface XServiceInfo
+ /** Get all supported service names.
+ * @return Supported service names.
+ */
+ public String[] getSupportedServiceNames() {
+ return getServiceNames();
+ }
+
+ // Implement the interface XServiceInfo
+ /** Test, if the given service will be supported.
+ * @param sService Service name.
+ * @return Return true, if the service will be supported.
+ */
+ public boolean supportsService( String sServiceName ) {
+ int len = m_serviceNames.length;
+
+ for( int i=0; i < len; i++) {
+ if ( sServiceName.equals( m_serviceNames[i] ) )
+ return true;
+ }
+
+ return false;
+ }
+
+ // Implement the interface XServiceInfo
+ /** Get the implementation name of the component.
+ * @return Implementation name of the component.
+ */
+ public String getImplementationName() {
+ return InspectorAddonImpl.class.getName();
+ }
+
+ }
+
+
+ /**
+ * Gives a factory for creating the service.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return returns a <code>XSingleComponentFactory</code> for creating
+ * the component
+ * @param sImplName the name of the implementation for which a
+ * service is desired
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static XSingleComponentFactory __getComponentFactory( String sImplName )
+ {
+ XSingleComponentFactory xFactory = null;
+ if ( sImplName.equals( InspectorAddonImpl.class.getName() ) )
+ xFactory = Factory.createComponentFactory(InspectorAddonImpl.class, InspectorAddonImpl.getServiceNames());
+ return xFactory;
+ }
+
+ /**
+ * Writes the service information into the given registry key.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return returns true if the operation succeeded
+ * @param regKey the registryKey
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
+ return Factory.writeRegistryServiceInfo(InspectorAddonImpl.class.getName(), InspectorAddonImpl.getServiceNames(), regKey);
+ }
+
+// __create( XComponentContext ){
+//
+// }
+}
diff --git a/odk/examples/java/Inspector/InspectorPane.java b/odk/examples/java/Inspector/InspectorPane.java
new file mode 100644
index 000000000000..14d144781943
--- /dev/null
+++ b/odk/examples/java/Inspector/InspectorPane.java
@@ -0,0 +1,629 @@
+/*************************************************************************
+ *
+ * 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.lib.uno.helper.WeakBase;
+import com.sun.star.uno.Any;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.uno.TypeClass;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.Type;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.beans.XIntrospectionAccess;
+import com.sun.star.beans.Property;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.reflection.XIdlMethod;
+import javax.swing.tree.ExpandVetoException;
+import org.openoffice.XInstanceInspector;
+import javax.swing.tree.TreePath;
+import javax.swing.event.TreeWillExpandListener;
+
+ public class InspectorPane extends WeakBase implements XInstanceInspector{ //, XServiceInfo
+ private XIdlMethod[] xIdlMethods;
+ private Property[] aProperties;
+ private boolean bIncludeContent = false;
+ private XComponentContext m_xComponentContext;
+ private XDialogProvider m_xDialogProvider;
+ private Introspector m_oIntrospector = null;
+ private SourceCodeGenerator m_oSourceCodeGenerator;
+ private XTreeControlProvider m_xTreeControlProvider;
+ private String sTitle = "";
+
+
+ /** The constructor of the inner class has a XMultiServiceFactory parameter.
+ * @param xMultiServiceFactory XMultiServiceFactory
+ */
+ public InspectorPane(XComponentContext _xComponentContext, XDialogProvider _xDialogProvider, XTreeControlProvider _xTreeControlProvider, int _nLanguage) {
+ m_xComponentContext = _xComponentContext;
+ m_xTreeControlProvider = _xTreeControlProvider;
+ m_xDialogProvider = _xDialogProvider;
+ m_oIntrospector = Introspector.getIntrospector(m_xComponentContext);
+ m_oSourceCodeGenerator = new SourceCodeGenerator(_nLanguage);
+ _xTreeControlProvider.addInspectorPane(this);
+ }
+
+
+ private void setMaximumOfProgressBar(Object _oUnoObject){
+ int nMaxValue = 0;
+ xIdlMethods = m_oIntrospector.getMethods(_oUnoObject);
+ aProperties = m_oIntrospector.getProperties(_oUnoObject);
+ }
+
+
+ /** Inspect the given object for methods, properties, interfaces, and
+ * services.
+ * @param a The object to inspect
+ * @throws RuntimeException If
+ */
+ public void inspect(java.lang.Object _oUserDefinedObject, String _sTitle) throws com.sun.star.uno.RuntimeException {
+ try {
+ Object oContainer = m_xTreeControlProvider.inspect(_oUserDefinedObject, _sTitle);
+ m_xDialogProvider.addInspectorPage(getTitle(), oContainer);
+ }
+ catch( Exception exception ) {
+ exception.printStackTrace(System.out);
+ }}
+
+
+ public void setTitle(String _sTitle){
+ if (_sTitle != null){
+ if (_sTitle.length() > 0){
+ sTitle = _sTitle;
+ }
+ }
+ }
+
+
+ public String getTitle(){
+ return sTitle;
+ }
+
+
+
+ private Type[] getTypes(Object _oUnoObject){
+ Type[] aTypes = null;
+ if (m_oIntrospector.isArray(_oUnoObject)){
+ aTypes = (Type[])_oUnoObject;
+ }
+ else{
+ aTypes = m_oIntrospector.getInterfaces(_oUnoObject);
+ }
+ return aTypes;
+ }
+
+
+ private Object invoke(XUnoMethodNode _oUnoMethodNode){
+ try{
+ String sParamValueDescription = "";
+ Object oUnoReturnObject = _oUnoMethodNode.invoke();
+ boolean bHasParameters = _oUnoMethodNode.hasParameters();
+ boolean bIsPrimitive = _oUnoMethodNode.isPrimitive();
+ if (bHasParameters){
+ sParamValueDescription = " (" + m_oSourceCodeGenerator.getMethodParameterValueDescription(_oUnoMethodNode, _oUnoMethodNode.getLastParameterObjects(), true) + ")";
+ }
+ if (oUnoReturnObject != null ){
+ String sNodeDescription = "";
+ XUnoNode oUnoNode = null;
+ if (_oUnoMethodNode.getXIdlMethod().getReturnType().getTypeClass().getValue() == TypeClass.VOID_value){
+ sNodeDescription += _oUnoMethodNode.getXIdlMethod().getReturnType().getName() + " " + _oUnoMethodNode.getXIdlMethod().getName() + sParamValueDescription;
+ _oUnoMethodNode.setLabel(sNodeDescription);
+ m_xTreeControlProvider.nodeChanged(_oUnoMethodNode);
+ }
+ else if (bHasParameters || !bIsPrimitive){
+ if (bIsPrimitive){
+ sNodeDescription += m_oSourceCodeGenerator.getStringValueOfObject(oUnoReturnObject, _oUnoMethodNode.getTypeClass());
+ }
+ else{
+ Any aReturnObject = Any.complete(oUnoReturnObject);
+ String sShortClassName = m_oIntrospector.getShortClassName(aReturnObject.getType().getTypeName());
+ sNodeDescription += m_oSourceCodeGenerator.getVariableNameforUnoObject(sShortClassName);
+ }
+ if (m_oIntrospector.isArray(oUnoReturnObject)){
+ if (m_oIntrospector.isUnoTypeObject(oUnoReturnObject)){
+ oUnoNode = addUnoFacetteNode(_oUnoMethodNode, XUnoFacetteNode.SINTERFACEDESCRIPTION, _oUnoMethodNode.getUnoObject());
+ }
+ else if(m_oIntrospector.isUnoPropertyTypeObject(oUnoReturnObject)){
+ oUnoNode = addUnoFacetteNode(_oUnoMethodNode, XUnoFacetteNode.SPROPERTYINFODESCRIPTION, oUnoReturnObject);
+ }
+ else if(m_oIntrospector.isUnoPropertyValueTypeObject(oUnoReturnObject)){
+ oUnoNode = addUnoFacetteNode(_oUnoMethodNode, XUnoFacetteNode.SPROPERTYVALUEDESCRIPTION, oUnoReturnObject);
+ }
+ }
+ if (oUnoNode == null){
+ if (bHasParameters){
+ sNodeDescription += sParamValueDescription;
+ }
+ oUnoNode = addUnoNode(null, oUnoReturnObject, sNodeDescription);
+ if (bHasParameters){
+ oUnoNode.setParameterObjects(_oUnoMethodNode.getLastParameterObjects());
+ }
+ }
+ if (oUnoNode != null){
+ oUnoNode.setFoldable(!bIsPrimitive);
+ _oUnoMethodNode.setFoldable(false);
+ _oUnoMethodNode.addChildNode(oUnoNode);
+ m_xTreeControlProvider.nodeInserted(_oUnoMethodNode, oUnoNode, _oUnoMethodNode.getChildCount()-1);
+ }
+ }
+ else{
+ if (bIsPrimitive){
+ sNodeDescription = _oUnoMethodNode.getStandardMethodDescription() + "=" + UnoMethodNode.getDisplayValueOfPrimitiveType(oUnoReturnObject);
+ _oUnoMethodNode.setLabel(sNodeDescription);
+ m_xTreeControlProvider.nodeChanged(_oUnoMethodNode);
+ }
+ }
+ }
+ // ReturnObject of method node == null..
+ else{
+ if (!bHasParameters){
+ _oUnoMethodNode.setLabel(_oUnoMethodNode.getLabel() + " = null");
+ }
+ else{
+ _oUnoMethodNode.setLabel(_oUnoMethodNode.getXIdlMethod().getName() + sParamValueDescription + " = null");
+ }
+ m_xTreeControlProvider.nodeChanged(_oUnoMethodNode);
+ }
+ return oUnoReturnObject;
+ }catch(Exception exception ) {
+ return null;
+ }}
+
+
+ public void invokeSelectedMethodNode(){
+ XTreePathProvider xTreePathProvider = m_xTreeControlProvider.getSelectedPath();
+ XUnoNode oUnoNode = xTreePathProvider.getLastPathComponent();
+ if (oUnoNode instanceof XUnoMethodNode){
+ invoke((XUnoMethodNode) oUnoNode);
+ m_xTreeControlProvider.expandPath(xTreePathProvider);
+ }
+ }
+
+
+ public void addSourceCodeOfSelectedNode(){
+ XTreePathProvider oTreePathProvider = m_xTreeControlProvider.getSelectedPath();
+ XUnoNode oUnoNode = oTreePathProvider.getLastPathComponent();
+ if (oUnoNode instanceof XUnoMethodNode){
+ XUnoMethodNode oUnoMethodNode = (XUnoMethodNode) oUnoNode;
+ if (!oUnoMethodNode.isInvoked() && oUnoMethodNode.isInvokable()){
+ invoke(oUnoMethodNode);
+ }
+ }
+ String sSourceCode = m_oSourceCodeGenerator.addSourceCodeOfUnoObject(oTreePathProvider, true, true, true);
+ m_xTreeControlProvider.setSourceCode(sSourceCode);
+ }
+
+
+ public void convertCompleteSourceCode(int _nLanguage){
+ String sSourceCode = m_oSourceCodeGenerator.convertAllUnoObjects(_nLanguage);
+ m_xTreeControlProvider.setSourceCode(sSourceCode);
+ }
+
+ protected XUnoNode getSelectedNode(){
+ return m_xTreeControlProvider.getSelectedNode();
+ }
+
+
+ // add the object to the hashtable for a possible access in the tree
+ private XUnoFacetteNode addUnoFacetteNode(XUnoNode _oParentNode, String _sNodeDescription, Object _oUnoObject){
+ return m_xTreeControlProvider.addUnoFacetteNode( _oParentNode, _sNodeDescription, _oUnoObject);
+ }
+
+
+ private XUnoMethodNode addMethodNode(Object _objectElement, XIdlMethod _xIdlMethod){
+ return m_xTreeControlProvider.addMethodNode(_objectElement, _xIdlMethod);
+ }
+
+
+
+ public void addMethodsToTreeNode(XUnoNode _oGrandParentNode, Object _oUnoParentObject, XIdlMethod[] _xIdlMethods){
+ if (this.m_oIntrospector.isValid(_xIdlMethods)){
+ for ( int n = 0; n < _xIdlMethods.length; n++ ) {
+ XIdlMethod xIdlMethod = _xIdlMethods[n];
+ if (!xIdlMethod.getDeclaringClass().getName().equals("com.sun.star.uno.XInterface")){
+ XUnoMethodNode oChildNode = addMethodNode(_oUnoParentObject, xIdlMethod);
+ if (oChildNode != null){
+ _oGrandParentNode.addChildNode(oChildNode);
+ }
+ }
+ }
+ }
+ }
+
+
+ private void addFacetteNodesToTreeNode(XUnoNode _oParentNode, Object _oUnoObject){
+ if (m_oIntrospector.hasMethods(_oUnoObject)){
+ XUnoFacetteNode oUnoFacetteNode = addUnoFacetteNode(_oParentNode, XUnoFacetteNode.SMETHODDESCRIPTION, _oUnoObject);
+ }
+ if (m_oIntrospector.hasProperties(_oUnoObject)){
+ XUnoFacetteNode oUnoFacetteNode = addUnoFacetteNode(_oParentNode, XUnoFacetteNode.SPROPERTYDESCRIPTION, _oUnoObject);
+ }
+ if (m_oIntrospector.hasInterfaces(_oUnoObject)){
+ XUnoFacetteNode oUnoFacetteNode = addUnoFacetteNode(_oParentNode, XUnoFacetteNode.SINTERFACEDESCRIPTION, _oUnoObject);
+ }
+ if (m_oIntrospector.isContainer(_oUnoObject)){
+ XUnoFacetteNode oUnoFacetteNode = addUnoFacetteNode(_oParentNode, XUnoFacetteNode.SCONTAINERDESCRIPTION, _oUnoObject);
+ }
+ if (m_oIntrospector.hasSupportedServices(_oUnoObject)){
+ XUnoFacetteNode oUnoFacetteNode = addUnoFacetteNode(_oParentNode, XUnoFacetteNode.SSERVICEDESCRIPTION, _oUnoObject);
+ }
+ }
+
+
+ private void addInterfacesToTreeNode(XUnoNode _oGrandParentNode, Object _oUnoParentObject, Type[] _aTypes) {
+ try {
+ if (_oUnoParentObject != null){
+ for ( int m = 0; m < _aTypes.length; m++ ) {
+ addUnoNode(_oGrandParentNode, _oUnoParentObject, _aTypes[m]);
+ }
+ }
+ }
+ catch( Exception exception ) {
+ exception.printStackTrace(System.out);
+ }}
+
+
+ // add all services for the given object to the tree under the node parent
+ private void addServicesToTreeNode(XUnoNode _oGrandParentNode, Object _oUnoObject) {
+ try{
+ XServiceInfo xServiceInfo = ( XServiceInfo ) UnoRuntime.queryInterface( XServiceInfo.class, _oUnoObject );
+ if ( xServiceInfo != null ){
+ String[] sSupportedServiceNames = xServiceInfo.getSupportedServiceNames();
+ for ( int m = 0; m < sSupportedServiceNames.length; m++ ) {
+ String sServiceName = sSupportedServiceNames[m];
+ if (sServiceName.length() > 0){
+ XUnoNode oUnoNode = addUnoNode(_oGrandParentNode, _oUnoObject, sSupportedServiceNames[m]);
+ oUnoNode.setNodeType(XUnoNode.nSERVICE);
+ }
+ }
+ }
+ }
+ catch(Exception exception) {
+ exception.printStackTrace(System.out);
+ }}
+
+
+ private void addPropertiesAndInterfacesOfService(XUnoNode _oUnoServiceNode){
+ String sServiceName = _oUnoServiceNode.getClassName();
+ Object oUnoObject = _oUnoServiceNode.getUnoObject();
+ addInterfacesToTreeNode(_oUnoServiceNode, oUnoObject, m_oIntrospector.getInterfaces(oUnoObject, sServiceName));
+ addPropertiesToTreeNode(_oUnoServiceNode, oUnoObject, m_oIntrospector.getProperties(oUnoObject, sServiceName));
+ }
+
+
+ private void addPropertiesToTreeNode(XUnoNode _oParentNode, Object _oUnoParentObject, Property[] _aProperties) {
+ try {
+ if (_aProperties.length > 0){
+ for ( int n = 0; n < _aProperties.length; n++ ){
+ Property aProperty = _aProperties[n];
+ XIntrospectionAccess xIntrospectionAccess = m_oIntrospector.getXIntrospectionAccess(_oUnoParentObject);
+ XPropertySet xPropertySet = ( XPropertySet ) UnoRuntime.queryInterface( XPropertySet.class, xIntrospectionAccess.queryAdapter(new Type( XPropertySet.class)));
+ if (xPropertySet != null) {
+ if (xPropertySet.getPropertySetInfo().hasPropertyByName(aProperty.Name)){
+ Object objectElement = xPropertySet.getPropertyValue(aProperty.Name);
+ if (objectElement != null) {
+ XUnoNode oChildNode = m_xTreeControlProvider.addUnoPropertyNode(_oUnoParentObject, aProperty, objectElement);
+ if (oChildNode != null){
+ _oParentNode.addChildNode(oChildNode);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ catch(Exception exception) {
+ exception.printStackTrace(System.out);
+ }}
+
+
+ public void addContainerElementsToTreeNode(XUnoNode _oParentNode, Object _oUnoParentObject){
+ Object[] oUnoContainerElements = m_oIntrospector.getUnoObjectsOfContainer(_oUnoParentObject);
+ if (m_oIntrospector.isValid(oUnoContainerElements)){
+ if (oUnoContainerElements.length > 0){
+ for (int i=0; i< oUnoContainerElements.length; i++){
+ XUnoNode oChildNode = addUnoNode(_oParentNode, oUnoContainerElements[i], UnoNode.getNodeDescription(oUnoContainerElements[i]));
+ m_xTreeControlProvider.nodeInserted(_oParentNode, oChildNode, _oParentNode.getChildCount()-1);
+ }
+ }
+ }
+ }
+
+
+ private XUnoNode addUnoNode(XUnoNode _oParentNode, Object _oUnoObject, String _sLabel ){
+ XUnoNode oUnoNode = this.m_xTreeControlProvider.addUnoNode(_oUnoObject);
+ oUnoNode.setLabel(_sLabel);
+ if (_oParentNode != null){
+ _oParentNode.addChildNode(oUnoNode);
+ }
+ setNodeFoldable(oUnoNode, _oUnoObject);
+ return oUnoNode;
+ }
+
+
+ private void setNodeFoldable(XUnoNode _oUnoNode, Object _oUnoObject){
+ if (_oUnoObject != null){
+ if (!m_oIntrospector.isObjectPrimitive(_oUnoObject)){
+ _oUnoNode.setFoldable(true);
+ }
+ }
+ }
+
+
+ private XUnoNode addUnoNode(XUnoNode _oParentNode, Object _oUnoObject, Type _aType){
+ XUnoNode oUnoNode = this.m_xTreeControlProvider.addUnoNode(_oUnoObject, _aType);
+ if (_oParentNode != null){
+ _oParentNode.addChildNode(oUnoNode);
+ }
+ setNodeFoldable(oUnoNode, _oUnoObject);
+ return oUnoNode;
+ }
+
+
+ private void addPropertySetInfoNodesToTreeNode(XUnoFacetteNode _oUnoFacetteNode, Object _oUnoObject){
+ if (_oUnoObject.getClass().isArray()){
+ Object[] object = ( Object[] ) _oUnoObject;
+ for ( int i = 0; i < object.length; i++ ) {
+ Property aProperty = (Property) object[i];
+ XUnoPropertyNode oUnoPropertyNode = m_xTreeControlProvider.addUnoPropertyNode(_oUnoObject, aProperty);
+ oUnoPropertyNode.setLabel(XUnoFacetteNode.SPROPERTYINFODESCRIPTION + " (" + aProperty.Name + ")");
+ oUnoPropertyNode.setFoldable(true);
+ _oUnoFacetteNode.addChildNode(oUnoPropertyNode);
+ }
+ }
+ }
+
+ private void addPrimitiveValuesToTreeNode(XUnoNode _oUnoNode, Object _oUnoObject){
+ if (_oUnoObject.getClass().isArray()){
+ if (!_oUnoObject.getClass().getComponentType().isPrimitive()){
+ Object[] object = ( Object[] ) _oUnoObject;
+ for ( int i = 0; i < object.length; i++ ) {
+ if (m_oIntrospector.isObjectPrimitive(object[i])){
+ XUnoNode oChildNode = addUnoNode(_oUnoNode, null, UnoNode.getNodeDescription(object[i]));
+ }
+ }
+ }
+ else{
+ String[] sDisplayValues = UnoNode.getDisplayValuesofPrimitiveArray(_oUnoObject);
+ for ( int i = 0; i < sDisplayValues.length; i++ ) {
+ XUnoNode oUnoNode = addUnoNode(_oUnoNode, null, sDisplayValues[i]);
+ }
+ }
+ }
+ }
+
+
+ private void addPropertySetInfoSubNodes(XUnoPropertyNode _oUnoPropertyNode){
+ Property aProperty = _oUnoPropertyNode.getProperty();
+ _oUnoPropertyNode.addChildNode(m_xTreeControlProvider.addUnoPropertyNodeWithName(aProperty));
+ _oUnoPropertyNode.addChildNode(m_xTreeControlProvider.addUnoPropertyNodeWithType(aProperty));
+ _oUnoPropertyNode.addChildNode(m_xTreeControlProvider.addUnoPropertyNodeWithHandle(aProperty));
+ _oUnoPropertyNode.addChildNode(m_xTreeControlProvider.addUnoPropertyNodeWithAttributesDescription(aProperty));
+ }
+
+
+ private void addPropertyValueSubNodes(XUnoFacetteNode _oUnoFacetteNode, Object _oUnoObject){
+ if (m_oIntrospector.isUnoPropertyValueTypeObject(_oUnoObject)){
+ Object[] object = ( Object[] ) _oUnoObject;
+ for ( int i = 0; i < object.length; i++ ) {
+ String sObjectClassName = object[i].getClass().getName();
+ if (sObjectClassName.equals("com.sun.star.beans.PropertyValue")){
+ XUnoNode oChildNode = null;
+ PropertyValue aPropertyValue = (PropertyValue) object[i];
+ if (! m_oIntrospector.isObjectPrimitive(aPropertyValue.Value)){
+ oChildNode = m_xTreeControlProvider.addUnoPropertyNode(_oUnoObject, aPropertyValue, _oUnoObject);
+ }
+ else{
+ oChildNode = addUnoNode(null, aPropertyValue.Value, UnoPropertyNode.getStandardPropertyValueDescription(aPropertyValue));
+ }
+ if (oChildNode != null){
+ _oUnoFacetteNode.addChildNode(oChildNode);
+ }
+ }
+ }
+ }
+ }
+
+
+ public boolean expandNode(XUnoNode _oUnoNode, XTreePathProvider _xTreePathProvider){
+ if ( _oUnoNode != null ) {
+ _oUnoNode.setFoldable(false);
+ if (m_xTreeControlProvider.isMethodNode(_oUnoNode)){
+ XUnoMethodNode oUnoMethodNode = (XUnoMethodNode) _oUnoNode;
+ if (!oUnoMethodNode.isInvoked()){
+ Object oUnoReturnObject = invoke((XUnoMethodNode) _oUnoNode);
+ if (oUnoReturnObject == null){
+ _oUnoNode.setFoldable(true);
+ return false;
+ }
+ }
+ }
+ else if (m_xTreeControlProvider.isPropertyNode(_oUnoNode)){
+ XUnoPropertyNode oUnoPropertyNode = (XUnoPropertyNode) _oUnoNode;
+ Object oUnoObject = oUnoPropertyNode.getUnoReturnObject();
+ if (oUnoPropertyNode.getPropertyNodeType() == XUnoPropertyNode.nPROPERTYSETINFOTYPE){
+ addPropertySetInfoSubNodes(oUnoPropertyNode);
+ }
+ else{
+ //TOOD this code is redundant!!!
+ if ( oUnoObject.getClass().isArray()){
+ // TOODO probably we should provid a possibility to insert also non-primitive nodes
+ addPrimitiveValuesToTreeNode(oUnoPropertyNode, oUnoObject);
+ }
+ else{
+ addFacetteNodesToTreeNode(oUnoPropertyNode, oUnoObject);
+ }
+ }
+ }
+ else if (m_xTreeControlProvider.isFacetteNode(_oUnoNode)){
+ XUnoFacetteNode oUnoFacetteNode = (XUnoFacetteNode) _oUnoNode;
+ Object oUnoObject = _oUnoNode.getUnoObject();
+ if (oUnoFacetteNode.isMethodNode()){
+ addMethodsToTreeNode(oUnoFacetteNode, oUnoObject, m_oIntrospector.getMethods(oUnoObject));
+ }
+ if (oUnoFacetteNode.isPropertyNode()){
+ String sNodeDescription = oUnoFacetteNode.getLabel();
+ // TODO: it's very dangerous to distinguishe the different UnoFacetteNodes only by the nodedescription
+ if (sNodeDescription.startsWith(XUnoFacetteNode.SPROPERTYINFODESCRIPTION)){
+ addPropertySetInfoNodesToTreeNode(oUnoFacetteNode, oUnoObject);
+ }
+ else if (sNodeDescription.startsWith(XUnoFacetteNode.SPROPERTYVALUEDESCRIPTION)){
+ addPropertyValueSubNodes(oUnoFacetteNode, oUnoObject);
+ }
+ else{
+ addPropertiesToTreeNode(oUnoFacetteNode, oUnoObject, m_oIntrospector.getProperties(oUnoObject));
+ }
+ }
+ if (oUnoFacetteNode.isServiceNode()){
+ addServicesToTreeNode(oUnoFacetteNode, oUnoObject);
+ }
+ if (oUnoFacetteNode.isInterfaceNode()){
+ addInterfacesToTreeNode(oUnoFacetteNode, oUnoObject, getTypes(oUnoObject));
+ }
+ if (oUnoFacetteNode.isContainerNode()){
+ addContainerElementsToTreeNode(oUnoFacetteNode, oUnoObject);
+ }
+ }
+ else if (_oUnoNode.getNodeType() == XUnoNode.nSERVICE){
+ addPropertiesAndInterfacesOfService(_oUnoNode);
+ }
+ else if (_oUnoNode.getNodeType() == XUnoNode.nINTERFACE){
+ Type aType = _oUnoNode.getUnoType();
+ if (aType != null){
+ addMethodsToTreeNode(_oUnoNode, _oUnoNode.getUnoObject(), m_oIntrospector.getMethodsOfInterface(aType));
+ }
+ }
+ else if (_oUnoNode.getNodeType() == XUnoNode.nOTHERS){
+ Object oUnoObject = _oUnoNode.getUnoObject();
+ if ( oUnoObject.getClass().isArray()){
+ // TOODO probably we should provid a possibility to insert also non-primitive nodes
+ addPrimitiveValuesToTreeNode(_oUnoNode, oUnoObject);
+ }
+ else{
+ addFacetteNodesToTreeNode(_oUnoNode, oUnoObject);
+ }
+ }
+ }
+ return true;
+ }
+
+
+
+ public void applyFilter(XUnoFacetteNode _oUnoFacetteNode, String _sFilter){
+ for (int i = 0; i < _oUnoFacetteNode.getChildCount(); i++){
+ XUnoNode oUnoNode = _oUnoFacetteNode.getChild(i);
+ boolean bIsVisible = oUnoNode.isFilterApplicable(_sFilter);
+ m_xTreeControlProvider.setNodeVisible(oUnoNode, bIsVisible);
+ }
+ _oUnoFacetteNode.setFilter(_sFilter);
+ }
+
+
+ /** In opposition to 'getUnoObjectOfTreeNode' this method inspects the passed node if it represents a Uno object
+ * If not it returns null
+ *
+ */
+ private Object getUnoObjectOfExplicitTreeNode(XTreePathProvider _xTreePathProvider){
+ XUnoNode oUnoNode = _xTreePathProvider.getLastPathComponent();
+ if (oUnoNode != null){
+ return oUnoNode.getUnoObject();
+ }
+ return null;
+ }
+
+
+ public String getFilter(XUnoNode _oUnoNode){
+ String sFilter = "";
+ if (_oUnoNode != null){
+ XUnoNode oUnoNode = _oUnoNode;
+ boolean bleaveLoop = false;
+ do{
+ if (m_xTreeControlProvider.isFacetteNode(oUnoNode)){
+ sFilter = ((XUnoFacetteNode) oUnoNode).getFilter();
+ bleaveLoop = true;
+ }
+ else{
+ if (oUnoNode.getParentNode() != null){
+ oUnoNode = oUnoNode.getParentNode();
+ }
+ else{
+ bleaveLoop = true;
+ }
+ }
+ } while(!bleaveLoop);
+ }
+ return sFilter;
+ }
+
+
+ /** In opposition to 'getUnoObjectOfexplictTreeNode' this method inspects the passed node if it represents a Uno object
+ * if not it keeps checking all ancestors until it finds a Uno representation
+ */
+ private Object getUnoObjectOfTreeNode(XTreePathProvider _xTreePathProvider){
+ XTreePathProvider xTreePathProvider = _xTreePathProvider;
+ HideableMutableTreeNode oNode = null;
+ Object oUnoObject = null;
+ while (xTreePathProvider != null){
+ oUnoObject = getUnoObjectOfExplicitTreeNode(xTreePathProvider);
+ if (oUnoObject != null){
+ if (oUnoObject instanceof String){
+ }
+ else{
+ if (!m_oIntrospector.isUnoTypeObject(oUnoObject)){
+ return oUnoObject;
+ }
+ }
+ }
+ xTreePathProvider = xTreePathProvider.getParentPath();
+ }
+ return null;
+ }
+
+
+ public void showPopUpMenu(Object _invoker, int x, int y) throws ClassCastException{
+ XUnoNode oUnoNode = getSelectedNode();
+ boolean bdoEnableInvoke = oUnoNode instanceof XUnoMethodNode;
+// boolean bdoEnableSourceCodeGeneration = true;
+ if (bdoEnableInvoke){
+ XUnoMethodNode oUnoMethodNode = (XUnoMethodNode) oUnoNode;
+ bdoEnableInvoke = oUnoMethodNode.isInvokable();
+// bdoEnableSourceCodeGeneration = bdoEnableInvoke;
+ }
+ m_xDialogProvider.enablePopupMenuItem(XDialogProvider.SINVOKE, bdoEnableInvoke);
+// m_xDialogProvider.enablePopupMenuItem(XDialogProvider.SADDTOSOURCECODE, bdoEnableSourceCodeGeneration);
+ m_xDialogProvider.showPopUpMenu(_invoker, x, y);
+ }
+}
+ \ No newline at end of file
diff --git a/odk/examples/java/Inspector/InstanceInspector.idl b/odk/examples/java/Inspector/InstanceInspector.idl
new file mode 100644
index 000000000000..8de7e920acd8
--- /dev/null
+++ b/odk/examples/java/Inspector/InstanceInspector.idl
@@ -0,0 +1,52 @@
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+
+#ifndef INCLUDED_ORG_OPENOFFICE_INSTANCEINSPECTOR_IDL
+#define INCLUDED_ORG_OPENOFFICE_INSTANCEINSPECTOR_IDL
+
+#include <XInstanceInspector.idl>
+
+
+module org { module openoffice {
+
+ /**
+ * This service describes an instance inspector which can inspect
+ * UNO objects and provides information about the implemented
+ * interfaces, the supported services and properties of this onject.
+ */
+ service InstanceInspector: XInstanceInspector;
+
+}; };
+
+#endif
diff --git a/odk/examples/java/Inspector/InstanceInspectorTest.odt b/odk/examples/java/Inspector/InstanceInspectorTest.odt
new file mode 100644
index 000000000000..74cde4e68e21
--- /dev/null
+++ b/odk/examples/java/Inspector/InstanceInspectorTest.odt
Binary files differ
diff --git a/odk/examples/java/Inspector/Introspector.java b/odk/examples/java/Inspector/Introspector.java
new file mode 100644
index 000000000000..cdae4f4d88b2
--- /dev/null
+++ b/odk/examples/java/Inspector/Introspector.java
@@ -0,0 +1,667 @@
+/*************************************************************************
+ *
+ * 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.beans.IllegalTypeException;
+import com.sun.star.beans.MethodConcept;
+import com.sun.star.beans.NamedValue;
+import com.sun.star.beans.Property;
+import com.sun.star.beans.XIntrospection;
+import com.sun.star.beans.XIntrospectionAccess;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.bridge.UnoUrlResolver;
+import com.sun.star.bridge.XUnoUrlResolver;
+import com.sun.star.comp.helper.Bootstrap;
+import com.sun.star.container.XEnumeration;
+import com.sun.star.container.XEnumerationAccess;
+import com.sun.star.container.XHierarchicalNameAccess;
+import com.sun.star.container.XIndexAccess;
+import com.sun.star.container.XNameAccess;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.lang.XTypeProvider;
+import com.sun.star.lib.uno.helper.WeakBase;
+import com.sun.star.reflection.ParamInfo;
+import com.sun.star.reflection.TypeDescriptionSearchDepth;
+import com.sun.star.reflection.XConstantTypeDescription;
+import com.sun.star.reflection.XConstantsTypeDescription;
+import com.sun.star.reflection.XIdlClass;
+import com.sun.star.reflection.XIdlField;
+import com.sun.star.reflection.XIdlMethod;
+import com.sun.star.reflection.XIdlReflection;
+import com.sun.star.reflection.XIndirectTypeDescription;
+import com.sun.star.reflection.XInterfaceTypeDescription;
+import com.sun.star.reflection.XInterfaceTypeDescription2;
+import com.sun.star.reflection.XPropertyTypeDescription;
+import com.sun.star.reflection.XServiceTypeDescription;
+import com.sun.star.reflection.XTypeDescription;
+import com.sun.star.reflection.XTypeDescriptionEnumeration;
+import com.sun.star.reflection.XTypeDescriptionEnumerationAccess;
+import com.sun.star.ucb.CommandAbortedException;
+import com.sun.star.ucb.XSimpleFileAccess;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.uno.Type;
+import com.sun.star.uno.TypeClass;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.util.URL;
+import java.util.List;
+import java.util.Vector;
+import javax.swing.JOptionPane;
+
+public class Introspector extends WeakBase{
+
+ private XIntrospection m_xIntrospection;
+ private XMultiComponentFactory m_xMultiComponentFactory;
+ private XComponentContext m_xComponentContext;
+ private XTypeDescriptionEnumerationAccess m_xTDEnumerationAccess;
+ private static XComponentContext xOfficeComponentContext;
+ private XIdlReflection mxIdlReflection;
+ private URL openHyperlink;
+ private static Introspector m_oIntrospector = null;
+ private XSimpleFileAccess xSimpleFileAccess = null;
+
+
+
+ public static Introspector getIntrospector(){
+ if (m_oIntrospector == null){
+ throw new NullPointerException();
+ }
+ else{
+ return m_oIntrospector;
+ }
+ }
+
+ public static Introspector getIntrospector(XComponentContext _xComponentContext){
+ if (m_oIntrospector == null){
+ m_oIntrospector = new Introspector(_xComponentContext);
+ }
+ return m_oIntrospector;
+ }
+
+
+ /** Creates a new instance of Introspection */
+ private Introspector(XComponentContext _xComponentContext) {
+ try{
+ m_xComponentContext = _xComponentContext;
+ m_xMultiComponentFactory = m_xComponentContext.getServiceManager();
+ Object o = m_xMultiComponentFactory.createInstanceWithContext("com.sun.star.beans.Introspection", m_xComponentContext);
+ m_xIntrospection = ( XIntrospection ) UnoRuntime.queryInterface(XIntrospection.class, o );
+ Object oCoreReflection = getXMultiComponentFactory().createInstanceWithContext("com.sun.star.reflection.CoreReflection", getXComponentContext());
+ mxIdlReflection = (XIdlReflection) UnoRuntime.queryInterface(XIdlReflection.class, oCoreReflection);
+ initTypeDescriptionManager();
+ }
+ catch( Exception exception ) {
+ System.err.println( exception );
+ }}
+
+
+ protected XComponentContext getXComponentContext(){
+ return m_xComponentContext;
+ }
+
+
+ protected XMultiComponentFactory getXMultiComponentFactory(){
+ return m_xMultiComponentFactory;
+ }
+
+
+ protected XIntrospectionAccess getXIntrospectionAccess(Object _oUnoComponent){
+ return m_xIntrospection.inspect(_oUnoComponent);
+ }
+
+
+ public boolean isContainer(Object _oUnoObject){
+ boolean bIsContainer = false;
+ try {
+ XIntrospectionAccess xIntrospectionAccessObject = getXIntrospectionAccess(_oUnoObject);
+ if (xIntrospectionAccessObject != null){
+ XEnumerationAccess xEnumerationAccess = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, xIntrospectionAccessObject.queryAdapter( new Type( XEnumerationAccess.class ) ) );
+ if (xEnumerationAccess != null){
+ XEnumeration xEnumeration = xEnumerationAccess.createEnumeration();
+ bIsContainer = xEnumeration.hasMoreElements();
+ }
+ if (!bIsContainer){
+ XIndexAccess xIndexAccess = (XIndexAccess) UnoRuntime.queryInterface( XIndexAccess.class, xIntrospectionAccessObject.queryAdapter(new Type( XIndexAccess.class )));
+ if (xIndexAccess != null){
+ bIsContainer = (xIndexAccess.getCount() > 0);
+ }
+ }
+ }
+ } catch (IllegalTypeException ex) {
+ ex.printStackTrace(System.out);
+ }
+ return bIsContainer;
+ }
+
+
+ // add all containers for the given object to the tree under the node
+ // parent
+ public Object[] getUnoObjectsOfContainer(Object _oUnoParentObject) {
+ Object[] oRetComponents = null;
+ try {
+ Vector oRetComponentsVector = new Vector();
+ XIntrospectionAccess xIntrospectionAccessObject = getXIntrospectionAccess(_oUnoParentObject);
+ if ( xIntrospectionAccessObject != null ) {
+ XEnumerationAccess xEnumerationAccess = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, xIntrospectionAccessObject.queryAdapter( new Type( XEnumerationAccess.class ) ) );
+ if ( xEnumerationAccess != null ) {
+ XEnumeration xEnumeration = xEnumerationAccess.createEnumeration();
+ while ( xEnumeration.hasMoreElements() ) {
+ oRetComponentsVector.add(xEnumeration.nextElement());
+ }
+ }
+ XIndexAccess xIndexAccess = (XIndexAccess) UnoRuntime.queryInterface( XIndexAccess.class, xIntrospectionAccessObject.queryAdapter(new Type( XIndexAccess.class )));
+ if ( xIndexAccess != null ) {
+ XIdlMethod mMethod = xIntrospectionAccessObject.getMethod("getByIndex", com.sun.star.beans.MethodConcept.INDEXCONTAINER);
+ for ( int i = 0; i < xIndexAccess.getCount(); i++ ) {
+ Object[][] aParamInfo = new Object[1][1];
+ aParamInfo[0] = new Integer[] { new Integer(i) };
+ oRetComponentsVector.add(mMethod.invoke(_oUnoParentObject, aParamInfo));
+ }
+ }
+ }
+ if (oRetComponentsVector != null){
+ oRetComponents = new Object[oRetComponentsVector.size()];
+ oRetComponentsVector.toArray(oRetComponents);
+ }
+ }
+ catch( Exception exception ) {
+ System.err.println( exception );
+ }
+ return oRetComponents;
+ }
+
+
+ protected XIdlMethod[] getMethodsOfInterface(Type _aType){
+ try{
+ XIdlClass xIdlClass = mxIdlReflection.forName(_aType.getTypeName());
+ return xIdlClass.getMethods();
+ }
+ catch( Exception e ) {
+ System.err.println( e );
+ return null;
+ }}
+
+
+ protected XIdlField[] getFieldsOfType(Type _aType){
+ try{
+ XIdlClass xIdlClass = mxIdlReflection.forName(_aType.getTypeName());
+ return xIdlClass.getFields();
+ }
+ catch( Exception e ) {
+ System.err.println( e );
+ return null;
+ }}
+
+
+ public boolean hasMethods(Object _oUnoObject){
+ boolean bHasMethods = (getMethods(_oUnoObject).length > 0);
+ return bHasMethods;
+ }
+
+
+ // add all methods for the given object to the tree under the node parent
+ public XIdlMethod[] getMethods(Object _oUnoParentObject) {
+ try {
+ XIntrospectionAccess xIntrospectionAccess = getXIntrospectionAccess(_oUnoParentObject);
+ if (xIntrospectionAccess != null){
+ XIdlMethod[] xIdlMethods = xIntrospectionAccess.getMethods(MethodConcept.ALL - MethodConcept.DANGEROUS);
+ return xIdlMethods;
+ }
+ }
+ catch( Exception e ) {
+ System.err.println( e );
+ }
+ return null;
+ }
+
+
+ public boolean hasProperties(Object _oUnoObject){
+ boolean bHasProperties = (getProperties(_oUnoObject).length > 0);
+ return bHasProperties;
+ }
+
+
+ protected Property[] getProperties( Object _oUnoParentObject){
+ try {
+ XIntrospectionAccess xIntrospectionAccess = getXIntrospectionAccess(_oUnoParentObject);
+ if (xIntrospectionAccess != null){
+ Property[] aProperties = xIntrospectionAccess.getProperties(com.sun.star.beans.PropertyConcept.ATTRIBUTES + com.sun.star.beans.PropertyConcept.PROPERTYSET);
+ return aProperties;
+ }
+ }
+ catch( Exception e ) {
+ System.err.println( e );
+ }
+ return null;
+ }
+
+
+ protected Property[] getProperties(Object _oUnoObject, String _sServiceName){
+ Property[] aProperties = getProperties(_oUnoObject);
+ List aListOfProperties = java.util.Arrays.asList(aProperties);
+ Vector aPropertiesVector = new Vector(aListOfProperties);
+ if (aProperties != null){
+ XPropertyTypeDescription[] xPropertyTypeDescriptions = getPropertyDescriptionsOfService(_sServiceName);
+ for (int i = aProperties.length - 1; i >= 0; i--){
+ if (!hasByName(xPropertyTypeDescriptions, _sServiceName + "." + aProperties[i].Name)){
+ aPropertiesVector.remove(i);
+ }
+ }
+ }
+ Property[] aRetProperties = new Property[aPropertiesVector.size()];
+ aPropertiesVector.toArray(aRetProperties);
+ return aRetProperties;
+ }
+
+
+ protected Type[] getInterfaces(Object _oUnoObject, String _sServiceName){
+ Type[] aTypes = getInterfaces(_oUnoObject);
+ List aListOfTypes = java.util.Arrays.asList(aTypes);
+ Vector aTypesVector = new Vector(aListOfTypes);
+ if (aTypes != null){
+ XInterfaceTypeDescription[] xInterfaceTypeDescriptions = getInterfaceDescriptionsOfService(_sServiceName);
+ for (int i = aTypes.length - 1; i >= 0; i--){
+ if (!hasByName(xInterfaceTypeDescriptions, aTypes[i].getTypeName())){
+ aTypesVector.remove(i);
+ }
+ }
+ }
+ Type[] aRetTypes = new Type[aTypesVector.size()];
+ aTypesVector.toArray(aRetTypes);
+ return aRetTypes;
+ }
+
+
+ public boolean hasInterfaces(Object _oUnoObject){
+ return (getInterfaces(_oUnoObject).length > 0);
+ }
+
+
+ protected Type[] getInterfaces(Object _oUnoParentObject){
+ Type[] aTypes = new Type[]{};
+ XTypeProvider xTypeProvider = ( XTypeProvider ) UnoRuntime.queryInterface( XTypeProvider.class, _oUnoParentObject);
+ if ( xTypeProvider != null ) {
+ aTypes = xTypeProvider.getTypes();
+ }
+ return aTypes;
+ }
+
+
+
+ public static boolean isObjectSequence(Object _oUnoObject){
+ Type aType = AnyConverter.getType(_oUnoObject);
+ return aType.getTypeClass().getValue() == TypeClass.SEQUENCE_value;
+ }
+
+
+ public static boolean isObjectPrimitive(Object _oUnoObject){
+ boolean breturn = false;
+ if (_oUnoObject != null){
+ Type aType = AnyConverter.getType(_oUnoObject);
+ breturn = isObjectPrimitive(_oUnoObject.getClass(), aType.getTypeClass());
+ }
+ return breturn;
+ }
+
+
+ public static boolean isPrimitive(TypeClass _typeClass){
+ return (( _typeClass == TypeClass.BOOLEAN )
+ || ( _typeClass == TypeClass.BYTE )
+ || ( _typeClass == TypeClass.CHAR )
+ || ( _typeClass == TypeClass.DOUBLE )
+ || ( _typeClass == TypeClass.ENUM )
+ || ( _typeClass == TypeClass.FLOAT )
+ || ( _typeClass == TypeClass.HYPER )
+ || ( _typeClass == TypeClass.LONG )
+ || ( _typeClass == TypeClass.SHORT )
+ || ( _typeClass == TypeClass.STRING )
+ || ( _typeClass == TypeClass.UNSIGNED_HYPER )
+ || ( _typeClass == TypeClass.UNSIGNED_LONG )
+ || ( _typeClass == TypeClass.UNSIGNED_SHORT ));
+ }
+
+ public static boolean isObjectPrimitive(Class _oUnoClass, TypeClass _typeClass){
+ return !( ( !_oUnoClass.isPrimitive() ) && ( _typeClass != TypeClass.ARRAY )
+ && ( _typeClass != TypeClass.BOOLEAN )
+ && ( _typeClass != TypeClass.BYTE )
+ && ( _typeClass != TypeClass.CHAR )
+ && ( _typeClass != TypeClass.DOUBLE )
+ && ( _typeClass != TypeClass.ENUM )
+ && ( _typeClass != TypeClass.FLOAT )
+ && ( _typeClass != TypeClass.HYPER )
+ && ( _typeClass != TypeClass.LONG )
+ && ( _typeClass != TypeClass.SHORT )
+ && ( _typeClass != TypeClass.STRING )
+ && ( _typeClass != TypeClass.UNSIGNED_HYPER )
+ && ( _typeClass != TypeClass.UNSIGNED_LONG )
+ && ( _typeClass != TypeClass.UNSIGNED_SHORT ));
+ }
+
+
+ protected void initTypeDescriptionManager() {
+ try {
+ Object oTypeDescriptionManager = getXComponentContext().getValueByName("/singletons/com.sun.star.reflection.theTypeDescriptionManager");
+ m_xTDEnumerationAccess = (XTypeDescriptionEnumerationAccess) UnoRuntime.queryInterface(XTypeDescriptionEnumerationAccess.class, oTypeDescriptionManager);
+ } catch ( java.lang.Exception e) {
+ System.out.println(System.out);
+ }}
+
+
+ protected XTypeDescriptionEnumerationAccess getXTypeDescriptionEnumerationAccess(){
+ return m_xTDEnumerationAccess;
+ }
+
+
+ protected XConstantTypeDescription[] getFieldsOfConstantGroup(String _sTypeClass){
+ XConstantTypeDescription[] xConstantTypeDescriptions = null;
+ try {
+ TypeClass[] eTypeClasses = new com.sun.star.uno.TypeClass[1];
+ eTypeClasses[0] = com.sun.star.uno.TypeClass.CONSTANTS;
+ XTypeDescriptionEnumeration xTDEnumeration = m_xTDEnumerationAccess.createTypeDescriptionEnumeration(getModuleName(_sTypeClass), eTypeClasses, TypeDescriptionSearchDepth.INFINITE);
+ while (xTDEnumeration.hasMoreElements()) {
+ XTypeDescription xTD = xTDEnumeration.nextTypeDescription();
+ if (xTD.getName().equals(_sTypeClass)){
+ XConstantsTypeDescription xConstantsTypeDescription = (XConstantsTypeDescription) UnoRuntime.queryInterface(XConstantsTypeDescription.class, xTD);
+ xConstantTypeDescriptions = xConstantsTypeDescription.getConstants();
+ }
+ String sName = xTD.getName();
+ }
+ return xConstantTypeDescriptions;
+ } catch ( java.lang.Exception e) {
+ System.out.println(System.out);
+ }
+ return null;
+ }
+
+ private XServiceTypeDescription getServiceTypeDescription(String _sServiceName, TypeClass _eTypeClass){
+ try{
+ if (_sServiceName.length() > 0){
+ TypeClass[] eTypeClasses = new com.sun.star.uno.TypeClass[2];
+ eTypeClasses[0] = com.sun.star.uno.TypeClass.SERVICE;
+ eTypeClasses[1] = _eTypeClass;
+ XTypeDescriptionEnumeration xTDEnumeration = getXTypeDescriptionEnumerationAccess().createTypeDescriptionEnumeration(Introspector.getModuleName(_sServiceName), eTypeClasses, TypeDescriptionSearchDepth.INFINITE);
+ while (xTDEnumeration.hasMoreElements()) {
+ XTypeDescription xTD = xTDEnumeration.nextTypeDescription();
+ if (xTD.getName().equals(_sServiceName)){
+ XServiceTypeDescription xServiceTypeDescription = (XServiceTypeDescription) UnoRuntime.queryInterface(XServiceTypeDescription.class, xTD);
+ return xServiceTypeDescription;
+ }
+ }
+ }
+ return null;
+ } catch (Exception ex) {
+ ex.printStackTrace(System.out);
+ return null;
+ }}
+
+
+ public XPropertyTypeDescription[] getPropertyDescriptionsOfService(String _sServiceName){
+ try {
+ XServiceTypeDescription xServiceTypeDescription = getServiceTypeDescription(_sServiceName, com.sun.star.uno.TypeClass.PROPERTY);
+ if (xServiceTypeDescription != null){
+ XPropertyTypeDescription[] xPropertyTypeDescriptions = xServiceTypeDescription.getProperties();
+ return xPropertyTypeDescriptions;
+ }
+ } catch ( java.lang.Exception e) {
+ System.out.println(System.out);
+ }
+ return new XPropertyTypeDescription[]{};
+ }
+
+
+ public XTypeDescription getReferencedType(String _sTypeName){
+ XTypeDescription xTypeDescription = null;
+ try{
+ XHierarchicalNameAccess xHierarchicalNameAccess = (XHierarchicalNameAccess) UnoRuntime.queryInterface(XHierarchicalNameAccess.class, m_xTDEnumerationAccess);
+ if (xHierarchicalNameAccess != null){
+ if (xHierarchicalNameAccess.hasByHierarchicalName(_sTypeName)){
+ XIndirectTypeDescription xIndirectTypeDescription = (XIndirectTypeDescription) UnoRuntime.queryInterface(XIndirectTypeDescription.class, xHierarchicalNameAccess.getByHierarchicalName(_sTypeName));
+ if (xIndirectTypeDescription != null){
+ xTypeDescription = xIndirectTypeDescription.getReferencedType();
+ }
+ }
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace(System.out);
+ }
+ return xTypeDescription;
+ }
+
+
+ public XInterfaceTypeDescription[] getInterfaceDescriptionsOfService(String _sServiceName){
+ try {
+ XServiceTypeDescription xServiceTypeDescription = getServiceTypeDescription(_sServiceName, com.sun.star.uno.TypeClass.INTERFACE);
+ if (xServiceTypeDescription != null){
+ XInterfaceTypeDescription[] xInterfaceTypeDescriptions = xServiceTypeDescription.getMandatoryInterfaces();
+ return xInterfaceTypeDescriptions;
+ }
+ } catch ( java.lang.Exception e) {
+ System.out.println(System.out);
+ }
+ return new XInterfaceTypeDescription[]{};
+ }
+
+
+ static boolean hasByName(XTypeDescription[] _xTypeDescriptions, String _sTypeName){
+ for (int i = 0; i < _xTypeDescriptions.length; i++){
+ if (_xTypeDescriptions[i].getName().equals(_sTypeName)){
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ public static String getModuleName(String _sTypeClass){
+ int nlastindex = _sTypeClass.lastIndexOf(".");
+ if (nlastindex > -1){
+ return _sTypeClass.substring(0, nlastindex);
+ }
+ else{
+ return "";
+ }
+ }
+
+
+ public static String getShortClassName(String _sClassName){
+ String sShortClassName = _sClassName;
+ int nindex = _sClassName.lastIndexOf(".");
+ if ((nindex < _sClassName.length()) && nindex > -1){
+ sShortClassName = _sClassName.substring(nindex + 1);
+ }
+ return sShortClassName;
+ }
+
+
+
+ public static boolean isUnoTypeObject(Object _oUnoObject){
+ return isOfUnoType(_oUnoObject, "com.sun.star.uno.Type");
+ }
+
+
+ public static boolean isUnoPropertyTypeObject(Object _oUnoObject){
+ return isOfUnoType(_oUnoObject, "com.sun.star.beans.Property");
+ }
+
+
+ public static boolean isUnoPropertyValueTypeObject(Object _oUnoObject){
+ return isOfUnoType(_oUnoObject, "com.sun.star.beans.PropertyValue");
+ }
+
+
+ public static boolean isOfUnoType(Object _oUnoObject, String _sTypeName){
+ boolean bIsUnoObject = false;
+ if (_oUnoObject != null){
+ if (_oUnoObject.getClass().isArray()){
+ if (!_oUnoObject.getClass().getComponentType().isPrimitive()){
+ Object[] oUnoArray = (Object[]) _oUnoObject;
+ if (oUnoArray.length > 0){
+ bIsUnoObject = ( oUnoArray[0].getClass().getName().equals(_sTypeName));
+ }
+ }
+ }
+ }
+ else{
+ bIsUnoObject = (_oUnoObject.getClass().getName().equals(_sTypeName));
+ }
+ return bIsUnoObject;
+ }
+
+
+ public String getConstantDisplayString(int _nValue, XConstantTypeDescription[] _xConstantTypeDescription, String _sDisplayString){
+ String sPrefix = "";
+ int[] nbits = new int[_xConstantTypeDescription.length];
+ for (int i = 0; i < _xConstantTypeDescription.length; i++){
+ short nConstantValue = ((Short) _xConstantTypeDescription[i].getConstantValue()).shortValue();
+ nbits[i] = _nValue & nConstantValue;
+ if (nbits[i] > 0){
+ _sDisplayString += sPrefix + _xConstantTypeDescription[i].getName();
+ sPrefix = " + ";
+ }
+ }
+ return _sDisplayString;
+ }
+
+
+ public static boolean isValid(Object[] _oObject){
+ if (_oObject != null){
+ if (_oObject.length > 0){
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ public static boolean isValid(Object _oObject){
+ if (_oObject != null){
+ return (!AnyConverter.isVoid(_oObject));
+ }
+ return false;
+ }
+
+
+ public static boolean isArray(Object _oObject){
+ return _oObject.getClass().isArray();
+ }
+
+
+ public boolean hasSupportedServices(Object _oUnoObject){
+ boolean bHasSupportedServices = false;
+ XServiceInfo xServiceInfo = ( XServiceInfo ) UnoRuntime.queryInterface( XServiceInfo.class, _oUnoObject);
+ if ( xServiceInfo != null ){
+ String[] sSupportedServiceNames = xServiceInfo.getSupportedServiceNames();
+ bHasSupportedServices = sSupportedServiceNames.length > 0;
+ }
+ return bHasSupportedServices;
+ }
+
+
+ public Object getValueOfText(TypeClass aTypeClass, String sText){
+ Object oReturn = null;
+ switch (aTypeClass.getValue()){
+ case TypeClass.CHAR_value:
+ break;
+ case TypeClass.DOUBLE_value:
+ oReturn = Double.valueOf(sText);
+ break;
+ case TypeClass.ENUM_value:
+ break;
+ case TypeClass.FLOAT_value:
+ oReturn = Float.valueOf(sText);
+ break;
+ case TypeClass.HYPER_value:
+ oReturn = Long.valueOf(sText);
+ break;
+ case TypeClass.LONG_value:
+ oReturn = Integer.valueOf(sText);
+ break;
+ case TypeClass.SHORT_value:
+ oReturn = Byte.valueOf(sText);
+ break;
+ case TypeClass.STRING_value:
+ oReturn = sText;
+ break;
+ case TypeClass.UNSIGNED_HYPER_value:
+ oReturn = Long.valueOf(sText);
+ break;
+ case TypeClass.UNSIGNED_LONG_value:
+ oReturn = Integer.valueOf(sText);
+ break;
+ case TypeClass.UNSIGNED_SHORT_value:
+ oReturn = Byte.valueOf(sText);
+ break;
+ default:
+ }
+ return oReturn;
+ }
+
+
+ public XSimpleFileAccess getXSimpleFileAccess(){
+ try {
+ if (xSimpleFileAccess == null){
+ Object oSimpleFileAccess = m_xComponentContext.getServiceManager().createInstanceWithContext("com.sun.star.ucb.SimpleFileAccess", m_xComponentContext);
+ xSimpleFileAccess = (XSimpleFileAccess) com.sun.star.uno.UnoRuntime.queryInterface(XSimpleFileAccess.class, oSimpleFileAccess);
+ }
+ return xSimpleFileAccess;
+ } catch (com.sun.star.uno.Exception ex) {
+ ex.printStackTrace(System.out);
+ return null;
+ }}
+
+
+ public boolean isValidSDKInstallationPath(String _sSDKInstallationPath){
+ boolean bIsValid = false;
+ try {
+ String sIDLFolder = Introspector.addToPath(_sSDKInstallationPath, Inspector.sIDLDOCUMENTSUBFOLDER);
+ String sIndexFile = Introspector.addToPath(_sSDKInstallationPath, "index.html");
+ if (getXSimpleFileAccess() != null){
+ bIsValid = (getXSimpleFileAccess().exists(sIDLFolder) && getXSimpleFileAccess().exists(sIndexFile));
+ }
+ } catch (com.sun.star.uno.Exception ex) {
+ ex.printStackTrace(System.out);
+ }
+ return bIsValid;
+ }
+
+
+ public static String addToPath(String _sPath, String _sSubPath){
+ if (!_sPath.endsWith("/")){
+ _sPath += "/";
+ }
+ return _sPath + _sSubPath;
+ }
+
+}
diff --git a/odk/examples/java/Inspector/Makefile b/odk/examples/java/Inspector/Makefile
new file mode 100644
index 000000000000..2b0c1b376c48
--- /dev/null
+++ b/odk/examples/java/Inspector/Makefile
@@ -0,0 +1,195 @@
+#*************************************************************************
+#
+# 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 InstanceInspector component example of the SDK.
+
+PRJ=../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+
+# we use the sample directory name dor separating this example
+# from others in the output directory
+SAMPLE_NAME=InstanceInspector
+SAMPLE_CLASS_OUT=$(OUT_CLASS)/$(SAMPLE_NAME)
+SAMPLE_GEN_OUT=$(OUT_MISC)/$(SAMPLE_NAME)
+
+# some special macro names for separating the component jar stuff
+COMP_NAME=Inspector
+COMP_CLASS_OUT=$(SAMPLE_CLASS_OUT)/$(COMP_NAME)
+COMP_GEN_OUT=$(SAMPLE_GEN_OUT)/$(COMP_NAME)
+COMP_RDB_NAME=$(COMP_NAME).uno.rdb
+COMP_RDB=$(COMP_GEN_OUT)/$(COMP_RDB_NAME)
+COMP_PACKAGE=$(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT)
+COMP_PACKAGE_URL=$(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)")
+COMP_JAR_NAME=$(COMP_NAME).uno.jar
+COMP_JAR=$(SAMPLE_CLASS_OUT)/$(COMP_JAR_NAME)
+COMP_JAR_MANIFEST=$(COMP_GEN_OUT)/$(COMP_NAME).uno.Manifest
+COMP_UNOPKG_MANIFEST = $(COMP_GEN_OUT)/META-INF/manifest.xml
+COMP_REGISTERFLAG=$(COMP_GEN_OUT)$(PS)java_$(COMP_NAME)_register_component.flag
+
+IDLFILES = InstanceInspector.idl \
+ XInstanceInspector.idl
+
+# normally the idl file should be stored in a directory tree fitting the
+# module structure, for the example we know the module structure
+PACKAGE = org/openoffice
+
+COMP_JAVAFILES = XDialogProvider.java XTreeControlProvider.java XTreePathProvider.java MethodParametersDialog.java HideableMutableTreeNode.java HideableTreeModel.java Introspector.java XUnoNode.java SwingUnoNode.java UnoNode.java XUnoMethodNode.java SwingUnoMethodNode.java UnoMethodNode.java XUnoPropertyNode.java SwingUnoPropertyNode.java UnoPropertyNode.java XUnoFacetteNode.java SwingUnoFacetteNode.java TDocSupplier.java UnoTreeRenderer.java InspectorAddon.java XLanguageSourceCodeGenerator.java SourceCodeGenerator.java InspectorPane.java SwingDialogProvider.java SwingTreeControlProvider.java SwingTreePathProvider.java Inspector.java
+COMP_CLASSFILES = $(patsubst %.java,$(COMP_CLASS_OUT)/%.class,$(COMP_JAVAFILES))
+
+GEN_CLASSFILES = $(patsubst %.idl,$(SAMPLE_CLASS_OUT)/$(PACKAGE)/%.class,$(IDLFILES))
+GEN_TYPELIST = $(subst /,.,$(patsubst %.idl,-T$(PACKAGE)/% ,$(IDLFILES)))
+GEN_URDFILES = $(patsubst %.idl,$(SAMPLE_GEN_OUT)/%.urd,$(IDLFILES))
+
+# the generated types are necessary for the component jar
+GEN_CLASSFILENAMES = $(subst $(SAMPLE_CLASS_OUT)/,,$(GEN_CLASSFILES))
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(SAMPLE_CLASS_OUT)\
+ $(PATH_SEPARATOR)$(COMP_CLASS_OUT))
+
+COMP_IMAGE_FILES= images/containers_16.png \
+ images/content_16.png \
+ images/interfaces_16.png \
+ images/methods_16.png \
+ images/properties_16.png \
+ images/services_16.png
+
+# Targets
+.PHONY: ALL
+ALL : JavaInspectorExample
+
+include $(SETTINGS)/stdtarget.mk
+
+# rule for component manifest file
+$(COMP_GEN_OUT)/%.Manifest :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo RegistrationClassName: $(basename $(basename $(@F)))> $@
+
+# rule for compiling the IDL files
+$(SAMPLE_GEN_OUT)/%.urd : %.idl
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(IDLC) -C -I. -I$(IDL_DIR) -O$(SAMPLE_GEN_OUT) $<
+
+# rule for creating the component rdb file
+$(COMP_GEN_OUT)/%.rdb : $(GEN_URDFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(REGMERGE) $@ /UCR $(GEN_URDFILES)
+
+# rule for creating IDL dependent class files
+$(GEN_CLASSFILES) : $(COMP_RDB)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(JAVAMAKER) -BUCR -nD $(GEN_TYPELIST) -O$(SAMPLE_CLASS_OUT) $(COMP_RDB) -X$(URE_TYPES) -X$(OFFICE_TYPES)
+
+# component as well as application are dependent from the generated types
+# rule for component class files
+$(COMP_CLASS_OUT)/%.class : %.java $(GEN_CLASSFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -sourcepath . -d $(COMP_CLASS_OUT) $<
+
+# rule for component jar file
+$(COMP_JAR) : $(COMP_JAR_MANIFEST) $(COMP_CLASSFILES) $(COMP_IMAGE_FILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAR) cvfm $@ $< -C $(COMP_CLASS_OUT) .
+ +cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_JAR) uvf $(@F) $(GEN_CLASSFILENAMES)
+ +$(SDK_JAR) uvf $@ $(COMP_IMAGE_FILES)
+
+# rule for component package manifest
+$(COMP_GEN_OUT)/%/manifest.xml :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
+ @echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@
+ @echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)Addons.xcu$(QM)"/$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)ProtocolHandler.xcu$(QM)"/$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-schema$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)ObjectInspector.xcs$(QM)"/$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)ObjectInspector.xcu$(QM)"/$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-typelibrary;type=RDB$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(SAMPLE_GEN_OUT)/,,$(@D))).uno.rdb$(QM)"/$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-component;type=Java$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(SAMPLE_GEN_OUT)/,,$(@D))).uno.jar$(QM)"/$(CSEP) >> $@
+ @echo $(OSEP)/manifest:manifest$(CSEP) >> $@
+
+# rule for component package file
+$(COMP_PACKAGE) : $(COMP_RDB) $(COMP_JAR) Addons.xcu ProtocolHandler.xcu ObjectInspector.xcu ObjectInspector.xcs $(COMP_UNOPKG_MANIFEST)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ cd $(subst /,$(PS),$(COMP_GEN_OUT)) && $(SDK_ZIP) ../../../bin/$(@F) $(COMP_RDB_NAME)
+
+ cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_ZIP) -u ../../bin/$(@F) $(COMP_JAR_NAME)
+ $(SDK_ZIP) -u $@ Addons.xcu ProtocolHandler.xcu ObjectInspector.xcu ObjectInspector.xcs
+ cd $(subst /,$(PS),$(COMP_GEN_OUT)) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
+
+$(COMP_REGISTERFLAG) : $(COMP_PACKAGE)
+ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES"
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(DEPLOYTOOL) $(COMP_PACKAGE_URL)
+ @echo flagged > $(subst /,$(PS),$@)
+else
+ @echo --------------------------------------------------------------------------------
+ @echo If you want to install your component automatically, please set the environment
+ @echo variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only
+ @echo possible if no office instance is running.
+ @echo --------------------------------------------------------------------------------
+endif
+
+JavaInspectorExample : $(COMP_REGISTERFLAG)
+ @echo --------------------------------------------------------------------------------
+ @echo The InstanceInspector component was installed if SDK_AUTO_DEPLOYMENT = YES.
+ @echo You can use this component inside your office installation, see the example
+ @echo document.
+ @echo -
+ @echo $(MAKE) InstanceInspectorTest.odt.load
+ @echo --------------------------------------------------------------------------------
+
+InstanceInspectorTest.odt.load : $(COMP_REGISTERFLAG)
+ "$(OFFICE_PROGRAM_PATH)$(PS)soffice" $(basename $@)
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_CLASS_OUT))
+ -$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_GEN_OUT))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL)))
diff --git a/odk/examples/java/Inspector/MethodParametersDialog.java b/odk/examples/java/Inspector/MethodParametersDialog.java
new file mode 100644
index 000000000000..803873703afb
--- /dev/null
+++ b/odk/examples/java/Inspector/MethodParametersDialog.java
@@ -0,0 +1,353 @@
+/*************************************************************************
+ *
+ * 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.reflection.ParamInfo;
+import com.sun.star.reflection.XIdlMethod;
+import com.sun.star.uno.TypeClass;
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.util.Vector;
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import javax.swing.JDialog;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+
+/**
+ * @author bc93774
+ */
+public class MethodParametersDialog extends JDialog{
+ private javax.swing.JPanel jPnlParamContainer;
+ private ParameterPanel[] m_aParameterPanels;
+ private ParamInfo[] m_aParamInfo;
+ private XIdlMethod m_xIdlMethod;
+ private ActionListener oActionListener;
+ private JButton jHelpButton = new JButton("Help");
+ private JButton jOKButton = new JButton("Ok");
+ private JButton jInvokeButton = new JButton("Invoke");
+ private Object m_oReturnButton = null;
+ private Object m_oUnoObject = null;
+ private Object m_oUnoReturnObject = null;
+ private JLabel jLblResult;
+ private JPanel jResultPanel = null;
+ private boolean bisdiposed = false;
+ private XUnoMethodNode m_xUnoMethodNode;
+
+
+ public MethodParametersDialog(XUnoMethodNode _xUnoMethodNode){
+ m_xUnoMethodNode = _xUnoMethodNode;
+ m_xIdlMethod = _xUnoMethodNode.getXIdlMethod();
+ m_aParamInfo = m_xIdlMethod.getParameterInfos();
+ m_oUnoObject = m_xUnoMethodNode.getUnoObject();
+ Object[] m_aParameterObjects = new Object[m_aParamInfo.length];
+ }
+
+
+ public Vector getMethodObjects() {
+ super.setModal(true);
+ addBorderPanel(getContentPane(), BorderLayout.NORTH);
+ addBorderPanel(getContentPane(), BorderLayout.WEST);
+ addBorderPanel(getContentPane(), BorderLayout.EAST);
+ jPnlParamContainer = new JPanel();
+ jPnlParamContainer.setLayout(new javax.swing.BoxLayout(jPnlParamContainer, javax.swing.BoxLayout.Y_AXIS));
+ JPanel jHeaderPanel = new JPanel(new BorderLayout());
+ JLabel jLblHeader = new JLabel();
+ jLblHeader.setText("Please insert the values for the given Parameters of the method '" + m_xIdlMethod.getName() + "'");
+ jHeaderPanel.add(jLblHeader,BorderLayout.WEST);
+ jPnlParamContainer.add(jHeaderPanel);
+
+ m_aParameterPanels = new ParameterPanel[m_aParamInfo.length];
+ for (int i = 0; i < m_aParameterPanels.length; i++){
+ m_aParameterPanels[i] = new ParameterPanel(m_aParamInfo[i]);
+ jPnlParamContainer.add(m_aParameterPanels[i]);
+ }
+ jPnlParamContainer.add(new ButtonPanel(), java.awt.BorderLayout.SOUTH);
+ getContentPane().add(jPnlParamContainer, java.awt.BorderLayout.CENTER);
+ pack();
+ setLocation(350, 350);
+ setTitle("Object Inspector - Parameter Values of '" + m_xIdlMethod.getName() + "'");
+ super.setFocusable(true);
+ super.setFocusableWindowState(true);
+ super.requestFocus();
+ m_aParameterPanels[0].getInputComponent().requestFocusInWindow();
+ setVisible(true);
+ if (!bisdiposed){
+ Vector aMethodObjects = new Vector();
+ for (int i = 0; i < m_aParameterPanels.length; i++){
+ aMethodObjects.add(m_aParameterPanels[i].getValue());
+ }
+ aMethodObjects.add(m_oUnoReturnObject);
+ return aMethodObjects;
+ }
+ else{
+ return null;
+ }
+ }
+
+
+ private void insertResultPanel(Exception _oInvocationException){
+ boolean bAddPanel = false;
+ if (jResultPanel == null){
+ jResultPanel = new JPanel(new BorderLayout());
+ bAddPanel = true;
+ }
+ else{
+ jResultPanel.removeAll();
+ }
+ jLblResult = new JLabel();
+ jLblResult.setMaximumSize(new java.awt.Dimension(getSize().width - 20, 57));
+ if (_oInvocationException != null){
+ jLblResult.setText("<html>Invoking the method cause an exception: <br>" + _oInvocationException.toString() + "</html>");
+ }
+ else{
+ jLblResult.setText("<html>The invocation of the method did not produce any error</html>");
+ }
+ jResultPanel.add(jLblResult,BorderLayout.WEST);
+ if (bAddPanel){
+ int nPos = jPnlParamContainer.getComponentCount() - 1;
+ jPnlParamContainer.add(jResultPanel, nPos);
+ }
+ super.pack();
+ super.validate();
+ }
+
+
+ private Object[] getParameterValues(){
+ Object[] oParameterValues = new Object[m_aParameterPanels.length];
+ for (int i = 0; i < m_aParameterPanels.length; i++){
+ oParameterValues[i] = m_aParameterPanels[i].getValue();
+ }
+ return oParameterValues;
+ }
+
+
+ private boolean isCompleted(){
+ boolean bIsCompleted = true;
+ for (int i = 0; i < m_aParameterPanels.length; i++){
+ bIsCompleted = m_aParameterPanels[i].isCompleted();
+ if (!bIsCompleted){
+ break;
+ }
+ }
+ return bIsCompleted;
+ }
+
+
+ private void addBorderPanel(java.awt.Container _jContainer, String _sLayout){
+ JPanel jPnlBorder = new JPanel();
+ jPnlBorder.setPreferredSize(new java.awt.Dimension(10, 10));
+ _jContainer.add(jPnlBorder, _sLayout);
+ }
+
+ private void addGapPanel(java.awt.Container _jContainer){
+ JPanel jPnlBorder = new JPanel();
+ jPnlBorder.setPreferredSize(new java.awt.Dimension(10, 10));
+ jPnlBorder.setMaximumSize(new java.awt.Dimension(10, 10));
+ _jContainer.add(jPnlBorder);
+ }
+
+
+ private class ParameterPanel extends JPanel{
+ private JComponent m_jComponent;
+ private TypeClass m_aTypeClass = null;
+
+ public ParameterPanel(ParamInfo _aParamInfo){
+ JTextField jTextField = new JTextField();
+ JComboBox jComboBox = new JComboBox();
+ m_aTypeClass = _aParamInfo.aType.getTypeClass();
+ setLayout(new java.awt.BorderLayout());
+ addBorderPanel(this, BorderLayout.NORTH);
+ addBorderPanel(this, BorderLayout.SOUTH);
+ JPanel jPnlCenter1 = new javax.swing.JPanel();
+ jPnlCenter1.setLayout(new javax.swing.BoxLayout(jPnlCenter1, javax.swing.BoxLayout.X_AXIS));
+ JLabel jLabel1 = new JLabel();
+ jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
+ String sParamText = _aParamInfo.aName + " (" + _aParamInfo.aType.getName() +")";
+ jLabel1.setText(sParamText);
+ jPnlCenter1.add(jLabel1);
+ addGapPanel(jPnlCenter1);
+ switch (m_aTypeClass.getValue()){
+ case TypeClass.BOOLEAN_value:
+ jComboBox.setBackground(new java.awt.Color(255, 255, 255));
+ jComboBox.setPreferredSize(new java.awt.Dimension(50, 19));
+ jComboBox.addItem("True");
+ jComboBox.addItem("False");
+ jComboBox.addKeyListener(new UpdateUIAdapter());
+ jPnlCenter1.add(jComboBox);
+ m_jComponent = jComboBox;
+ break;
+ case TypeClass.BYTE_value:
+ case TypeClass.CHAR_value:
+ case TypeClass.DOUBLE_value:
+ case TypeClass.ENUM_value:
+ case TypeClass.FLOAT_value:
+ case TypeClass.HYPER_value:
+ case TypeClass.LONG_value:
+ case TypeClass.SHORT_value:
+ case TypeClass.STRING_value:
+ case TypeClass.UNSIGNED_HYPER_value:
+ case TypeClass.UNSIGNED_LONG_value:
+ case TypeClass.UNSIGNED_SHORT_value:
+ jTextField.setPreferredSize(new java.awt.Dimension(50, 19));
+ jTextField.addKeyListener(new UpdateUIAdapter());
+ jPnlCenter1.add(jTextField);
+ m_jComponent = jTextField;
+ break;
+ default:
+ System.out.println("Type " + m_aTypeClass.getValue() + " not yet defined in 'ParameterPanel()'");
+ }
+ add(jPnlCenter1, java.awt.BorderLayout.CENTER);
+ JPanel jPnlEast = new JPanel();
+ add(jPnlEast, BorderLayout.EAST);
+ }
+
+ private JComponent getInputComponent(){
+ return m_jComponent;
+ }
+
+ public Object getValue(){
+ Object oReturn = null;
+ if (m_jComponent instanceof JTextField){
+ String sText = ((JTextField) m_jComponent).getText();
+ oReturn = Introspector.getIntrospector().getValueOfText(m_aTypeClass, sText);
+ }
+ else{
+ JComboBox jComboBox = ((JComboBox) m_jComponent);
+ oReturn = Boolean.valueOf(jComboBox.getSelectedIndex() == 0);
+ }
+ return oReturn;
+ }
+
+
+ public boolean isCompleted(){
+ if (m_jComponent instanceof JTextField){
+ return !((JTextField) m_jComponent).getText().equals("");
+ }
+ else{
+ return true;
+ }
+ }
+ }
+
+
+ private class UpdateUIAdapter extends KeyAdapter{
+ public void keyReleased(KeyEvent e){
+ boolean bIsCompleted = isCompleted();
+ jOKButton.setEnabled(bIsCompleted);
+ jInvokeButton.setEnabled(bIsCompleted);
+ if (jLblResult != null){
+ jLblResult.setEnabled(false);
+ jLblResult.invalidate();
+ }
+ }
+ }
+
+
+
+ private class ButtonPanel extends JPanel{
+ public ButtonPanel(){
+ super();
+ setLayout(new BorderLayout());
+ addBorderPanel(this, BorderLayout.NORTH);
+ addBorderPanel(this, BorderLayout.SOUTH);
+ JPanel jPnlBottomCenter = new JPanel();
+ jPnlBottomCenter.setLayout(new javax.swing.BoxLayout(jPnlBottomCenter, javax.swing.BoxLayout.X_AXIS));
+ jHelpButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ oActionListener.actionPerformed(e);
+ }
+ });
+ jHelpButton.setEnabled(oActionListener != null);
+ jPnlBottomCenter.add(jHelpButton);
+ addGapPanel(jPnlBottomCenter);
+ jOKButton.setEnabled(false);
+ jOKButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ invokeParameterMethod();
+ dispose();
+ }
+ });
+ jOKButton.setEnabled(isCompleted());
+ jInvokeButton.setEnabled(isCompleted());
+ jInvokeButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ invokeParameterMethod();
+ }
+ });
+
+ jPnlBottomCenter.add(jOKButton);
+ addGapPanel(jPnlBottomCenter);
+ jPnlBottomCenter.add(jInvokeButton);
+ addGapPanel(jPnlBottomCenter);
+ JButton jCancelButton = new JButton("Cancel");
+ jCancelButton.setFocusCycleRoot(true);
+ jCancelButton.setFocusPainted(true);
+ jCancelButton.addActionListener(new ActionListener(){
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ bisdiposed = true;
+ dispose();
+ }
+ });
+
+ jPnlBottomCenter.add(jCancelButton);
+ add(jPnlBottomCenter);
+ }
+ }
+
+
+ public void addActionListener(ActionListener _oActionListener){
+ oActionListener = _oActionListener;
+ jHelpButton.setEnabled(oActionListener != null);
+ }
+
+
+ public void invokeParameterMethod(){
+ try{
+ Object[] oParameters = getParameterValues();
+ m_oUnoReturnObject = m_xUnoMethodNode.invoke(m_oUnoObject, oParameters);
+ insertResultPanel(null);
+ } catch (Exception ex) {
+ insertResultPanel(ex);
+ m_oUnoReturnObject = null;
+ }}
+
+}
diff --git a/odk/examples/java/Inspector/ObjectInspector.xcs b/odk/examples/java/Inspector/ObjectInspector.xcs
new file mode 100755
index 000000000000..01a35ca111c0
--- /dev/null
+++ b/odk/examples/java/Inspector/ObjectInspector.xcs
@@ -0,0 +1,18 @@
+<?xml version='1.0' encoding='UTF-8'?>
+
+<oor:component-schema
+ xmlns:oor="http://openoffice.org/2001/registry"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ oor:name="ObjectInspector"
+ oor:package="org.openoffice.inspector"
+ xml:lang="en-US">
+ <info>
+ <desc>Configuration parameters for the Object Inspector.</desc>
+ </info>
+ <component>
+ <prop oor:name="Language" oor:type="xs:string"/>
+ <prop oor:name="SDKPath" oor:type="xs:string"/>
+ </component>
+
+</oor:component-schema>
diff --git a/odk/examples/java/Inspector/ObjectInspector.xcu b/odk/examples/java/Inspector/ObjectInspector.xcu
new file mode 100755
index 000000000000..93c2711f2ec8
--- /dev/null
+++ b/odk/examples/java/Inspector/ObjectInspector.xcu
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE local [
+ <!ENTITY ProductName "Object Inspector">
+ <!ENTITY ProductVersion "0.8">
+]>
+<oor:component-data
+ xmlns:oor="http://openoffice.org/2001/registry"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ oor:name="ObjectInspector" oor:package="org.openoffice.inspector">
+ <prop oor:name="Language" oor:type="xs:string">
+ <value>Java</value>
+ </prop>
+ <prop oor:name="SDKPath" oor:type="xs:string">
+ <value></value>
+ </prop>
+
+</oor:component-data>
+
diff --git a/odk/examples/java/Inspector/ProtocolHandler.xcu b/odk/examples/java/Inspector/ProtocolHandler.xcu
new file mode 100755
index 000000000000..932c0f208cc9
--- /dev/null
+++ b/odk/examples/java/Inspector/ProtocolHandler.xcu
@@ -0,0 +1,11 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<oor:component-data oor:name="ProtocolHandler" oor:package="org.openoffice.Office" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <node oor:name="HandlerSet">
+ <node oor:name="InspectorAddon$InspectorAddonImpl" oor:op="replace">
+ <prop oor:name="Protocols" oor:type="oor:string-list">
+ <value>org.openoffice.Office.addon.Inspector:*</value>
+ </prop>
+ </node>
+ </node>
+</oor:component-data>
+
diff --git a/odk/examples/java/Inspector/ProtocolHandlerAddon.java b/odk/examples/java/Inspector/ProtocolHandlerAddon.java
new file mode 100644
index 000000000000..2844d25e3def
--- /dev/null
+++ b/odk/examples/java/Inspector/ProtocolHandlerAddon.java
@@ -0,0 +1,283 @@
+/*************************************************************************
+ *
+ * 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.XComponentContext;
+import com.sun.star.lib.uno.helper.Factory;
+import com.sun.star.lang.XSingleComponentFactory;
+import com.sun.star.lib.uno.helper.WeakBase;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.registry.XRegistryKey;
+import com.sun.star.lang.XInitialization;
+import com.sun.star.lang.XTypeProvider;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.uno.Type;
+import com.sun.star.frame.XStatusListener;
+import com.sun.star.frame.XDispatchProvider;
+import com.sun.star.frame.XDispatch;
+import com.sun.star.frame.XModel;
+import com.sun.star.frame.XFrame;
+import com.sun.star.frame.DispatchDescriptor;
+import com.sun.star.awt.XToolkit;
+import com.sun.star.awt.XWindowPeer;
+import com.sun.star.awt.XMessageBox;
+import com.sun.star.awt.WindowAttribute;
+import com.sun.star.awt.WindowClass;
+import com.sun.star.awt.WindowDescriptor;
+import com.sun.star.awt.Rectangle;
+
+public class ProtocolHandlerAddon {
+ /** This class implements the component. At least the interfaces XServiceInfo,
+ * XTypeProvider, and XInitialization should be provided by the service.
+ */
+ public static class ProtocolHandlerAddonImpl extends WeakBase implements
+ XDispatchProvider,
+ XDispatch,
+ XInitialization,
+ XServiceInfo {
+
+ /** The service name, that must be used to get an instance of this service.
+ */
+ static private final String[] m_serviceNames = { "com.sun.star.frame.ProtocolHandler" };
+
+ /** The component context, that gives access to the service manager and all registered services.
+ */
+ private XComponentContext m_xCmpCtx;
+
+ /** The toolkit, that we can create UNO dialogs.
+ */
+ private XToolkit m_xToolkit;
+
+ /** The frame where the addon depends on.
+ */
+ private XFrame m_xFrame;
+ private XStatusListener m_xStatusListener;
+
+
+ /** The constructor of the inner class has a XMultiServiceFactory parameter.
+ * @param xmultiservicefactoryInitialization A special service factory
+ * could be introduced while initializing.
+ */
+ public ProtocolHandlerAddonImpl( XComponentContext xComponentContext ) {
+ m_xCmpCtx = xComponentContext;
+ }
+
+ /** This method is a member of the interface for initializing an object
+ * directly after its creation.
+ * @param object This array of arbitrary objects will be passed to the
+ * component after its creation.
+ * @throws Exception Every exception will not be handled, but will be
+ * passed to the caller.
+ */
+ public void initialize( Object[] object )
+ throws com.sun.star.uno.Exception {
+
+ if ( object.length > 0 )
+ {
+ m_xFrame = ( XFrame ) UnoRuntime.queryInterface(
+ XFrame.class, object[ 0 ] );
+ }
+
+ // Create the toolkit to have access to it later
+ m_xToolkit = (XToolkit) UnoRuntime.queryInterface(
+ XToolkit.class,
+ m_xCmpCtx.getServiceManager().createInstanceWithContext("com.sun.star.awt.Toolkit",
+ m_xCmpCtx));
+ }
+
+ /** This method returns an array of all supported service names.
+ * @return Array of supported service names.
+ */
+ public String[] getSupportedServiceNames() {
+ return getServiceNames();
+ }
+
+ public static String[] getServiceNames() {
+ return m_serviceNames;
+ }
+
+ /** This method returns true, if the given service will be
+ * supported by the component.
+ * @param stringService Service name.
+ * @return True, if the given service name will be supported.
+ */
+ 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;
+ }
+
+ /** Return the class name of the component.
+ * @return Class name of the component.
+ */
+ public String getImplementationName() {
+ return ProtocolHandlerAddonImpl.class.getName();
+ }
+
+ // XDispatchProvider
+ public XDispatch queryDispatch( /*IN*/com.sun.star.util.URL aURL,
+ /*IN*/String sTargetFrameName,
+ /*IN*/int iSearchFlags ) {
+ XDispatch xRet = null;
+ if ( aURL.Protocol.compareTo("org.openoffice.Office.addon.example:") == 0 ) {
+ if ( aURL.Path.compareTo( "Function1" ) == 0 )
+ xRet = this;
+ if ( aURL.Path.compareTo( "Function2" ) == 0 )
+ xRet = this;
+ if ( aURL.Path.compareTo( "Help" ) == 0 )
+ xRet = this;
+ }
+ return xRet;
+ }
+
+ public XDispatch[] queryDispatches( /*IN*/DispatchDescriptor[] seqDescripts ) {
+ int nCount = seqDescripts.length;
+ XDispatch[] lDispatcher = new XDispatch[nCount];
+
+ for( int i=0; i<nCount; ++i )
+ lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL,
+ seqDescripts[i].FrameName,
+ seqDescripts[i].SearchFlags );
+
+ return lDispatcher;
+ }
+
+ // XDispatch
+ public void dispatch( /*IN*/com.sun.star.util.URL aURL,
+ /*IN*/com.sun.star.beans.PropertyValue[] aArguments ) {
+
+ if ( aURL.Protocol.compareTo("org.openoffice.Office.addon.example:") == 0 )
+ {
+ if ( aURL.Path.compareTo( "Function1" ) == 0 )
+ {
+ showMessageBox("SDK DevGuide Add-On example", "Function 1 activated");
+ }
+ if ( aURL.Path.compareTo( "Function2" ) == 0 )
+ {
+ showMessageBox("SDK DevGuide Add-On example", "Function 2 activated");
+ }
+ if ( aURL.Path.compareTo( "Help" ) == 0 )
+ {
+ showMessageBox("About SDK DevGuide Add-On example", "This is the SDK Add-On example");
+ }
+ }
+ }
+
+ public void addStatusListener( /*IN*/XStatusListener xControl,
+ /*IN*/com.sun.star.util.URL aURL ) {
+ }
+
+ public void removeStatusListener( /*IN*/XStatusListener xControl,
+ /*IN*/com.sun.star.util.URL aURL ) {
+ }
+
+ public void showMessageBox(String sTitle, String sMessage) {
+ try {
+ if ( null != m_xFrame && null != m_xToolkit ) {
+
+ // describe window properties.
+ WindowDescriptor aDescriptor = new WindowDescriptor();
+ aDescriptor.Type = WindowClass.MODALTOP;
+ aDescriptor.WindowServiceName = new String( "infobox" );
+ aDescriptor.ParentIndex = -1;
+ aDescriptor.Parent = (XWindowPeer)UnoRuntime.queryInterface(
+ XWindowPeer.class, m_xFrame.getContainerWindow());
+ aDescriptor.Bounds = new Rectangle(0,0,300,200);
+ aDescriptor.WindowAttributes = WindowAttribute.BORDER |
+ WindowAttribute.MOVEABLE |
+ WindowAttribute.CLOSEABLE;
+
+ XWindowPeer xPeer = m_xToolkit.createWindow( aDescriptor );
+ if ( null != xPeer ) {
+ XMessageBox xMsgBox = (XMessageBox)UnoRuntime.queryInterface(
+ XMessageBox.class, xPeer);
+ if ( null != xMsgBox )
+ {
+ xMsgBox.setCaptionText( sTitle );
+ xMsgBox.setMessageText( sMessage );
+ xMsgBox.execute();
+ }
+ }
+ }
+ } catch ( com.sun.star.uno.Exception e) {
+ // do your error handling
+ }
+ }
+ }
+
+
+ /** Gives a factory for creating the service.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return Returns a <code>XSingleServiceFactory</code> for creating the
+ * component.
+ * @see com.sun.star.comp.loader.JavaLoader#
+ * @param stringImplementationName The implementation name of the component.
+ * @param xmultiservicefactory The service manager, who gives access to every
+ * known service.
+ * @param xregistrykey Makes structural information (except regarding tree
+ * structures) of a single
+ * registry key accessible.
+ */
+ public static XSingleComponentFactory __getComponentFactory( String sImplementationName ) {
+ XSingleComponentFactory xFactory = null;
+
+ if ( sImplementationName.equals( ProtocolHandlerAddonImpl.class.getName() ) )
+ xFactory = Factory.createComponentFactory(ProtocolHandlerAddonImpl.class,
+ ProtocolHandlerAddonImpl.getServiceNames());
+
+ return xFactory;
+ }
+
+ /** Writes the service information into the given registry key.
+ * This method is called by the <code>JavaLoader</code>.
+ * @return returns true if the operation succeeded
+ * @see com.sun.star.comp.loader.JavaLoader#
+ * @see com.sun.star.lib.uno.helper.Factory#
+ * @param xregistrykey Makes structural information (except regarding tree
+ * structures) of a single
+ * registry key accessible.
+ */
+ public static boolean __writeRegistryServiceInfo(
+ XRegistryKey xRegistryKey ) {
+ return Factory.writeRegistryServiceInfo(
+ ProtocolHandlerAddonImpl.class.getName(),
+ ProtocolHandlerAddonImpl.getServiceNames(),
+ xRegistryKey );
+ }
+}
diff --git a/odk/examples/java/Inspector/SourceCodeGenerator.java b/odk/examples/java/Inspector/SourceCodeGenerator.java
new file mode 100644
index 000000000000..932854cd0d28
--- /dev/null
+++ b/odk/examples/java/Inspector/SourceCodeGenerator.java
@@ -0,0 +1,1766 @@
+/*************************************************************************
+ *
+ * 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.beans.UnknownPropertyException;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.container.XNameAccess;
+import com.sun.star.lang.Locale;
+import com.sun.star.lang.WrappedTargetException;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.reflection.ParamInfo;
+import com.sun.star.reflection.XIdlClass;
+import com.sun.star.reflection.XIdlMethod;
+import com.sun.star.reflection.XTypeDescription;
+import com.sun.star.text.XTextTablesSupplier;
+import com.sun.star.uno.Any;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.uno.Type;
+import com.sun.star.uno.TypeClass;
+import com.sun.star.uno.UnoRuntime;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Vector;
+
+
+
+public class SourceCodeGenerator {
+ private Vector sExceptions = new Vector();
+ Vector sHeaderStatements = new HeaderStatements();
+ private XLanguageSourceCodeGenerator m_xLanguageSourceCodeGenerator;
+ private String sHeaderCode = "";
+ private String sStatementCode = "";
+ private String sMainMethodSignature = "";
+
+ private Hashtable aVariables = new Hashtable();
+ private final String SSUFFIXSEPARATOR = "_";
+ private final String SVARIABLENAME = "VariableName";
+ private final String SARRAYVARIABLENAME = "VariableNameList";
+ private final String SUNOOBJECTNAME = "oUnobject";
+ private final String SUNOSTRUCTNAME = "aUnoStruct";
+ private Introspector m_oIntrospector;
+ private Vector aTreepathProviders = new Vector();
+ private XTreePathProvider xTreepathProvider = null;
+ private boolean baddExceptionHandling = false;
+ private boolean bXPropertySetExceptionsAreAdded = false;
+ private XUnoNode oInitialUnoNode = null;
+ private final String sINITIALVARIABLENAME = "_oUnoEntryObject";
+
+
+ /** Creates a new instance of SourceCodeGenerator */
+ public SourceCodeGenerator(int _nLanguage) {
+ this.setLanguage(_nLanguage);
+ m_oIntrospector = Introspector.getIntrospector();
+ }
+
+
+ public String addSourceCodeOfUnoObject(XTreePathProvider _xTreepathProvider, boolean _brememberPath, boolean _bAddMethodSignature, boolean _baddHeader){
+ String sSourceCode = "";
+ String sVariableName = "";
+ if (_xTreepathProvider != null) {
+ for (int i = 0; i < _xTreepathProvider.getPathCount(); i++){
+ XUnoNode oUnoNode = _xTreepathProvider.getPathComponent(i);
+ if (i == 0){
+ sVariableName = sINITIALVARIABLENAME;
+ oInitialUnoNode = oUnoNode;
+ }
+ else{
+ if (oUnoNode instanceof XUnoMethodNode){
+ XUnoMethodNode oUnoMethodNode = (XUnoMethodNode) oUnoNode;
+ if (oUnoMethodNode.isInvoked()){
+ UnoObjectDefinition oUnoReturnObjectDefinition = getUnoObjectDefinition(_xTreepathProvider, oUnoMethodNode, i);
+ if (!isVariableDeclared(oUnoReturnObjectDefinition, this.generateVariableNameFromMethod(oUnoMethodNode.getXIdlMethod()))){
+// sStatementCode += "\n";
+ sStatementCode += "\n" + getMethodStatementSourceCode(oUnoMethodNode, sVariableName, oUnoReturnObjectDefinition);
+ }
+ sVariableName = oUnoReturnObjectDefinition.getVariableName();
+ }
+ }
+ else if (oUnoNode instanceof XUnoPropertyNode){
+ XUnoPropertyNode oUnoPropertyNode = (XUnoPropertyNode) oUnoNode;
+ Any oReturnObject = com.sun.star.uno.Any.complete(oUnoPropertyNode.getUnoReturnObject());
+ UnoObjectDefinition oUnoReturnObjectDefinition = new UnoObjectDefinition(oReturnObject);
+ if (!isVariableDeclared(oUnoReturnObjectDefinition, oUnoPropertyNode.getProperty().Name)){
+// sStatementCode += "\n";
+ sStatementCode += "\n" + getPropertyStatementSourceCode(oUnoPropertyNode, sVariableName, oUnoReturnObjectDefinition);
+ }
+ sVariableName = oUnoReturnObjectDefinition.getVariableName();
+ }
+ }
+ }
+ }
+ String sCompleteCode = combineCompleteSourceCode(sMainMethodSignature, _baddHeader);
+ xTreepathProvider = _xTreepathProvider;
+ if (_brememberPath){
+ aTreepathProviders.add(_xTreepathProvider);
+ }
+ return sCompleteCode;
+ }
+
+
+ private void setLanguage(int _nLanguage){
+ XLanguageSourceCodeGenerator xLanguageSourceCodeGenerator = null;
+ switch(_nLanguage){
+ case XLanguageSourceCodeGenerator.nJAVA:
+ xLanguageSourceCodeGenerator = new JavaCodeGenerator();
+ break;
+ case XLanguageSourceCodeGenerator.nCPLUSPLUS:
+ xLanguageSourceCodeGenerator = new CPlusPlusCodeGenerator();
+ break;
+ case XLanguageSourceCodeGenerator.nBASIC:
+ xLanguageSourceCodeGenerator = new BasicCodeGenerator();
+ break;
+ default:
+ System.out.println("Unknown Sourcecode Language. Check Menus!");
+ }
+ if (xLanguageSourceCodeGenerator != null){
+ m_xLanguageSourceCodeGenerator = xLanguageSourceCodeGenerator;
+ }
+ }
+
+ private void resetSourceCodeGeneration(int _nLanguage){
+ aVariables.clear();
+ this.sHeaderStatements.clear();
+ setLanguage(_nLanguage);
+ String sHeaderCode = "";
+ sStatementCode = "";
+ }
+
+ private String generateVariableNameFromMethod(String _sMethodName, String _sPrefix, boolean _bConsiderAll){
+ String sReturn = "";
+ if (_sMethodName.startsWith(_sPrefix)){
+ int nPrefixLength = _sPrefix.length();
+ if (_sMethodName.length() > nPrefixLength){
+ String sChar = _sMethodName.substring(nPrefixLength, nPrefixLength + 1);
+ String sUpperChar = sChar.toUpperCase();
+ if (sUpperChar.equals(sChar)){
+ if (_bConsiderAll){
+ sReturn = _sMethodName;
+ }
+ else{
+ sReturn = _sMethodName.substring(nPrefixLength, _sMethodName.length());
+ }
+ }
+ }
+ }
+ return sReturn;
+ }
+
+
+ private String generateVariableNameFromMethod(XIdlMethod _xIdlMethod){
+ // todo: refactor this!!!
+ String sMethodName = _xIdlMethod.getName();
+ String sReturn = "";
+ sReturn = generateVariableNameFromMethod(sMethodName, "getBy", false);
+ if (sReturn.equals("")){
+ sReturn = generateVariableNameFromMethod(sMethodName, "get", false);
+ }
+ if (sReturn.equals("")){
+ sReturn = generateVariableNameFromMethod(sMethodName, "attach", false);
+ }
+ if (sReturn.equals("")){
+ sReturn = generateVariableNameFromMethod(sMethodName, "assign", false);
+ }
+ if (sReturn.equals("")){
+ sReturn = generateVariableNameFromMethod(sMethodName, "attach", false);
+ }
+ if (sReturn.equals("")){
+ sReturn = generateVariableNameFromMethod(sMethodName, "create", false);
+ }
+ if (sReturn.equals("")){
+ sReturn = generateVariableNameFromMethod(sMethodName, "is", true);
+ }
+ if (sReturn.equals("")){
+ sReturn = generateVariableNameFromMethod(sMethodName, "has", true);
+ }
+ if (sReturn.equals("")){
+ sReturn = sMethodName;
+ }
+ return sReturn;
+ }
+
+
+ public String convertAllUnoObjects(int _nLanguage){
+ String sSourceCode = "";
+ resetSourceCodeGeneration(_nLanguage);
+ int ncount = aTreepathProviders.size();
+ for (int i=0; i< ncount; i++){
+ sSourceCode = addSourceCodeOfUnoObject((XTreePathProvider) aTreepathProviders.get(i), false, (i==0), (i == (ncount-1)));
+ }
+ return sSourceCode;
+ }
+
+ private UnoObjectDefinition getUnoObjectDefinition(XTreePathProvider _xTreePathProvider, XUnoMethodNode _oUnoMethodNode, int _nindex){
+ XUnoNode oUnoNode = null;
+ Object oUnoReturnObject = null;
+ Object[] oParamObjects = null;
+ XIdlClass xIdlClass = _oUnoMethodNode.getXIdlMethod().getReturnType();
+ String sTypeName = xIdlClass.getName();
+ TypeClass aTypeClass = xIdlClass.getTypeClass();
+ if (aTypeClass.getValue() != TypeClass.VOID_value){
+ if (_xTreePathProvider.getPathCount() > _nindex + 1){
+ oUnoNode = _xTreePathProvider.getPathComponent(_nindex + 1);
+ oUnoReturnObject = oUnoNode.getUnoObject();
+ }
+ }
+ if (oUnoReturnObject == null){
+ oUnoReturnObject = _oUnoMethodNode.getLastUnoReturnObject();
+ }
+ UnoObjectDefinition oUnoObjectDefinition = new UnoObjectDefinition(oUnoReturnObject, sTypeName, aTypeClass);
+ if (_oUnoMethodNode.hasParameters()){
+ if (oUnoNode != null){
+ oParamObjects = oUnoNode.getParameterObjects();
+ }
+ else{
+ oParamObjects = _oUnoMethodNode.getLastParameterObjects();
+ }
+ }
+ if (oParamObjects != null){
+ oUnoObjectDefinition.addParameterObjects(oParamObjects);
+ }
+ return oUnoObjectDefinition;
+ }
+
+
+ private String combineCompleteSourceCode(String _sMethodSignature, boolean _bAddHeader){
+ String sCompleteCode = "";
+ if (_bAddHeader){
+ sMainMethodSignature = m_xLanguageSourceCodeGenerator.getMainMethodSignatureSourceCode(oInitialUnoNode, sINITIALVARIABLENAME);
+ m_xLanguageSourceCodeGenerator.assignqueryInterfaceHeaderSourceCode();
+ sCompleteCode += getHeaderSourceCode();
+ }
+ sCompleteCode += sMainMethodSignature;
+ sCompleteCode += sStatementCode;
+ if (_bAddHeader){
+ sCompleteCode += m_xLanguageSourceCodeGenerator.getMethodTerminationSourceCode();
+ sCompleteCode += "\n" + m_xLanguageSourceCodeGenerator.getCommentSign() + "...";
+ }
+ return sCompleteCode;
+ }
+
+
+ public String getPropertyStatementSourceCode(XUnoPropertyNode _oUnoPropertyNode, String _sVariableName, UnoObjectDefinition _oUnoReturnObjectDefinition){
+ String sReturnObjectVariableDefinition = "";
+ String sStatement = "";
+ String sPropertyName = _oUnoPropertyNode.getProperty().Name;
+ UnoObjectDefinition oUnoObjectDefinition = new UnoObjectDefinition(_oUnoPropertyNode.getUnoObject(), "com.sun.star.beans.XPropertySet");
+ if (!m_xLanguageSourceCodeGenerator.needsqueryInterface() || (oUnoObjectDefinition.getTypeClass().getValue() == TypeClass.STRUCT_value)){
+ oUnoObjectDefinition.setVariableName(_sVariableName);
+ if (oUnoObjectDefinition.getTypeClass().getValue() == TypeClass.STRUCT_value){
+ sReturnObjectVariableDefinition = getVariableInitialization(_oUnoReturnObjectDefinition, false);
+ sStatement += m_xLanguageSourceCodeGenerator.getStructSourceCode(sReturnObjectVariableDefinition, oUnoObjectDefinition.getVariableName(), sPropertyName);
+ return sStatement;
+ }
+ }
+ sStatement += addQueryInterfaceSourceCode(oUnoObjectDefinition, _sVariableName, "com.sun.star.beans.XPropertySet");
+ if (_oUnoReturnObjectDefinition.getTypeClass().getValue() != TypeClass.VOID_value){
+ sReturnObjectVariableDefinition = getVariableInitialization(_oUnoReturnObjectDefinition, true);
+ }
+ sStatement += m_xLanguageSourceCodeGenerator.getPropertyValueGetterSourceCode(sPropertyName, sReturnObjectVariableDefinition, oUnoObjectDefinition.getVariableName(), _oUnoReturnObjectDefinition.getTypeClass(), _oUnoReturnObjectDefinition.getTypeName());
+ addXPropertySetRelatedExceptions();
+ return sStatement;
+ }
+
+
+ public String getMethodStatementSourceCode(XUnoMethodNode _oUnoMethodNode, String _sVariableName, UnoObjectDefinition _oUnoReturnObjectDefinition){
+ String sReturnObjectVariableDefinition = "";
+ String sStatement = "";
+ XIdlMethod xIdlMethod = _oUnoMethodNode.getXIdlMethod();
+ TypeClass aReturnTypeClass = xIdlMethod.getReturnType().getTypeClass();
+ UnoObjectDefinition oUnoObjectDefinition = new UnoObjectDefinition(_oUnoMethodNode.getUnoObject(), _oUnoMethodNode.getClassName());
+ String sVariableStemName = this.generateVariableNameFromMethod(xIdlMethod);
+ sStatement += addQueryInterfaceSourceCode(oUnoObjectDefinition, _sVariableName, oUnoObjectDefinition.getTypeName());
+ if (_oUnoReturnObjectDefinition.getTypeClass().getValue() != TypeClass.VOID_value){
+ sReturnObjectVariableDefinition = getVariableInitialization(_oUnoReturnObjectDefinition, false) + " = ";
+ }
+ Object[] oParamObjects = _oUnoReturnObjectDefinition.getParameterObjects();
+ String sParameterCode = getMethodParameterValueDescription(_oUnoMethodNode, oParamObjects, false);
+ String sSeparator = m_xLanguageSourceCodeGenerator.getMethodSeparator();
+ sStatement += "\t" + sReturnObjectVariableDefinition + oUnoObjectDefinition.getVariableName() + sSeparator + xIdlMethod.getName() + "(" + sParameterCode + ")";
+ sStatement += m_xLanguageSourceCodeGenerator.getStatementTerminationCharacter();
+ addExceptions(xIdlMethod);
+ return sStatement;
+ }
+
+
+ private String addQueryInterfaceSourceCode(UnoObjectDefinition _oUnoObjectDefinition, String _sVariableName, String _sTypeName){
+ String sLocStatement = "";
+ if (m_xLanguageSourceCodeGenerator.needsqueryInterface()){
+ if (!isVariableDeclared(_oUnoObjectDefinition, "")){
+ String sObjectVariableDefinition = getVariableDeclaration(_oUnoObjectDefinition, false, "");
+ sLocStatement += m_xLanguageSourceCodeGenerator.getqueryInterfaceSourceCode(_sTypeName, sObjectVariableDefinition, _sVariableName);
+ }
+ }
+ else{
+ _oUnoObjectDefinition.setVariableName(_sVariableName);
+ }
+ return sLocStatement;
+ }
+
+
+ private void addXPropertySetRelatedExceptions(){
+ if (!bXPropertySetExceptionsAreAdded){
+ sExceptions.add("com.sun.star.beans.UnknownPropertyException");
+ sExceptions.add("com.sun.star.lang.WrappedTargetException");
+ sExceptions.add("com.sun.star.lang.IllegalArgumentException");
+ bXPropertySetExceptionsAreAdded = true;
+ baddExceptionHandling = true;
+ }
+ }
+
+
+ private void addExceptions(XIdlMethod _xIdlMethod){
+ XIdlClass[] xIdlClasses = _xIdlMethod.getExceptionTypes();
+ for (int i = 0; i > xIdlClasses.length; i++){
+ sExceptions.add(xIdlClasses[0].getName());
+ baddExceptionHandling = true;
+ }
+ }
+
+ private String getRootDescription(XUnoNode _oUnoNode){
+ return "_o" + _oUnoNode.toString();
+ }
+
+
+ private String getHeaderSourceCode(){
+ Enumeration aEnumeration = aVariables.elements();
+ while(aEnumeration.hasMoreElements()){
+ UnoObjectDefinition oUnoObjectDefinition = (UnoObjectDefinition) aEnumeration.nextElement();
+ String sCurHeaderStatement = m_xLanguageSourceCodeGenerator.getHeaderSourceCode(oUnoObjectDefinition.getUnoObject(), oUnoObjectDefinition.getTypeName(), oUnoObjectDefinition.getTypeClass());
+ sHeaderStatements.add(sCurHeaderStatement);
+ }
+ String sHeaderSourcecode = "";
+ String[] sHeaderStatementArray = new String[sHeaderStatements.size()];
+ sHeaderStatements.toArray(sHeaderStatementArray);
+ java.util.Arrays.sort(sHeaderStatementArray);
+ for (int i = 0; i < sHeaderStatementArray.length; i++){
+ sHeaderSourcecode += sHeaderStatementArray[i];
+ }
+ sHeaderSourcecode += m_xLanguageSourceCodeGenerator.getFinalHeaderStatements();
+ return sHeaderSourcecode +"\n" + m_xLanguageSourceCodeGenerator.getCommentSign() + "...\n";
+ }
+
+
+ private class HeaderStatements extends Vector{
+
+ public boolean contains(Object _oElement){
+ String sCompName = (String) _oElement;
+ for (int i = 0; i < this.size(); i++){
+ String sElement = (String) this.get(i);
+ if (sElement.equals(sCompName)){
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ public boolean add(Object _oElement){
+ if (_oElement instanceof String){
+ if (!contains(_oElement)){
+ super.add(_oElement);
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+
+
+ private boolean isVariableDeclared(UnoObjectDefinition _oUnoObjectDefinition, String _sDefaultStemName){
+ boolean bisDeclared = false;
+ if (!_sDefaultStemName.equals("")){
+ _oUnoObjectDefinition.setCentralVariableStemName(_sDefaultStemName);
+ }
+ String sVariableStemName = _oUnoObjectDefinition.getVariableStemName();
+ bisDeclared = aVariables.containsKey(sVariableStemName);
+ if (bisDeclared){
+ Object oUnoObject = _oUnoObjectDefinition.getUnoObject();
+ if (m_oIntrospector.isObjectPrimitive(oUnoObject)){
+ bisDeclared = false;
+ }
+ else if (m_oIntrospector.isObjectSequence(oUnoObject)){
+ bisDeclared = false;
+ }
+ else{
+ String sCompVariableName = sVariableStemName;
+ String sUnoObjectIdentity = oUnoObject.toString();
+ boolean bleaveloop = false;
+ int a = 2;
+ while (!bleaveloop){
+ if (aVariables.containsKey(sCompVariableName)){
+ Object oUnoCompObject = ((UnoObjectDefinition) aVariables.get(sCompVariableName)).getUnoObject();
+ String sUnoCompObjectIdentity = oUnoCompObject.toString();
+ bleaveloop = sUnoCompObjectIdentity.equals(sUnoObjectIdentity);
+ bisDeclared = bleaveloop;
+ if (!bleaveloop){
+ sCompVariableName = sVariableStemName + SSUFFIXSEPARATOR + a++;
+ }
+ }
+ else{
+ bleaveloop = true;
+ bisDeclared = false;
+ }
+ }
+ }
+ }
+ return bisDeclared;
+ }
+
+
+ private String addUniqueVariableName(String _sStemVariableName, UnoObjectDefinition _oUnoObjectDefinition){
+ boolean bElementexists = true;
+ int a = 2;
+ String sCompName = _sStemVariableName;
+ while (bElementexists){
+ if (! aVariables.containsKey(sCompName)){
+ aVariables.put(sCompName, _oUnoObjectDefinition);
+ break;
+ }
+ sCompName = _sStemVariableName + SSUFFIXSEPARATOR + a++;
+ }
+ return sCompName;
+ }
+
+
+
+ private String getTypeString(String _sTypeName, TypeClass _aTypeClass, boolean _bAsHeaderSourceCode){
+ String sTypeString = "";
+ switch (_aTypeClass.getValue()){
+ case TypeClass.BOOLEAN_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getbooleanTypeDescription();
+ break;
+ case TypeClass.BYTE_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getbyteTypeDescription();
+ break;
+ case TypeClass.CHAR_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getcharTypeDescription();
+ break;
+ case TypeClass.DOUBLE_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getdoubleTypeDescription();
+ break;
+ case TypeClass.FLOAT_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getfloatTypeDescription();
+ break;
+ case TypeClass.HYPER_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.gethyperTypeDescription();
+ break;
+ case TypeClass.LONG_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getlongTypeDescription();
+ break;
+ case TypeClass.SHORT_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getshortTypeDescription();
+ break;
+ case TypeClass.STRING_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getstringTypeDescription(_bAsHeaderSourceCode);
+ break;
+ case TypeClass.UNSIGNED_HYPER_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getunsignedhyperTypeDescription();
+ break;
+ case TypeClass.UNSIGNED_LONG_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getunsignedlongTypeDescription();
+ break;
+ case TypeClass.UNSIGNED_SHORT_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getdoubleTypeDescription();
+ break;
+ case TypeClass.SEQUENCE_value:
+ //TODO consider mulitdimensional Arrays
+ XTypeDescription xTypeDescription = Introspector.getIntrospector().getReferencedType(_sTypeName);
+ if (xTypeDescription != null){
+ sTypeString = getTypeString(xTypeDescription.getName(), xTypeDescription.getTypeClass(), _bAsHeaderSourceCode);
+ }
+ break;
+ case TypeClass.ANY_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getanyTypeDescription(_bAsHeaderSourceCode);
+ break;
+ case TypeClass.TYPE_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getObjectTypeDescription("com.sun.star.uno.Type", _bAsHeaderSourceCode);
+ break;
+ case TypeClass.ENUM_value:
+ case TypeClass.STRUCT_value:
+ case TypeClass.INTERFACE_ATTRIBUTE_value:
+ case TypeClass.INTERFACE_METHOD_value:
+ case TypeClass.INTERFACE_value:
+ case TypeClass.PROPERTY_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getObjectTypeDescription(_sTypeName, _bAsHeaderSourceCode);
+ break;
+ default:
+ }
+ return sTypeString;
+ }
+
+
+ private String getVariableDeclaration(UnoObjectDefinition _oUnoObjectDefinition, boolean _bInitialize, String _sVariableDefaultName){
+ TypeClass aTypeClass = _oUnoObjectDefinition.getTypeClass();
+ TypeClass aLocTypeClass = aTypeClass;
+ boolean bIsArray = false;
+ if (_oUnoObjectDefinition.getUnoObject() != null){
+ bIsArray = m_oIntrospector.isObjectSequence(_oUnoObjectDefinition.getUnoObject());
+ }
+ else{
+ bIsArray = _oUnoObjectDefinition.getTypeClass().getValue() == TypeClass.SEQUENCE_value;
+ }
+ String sVariableName = _oUnoObjectDefinition.getVariableName(_sVariableDefaultName);
+ String sTypeName = _oUnoObjectDefinition.getTypeName();
+ String sTypeString = getTypeString(sTypeName, aLocTypeClass, false);
+ if (bIsArray){
+ XTypeDescription xTypeDescription = Introspector.getIntrospector().getReferencedType(sTypeName);
+ if (xTypeDescription != null){
+ aLocTypeClass = xTypeDescription.getTypeClass();
+ }
+ }
+ String sVariableDeclaration = m_xLanguageSourceCodeGenerator.getVariableDeclaration(sTypeString, sVariableName, bIsArray, aLocTypeClass, _bInitialize);
+ addUniqueVariableName(sVariableName, _oUnoObjectDefinition);
+ return sVariableDeclaration;
+ }
+
+
+ public String getVariableInitialization(UnoObjectDefinition _oUnoObjectDefinition, boolean _bInitialize){
+ String sObjectVariableDeclaration = "";
+ String sVariableName = _oUnoObjectDefinition.getVariableName();
+ if (isVariableDeclared(_oUnoObjectDefinition, "")){
+ sObjectVariableDeclaration = sVariableName;
+ }
+ else{
+ sObjectVariableDeclaration = getVariableDeclaration(_oUnoObjectDefinition, _bInitialize, "");
+ }
+ return sObjectVariableDeclaration;
+ }
+
+
+
+ public String getVariableNameforUnoObject(String _sShortClassName){
+ if (_sShortClassName.startsWith("X")){
+ return "x" + _sShortClassName.substring(1);
+ }
+ else{
+ return _sShortClassName;
+ }
+ }
+
+
+class UnoObjectDefinition{
+ Object m_oUnoObject = null;
+ Type aType = null;
+ String sVariableStemName = "";
+ String m_sCentralVariableStemName = "";
+ String sVariableName = "";
+ String m_sTypeName = "";
+ TypeClass m_aTypeClass = null;
+ Object[] m_oParameterObjects = null;
+
+
+ public UnoObjectDefinition(Any _oUnoObject){
+ m_sTypeName = _oUnoObject.getType().getTypeName();
+ m_aTypeClass = _oUnoObject.getType().getTypeClass();
+ m_oUnoObject = _oUnoObject;
+ m_sCentralVariableStemName = getCentralVariableStemName(m_aTypeClass);
+ }
+
+
+ public UnoObjectDefinition(Object _oUnoObject, String _sTypeName, TypeClass _aTypeClass){
+ m_oUnoObject = _oUnoObject;
+ m_sTypeName = _sTypeName;
+ m_aTypeClass = _aTypeClass;
+ m_sCentralVariableStemName = getCentralVariableStemName(m_aTypeClass);
+ }
+
+
+ public UnoObjectDefinition(Object _oUnoObject, String _sTypeName){
+ m_oUnoObject = _oUnoObject;
+ m_sTypeName = _sTypeName;
+ m_aTypeClass = AnyConverter.getType(_oUnoObject).getTypeClass();
+ m_sCentralVariableStemName = getCentralVariableStemName(m_aTypeClass);
+ }
+
+
+ private String getCentralVariableStemName(TypeClass _aTypeClass){
+ String sCentralVariableStemName = "";
+ int nTypeClass = _aTypeClass.getValue();
+ switch(nTypeClass){
+ case TypeClass.SEQUENCE_value:
+ //TODO consider mulitdimensional Arrays
+ XTypeDescription xTypeDescription = Introspector.getIntrospector().getReferencedType(getTypeName());
+ if (xTypeDescription != null){
+ sCentralVariableStemName = getCentralVariableStemName(xTypeDescription.getTypeClass());
+ }
+ break;
+ case TypeClass.TYPE_value:
+ sCentralVariableStemName = SVARIABLENAME;
+ break;
+ case TypeClass.STRUCT_value:
+ sCentralVariableStemName = Introspector.getShortClassName(getTypeName());
+ break;
+ case TypeClass.INTERFACE_ATTRIBUTE_value:
+ case TypeClass.INTERFACE_METHOD_value:
+ case TypeClass.INTERFACE_value:
+ case TypeClass.PROPERTY_value:
+ String sShortClassName = m_oIntrospector.getShortClassName(getTypeName());
+ sCentralVariableStemName = getVariableNameforUnoObject(sShortClassName);
+ default:
+ sCentralVariableStemName = SVARIABLENAME;
+ }
+ return sCentralVariableStemName;
+ }
+
+ /** may return null
+ */
+ public Object getUnoObject(){
+ return m_oUnoObject;
+ }
+
+
+ public void setTypeClass(TypeClass _aTypeClass){
+ sVariableStemName = "";
+ m_aTypeClass = _aTypeClass;
+ }
+
+
+ public TypeClass getTypeClass(){
+ return m_aTypeClass;
+ }
+
+
+ public void setTypeName(String _sTypeName){
+ sVariableStemName = "";
+ m_sTypeName = _sTypeName;
+ }
+
+
+ public String getTypeName(){
+ return m_sTypeName;
+ }
+
+
+ public void setCentralVariableStemName(String _sCentralVariableStemName){
+ m_sCentralVariableStemName = _sCentralVariableStemName;
+ }
+
+
+ public String getVariableStemName(){
+ if (sVariableStemName.equals("")){
+ sVariableStemName = getVariableStemName(m_aTypeClass);
+ }
+ return sVariableStemName;
+ }
+
+
+ public void addParameterObjects(Object[] _oParameterObjects){
+ m_oParameterObjects = _oParameterObjects;
+ }
+
+
+ public Object[] getParameterObjects(){
+ return m_oParameterObjects;
+ }
+
+
+ public boolean hasParameterObjects(){
+ boolean breturn = false;
+ if (m_oParameterObjects != null){
+ breturn = m_oParameterObjects.length > 0;
+ }
+ return breturn;
+ }
+
+
+ public String getVariableStemName(TypeClass _aTypeClass){
+ int nTypeClass = _aTypeClass.getValue();
+ switch(nTypeClass){
+ case TypeClass.BOOLEAN_value:
+ sVariableStemName = "b" + m_sCentralVariableStemName;
+ break;
+ case TypeClass.DOUBLE_value:
+ case TypeClass.FLOAT_value:
+ sVariableStemName = "f" + m_sCentralVariableStemName;
+ break;
+ case TypeClass.BYTE_value:
+ case TypeClass.HYPER_value:
+ case TypeClass.LONG_value:
+ case TypeClass.UNSIGNED_HYPER_value:
+ case TypeClass.UNSIGNED_LONG_value:
+ case TypeClass.UNSIGNED_SHORT_value:
+ case TypeClass.SHORT_value:
+ sVariableStemName = "n" + m_sCentralVariableStemName;
+ break;
+ case TypeClass.CHAR_value:
+ case TypeClass.STRING_value:
+ sVariableStemName = "s" + m_sCentralVariableStemName;
+ break;
+ case TypeClass.SEQUENCE_value:
+ //TODO consider mulitdimensional Arrays
+ XTypeDescription xTypeDescription = Introspector.getIntrospector().getReferencedType(getTypeName());
+ if (xTypeDescription != null){
+ sVariableStemName = getVariableStemName(xTypeDescription.getTypeClass());
+ }
+ break;
+ case TypeClass.TYPE_value:
+ sVariableStemName = "a" + m_sCentralVariableStemName;
+ break;
+ case TypeClass.ANY_value:
+ sVariableStemName = "o" + m_sCentralVariableStemName;
+ break;
+ case TypeClass.STRUCT_value:
+ case TypeClass.ENUM_value:
+ sVariableStemName = "a" + m_sCentralVariableStemName;
+ break;
+ case TypeClass.INTERFACE_ATTRIBUTE_value:
+ case TypeClass.INTERFACE_METHOD_value:
+ case TypeClass.INTERFACE_value:
+ case TypeClass.PROPERTY_value:
+ String sShortClassName = m_oIntrospector.getShortClassName(getTypeName());
+ sVariableStemName = getVariableNameforUnoObject(sShortClassName);
+ default:
+ }
+ return sVariableStemName;
+ }
+
+
+ private void setVariableName(String _sVariableName){
+ sVariableName = _sVariableName;
+ }
+
+
+ private String getVariableName(String _sCentralVariableStemName){
+ if (!_sCentralVariableStemName.equals("")){
+ this.m_sCentralVariableStemName = _sCentralVariableStemName;
+ }
+ return getVariableName();
+ }
+
+
+ private String getVariableName() throws NullPointerException{
+ if (sVariableName.equals("")){
+ int a = 2;
+ sVariableName = getVariableStemName();
+ boolean bleaveloop = false;
+ while (!bleaveloop){
+ if (aVariables.containsKey(sVariableName)){
+ String sUnoObjectIdentity = ((UnoObjectDefinition) aVariables.get(sVariableName)).getUnoObject().toString();
+ if (m_oUnoObject != null){
+ if ((sUnoObjectIdentity.equals(m_oUnoObject.toString()) && (!m_oIntrospector.isPrimitive(this.getTypeClass())) &&
+ (! m_oIntrospector.isObjectSequence(m_oUnoObject)))){
+ bleaveloop = true;
+ }
+ else{
+ sVariableName = getVariableStemName() + SSUFFIXSEPARATOR + a++;
+ }
+ }
+ else{
+ bleaveloop = true;
+ }
+ }
+ else{
+ bleaveloop = true;
+ // throw new NullPointerException("SourceCode Variable " + _sStemVariableName + " not defined");
+ }
+ }
+ }
+ return sVariableName;
+ }
+ }
+
+
+ public String getStringValueOfObject(Object _oUnoObject, TypeClass _aTypeClass){
+ String sReturn = "";
+ switch (_aTypeClass.getValue()){
+ case TypeClass.BOOLEAN_value:
+ boolean bbooleanValue = ((Boolean) _oUnoObject).booleanValue();
+ sReturn += Boolean.toString(bbooleanValue);
+ case TypeClass.CHAR_value:
+ break;
+ case TypeClass.DOUBLE_value:
+ double fdoubleValue = ((Double) _oUnoObject).doubleValue();
+ sReturn += Double.toString(fdoubleValue);
+ break;
+ case TypeClass.ENUM_value:
+ break;
+ case TypeClass.FLOAT_value:
+ float floatValue = ((Float) _oUnoObject).floatValue();
+ sReturn += Float.toString(floatValue);
+ break;
+ case TypeClass.HYPER_value:
+ long nlongValue = ((Long) _oUnoObject).longValue();
+ sReturn += Long.toString(nlongValue);
+ break;
+ case TypeClass.LONG_value:
+ int nintValue = ((Integer) _oUnoObject).intValue();
+ sReturn += Integer.toString(nintValue);
+ break;
+ case TypeClass.SHORT_value:
+ short nshortValue = ((Short) _oUnoObject).shortValue();
+ sReturn += Short.toString(nshortValue);
+ break;
+ case TypeClass.STRING_value:
+ sReturn += (String) _oUnoObject;
+ break;
+ case TypeClass.UNSIGNED_HYPER_value:
+ nlongValue = ((Long) _oUnoObject).longValue();
+ sReturn += Long.toString(nlongValue);
+ break;
+ case TypeClass.UNSIGNED_LONG_value:
+ nintValue = ((Integer) _oUnoObject).intValue();
+ sReturn += Integer.toString(nintValue);
+ break;
+ case TypeClass.UNSIGNED_SHORT_value:
+ nshortValue = ((Short) _oUnoObject).shortValue();
+ sReturn += Short.toString(nshortValue);
+ break;
+ default:
+ System.out.println("Type " + _aTypeClass.getValue() + " not yet defined in 'getStringValueOfObject()'");
+ }
+ return sReturn;
+ }
+
+
+ public String getMethodParameterValueDescription(XUnoMethodNode _oUnoMethodNode, Object[] _oParamObjects, boolean _bIncludeParameterNames){
+ String sParamSourceCode = "";
+ ParamInfo[] aParamInfos = _oUnoMethodNode.getXIdlMethod().getParameterInfos();
+ if (_oParamObjects != null){
+ for (int i = 0; i < _oParamObjects.length; i++){
+ TypeClass aTypeClass = aParamInfos[i].aType.getTypeClass();
+ if (_bIncludeParameterNames){
+ sParamSourceCode += aParamInfos[i].aName + "=";
+ }
+ String sParamDescription = getStringValueOfObject(_oParamObjects[i], aTypeClass);
+ sParamDescription = this.m_xLanguageSourceCodeGenerator.castLiteral(sParamDescription, aTypeClass);
+ sParamSourceCode += sParamDescription;
+
+ if (i < _oParamObjects.length - 1){
+ sParamSourceCode += ", ";
+ }
+ }
+ }
+ return sParamSourceCode;
+ }
+
+
+ public class JavaCodeGenerator implements XLanguageSourceCodeGenerator{
+ String sStatementsCode = "";
+ boolean bAddAnyConverter = false;
+// boolean bAddTypeImport = false;
+ boolean bIsPropertyUnoObjectDefined = false;
+
+ public JavaCodeGenerator(){
+ }
+
+
+ public String getStatementTerminationCharacter(){
+ return ";";
+ }
+
+
+ public String getHeaderSourceCode(Object _oUnoObject, String _sClassName, TypeClass _aTypeClass){
+ String sClassName = _sClassName;
+ String sHeaderStatement = "";
+ if (_oUnoObject != null){
+ if (!m_oIntrospector.isObjectPrimitive(_oUnoObject)){
+ if (m_oIntrospector.isObjectSequence(_oUnoObject)){
+ XTypeDescription xTypeDescription = m_oIntrospector.getReferencedType(sClassName);
+ if (xTypeDescription != null){
+ if (!m_oIntrospector.isPrimitive(xTypeDescription.getTypeClass())){
+ sClassName = getTypeString(xTypeDescription.getName(), xTypeDescription.getTypeClass(), true);
+ }
+ // primitive Types are not supposed to turn up in the import section...
+ else{
+ sClassName = "";
+ }
+ }
+ }
+ else{
+ sClassName = getTypeString(_sClassName, _aTypeClass, true);
+ }
+ }
+ else if (_aTypeClass.getValue() == TypeClass.ENUM_value){
+ sClassName = _sClassName;
+ }
+ else{
+ sClassName = "";
+ }
+ if (!sClassName.equals("")){
+ sHeaderStatement = "import " + sClassName + ";\n";
+ }
+ }
+ return sHeaderStatement;
+ }
+
+
+ public String getFinalHeaderStatements(){
+ return "";
+ }
+
+
+ public void assignqueryInterfaceHeaderSourceCode(){
+ sHeaderStatements.add("import com.sun.star.uno.UnoRuntime;\n");
+ sHeaderStatements.add("import com.sun.star.uno.XInterface;\n");
+ if (bAddAnyConverter){
+ sHeaderStatements.add("import com.sun.star.uno.AnyConverter;\n");
+ }
+ }
+
+
+
+ public String getConvertedSourceCodeValueOfObject(String _sReturnVariableName, String _sObjectDescription, TypeClass _aTypeClass, String _sTypeName){
+ boolean bLocAddAnyConverter = true;
+ String sReturn = "";
+ switch (_aTypeClass.getValue()){
+ case TypeClass.BOOLEAN_value:
+ sReturn = _sReturnVariableName + " = AnyConverter.toBoolean(" + _sObjectDescription + ")";
+ break;
+ case TypeClass.CHAR_value:
+ sReturn = _sReturnVariableName + " = AnyConverter.toChar(" + _sObjectDescription + ")";
+ break;
+ case TypeClass.BYTE_value:
+ sReturn = _sReturnVariableName + " = AnyConverter.toByte(" + _sObjectDescription + ")";
+ break;
+ case TypeClass.DOUBLE_value:
+ sReturn = _sReturnVariableName + " = AnyConverter.toDouble(" + _sObjectDescription + ")";
+ break;
+ case TypeClass.FLOAT_value:
+ sReturn = _sReturnVariableName + " = AnyConverter.toFloat(" + _sObjectDescription + ")";
+ break;
+ case TypeClass.UNSIGNED_HYPER_value:
+ sReturn = _sReturnVariableName + " = AnyConverter.toUnsignedLong(" + _sObjectDescription + ")";
+ break;
+ case TypeClass.HYPER_value:
+ sReturn = _sReturnVariableName + " = AnyConverter.toLong(" + _sObjectDescription + ")";
+ break;
+ case TypeClass.UNSIGNED_LONG_value:
+ sReturn = _sReturnVariableName + " = AnyConverter.toUnsignedInt(" + _sObjectDescription + ")";
+ break;
+ case TypeClass.LONG_value:
+ sReturn = _sReturnVariableName + " = AnyConverter.toInt(" + _sObjectDescription + ")";
+ break;
+ case TypeClass.SHORT_value:
+ sReturn = _sReturnVariableName + " = AnyConverter.toShort(" + _sObjectDescription + ")";
+ break;
+ case TypeClass.UNSIGNED_SHORT_value:
+ sReturn = _sReturnVariableName + " = AnyConverter.toUnsignedShort(" + _sObjectDescription + ")";
+ break;
+ case TypeClass.STRING_value:
+ sReturn = _sReturnVariableName + " = AnyConverter.toString(" + _sObjectDescription + ")";
+ break;
+ default:
+ String sShortTypeName = Introspector.getShortClassName(_sTypeName);
+ if (bIsPropertyUnoObjectDefined){
+ sReturn = "oUnoObject = " + _sObjectDescription + ";\n\t";
+ }
+ else{
+ sReturn = "Object oUnoObject = " + _sObjectDescription + ";\n\t";
+ bIsPropertyUnoObjectDefined = true;
+ }
+ sReturn += _sReturnVariableName + " = (" + sShortTypeName + ") AnyConverter.toObject(" + sShortTypeName + ".class, oUnoObject);";
+// this.bAddTypeImport = true;
+ break;
+ }
+ if (!bAddAnyConverter){
+ bAddAnyConverter = bLocAddAnyConverter;
+ }
+ return sReturn;
+ }
+
+
+ public String getStructSourceCode(String _sReturnVariableDescription, String _sObjectDescription, String _sMember){
+ return "\t" + _sReturnVariableDescription + " = " + _sObjectDescription + "." + _sMember + ";";
+ }
+
+ public String getMainMethodSignatureSourceCode(XUnoNode _oUnoNode, String _soReturnObjectDescription){
+ //TODO try to use + _oUnoNode.getClassName() instead of the hack
+ String sReturn = "public void codesnippet(XInterface " + _soReturnObjectDescription + "){";
+ if (baddExceptionHandling){
+ sReturn += "\ntry{";
+ }
+ return sReturn;
+ }
+
+ public String getMethodSeparator(){
+ return ".";
+ }
+
+ public boolean needsqueryInterface(){
+ return true;
+ }
+
+ public String getqueryInterfaceSourceCode(String _sClassName, String _sReturnVariableName, String _sIncomingObjectName){
+ String sShortClassName = m_oIntrospector.getShortClassName(_sClassName);
+ return "\t" + _sReturnVariableName + " = (" + sShortClassName + ") UnoRuntime.queryInterface(" + sShortClassName + ".class, " + _sIncomingObjectName + ");\n";
+ }
+
+
+ public String getPropertyValueGetterSourceCode(String _sPropertyName, String _sReturnVariableName, String _sIncomingObjectName, TypeClass _aTypeClass, String _sTypeName){
+ String sObjectDescription = _sIncomingObjectName + ".getPropertyValue(\"" + _sPropertyName + "\")";
+ String sReturn = getConvertedSourceCodeValueOfObject(_sReturnVariableName, sObjectDescription, _aTypeClass, _sTypeName);
+ sReturn += ";";
+ sReturn = "\t" + sReturn;
+ return sReturn;
+// return "\t" + _sReturnVariableName + " = " + _sIncomingObjectName + ".getPropertyValue(\"" + _sPropertyName + "\");";
+ }
+
+
+ public String getObjectTypeDescription(String _sClassName, boolean _bAsHeader){
+ String sReturn = "";
+ if (_bAsHeader){
+ sReturn = _sClassName;
+ }
+ else{
+ sReturn = m_oIntrospector.getShortClassName(_sClassName);
+ }
+ return sReturn;
+ }
+
+
+ public String getMethodTerminationSourceCode(){
+ String sReturn = "";
+ int nIndex = 1;
+ String sExceptionName = "e";
+ if (baddExceptionHandling){
+ for (int i = 0; i < sExceptions.size(); i++){
+ String sCurException = (String) sExceptions.get(i);
+ if (sReturn.indexOf(sCurException) == -1){
+ if (nIndex > 1){
+ sExceptionName = "e"+ nIndex;
+ }
+ else{
+ sReturn +="\n}";
+ }
+ sReturn += "catch (" + sCurException + " " + sExceptionName + "){\n";
+ sReturn += "\t" + sExceptionName + ".printStackTrace(System.out);\n";
+ sReturn += "\t" + getCommentSign() + "Enter your Code here...\n}";
+ nIndex++;
+ }
+ }
+ }
+ sReturn += "\n}";
+ return sReturn;
+ }
+
+ public String castLiteral(String _sExpression, TypeClass _aTypeClass){
+ String sReturn = "";
+ switch (_aTypeClass.getValue()){
+ case TypeClass.BOOLEAN_value:
+ sReturn = _sExpression;
+ break;
+ case TypeClass.BYTE_value:
+ sReturn = "(byte) " + _sExpression;
+ break;
+ case TypeClass.CHAR_value:
+ sReturn = "'" + _sExpression + "'";
+ break;
+ case TypeClass.DOUBLE_value:
+ sReturn = "(double) " + _sExpression;
+ break;
+ case TypeClass.FLOAT_value:
+ sReturn = "(float) " + _sExpression;
+ break;
+ case TypeClass.UNSIGNED_SHORT_value:
+ case TypeClass.SHORT_value:
+ sReturn = "(short) " + _sExpression;
+ break;
+ case TypeClass.STRING_value:
+ sReturn = "\"" + _sExpression + "\"";
+ break;
+ case TypeClass.HYPER_value:
+ case TypeClass.UNSIGNED_HYPER_value:
+ sReturn = "(long) " + _sExpression;
+ break;
+ case TypeClass.LONG_value:
+ sReturn = _sExpression;
+ break;
+ case TypeClass.ENUM_value:
+ default:
+ sReturn = _sExpression;
+ System.out.println("Type " + _aTypeClass.getValue() + " not yet defined in 'castliteral()'");
+ }
+ return sReturn;
+ }
+
+
+ public String getbooleanTypeDescription(){
+ return "boolean";
+ }
+
+ public String getbyteTypeDescription(){
+ return "byte";
+ }
+
+ public String getshortTypeDescription(){
+ return "short";
+ }
+
+ public String getunsignedshortTypeDescription(){
+ return "short";
+ }
+
+ public String getlongTypeDescription(){
+ return "int";
+ }
+
+ public String getunsignedlongTypeDescription(){
+ return "int";
+ }
+
+ public String gethyperTypeDescription(){
+ return "long";
+ }
+
+ public String getunsignedhyperTypeDescription(){
+ return "long";
+ }
+
+ public String getfloatTypeDescription(){
+ return "float";
+ }
+
+ public String getdoubleTypeDescription(){
+ return "double";
+ }
+
+ public String getcharTypeDescription(){
+ return "char";
+ }
+
+ public String getstringTypeDescription(boolean _bAsHeaderSourceCode){
+ if (_bAsHeaderSourceCode){
+ return "";
+ }
+ else{
+ return "String";
+ }
+ }
+
+ public String gettypeTypeDescription(boolean _bAsHeaderSourceCode){
+ if (_bAsHeaderSourceCode){
+ return "com.sun.star.uno.Type";
+ }
+ else{
+ return "Type";
+ }
+ }
+
+ public String getanyTypeDescription(boolean _bAsHeaderSourceCode){
+ if (_bAsHeaderSourceCode){
+ return "";
+ }
+ else{
+ return "Object";
+ }
+ }
+
+
+ public String getStringValue(String _sValue){
+ return _sValue;
+ }
+
+
+ public String getVariableDeclaration(String _sTypeString, String _sVariableName, boolean _bIsArray, TypeClass _aTypeClass, boolean _bInitialize){
+ String sReturn = "";
+ if (_bIsArray){
+ sReturn = _sTypeString + "[] " + _sVariableName;
+ }
+ else{
+ sReturn = _sTypeString + " " + _sVariableName;
+ }
+ return sReturn;
+ }
+
+
+ public String getArrayDeclaration(String _sVariableDeclaration){
+ String sReturn = "";
+ String[] sDeclarations = _sVariableDeclaration.split(" ");
+ for (int i = 0; i< sDeclarations.length;i++){
+ sReturn += sDeclarations[i];
+ if (i == 0){
+ sReturn += "[]";
+ }
+ if (i < (sDeclarations.length -1)){
+ sReturn += " ";
+ }
+ }
+ return sReturn;
+ }
+
+ public String getCommentSign(){
+ return "//";
+ }
+ }
+
+
+ public class BasicCodeGenerator implements XLanguageSourceCodeGenerator{
+ String sStatementsCode = "";
+
+ public BasicCodeGenerator(){
+ }
+
+ public String getHeaderSourceCode(Object _oUnoObject, String _sClassName, TypeClass _aTypeClass){
+ String sHeaderStatement = "";
+ return sHeaderStatement;
+ }
+
+ public String getFinalHeaderStatements(){
+ return "";
+ }
+
+ public String getMainMethodSignatureSourceCode(XUnoNode _oUnoNode, String _soReturnObjectDescription){
+ //TODO try to use + _oUnoNode.getClassName() instead of the hack
+ return "Sub Main(" + _soReturnObjectDescription + " as " + getanyTypeDescription(false) + ")";
+ }
+
+ public boolean needsqueryInterface(){
+ return false;
+ }
+
+ public void assignqueryInterfaceHeaderSourceCode(){
+ }
+
+ public String getMethodSeparator(){
+ return ".";
+ }
+
+
+ public String getqueryInterfaceSourceCode(String _sClassName, String _sReturnVariableName, String _sIncomingObjectName){
+ return _sIncomingObjectName;
+ }
+
+
+ public String getPropertyValueGetterSourceCode(String _sPropertyName, String _sReturnVariableName, String _sIncomingObjectName, TypeClass _aTypeClass, String _sTypeName){
+ return "\t" + _sReturnVariableName + " = " + _sIncomingObjectName + "." + _sPropertyName;
+ }
+
+
+ public String getStructSourceCode(String _sReturnVariableDescription, String _sObjectDescription, String _sMember){
+ return getPropertyValueGetterSourceCode(_sMember, _sReturnVariableDescription, _sObjectDescription, null, "" );
+ }
+
+ public String getConvertedSourceCodeValueOfObject(String _sReturnVariableName, String _sObjectDescription, TypeClass _aTypeClass, String _sTypeName){
+ return _sReturnVariableName + " = " + _sObjectDescription;
+ }
+
+
+ public String getObjectTypeDescription(String _sClassName, boolean _bAsHeader){
+ return "Object";
+ }
+
+
+ public String getMethodTerminationSourceCode(){
+ return "\nEnd Sub\n";
+ }
+
+
+ public String castLiteral(String _sExpression, TypeClass _aTypeClass){
+ String sReturn = "";
+ switch (_aTypeClass.getValue()){
+ case TypeClass.BOOLEAN_value:
+ case TypeClass.BYTE_value:
+ case TypeClass.DOUBLE_value:
+ case TypeClass.FLOAT_value:
+ case TypeClass.UNSIGNED_SHORT_value:
+ case TypeClass.SHORT_value:
+ case TypeClass.LONG_value:
+ case TypeClass.UNSIGNED_LONG_value:
+ case TypeClass.HYPER_value:
+ case TypeClass.UNSIGNED_HYPER_value:
+ sReturn = _sExpression;
+ break;
+ case TypeClass.CHAR_value:
+ case TypeClass.STRING_value:
+ sReturn = "\"" +_sExpression + "\"";
+ break;
+ case TypeClass.ENUM_value:
+ default:
+ sReturn = _sExpression;
+ System.out.println("Type " + _aTypeClass.getValue() + " not yet defined in 'castliteral()'");
+ }
+ return sReturn;
+ }
+
+
+
+ public String getbooleanTypeDescription(){
+ return "Boolean";
+ }
+
+ public String getbyteTypeDescription(){
+ return "Integer";
+ }
+
+ public String getshortTypeDescription(){
+ return "Integer";
+ }
+
+ public String getunsignedshortTypeDescription(){
+ return "Integer";
+ }
+
+ public String getlongTypeDescription(){
+ return "Integer";
+ }
+
+ public String getunsignedlongTypeDescription(){
+ return "Long";
+ }
+
+ public String gethyperTypeDescription(){
+ return "Long";
+ }
+
+ public String getunsignedhyperTypeDescription(){
+ return "Long";
+ }
+
+ public String getfloatTypeDescription(){
+ return "Double";
+ }
+
+ public String getdoubleTypeDescription(){
+ return "Double";
+ }
+
+ public String getcharTypeDescription(){
+ return "String";
+ }
+
+ public String getstringTypeDescription(boolean _bAsHeaderSourceCode){
+ if (_bAsHeaderSourceCode){
+ return "";
+ }
+ else{
+ return "String";
+ }
+ }
+
+ public String gettypeTypeDescription(boolean _bAsHeaderSourceCode){
+ if (_bAsHeaderSourceCode){
+ return "";
+ }
+ else{
+ return "Object";
+ }
+ }
+
+ public String getanyTypeDescription(boolean _bAsHeaderSourceCode){
+ if (_bAsHeaderSourceCode){
+ return "";
+ }
+ else{
+ return "Object";
+ }
+ }
+
+ public String getStatementTerminationCharacter(){
+ return "";
+ }
+
+
+ public String getVariableDeclaration(String _sTypeString, String _sVariableName, boolean bIsArray, TypeClass _aTypeClass, boolean _bInitialize){
+ String sReturn = "";
+ if (bIsArray){
+ sReturn = "Dim " + _sVariableName + "() as " + _sTypeString + "\n\t" + _sVariableName;
+ }
+ else{
+ sReturn = "Dim " + _sVariableName + " as " + _sTypeString + "\n\t" + _sVariableName;
+ }
+ return sReturn;
+ }
+
+
+ public String getStringValue(String _sValue){
+ return _sValue;
+ }
+
+
+ public String getArrayDeclaration(String _sVariableDeclaration){
+ String sReturn = "";
+ String[] sDeclarations = _sVariableDeclaration.split(" ");
+ for (int i = 0; i< sDeclarations.length;i++){
+ sReturn += sDeclarations[i];
+ if (i == 0){
+ sReturn += "[]";
+ }
+ if (i < (sDeclarations.length -1)){
+ sReturn += " ";
+ }
+ }
+ return sReturn;
+ }
+
+ public String getCommentSign(){
+ return "'";
+ }
+
+ }
+
+ public class CPlusPlusCodeGenerator implements XLanguageSourceCodeGenerator{
+ String sStatementsCode = "";
+ boolean bIncludeStringHeader = false;
+ boolean bIncludeAny = false;
+ boolean bIncludeSequenceHeader = false;
+
+ public CPlusPlusCodeGenerator(){
+ }
+
+ private String getCSSNameSpaceString(){
+ return "css";
+ }
+
+ public String getStatementTerminationCharacter(){
+ return ";";
+ }
+
+
+ public String getHeaderSourceCode(Object _oUnoObject, String _sClassName, TypeClass _aTypeClass){
+ String sClassName = _sClassName;
+ String sHeaderStatement = "";
+ if (_oUnoObject != null){
+ if (!m_oIntrospector.isObjectPrimitive(_oUnoObject)){
+ if (m_oIntrospector.isObjectSequence(_oUnoObject)){
+ XTypeDescription xTypeDescription = m_oIntrospector.getReferencedType(sClassName);
+ if (xTypeDescription != null){
+ if (!m_oIntrospector.isPrimitive(xTypeDescription.getTypeClass())){
+ sClassName = getTypeString(xTypeDescription.getName(), xTypeDescription.getTypeClass(), true);
+ }
+ // primitive Types are not supposed to turn up in the import section...
+ else{
+ sClassName = "";
+ }
+ }
+ }
+ else{
+ sClassName = getTypeString(_sClassName, _aTypeClass, true);
+ }
+ if (!sClassName.equals("")){
+ sHeaderStatement = getHeaderOfClass(sClassName);
+ }
+ }
+ }
+ return sHeaderStatement;
+ }
+
+
+
+ public String getFinalHeaderStatements(){
+ String sReturn = "";
+ sReturn += "\nnamespace " + getCSSNameSpaceString() + " = com::sun::star;\n";
+ sReturn += "using namespace rtl;\n";
+ return sReturn;
+ }
+
+
+ private String getHeaderOfClass(String _sClassName){
+ return "#include \"" + _sClassName.replace('.', '/') + ".hpp\"\n"; // #include <com/sun/star/uno/XComponentContext.hpp>
+ }
+
+
+
+ public void assignqueryInterfaceHeaderSourceCode(){
+ sHeaderStatements.add("#include \"sal/config.h\"\n");
+ sHeaderStatements.add("#include \"sal/types.h\"\n");
+ if (bIncludeStringHeader){
+ sHeaderStatements.add("#include \"rtl/ustring.hxx\"\n");
+ }
+ sHeaderStatements.add("#include \"com/sun/star/uno/Reference.hxx\"\n");
+ if (bIncludeSequenceHeader){
+ sHeaderStatements.add("#include \"com/sun/star/uno/Sequence.hxx\"\n");
+ }
+ sHeaderStatements.add(getHeaderOfClass("com.sun.star.uno.XInterface"));
+ if (bIncludeAny){
+ sHeaderStatements.add(getHeaderOfClass("com.sun.star.uno.Any"));
+ }
+ }
+
+
+ public String getMainMethodSignatureSourceCode(XUnoNode _oUnoNode, String _soReturnObjectDescription){
+ String sReturn = "";
+ sReturn = "void codesnippet(const " + getCSSNameSpaceString() + "::uno::Reference<" + getCSSNameSpaceString() + "::uno::XInterface>& " + _soReturnObjectDescription + " ){";
+ int a = 0;
+ if (!sExceptions.contains("com.sun.star.uno.RuntimeException")){
+ sExceptions.add("com.sun.star.uno.RuntimeException");
+ }
+ if (baddExceptionHandling){
+ sReturn += "\n//throw ";
+ for (int i = 0; i < sExceptions.size(); i++){
+ String sCurException = (String) sExceptions.get(i);
+ if (sReturn.indexOf(sCurException) == -1){
+ if (a++ > 0){
+ sReturn += ", ";
+ }
+ sReturn += getObjectTypeDescription(sCurException, false);
+
+ }
+ }
+
+ }
+ sReturn += "{";
+ return sReturn;
+ }
+
+
+ public boolean needsqueryInterface(){
+ return true;
+ }
+
+
+ public String getqueryInterfaceSourceCode(String _sClassName, String _sReturnVariableName, String _sIncomingObjectName){
+ return "\t" + _sReturnVariableName + "( " + _sIncomingObjectName + ", " + getCSSNameSpaceString() + "::uno::UNO_QUERY_THROW);\n";
+ }
+
+
+ public String getPropertyValueGetterSourceCode(String _sPropertyName, String _sReturnVariableName, String _sIncomingObjectName, TypeClass _aTypeClass, String _sTypeName){
+ String sFirstLine = "\t";
+ String sReturnVariableName = _sReturnVariableName;
+ // e.g. uno::Any a = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" )) );
+ String[] sVarDefinition = _sReturnVariableName.split("=");
+ if (sVarDefinition.length > 0){
+ String sVariable = sVarDefinition[0];
+ String[] sVarDeclaration = sVariable.split(" ");
+ if (sVarDeclaration.length > 0){
+ sFirstLine += sReturnVariableName + ";\n";
+ sReturnVariableName = sVarDeclaration[sVarDeclaration.length-1];
+ }
+ }
+ String sObjectDescription = _sIncomingObjectName + "->getPropertyValue(" + getStringValue(_sPropertyName) + ")";
+ String sSecondLine = "\t" + getConvertedSourceCodeValueOfObject(sReturnVariableName, sObjectDescription, _aTypeClass, _sTypeName) + ";";
+ return sFirstLine + sSecondLine;
+ }
+
+
+ public String getStructSourceCode(String _sReturnVariableDescription, String _sObjectDescription, String _sMember){
+ return "\t" + _sReturnVariableDescription + " = " + _sObjectDescription + "->" + _sMember + ";";
+ }
+
+
+ public String getConvertedSourceCodeValueOfObject(String _sReturnVariableName, String _sObjectDescription, TypeClass _aTypeClass, String _sTypeName){
+// if (m_oIntrospector.isPrimitive(_aTypeClass)){
+ return _sObjectDescription + " >>= " + _sReturnVariableName;
+// }
+// else{
+// return _sReturnVariableName + " = " + _sObjectDescription;
+// }
+ }
+
+
+ public String getStringValue(String _sValue){
+ bIncludeStringHeader = true;
+ return "OUString(RTL_CONSTASCII_USTRINGPARAM(\"" + _sValue + "\"))";
+ }
+
+
+ public String getObjectTypeDescription(String _sClassName, boolean _bAsHeader){
+ String sReturn = "";
+ if (_bAsHeader){
+ sReturn = _sClassName.replace('.', '/');
+ }
+ else{
+ String sModuleName = m_oIntrospector.getModuleName(_sClassName);
+ sModuleName = m_oIntrospector.getShortClassName(sModuleName);
+ sReturn = getCSSNameSpaceString() + "::" + sModuleName + "::" + m_oIntrospector.getShortClassName(_sClassName);
+ }
+ return sReturn;
+ }
+
+
+ public String getMethodTerminationSourceCode(){
+ return "\n}";
+ }
+
+ public String getMethodSeparator(){
+ return "->";
+ }
+
+
+ public String castLiteral(String _sExpression, TypeClass _aTypeClass){
+ String sReturn = "";
+ switch (_aTypeClass.getValue()){
+ case TypeClass.BOOLEAN_value:
+ case TypeClass.BYTE_value:
+ case TypeClass.DOUBLE_value:
+ case TypeClass.FLOAT_value:
+ case TypeClass.UNSIGNED_SHORT_value:
+ case TypeClass.SHORT_value:
+ case TypeClass.LONG_value:
+ case TypeClass.UNSIGNED_LONG_value:
+ case TypeClass.HYPER_value:
+ case TypeClass.UNSIGNED_HYPER_value:
+ sReturn = _sExpression;
+ break;
+ case TypeClass.CHAR_value:
+ sReturn = "'" + _sExpression + "'";
+ break;
+ case TypeClass.STRING_value:
+ sReturn = getStringValue(_sExpression);
+ break;
+ case TypeClass.ENUM_value:
+ default:
+ sReturn = _sExpression;
+ System.out.println("Type " + _aTypeClass.getValue() + " not yet defined in 'castliteral()'");
+ }
+ return sReturn;
+ }
+
+ public String getbooleanTypeDescription(){
+ return "sal_Bool";
+ }
+
+ public String getbyteTypeDescription(){
+ return "sal_Int8";
+ }
+
+ public String getshortTypeDescription(){
+ return "sal_Int16";
+ }
+
+ public String getunsignedshortTypeDescription(){
+ return "sal_uInt16";
+ }
+
+ public String getlongTypeDescription(){
+ return "sal_Int32";
+ }
+
+ public String getunsignedlongTypeDescription(){
+ return "sal_uInt32";
+ }
+
+ public String gethyperTypeDescription(){
+ return "sal_Int64";
+ }
+
+ public String getunsignedhyperTypeDescription(){
+ return "sal_uInt64";
+ }
+
+ public String getfloatTypeDescription(){
+ return "float";
+ }
+
+ public String getdoubleTypeDescription(){
+ return "double";
+ }
+
+ public String getcharTypeDescription(){
+ return "sal_Unicode";
+ }
+
+ public String getstringTypeDescription(boolean _bAsHeaderSourceCode){
+ bIncludeStringHeader = true;
+ if (_bAsHeaderSourceCode){
+ return "";
+ }
+ else{
+ return "OUString";
+ }
+ }
+
+ public String gettypeTypeDescription(boolean _bAsHeaderSourceCode){
+ if (_bAsHeaderSourceCode){
+ return "com/sun/star/uno/Type";
+ }
+ else{
+ return "Type";
+ }
+ }
+
+ public String getanyTypeDescription(boolean _bAsHeaderSourceCode){
+ if (_bAsHeaderSourceCode){
+ return "com/sun/star/uno/XInterface";
+ }
+ else{
+ return "XInterface";
+ }
+ }
+
+
+ public String getVariableDeclaration(String _sTypeString, String _sVariableName, boolean bIsArray, TypeClass _aTypeClass, boolean _bInitialize){
+ boolean bIsPrimitive = m_oIntrospector.isPrimitive(_aTypeClass);
+
+ // uno::Reference< frame::XDispatch > m_xDispatch
+ String sReturn = "";
+ if (bIsArray){
+ bIncludeSequenceHeader = true;
+ sReturn = getCSSNameSpaceString() + "::uno::Sequence<" + _sTypeString + "> " + _sVariableName;
+ }
+ else{
+ if (bIsPrimitive){
+ sReturn = _sTypeString + " " + _sVariableName;
+ if (_bInitialize){
+ switch (_aTypeClass.getValue()){
+ case TypeClass.BOOLEAN_value:
+ sReturn = sReturn + " = false";
+ break;
+ case TypeClass.BYTE_value:
+ case TypeClass.UNSIGNED_SHORT_value:
+ case TypeClass.SHORT_value:
+ case TypeClass.LONG_value:
+ case TypeClass.UNSIGNED_LONG_value:
+ case TypeClass.HYPER_value:
+ case TypeClass.UNSIGNED_HYPER_value:
+ sReturn = sReturn + " = 0";
+ break;
+ case TypeClass.DOUBLE_value:
+ case TypeClass.FLOAT_value:
+ sReturn = sReturn + " = 0.0";
+ break;
+ case TypeClass.CHAR_value:
+ sReturn = sReturn + "'0'";
+ break;
+ case TypeClass.STRING_value:
+ sReturn = _sTypeString + " " + _sVariableName;
+ break;
+ default:
+ sReturn = _sTypeString + " " + _sVariableName;
+ System.out.println("Type " + _aTypeClass.getValue() + " not yet defined in 'getVariableDeclaration()'");
+ }
+ }
+ }
+ else{
+ sReturn = getCSSNameSpaceString() + "::uno::Reference<" + _sTypeString + "> " +_sVariableName;
+ }
+ }
+ return sReturn;
+ }
+
+ public String getArrayDeclaration(String _sVariableDeclaration){
+ this.bIncludeSequenceHeader = true;
+ String sReturn = "";
+ String[] sDeclarations = _sVariableDeclaration.split(" ");
+ if (sDeclarations.length == 2){
+ sReturn = getCSSNameSpaceString() +"::uno::Sequence<" + sDeclarations[1] + ">";
+ }
+ return sReturn;
+ }
+
+ public String getCommentSign(){
+ return "//";
+ }
+
+ }
+}
diff --git a/odk/examples/java/Inspector/SwingDialogProvider.java b/odk/examples/java/Inspector/SwingDialogProvider.java
new file mode 100644
index 000000000000..7b85070c2491
--- /dev/null
+++ b/odk/examples/java/Inspector/SwingDialogProvider.java
@@ -0,0 +1,442 @@
+/*************************************************************************
+ *
+ * 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.XComponentContext;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.event.ActionListener;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+import java.awt.event.KeyEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import javax.swing.ButtonGroup;
+import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JDialog;
+import javax.swing.JEditorPane;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
+import javax.swing.JRadioButtonMenuItem;
+import javax.swing.JTabbedPane;
+import javax.swing.KeyStroke;
+
+
+
+public class SwingDialogProvider implements XDialogProvider{
+
+ private JPopupMenu m_jPopupMenu = new JPopupMenu();
+ private XComponentContext m_xComponentContext;
+ private Inspector._Inspector m_oInspector;
+ private JDialog m_jInspectorDialog = new JDialog();
+ private JTabbedPane m_jTabbedPane1 = new JTabbedPane();
+ private Container cp;
+
+ private JMenu jMnuOptions = new JMenu("Options");
+ private JRadioButtonMenuItem jJavaMenuItem = null;
+ private JRadioButtonMenuItem jCPlusPlusMenuItem = null;
+ private JRadioButtonMenuItem jBasicMenuItem = null;
+
+ /** Creates a new instance of SwingPopupMentuProvider */
+ public SwingDialogProvider(Inspector._Inspector _oInspector, String _sTitle) {
+ m_oInspector = _oInspector;
+ m_xComponentContext = _oInspector.getXComponentContext();
+ insertMenus();
+ initializePopupMenu();
+ cp = m_jInspectorDialog.getContentPane();
+ cp.setLayout(new java.awt.BorderLayout(0, 10));
+ m_jTabbedPane1.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
+ m_jInspectorDialog.addWindowListener(new InspectorWindowAdapter());
+ m_jInspectorDialog.addComponentListener(new InspectorComponentAdapter());
+ m_jInspectorDialog.setTitle(_sTitle);
+ m_jInspectorDialog.setLocation(100, 50);
+ m_jInspectorDialog.getContentPane().add(m_jTabbedPane1);
+ }
+
+
+
+ public JDialog getDialog(){
+ return m_jInspectorDialog;
+ }
+
+
+ public void addMenuBar(JMenuBar _jMenuBar){
+ getDialog().setJMenuBar(_jMenuBar);
+ }
+
+
+ public void removeTabPaneByIndex(int _nIndex){
+ if (_nIndex > -1){
+ String sSelInspectorPanelTitle = m_jTabbedPane1.getTitleAt(_nIndex);
+ m_jTabbedPane1.remove(_nIndex);
+ m_oInspector.getInspectorPages().remove(sSelInspectorPanelTitle);
+ }
+ }
+
+
+ public void selectInspectorPageByIndex(int nTabIndex){
+ m_jTabbedPane1.setSelectedIndex(nTabIndex);
+ }
+
+
+ public int getInspectorPageCount(){
+ return m_jTabbedPane1.getTabCount();
+ }
+
+
+ public JTabbedPane getTabbedPane(){
+ return m_jTabbedPane1;
+ }
+
+
+ public InspectorPane getSelectedInspectorPage(){
+ int nIndex = m_jTabbedPane1.getSelectedIndex();
+ return getInspectorPage(nIndex);
+ }
+
+
+ public InspectorPane getInspectorPage(int _nIndex){
+ InspectorPane oInspectorPane = null;
+ if (_nIndex > -1){
+ JPanel jPnlContainerInspectorPanel = (JPanel) m_jTabbedPane1.getComponentAt(_nIndex);
+ String sInspectorPanelTitle = m_jTabbedPane1.getTitleAt(_nIndex);
+ oInspectorPane = (InspectorPane) m_oInspector.getInspectorPages().get(sInspectorPanelTitle);
+ }
+ return oInspectorPane;
+ }
+
+
+ public void removeTabPanes(){
+ int nCount = m_jTabbedPane1.getTabCount();
+ if (nCount > 0){
+ for (int i = nCount-1; i >= 0; i--){
+ removeTabPaneByIndex(i);
+ }
+ }
+ }
+
+ public void removeSelectedTabPane(){
+ int nIndex = getTabbedPane().getSelectedIndex();
+ removeTabPaneByIndex(nIndex);
+ }
+
+
+ private class InspectorComponentAdapter extends ComponentAdapter{
+ public void componentHidden(ComponentEvent e){
+ m_jInspectorDialog.pack();
+ m_jInspectorDialog.invalidate();
+
+ }
+
+ public void componentShown(ComponentEvent e){
+ m_jInspectorDialog.pack();
+ m_jInspectorDialog.invalidate();
+ }
+ }
+
+ private class InspectorWindowAdapter extends WindowAdapter{
+ public void windowClosed(WindowEvent e){
+ removeTabPanes();
+ m_oInspector.disposeHiddenDocuments();
+ }
+
+ public void windowClosing(WindowEvent e){
+ removeTabPanes();
+ m_oInspector.disposeHiddenDocuments();
+ }
+ }
+
+
+
+ private void initializePopupMenu(){
+ m_jPopupMenu.add(getInspectMenuItem("Inspect"));
+ m_jPopupMenu.add(getSourceCodeMenuItem(SADDTOSOURCECODE));
+ m_jPopupMenu.add(getInvokeMenuItem(SINVOKE));
+ m_jPopupMenu.addSeparator();
+ m_jPopupMenu.add(getHelpMenuItem("Help"));
+ }
+
+
+ private void addOpenDocumentMenu(JMenu _jMnuRoot){
+ ActionListener oActionListener = new ActionListener(){
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ String sTDocUrl = evt.getActionCommand();
+ m_oInspector.inspectOpenDocument(sTDocUrl);
+ }
+ };
+ String[] sTDocUrls = m_oInspector.getTDocUrls();
+ String[] sTDocTitles = m_oInspector.getTDocTitles(sTDocUrls);
+ for (int i = 0; i < sTDocUrls.length; i++){
+ addSingleMenuItem(_jMnuRoot, sTDocTitles[i], sTDocUrls[i], oActionListener);
+ }
+ }
+
+
+ private void addApplicationDocumentMenu(JMenu _jMnuRoot){
+ ActionListener oActionListener = new ActionListener(){
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ String sApplicationDocUrl = evt.getActionCommand();
+ m_oInspector.inspectOpenEmptyDocument(sApplicationDocUrl);
+ }
+ };
+ String[][] sApplUrls = m_oInspector.getApplicationUrls();
+ for (int i = 0; i < sApplUrls.length; i++){
+ addSingleMenuItem(_jMnuRoot, sApplUrls[i][1], sApplUrls[i][0], oActionListener);
+ }
+ }
+
+
+ private void addSingleMenuItem(JMenu _jMnuOpenDocs, String _sTitle, String _sActionCommand, ActionListener _oActionListener){
+ javax.swing.JMenuItem jMnuItemOpenDoc = new javax.swing.JMenuItem(_sTitle);
+ jMnuItemOpenDoc.setActionCommand(_sActionCommand);
+ jMnuItemOpenDoc.addActionListener(_oActionListener);
+ _jMnuOpenDocs.add(jMnuItemOpenDoc);
+ }
+
+
+ private void addHelpMenu(JMenuBar _jInspectMenuBar){
+ JMenu jMnuHelp = new JMenu("Help");
+ jMnuHelp.add(getHelpMenuItem("Idl-Help"));
+ _jInspectMenuBar.add(jMnuHelp);
+ }
+
+
+ private JMenuItem getHelpMenuItem(String _sMenuTitle){
+ JMenuItem jMnuHelpItem = new JMenuItem(_sMenuTitle);
+ jMnuHelpItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
+ jMnuHelpItem.setMnemonic('H');
+ jMnuHelpItem.addActionListener(new ActionListener(){
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ m_oInspector.openIdlFileforSelectedNode();
+ }
+ });
+ return jMnuHelpItem;
+ }
+
+ private void addFileMenu(JMenuBar _jInspectMenuBar){
+ JMenu jMnuFile = new JMenu("File");
+ JMenuItem jMnuItemRemoveInspector = new JMenuItem("Remove");
+ jMnuItemRemoveInspector.addActionListener(new ActionListener(){
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ removeSelectedTabPane();
+ }
+ });
+ jMnuFile.add(jMnuItemRemoveInspector);
+ JMenuItem jMnuItemExit = new JMenuItem("Exit");
+ jMnuItemExit.addActionListener(new ActionListener(){
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ getDialog().dispose();
+ }
+ });
+ jMnuFile.add(jMnuItemExit);
+ _jInspectMenuBar.add(jMnuFile);
+ }
+
+ private JMenuItem getInspectMenuItem(String _sLabel){
+ JMenuItem jMnuSelectedObject = new JMenuItem(_sLabel);
+ jMnuSelectedObject.addActionListener(new ActionListener(){
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ m_oInspector.inspectSelectedNode();
+ }
+ });
+ return jMnuSelectedObject;
+ }
+
+
+ private JMenuItem getSourceCodeMenuItem(String _sLabel){
+ JMenuItem jMnuSelectedObject = new JMenuItem(_sLabel);
+ jMnuSelectedObject.addActionListener(new ActionListener(){
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ m_oInspector.addSourceCodeOfSelectedNode();
+ }
+ });
+ return jMnuSelectedObject;
+ }
+
+ private JMenuItem getInvokeMenuItem(String _sLabel){
+ JMenuItem jMnuSelectedObject = new JMenuItem(_sLabel);
+ jMnuSelectedObject.addActionListener(new ActionListener(){
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ m_oInspector.invokeSelectedMethod();
+ }
+ });
+ return jMnuSelectedObject;
+ }
+
+
+ private void addInspectMenu(JMenuBar _jInspectMenuBar){
+ JMenu jMnuInspect = new JMenu("Inspect");
+ addApplicationDocumentMenu(jMnuInspect);
+ jMnuInspect.addSeparator();
+ addGlobalServiceManagerMenu(jMnuInspect);
+ jMnuInspect.addSeparator();
+ jMnuInspect.add(getInspectMenuItem("Selected Object"));
+ jMnuInspect.addSeparator();
+ addOpenDocumentMenu(jMnuInspect);
+ _jInspectMenuBar.add(jMnuInspect);
+ }
+
+ public int getLanguage(){
+ return XLanguageSourceCodeGenerator.nJAVA;
+ }
+
+
+ public void selectSourceCodeLanguage(int _nLanguage){
+ switch (_nLanguage){
+ case XLanguageSourceCodeGenerator.nJAVA:
+ jJavaMenuItem.setSelected(true);
+ break;
+ case XLanguageSourceCodeGenerator.nCPLUSPLUS:
+ jCPlusPlusMenuItem.setSelected(true);
+ break;
+ case XLanguageSourceCodeGenerator.nBASIC:
+ jBasicMenuItem.setSelected(true);
+ break;
+ default:
+ System.out.println("Warning: Sourcecode language is not defined!");
+ }
+ }
+
+ private JRadioButtonMenuItem addLanguageMenuItem(ButtonGroup _group, String _sLanguageTitle, boolean _bSelect, char _sMnemonic, final int _nLanguage){
+ JRadioButtonMenuItem jMenuItem = new JRadioButtonMenuItem(_sLanguageTitle, _bSelect);
+ jMenuItem.setMnemonic(_sMnemonic);
+ _group.add(jMenuItem);
+ jMenuItem.addActionListener(new ActionListener(){
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ m_oInspector.setSourceCodeLanguage(_nLanguage);
+ }
+ });
+ return jMenuItem;
+ }
+
+
+ public String getIDLPath(){
+ return this.m_oInspector.getIDLPath();
+ }
+
+ private void addOptionsMenu(JMenuBar _jInspectMenuBar){
+ ButtonGroup oButtonGroup = new ButtonGroup();
+ jJavaMenuItem = addLanguageMenuItem(oButtonGroup, "Generate Java Sourcecode", true, 'J', XLanguageSourceCodeGenerator.nJAVA);
+ jMnuOptions.add(jJavaMenuItem);
+ jCPlusPlusMenuItem = addLanguageMenuItem(oButtonGroup, "Generate C++ Sourcecode", false, 'C', XLanguageSourceCodeGenerator.nCPLUSPLUS);
+ jMnuOptions.add(jCPlusPlusMenuItem);
+ jBasicMenuItem = addLanguageMenuItem(oButtonGroup, "Generate OpenOffice.org Basic Sourcecode", false, 'B', XLanguageSourceCodeGenerator.nBASIC);
+ jMnuOptions.add(jBasicMenuItem);
+ jMnuOptions.addSeparator();
+ JMenuItem jMenuItem = new JMenuItem("Path to SDK-Installation");
+ jMenuItem.setMnemonic('I');
+ jMenuItem.addActionListener(new ActionListener(){
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ m_oInspector.assignSDKPath();
+ }
+ });
+
+ jMnuOptions.add(jMenuItem);
+ _jInspectMenuBar.add(jMnuOptions);
+ }
+
+
+ private void insertMenus(){
+ JMenuBar jMenuBar1 = new javax.swing.JMenuBar();
+ addFileMenu(jMenuBar1);
+ addInspectMenu(jMenuBar1);
+ JMenu jMnuEdit = new JMenu("Edit");
+ JMenu jMnuView = new JMenu("View");
+ addOptionsMenu(jMenuBar1);
+ jMenuBar1.setFont(new java.awt.Font("Dialog", 0, 12));
+ jMenuBar1.add(jMnuEdit);
+ jMenuBar1.add(jMnuView);
+ addHelpMenu(jMenuBar1);
+ addMenuBar(jMenuBar1);
+ }
+
+ private void addGlobalServiceManagerMenu(JMenu _jMnuRoot){
+ JMenuItem jMnuGlobalServiceManager = new JMenuItem("Global Service Manager");
+ jMnuGlobalServiceManager.addActionListener(new ActionListener(){
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ m_oInspector.inspect(m_xComponentContext.getServiceManager(), "Global ServiceManager");
+ }
+ });
+ _jMnuRoot.add(jMnuGlobalServiceManager);
+ }
+
+
+
+ public void enablePopupMenuItem(String _sMenuTitle, boolean _bdoEnable){
+ Component[] oComponents = m_jPopupMenu.getComponents();
+ for (int i = 0; i < oComponents.length; i++){
+ if (oComponents[i] instanceof JMenuItem){
+ JMenuItem jMenuItem = (JMenuItem) oComponents[i];
+ if (jMenuItem.getText().equals(_sMenuTitle)){
+ jMenuItem.setEnabled(_bdoEnable);
+ }
+ }
+ }
+ }
+
+
+ public void showPopUpMenu(Object _invoker, int x, int y) throws ClassCastException{
+ if (_invoker instanceof Component){
+ m_jPopupMenu.show((Component) _invoker, x, y);
+ }
+ }
+
+
+ public void show(int _nPageIndex){
+ Dimension aDimension = m_jInspectorDialog.getSize();
+ selectInspectorPageByIndex(_nPageIndex);
+ if (_nPageIndex > 0){
+ m_jInspectorDialog.setSize(aDimension);
+ }
+ else{
+ m_jInspectorDialog.pack();
+ }
+// m_jInspectorDialog.paint(m_jInspectorDialog.getGraphics());
+ m_jInspectorDialog.setVisible(true);
+ }
+
+ public void paint(){
+ m_jTabbedPane1.paintImmediately(m_jTabbedPane1.getBounds());
+ }
+
+
+ public void addInspectorPage(String _sTitle, Object _oContainer) throws ClassCastException{
+ if (_oContainer instanceof Component){
+ m_jTabbedPane1.addTab(_sTitle, (Component) _oContainer);
+ }
+ }
+}
diff --git a/odk/examples/java/Inspector/SwingTreeControlProvider.java b/odk/examples/java/Inspector/SwingTreeControlProvider.java
new file mode 100644
index 000000000000..bf00acd77d0b
--- /dev/null
+++ b/odk/examples/java/Inspector/SwingTreeControlProvider.java
@@ -0,0 +1,427 @@
+/*************************************************************************
+ *
+ * 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.beans.Property;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.lang.NullPointerException;
+import com.sun.star.reflection.XConstantTypeDescription;
+import com.sun.star.reflection.XIdlMethod;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.uno.Type;
+import java.awt.BorderLayout;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JProgressBar;
+import javax.swing.JScrollBar;
+import javax.swing.JScrollPane;
+import javax.swing.JSplitPane;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+import javax.swing.JTree;
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.event.TreeSelectionListener;
+import javax.swing.event.TreeWillExpandListener;
+import javax.swing.tree.DefaultTreeSelectionModel;
+import javax.swing.tree.ExpandVetoException;
+import javax.swing.tree.TreePath;
+import javax.swing.tree.TreeSelectionModel;
+
+
+
+public class SwingTreeControlProvider implements XTreeControlProvider{
+ private JTextArea jtxtGeneratedSourceCode = new JTextArea();
+ private JTextField jtxtFilter = new JTextField();
+ private javax.swing.JLabel jlblFilter = new javax.swing.JLabel("Set a filter");
+ private JPanel jPnlBottom = new JPanel(new BorderLayout());
+ private JPanel jPanelProgress = new JPanel(new BorderLayout());
+ private JPanel jPnlPath = new JPanel(new BorderLayout());
+ private JLabel jLblPath = new JLabel("Generated source code");
+ private JProgressBar jProgressBar1 = new JProgressBar();
+ private JTree jTree = new javax.swing.JTree();
+ private XDialogProvider m_xDialogProvider;
+ private HideableTreeModel treeModel;
+ private UnoTreeRenderer oUnoTreeRenderer;
+ private InspectorPane m_oInspectorPane;
+ private Object oUserDefinedObject = null;
+ private boolean bIsUserDefined = false;
+ private SwingUnoNode oRootNode;
+
+ private final int nDIALOGWIDTH = 800;
+
+
+
+ public SwingTreeControlProvider(XDialogProvider _xDialogProvider){
+ m_xDialogProvider = _xDialogProvider;
+ }
+
+
+ public void addInspectorPane(InspectorPane _oInspectorPane){
+ m_oInspectorPane = _oInspectorPane;
+ }
+
+ public InspectorPane getInspectorPane() throws NullPointerException{
+ if (m_oInspectorPane == null){
+ throw new NullPointerException("InspectorPage has not been added to TreeControl");
+ }
+ else{
+ return m_oInspectorPane;
+ }
+ }
+
+ private void ComponentSelector(Object _oRootObject, String _sRootTreeNodeName) {
+ String sTreeNodeName = _sRootTreeNodeName;
+ oRootNode = new SwingUnoNode(_oRootObject);
+ oRootNode.setLabel(_sRootTreeNodeName);
+ treeModel = new HideableTreeModel(oRootNode);
+ jTree.setModel(treeModel);
+ jTree.setRootVisible(true);
+ jTree.setVisible(true);
+ oRootNode.setFoldable(true);
+ enableFilterElements(null);
+ }
+
+
+
+ private void insertTopPanel(JPanel _jPnlCenter){
+ javax.swing.JPanel jPnlTop = new javax.swing.JPanel(new BorderLayout(10, 10));
+ jPnlTop.setPreferredSize(new java.awt.Dimension(nDIALOGWIDTH, 20));
+ jlblFilter.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
+ jlblFilter.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
+ jPnlTop.add(jlblFilter, java.awt.BorderLayout.WEST);
+ jtxtFilter.setHorizontalAlignment(javax.swing.JTextField.LEFT);
+ jtxtFilter.setPreferredSize(new java.awt.Dimension(200, 10));
+ jtxtFilter.addKeyListener(new InspectorKeyFilterAdapter());
+ jPnlTop.add(jtxtFilter, java.awt.BorderLayout.CENTER);
+ _jPnlCenter.add(jPnlTop, java.awt.BorderLayout.NORTH);
+ }
+
+
+ private void insertBottomPanel(JSplitPane _jSplitPane){ //JPanel _jPnlCenter){
+ jtxtGeneratedSourceCode.setTabSize(4);
+ jtxtGeneratedSourceCode.getAccessibleContext().setAccessibleName("generated SourceCode");
+ JScrollPane jScrollPane = new JScrollPane(jtxtGeneratedSourceCode);
+ jScrollPane.setPreferredSize(new Dimension(nDIALOGWIDTH,205));
+ jtxtGeneratedSourceCode.setEditable(false);
+ _jSplitPane.setBottomComponent(jScrollPane);
+ }
+
+ private void insertBorderPanes(Container _cp){
+ JPanel jPnlEast = new JPanel(new BorderLayout());
+ JPanel jPnlNorth = new JPanel(new BorderLayout());
+ JPanel jPnlSouth = new JPanel(new BorderLayout());
+ JPanel jPnlWest = new JPanel(new BorderLayout());
+ _cp.add(jPnlNorth, java.awt.BorderLayout.NORTH);
+ jPnlWest.setPreferredSize(new java.awt.Dimension(10, 10));
+ _cp.add(jPnlWest, java.awt.BorderLayout.WEST);
+ jPnlEast.setPreferredSize(new java.awt.Dimension(10, 10));
+ _cp.add(jPnlEast, java.awt.BorderLayout.EAST);
+ jPnlSouth.setPreferredSize(new java.awt.Dimension(10, 10));
+ _cp.add(jPnlSouth, java.awt.BorderLayout.SOUTH);
+ }
+
+
+ public String enableFilterElements(XUnoNode _oUnoNode){
+ String sFilter ="";
+ boolean bIsFacetteNode = isFacetteNode(_oUnoNode);
+ this.jtxtFilter.setEnabled(bIsFacetteNode);
+ this.jlblFilter.setEnabled(bIsFacetteNode);
+ sFilter = m_oInspectorPane.getFilter(_oUnoNode);
+ jtxtFilter.setText(sFilter);
+ return sFilter;
+ }
+
+
+ private class InspectorKeyFilterAdapter extends KeyAdapter{
+ public void keyReleased(KeyEvent e){
+ String sFilter = jtxtFilter.getText();
+ SwingTreePathProvider oSwingTreePathProvider = new SwingTreePathProvider(jTree.getSelectionPath());
+ XUnoNode oUnoNode = oSwingTreePathProvider.getLastPathComponent();
+ if (oUnoNode instanceof XUnoFacetteNode){
+ m_oInspectorPane.applyFilter((XUnoFacetteNode) oUnoNode, sFilter);
+ }
+ }
+ }
+
+
+
+ /** Inspect the given object for methods, properties, interfaces, and
+ * services.
+ * @param a The object to inspect
+ * @throws RuntimeException If
+ */
+ public Object inspect(java.lang.Object _oUserDefinedObject, String _sTitle) throws com.sun.star.uno.RuntimeException {
+ JPanel jPnlContainer = new javax.swing.JPanel(new BorderLayout(10, 10));
+ try {
+ javax.swing.JPanel jPnlCenter = new javax.swing.JPanel();
+ bIsUserDefined = (_oUserDefinedObject != null);
+ if (bIsUserDefined){
+ oUserDefinedObject = _oUserDefinedObject;
+ m_oInspectorPane.setTitle(_sTitle);
+ }
+ javax.swing.JScrollPane jScrollPane1 = new javax.swing.JScrollPane();
+ TreeSelectionModel tsm = new DefaultTreeSelectionModel();
+ tsm.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
+ jTree.setSelectionModel(tsm);
+ jTree.setVisible(false);
+ jPnlCenter.setLayout(new java.awt.BorderLayout(10, 10));
+ jPnlCenter.getAccessibleContext().setAccessibleName("inspection tab view");
+ insertTopPanel(jPnlCenter);
+ jScrollPane1.setViewportView(jTree);
+ jScrollPane1.setPreferredSize(new java.awt.Dimension(600, 600));
+ jScrollPane1.getAccessibleContext().setAccessibleName("API view scroll pane");
+
+ JScrollBar jHScrollBar = jScrollPane1.createHorizontalScrollBar();
+ jHScrollBar.getAccessibleContext().setAccessibleName("API view horizontal scroll bar");
+ jScrollPane1.setHorizontalScrollBar(jHScrollBar);
+
+ JScrollBar jVScrollBar = jScrollPane1.createVerticalScrollBar();
+ jVScrollBar.getAccessibleContext().setAccessibleName("API view vertical scroll bar");
+ jScrollPane1.setVerticalScrollBar(jVScrollBar);
+
+ JSplitPane jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
+ jSplitPane.setTopComponent(jScrollPane1);
+ jPnlCenter.add(jSplitPane, java.awt.BorderLayout.CENTER);
+ jSplitPane.setDividerLocation(500);
+ insertBottomPanel(jSplitPane);
+ UnoTreeRenderer oUnoTreeRenderer = new UnoTreeRenderer();
+ jTree.setCellRenderer(oUnoTreeRenderer);
+ jTree.addTreeSelectionListener(
+ new TreeSelectionListener() {
+ public void valueChanged(TreeSelectionEvent event) {
+ TreePath tp = event.getNewLeadSelectionPath();
+ if (tp != null){
+ XUnoNode oUnoNode = getSelectedNode();
+ String sFilter = enableFilterElements(oUnoNode);
+ }
+ }
+ }
+ );
+ // Add KeyListener for help
+ jTree.addKeyListener( new java.awt.event.KeyAdapter() {
+ public void keyReleased(java.awt.event.KeyEvent event) {
+ if ( event.getKeyCode() == KeyEvent.VK_F1 ) {
+ // function key F1 pressed
+ TreePath aTreePath = jTree.getSelectionPath();
+ SwingUnoNode oUnoNode = (SwingUnoNode) aTreePath.getLastPathComponent();
+ oUnoNode.openIdlDescription(m_xDialogProvider.getIDLPath());
+ }
+ }
+ });
+ jTree.addMouseListener(new MouseAdapter() {
+ public void mousePressed (MouseEvent e) {
+ if (e.isPopupTrigger()){
+ m_oInspectorPane.showPopUpMenu(e.getComponent(), e.getX(), e.getY());
+ }
+ //unfortunately under Windows the method "isPopupTrigger" always returns false
+ else if ((e.getModifiersEx() & MouseEvent.BUTTON3_DOWN_MASK) == MouseEvent.BUTTON3_DOWN_MASK){
+ m_oInspectorPane.showPopUpMenu(e.getComponent(), e.getX(), e.getY());
+ }
+ }
+ });
+ jPnlContainer.add(jPnlCenter, java.awt.BorderLayout.CENTER);
+ insertBorderPanes(jPnlContainer);
+ if (this.bIsUserDefined){
+ ComponentSelector(oUserDefinedObject, m_oInspectorPane.getTitle());
+ }
+ m_xDialogProvider.addInspectorPage(m_oInspectorPane.getTitle(), jPnlContainer);
+ addTreeExpandListener();
+ }
+ catch( Exception exception ) {
+ exception.printStackTrace(System.out);
+ }
+ return jPnlContainer;
+ }
+
+ public HideableTreeModel getModel(){
+ return treeModel;
+ }
+
+
+ public void addTreeExpandListener(){
+ jTree.addTreeWillExpandListener(
+ new TreeWillExpandListener() {
+ public void treeWillExpand(javax.swing.event.TreeExpansionEvent event) throws javax.swing.tree.ExpandVetoException {
+ SwingTreePathProvider oSwingTreePathProvider = new SwingTreePathProvider(event.getPath());
+ XUnoNode oUnoNode = oSwingTreePathProvider.getLastPathComponent();
+ if (!m_oInspectorPane.expandNode(oUnoNode, oSwingTreePathProvider)){
+ throw new ExpandVetoException(event);
+ }
+ }
+
+ public void treeWillCollapse( javax.swing.event.TreeExpansionEvent evt) throws javax.swing.tree.ExpandVetoException {
+ }
+ });
+ }
+
+
+ public void setSourceCode(String _sSourceCode){
+ jtxtGeneratedSourceCode.setText(_sSourceCode);
+ }
+
+
+ public XTreePathProvider getSelectedPath(){
+ return new SwingTreePathProvider(jTree.getSelectionPath());
+ }
+
+
+ public void expandPath(XTreePathProvider _xTreePathProvider) throws ClassCastException{
+ SwingTreePathProvider oSwingTreePathProvider = (SwingTreePathProvider) _xTreePathProvider;
+ jTree.expandPath(oSwingTreePathProvider.getSwingTreePath());
+ }
+
+
+ public XUnoNode getSelectedNode(){
+ XUnoNode oUnoNode = null;
+ TreePath aTreePath = jTree.getSelectionPath();
+ Object oNode = aTreePath.getLastPathComponent();
+ if (oNode instanceof XUnoNode){
+ oUnoNode = (XUnoNode) oNode;
+ }
+ return oUnoNode;
+ }
+
+
+ public void nodeInserted(XUnoNode _oParentNode, XUnoNode _oChildNode, int index) {
+ getModel().nodeInserted(_oParentNode, _oChildNode, _oParentNode.getChildCount()-1);
+ }
+
+
+ public void nodeChanged(XUnoNode _oNode) {
+ getModel().nodeChanged(_oNode);
+ }
+
+
+ public boolean setNodeVisible(Object node, boolean v) {
+ return getModel().setNodeVisible(node, v);
+ }
+
+
+ public boolean isPropertyNode(XUnoNode _oUnoNode){
+ return (_oUnoNode instanceof SwingUnoPropertyNode);
+ }
+
+
+ public boolean isMethodNode(XUnoNode _oUnoNode){
+ return (_oUnoNode instanceof SwingUnoMethodNode);
+ }
+
+
+ public boolean isFacetteNode(XUnoNode _oUnoNode){
+ return (_oUnoNode instanceof SwingUnoFacetteNode);
+ }
+
+
+ public XUnoNode addUnoNode(Object _oUnoObject){
+ return new SwingUnoNode(_oUnoObject);
+ }
+
+
+ public XUnoNode addUnoNode(Object _oUnoObject, Type _aType){
+ return new SwingUnoNode(_oUnoObject, _aType);
+ }
+
+
+ public XUnoFacetteNode addUnoFacetteNode(XUnoNode _oParentNode, String _sNodeDescription, Object _oUnoObject){
+ SwingUnoFacetteNode oSwingUnoFacetteNode = new SwingUnoFacetteNode(_oUnoObject);
+ oSwingUnoFacetteNode.setLabel(_sNodeDescription);
+ if (_oParentNode != null){
+ ((SwingUnoNode) _oParentNode).addChildNode(oSwingUnoFacetteNode);
+ }
+ return oSwingUnoFacetteNode;
+ }
+
+
+ public XUnoMethodNode addMethodNode(Object _objectElement, XIdlMethod _xIdlMethod){
+ SwingUnoMethodNode oSwingUnoMethodNode = new SwingUnoMethodNode(_xIdlMethod, _objectElement, m_xDialogProvider);
+ return oSwingUnoMethodNode;
+ }
+
+
+ public XUnoPropertyNode addUnoPropertyNodeWithName(Property _aProperty){
+ SwingUnoPropertyNode oUnoPropertyNode = new SwingUnoPropertyNode(_aProperty);
+ oUnoPropertyNode.setLabel("Name: " + _aProperty.Name);
+ return oUnoPropertyNode;
+ }
+
+
+ public XUnoPropertyNode addUnoPropertyNodeWithHandle(Property _aProperty){
+ SwingUnoPropertyNode oUnoPropertyNode = new SwingUnoPropertyNode(_aProperty);
+ oUnoPropertyNode.setLabel("Handle: " + _aProperty.Handle);
+ return oUnoPropertyNode;
+ }
+
+
+ public XUnoPropertyNode addUnoPropertyNodeWithType(Property _aProperty){
+ SwingUnoPropertyNode oUnoPropertyNode = new SwingUnoPropertyNode(_aProperty);
+ oUnoPropertyNode.setLabel("Type: " + _aProperty.Type.getTypeName());
+ return oUnoPropertyNode;
+ }
+
+
+ public XUnoPropertyNode addUnoPropertyNodeWithAttributesDescription(Property _aProperty){
+ SwingUnoPropertyNode oUnoPropertyNode = new SwingUnoPropertyNode(_aProperty);
+ XConstantTypeDescription[] xPropertyAttributesTypeDescriptions = Introspector.getIntrospector().getFieldsOfConstantGroup("com.sun.star.beans.PropertyAttribute");
+ String sDisplay = Introspector.getIntrospector().getConstantDisplayString((int) _aProperty.Attributes, xPropertyAttributesTypeDescriptions, "Attributes: ");
+ oUnoPropertyNode.setLabel(sDisplay);
+ return oUnoPropertyNode;
+ }
+
+
+ public XUnoPropertyNode addUnoPropertyNode(Object _oUnoObject, Property _aProperty){
+ SwingUnoPropertyNode oUnoPropertyNode = new SwingUnoPropertyNode(_aProperty, _oUnoObject, null);
+ oUnoPropertyNode.setPropertyNodeType(XUnoPropertyNode.nPROPERTYSETINFOTYPE);
+ oUnoPropertyNode.setLabel(UnoPropertyNode.getStandardPropertyDescription(_aProperty, null));
+ return oUnoPropertyNode;
+ }
+
+
+ public XUnoPropertyNode addUnoPropertyNode(Object _oUnoObject, Property _aProperty, Object _oUnoReturnObject){
+ SwingUnoPropertyNode oUnoPropertyNode = new SwingUnoPropertyNode(_aProperty, _oUnoObject, _oUnoReturnObject);
+ oUnoPropertyNode.setLabel(UnoPropertyNode.getStandardPropertyDescription(_aProperty, _oUnoReturnObject));
+ return oUnoPropertyNode;
+ }
+
+
+ public XUnoPropertyNode addUnoPropertyNode(Object _oUnoObject, PropertyValue _aPropertyValue, Object _oReturnObject){
+ SwingUnoPropertyNode oUnoPropertyNode = new SwingUnoPropertyNode(_aPropertyValue, _oUnoObject, _oReturnObject);
+ oUnoPropertyNode.setLabel(UnoPropertyNode.getStandardPropertyValueDescription(_aPropertyValue));
+ return oUnoPropertyNode;
+ }
+}
diff --git a/odk/examples/java/Inspector/SwingTreePathProvider.java b/odk/examples/java/Inspector/SwingTreePathProvider.java
new file mode 100644
index 000000000000..37376c269b42
--- /dev/null
+++ b/odk/examples/java/Inspector/SwingTreePathProvider.java
@@ -0,0 +1,40 @@
+import javax.swing.tree.TreePath;
+
+
+public class SwingTreePathProvider implements XTreePathProvider {
+ TreePath m_aTreePath;
+
+ /** Creates a new instance of TreePathProvider */
+ public SwingTreePathProvider(TreePath _aTreePath) {
+ m_aTreePath = _aTreePath;
+ }
+
+
+ public XUnoNode getLastPathComponent(){
+ return (XUnoNode) m_aTreePath.getLastPathComponent();
+ }
+
+
+ public XUnoNode getPathComponent(int i){
+ return (XUnoNode) m_aTreePath.getPathComponent(i);
+ }
+
+ public int getPathCount(){
+ return m_aTreePath.getPathCount();
+ }
+
+
+ public XTreePathProvider getParentPath(){
+ return new SwingTreePathProvider(m_aTreePath.getParentPath());
+ }
+
+
+ public XTreePathProvider pathByAddingChild(XUnoNode _oUnoNode){
+ TreePath aTreePath = m_aTreePath.pathByAddingChild(_oUnoNode);
+ return new SwingTreePathProvider(aTreePath);
+ }
+
+ public TreePath getSwingTreePath(){
+ return m_aTreePath;
+ }
+}
diff --git a/odk/examples/java/Inspector/SwingUnoFacetteNode.java b/odk/examples/java/Inspector/SwingUnoFacetteNode.java
new file mode 100644
index 000000000000..1fbc0f1acb93
--- /dev/null
+++ b/odk/examples/java/Inspector/SwingUnoFacetteNode.java
@@ -0,0 +1,84 @@
+/*************************************************************************
+ *
+ * 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.reflection.XIdlMethod;
+import com.sun.star.uno.Type;
+import com.sun.star.uno.XComponentContext;
+import javax.swing.tree.DefaultMutableTreeNode;
+
+public class SwingUnoFacetteNode extends SwingUnoNode implements XUnoFacetteNode{
+ String m_sFilter = "";
+
+ /** Creates a new instance of UnoMethodNode */
+ public SwingUnoFacetteNode(Object _oUnoObject){
+ super(_oUnoObject);
+ setFoldable(true);
+ }
+
+
+ public String getFilter(){
+ return m_sFilter;
+ }
+
+ public void setFilter(String _sFilter){
+ m_sFilter = _sFilter;
+ }
+
+ public String getName(){
+ return toString();
+ }
+
+// TODO The implementation of the following methods is not really robust and should be changed!!!
+ public boolean isMethodNode(){
+ return ((String) getUserObject()).equals(SMETHODDESCRIPTION);
+ }
+
+ public boolean isPropertyNode(){
+ String sNodeDescription = (String) getUserObject();
+ return ((sNodeDescription.equals(SPROPERTYDESCRIPTION)) || (sNodeDescription.equals(SPROPERTYINFODESCRIPTION)) || (sNodeDescription.equals(SPROPERTYVALUEDESCRIPTION)));
+ }
+
+ public boolean isContainerNode(){
+ return ((String) getUserObject()).equals(SCONTAINERDESCRIPTION);
+ }
+
+ public boolean isServiceNode(){
+ return ((String) getUserObject()).equals(SSERVICEDESCRIPTION);
+ }
+
+ public boolean isInterfaceNode(){
+ return ((String) getUserObject()).equals(SINTERFACEDESCRIPTION);
+ }
+}
+
diff --git a/odk/examples/java/Inspector/SwingUnoMethodNode.java b/odk/examples/java/Inspector/SwingUnoMethodNode.java
new file mode 100644
index 000000000000..3487d430dfb5
--- /dev/null
+++ b/odk/examples/java/Inspector/SwingUnoMethodNode.java
@@ -0,0 +1,138 @@
+/*************************************************************************
+ *
+ * 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.reflection.XIdlMethod;
+import com.sun.star.uno.TypeClass;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Vector;
+
+
+
+public class SwingUnoMethodNode extends SwingUnoNode implements ActionListener, XUnoMethodNode{
+
+ private UnoMethodNode m_oUnoMethodNode;
+ private XDialogProvider m_xDialogProvider = null;
+
+ public SwingUnoMethodNode(XIdlMethod _xIdlMethod, Object _oUnoObject, XDialogProvider _xDialogProvider) {
+ super(_oUnoObject);
+ m_oUnoMethodNode = new UnoMethodNode(_xIdlMethod, _oUnoObject, this);
+ m_xDialogProvider = _xDialogProvider;
+ setUserObject(m_oUnoMethodNode.getNodeDescription());
+ if (m_oUnoMethodNode.isFoldable()){
+ setFoldable(true);
+ }
+ }
+
+ public boolean isFoldable(){
+ return m_oUnoMethodNode.isFoldable();
+ }
+
+ public String getName(){
+ return m_oUnoMethodNode.getName();
+ }
+
+ public String getClassName(){
+ String sClassName = "";
+ sClassName = getXIdlMethod().getDeclaringClass().getName();
+ if (sClassName.equals("")){
+ sClassName = super.getClassName();
+ }
+ return sClassName;
+ }
+
+ public String getAnchor(){
+ return m_oUnoMethodNode.getAnchor();
+ }
+
+ public Object invoke(Object _oUnoObject, Object[] _oParameters) throws com.sun.star.uno.Exception{
+ return m_oUnoMethodNode.invoke(_oUnoObject, _oParameters);
+ }
+
+
+ public Object[] getLastParameterObjects(){
+ return m_oUnoMethodNode.getLastParameterObjects();
+ }
+
+ public Object getLastUnoReturnObject(){
+ return m_oUnoMethodNode.getLastUnoReturnObject();
+ }
+
+ public TypeClass getTypeClass() {
+ return m_oUnoMethodNode.getTypeClass();
+ }
+
+ public XIdlMethod getXIdlMethod() {
+ return m_oUnoMethodNode.getXIdlMethod();
+ }
+
+ public boolean hasParameters() {
+ return m_oUnoMethodNode.hasParameters();
+ }
+
+ public Object invoke() throws com.sun.star.uno.Exception{
+ return m_oUnoMethodNode.invoke();
+ }
+
+ public boolean isInvoked() {
+ return m_oUnoMethodNode.isInvoked();
+ }
+
+ public boolean isInvokable(){
+ return m_oUnoMethodNode.isInvokable();
+ }
+
+ public boolean isPrimitive() {
+ return m_oUnoMethodNode.isPrimitive();
+ }
+
+ public void actionPerformed(ActionEvent e){
+ openIdlDescription(m_xDialogProvider.getIDLPath());
+ }
+
+ public Vector getMethodObjects(){
+ MethodParametersDialog oMethodParametersDialog = new MethodParametersDialog(this);
+ oMethodParametersDialog.addActionListener(this);
+ return oMethodParametersDialog.getMethodObjects();
+ }
+
+
+ public String getParameterDescription(){
+ return m_oUnoMethodNode.getParameterDescription();
+ }
+
+
+ public String getStandardMethodDescription(){
+ return m_oUnoMethodNode.getStandardMethodDescription();
+ }
+} \ No newline at end of file
diff --git a/odk/examples/java/Inspector/SwingUnoNode.java b/odk/examples/java/Inspector/SwingUnoNode.java
new file mode 100644
index 000000000000..14f23e94ad6d
--- /dev/null
+++ b/odk/examples/java/Inspector/SwingUnoNode.java
@@ -0,0 +1,156 @@
+/*************************************************************************
+ *
+ * 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.Type;
+import javax.swing.tree.TreeNode;
+
+
+public class SwingUnoNode extends HideableMutableTreeNode implements XUnoNode{
+ private UnoNode m_oUnoNode;
+
+ /** Creates a new instance of SwingUnoNode */
+ public SwingUnoNode(Object _oUnoObject) {
+ super();
+ m_oUnoNode = new UnoNode(_oUnoObject);
+ }
+
+
+ public SwingUnoNode(Object _oUnoObject, Type _aType) {
+ super();
+ m_oUnoNode = new UnoNode(_oUnoObject, _aType);
+ if (_aType != null){
+ this.setLabel(_aType.getTypeName());
+ }
+ }
+
+
+ public Object getUnoObject(){
+ return m_oUnoNode.getUnoObject();
+ }
+
+ public void setVisible(String _sFilter){
+ boolean bisVisible = isFilterApplicable(_sFilter);
+ super.setVisible(bisVisible);
+ }
+
+ public boolean isFilterApplicable(String _sFilter) {
+ return m_oUnoNode.isFilterApplicable(_sFilter, getName());
+ }
+
+ public void setParameterObjects(Object[] _oParamObjects) {
+ m_oUnoNode.setParameterObjects(_oParamObjects);
+ }
+
+ public void openIdlDescription(String _SDKPath) {
+ m_oUnoNode.openIdlDescription(_SDKPath, getClassName(), getAnchor());
+ }
+
+ public Object[] getParameterObjects() {
+ return m_oUnoNode.getParameterObjects();
+ }
+
+ public String getClassName(){
+ String sClassName = m_oUnoNode.getClassName();
+ if (sClassName.equals("")){
+ TreeNode oTreeNode = getParent();
+ if (oTreeNode != null){
+ if (oTreeNode instanceof XUnoNode){
+ SwingUnoNode oUnoNode = (SwingUnoNode) oTreeNode;
+ sClassName = oUnoNode.getClassName();
+ }
+ }
+ }
+ return sClassName;
+ }
+
+ public String getAnchor() {
+ return m_oUnoNode.getAnchor();
+ }
+
+
+ public void setFoldable(boolean _bIsFoldable){
+ if (_bIsFoldable){
+ addDummyNode();
+ }
+ else{
+ removeDummyNode();
+ }
+ }
+
+
+ public XUnoNode getParentNode(){
+ return (SwingUnoNode) super.getParent();
+ }
+
+
+ public void addChildNode(XUnoNode _xUnoNode) {
+ super.add((SwingUnoNode) _xUnoNode);
+ }
+
+ public void setLabel(String _sLabel){
+ super.setUserObject(_sLabel);
+ this.m_oUnoNode.setLabel(_sLabel);
+ }
+
+ public String getLabel(){
+ return (String) super.getUserObject();
+ }
+
+
+ public int getChildCount(){
+ return super.getChildCount();
+ }
+
+
+ public XUnoNode getChild(int _i){
+ return (SwingUnoNode) super.getChildAt(_i);
+ }
+
+ public int getNodeType(){
+ return m_oUnoNode.getNodeType();
+ }
+
+ public void setNodeType(int _nNodeType){
+ m_oUnoNode.setNodeType(_nNodeType);
+ }
+
+
+ public String getName(){
+ return getClassName();
+ }
+
+
+ public Type getUnoType(){
+ return m_oUnoNode.getUnoType();
+ }
+}
diff --git a/odk/examples/java/Inspector/SwingUnoPropertyNode.java b/odk/examples/java/Inspector/SwingUnoPropertyNode.java
new file mode 100644
index 000000000000..34decfec1d1c
--- /dev/null
+++ b/odk/examples/java/Inspector/SwingUnoPropertyNode.java
@@ -0,0 +1,96 @@
+/*************************************************************************
+ *
+ * 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.beans.Property;
+import com.sun.star.beans.PropertyValue;
+
+public class SwingUnoPropertyNode extends SwingUnoNode implements XUnoPropertyNode{
+
+ private UnoPropertyNode m_oUnoPropertyNode = null;
+
+
+ public SwingUnoPropertyNode(Property _aProperty, Object _oUnoObject, Object _oUnoReturnObject) {
+ super(_oUnoObject);
+ m_oUnoPropertyNode = new UnoPropertyNode(_aProperty, _oUnoObject, _oUnoReturnObject);
+ super.setUserObject(m_oUnoPropertyNode.getLabel());
+ setFoldable(m_oUnoPropertyNode.isFoldable());
+ }
+
+
+ public SwingUnoPropertyNode(Property _aProperty){
+ super(null);
+ m_oUnoPropertyNode = new UnoPropertyNode(_aProperty);
+ }
+
+
+ public SwingUnoPropertyNode(PropertyValue _aPropertyValue, Object _oUnoObject, Object _oUnoReturnObject) {
+ super(_oUnoObject);
+ m_oUnoPropertyNode = new UnoPropertyNode(_aPropertyValue, _oUnoObject, _oUnoReturnObject);
+ }
+
+ public String getName(){
+ return m_oUnoPropertyNode.getName();
+ }
+
+
+ public Object getUnoReturnObject(){
+ return m_oUnoPropertyNode.getUnoReturnObject();
+ }
+
+
+ public String getClassName(){
+ String sClassName = m_oUnoPropertyNode.getClassName();
+ if (sClassName.equals("")){
+ sClassName = super.getClassName();
+ }
+ return sClassName;
+ }
+
+ public String getAnchor(){
+ return m_oUnoPropertyNode.getAnchor();
+ }
+
+ public int getPropertyNodeType(){
+ return m_oUnoPropertyNode.getPropertyNodeType();
+ }
+
+
+ public void setPropertyNodeType(int _nPropertyType){
+ m_oUnoPropertyNode.setPropertyNodeType(_nPropertyType);
+ }
+
+ public Property getProperty(){
+ return m_oUnoPropertyNode.getProperty();
+ }
+
+}
diff --git a/odk/examples/java/Inspector/TDocSupplier.java b/odk/examples/java/Inspector/TDocSupplier.java
new file mode 100644
index 000000000000..81d8ca05e533
--- /dev/null
+++ b/odk/examples/java/Inspector/TDocSupplier.java
@@ -0,0 +1,168 @@
+
+/*************************************************************************
+ *
+ * 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.beans.Property;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.frame.XComponentLoader;
+import com.sun.star.frame.XModel;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.sdbc.XRow;
+import com.sun.star.ucb.Command;
+import com.sun.star.ucb.XCommandProcessor;
+import com.sun.star.ucb.XContent;
+import com.sun.star.ucb.XContentIdentifier;
+import com.sun.star.ucb.XContentIdentifierFactory;
+import com.sun.star.ucb.XContentProvider;
+import com.sun.star.ucb.XSimpleFileAccess;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+import javax.swing.JOptionPane;
+
+
+public class TDocSupplier {
+ private XMultiComponentFactory m_xMultiComponentFactory;
+ private XComponentContext m_xComponentContext;
+
+
+ /** Creates a new instance of TDocSupplier */
+ public TDocSupplier(XComponentContext _xComponentContext) {
+ m_xComponentContext = _xComponentContext;
+ m_xMultiComponentFactory = m_xComponentContext.getServiceManager();
+ }
+
+
+ protected XComponentContext getXComponentContext(){
+ return m_xComponentContext;
+ }
+
+
+ protected XMultiComponentFactory getXMultiComponentFactory(){
+ return m_xMultiComponentFactory;
+ }
+
+ public XModel getXModelByTDocUrl(String _sTDocUrl){
+ try{
+ XRow xRow = getXRowOfTDocUrl(_sTDocUrl, "DocumentModel");
+ if (xRow != null){
+ Object oModel = xRow.getObject(1, null);
+ XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, oModel);
+ return xModel;
+ }
+ }catch(Exception exception){
+ exception.printStackTrace(System.out);
+ }
+ JOptionPane.showMessageDialog(new javax.swing.JFrame(), "The selected Document could not be opened!", "Object Inspector", JOptionPane.ERROR_MESSAGE);
+ return null;
+ }
+
+
+ public String getTitleByTDocUrl(String _sTDocUrl){
+ try{
+ XRow xRow = this.getXRowOfTDocUrl(_sTDocUrl, "Title");
+ if (xRow != null){
+ return xRow.getString(1);
+ }
+ }catch(Exception exception){
+ exception.printStackTrace(System.out);
+ }
+ JOptionPane.showMessageDialog(new javax.swing.JFrame(), "The selected Document could not be opened!", "Object Inspector", JOptionPane.ERROR_MESSAGE);
+ return "";
+ }
+
+
+ private XRow getXRowOfTDocUrl(String _sTDocUrl, String _sPropertyName){
+ try{
+ String[] keys = new String[2];
+ keys[ 0 ] = "Local";
+ keys[ 1 ] = "Office";
+ Object oUCB = getXMultiComponentFactory().createInstanceWithArgumentsAndContext( "com.sun.star.ucb.UniversalContentBroker", keys, getXComponentContext() );
+ XContentIdentifierFactory xIdFactory = (XContentIdentifierFactory)UnoRuntime.queryInterface(XContentIdentifierFactory.class, oUCB);
+ XContentProvider xProvider = (XContentProvider)UnoRuntime.queryInterface(XContentProvider.class, oUCB);
+ XContentIdentifier xId = xIdFactory.createContentIdentifier(_sTDocUrl);
+ XContent xContent = xProvider.queryContent(xId);
+ XCommandProcessor xCmdProcessor = (XCommandProcessor) UnoRuntime.queryInterface(XCommandProcessor.class, xContent);
+ Property aProperty = new Property();
+ aProperty.Name = _sPropertyName; // "DocumentModel"; //DocumentModel
+ Command aCommand = new Command();
+ aCommand.Name = "getPropertyValues";
+ aCommand.Handle = -1; // not available
+ aCommand.Argument = new Property[]{aProperty};
+ Object oAny = xCmdProcessor.execute(aCommand, 0, null);
+ XRow xRow = (XRow) UnoRuntime.queryInterface(XRow.class, oAny);
+ return xRow;
+ }catch(Exception exception){
+ exception.printStackTrace(System.out);
+ return null;
+ }}
+
+
+ protected String[] getTDocTitles(String[] _sTDocUrls){
+ String[] sTitles = new String[_sTDocUrls.length];
+ for (int i = 0; i < _sTDocUrls.length; i++){
+ sTitles[i] = getTitleByTDocUrl(_sTDocUrls[i]);
+ }
+ return sTitles;
+ }
+
+
+ protected String[] getTDocUrls(){
+ try{
+ Object oSimpleFileAccess = getXMultiComponentFactory().createInstanceWithContext("com.sun.star.ucb.SimpleFileAccess", getXComponentContext());
+ XSimpleFileAccess xSimpleFileAccess = (XSimpleFileAccess) UnoRuntime.queryInterface(XSimpleFileAccess.class, oSimpleFileAccess);
+ String[] sContent = xSimpleFileAccess.getFolderContents("vnd.sun.star.tdoc:/", false);
+ return sContent;
+ } catch( Exception e ) {
+ System.err.println( e );
+ return new String[]{};
+ }}
+
+
+ public XComponent openEmptyDocument(String _sUrl){
+ try{
+ PropertyValue[] aPropertyValues = new PropertyValue[1];
+ aPropertyValues[0] = new PropertyValue();
+ aPropertyValues[0].Name = "Hidden";
+ aPropertyValues[0].Value = Boolean.TRUE;
+ Object oDesktop = getXMultiComponentFactory().createInstanceWithContext("com.sun.star.frame.Desktop", getXComponentContext());
+ XComponentLoader xCL = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, oDesktop);
+ return xCL.loadComponentFromURL(_sUrl, "_default", 0, aPropertyValues);
+ }
+ catch( Exception exception ) {
+ System.err.println( exception );
+ return null;
+ }}
+
+}
diff --git a/odk/examples/java/Inspector/TestInspector.java b/odk/examples/java/Inspector/TestInspector.java
new file mode 100644
index 000000000000..e7583f944d09
--- /dev/null
+++ b/odk/examples/java/Inspector/TestInspector.java
@@ -0,0 +1,88 @@
+/*************************************************************************
+ *
+ * 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.lang.XSingleComponentFactory;
+import com.sun.star.uno.UnoRuntime;
+
+import java.io.DataInputStream;
+
+public class TestInspector {
+
+ public static void main(String args[]) {
+ com.sun.star.uno.XComponentContext xContext = null;
+ try {
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ if( xContext != null )
+ System.out.println("Connected to a running office ...");
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.out);
+ System.exit(1);
+ }
+
+ try {
+ com.sun.star.lang.XMultiComponentFactory xMCF = xContext.getServiceManager();
+ // Creating an instance of the instance inspector with arguments
+
+ XSingleComponentFactory xFactory = Inspector.__getComponentFactory(Inspector._Inspector.class.getName());
+ Object obj= null;
+ if (xFactory != null) {
+ obj = xFactory.createInstanceWithContext(xContext);
+ }
+ org.openoffice.XInstanceInspector xInstInspector = null;
+ if (obj != null) {
+ xInstInspector = (org.openoffice.XInstanceInspector)UnoRuntime.queryInterface(org.openoffice.XInstanceInspector.class, obj);
+ }
+
+ /* A desktop environment contains tasks with one or more
+ frames in which components can be loaded. Desktop is the
+ environment for components which can instanciate within
+ frames. */
+ com.sun.star.frame.XComponentLoader xCmpLoader = (com.sun.star.frame.XComponentLoader)UnoRuntime.queryInterface( com.sun.star.frame.XComponentLoader.class,
+ xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext));
+
+ // Load a new spreadsheet document, which will be automaticly
+ // displayed and is used for inspection
+ com.sun.star.lang.XComponent xComp = xCmpLoader.loadComponentFromURL("private:factory/scalc", "_blank", 0, new com.sun.star.beans.PropertyValue[0] );
+ xInstInspector.inspect(xCmpLoader, "");
+ System.out.println("You can now inspect the new spreadsheet " + "document ...\n");
+ }
+ catch( Exception e ) {
+ System.err.println( e + e.getMessage());
+ e.printStackTrace();
+ }
+// System.exit( 0 );
+ }
+}
diff --git a/odk/examples/java/Inspector/UnoFacetteNode.java b/odk/examples/java/Inspector/UnoFacetteNode.java
new file mode 100644
index 000000000000..0fd91e434736
--- /dev/null
+++ b/odk/examples/java/Inspector/UnoFacetteNode.java
@@ -0,0 +1,85 @@
+/*************************************************************************
+ *
+ * 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.reflection.XIdlMethod;
+import com.sun.star.uno.Type;
+import com.sun.star.uno.XComponentContext;
+import javax.swing.tree.DefaultMutableTreeNode;
+
+public class UnoFacetteNode extends UnoNode{
+ String m_sFilter = "";
+
+
+ /** Creates a new instance of UnoMethodNode */
+ public UnoFacetteNode(Object _oUnoObject){
+ super(_oUnoObject);
+ addDummyNode();
+ }
+
+
+ public String getFilter(){
+ return m_sFilter;
+ }
+
+ public void setFilter(String _sFilter){
+ m_sFilter = _sFilter;
+ }
+
+ public String getName(){
+ return toString();
+ }
+
+// TODO The implementation of the following nodes is not really robust and should be changed!!!
+ public boolean isMethodNode(){
+ return ((String) getUserObject()).equals(SMETHODDESCRIPTION);
+ }
+
+ public boolean isPropertyNode(){
+ String sNodeDescription = (String) getUserObject();
+ return ((sNodeDescription.equals(SPROPERTYDESCRIPTION)) || (sNodeDescription.equals(SPROPERTYINFODESCRIPTION)) || (sNodeDescription.equals(SPROPERTYVALUEDESCRIPTION)));
+ }
+
+ public boolean isContainerNode(){
+ return ((String) getUserObject()).equals(SCONTAINERDESCRIPTION);
+ }
+
+ public boolean isServiceNode(){
+ return ((String) getUserObject()).equals(SSERVICEDESCRIPTION);
+ }
+
+ public boolean isInterfaceNode(){
+ return ((String) getUserObject()).equals(SINTERFACEDESCRIPTION);
+ }
+}
+
diff --git a/odk/examples/java/Inspector/UnoMethodNode.java b/odk/examples/java/Inspector/UnoMethodNode.java
new file mode 100644
index 000000000000..d80aa6f70d6b
--- /dev/null
+++ b/odk/examples/java/Inspector/UnoMethodNode.java
@@ -0,0 +1,228 @@
+/*************************************************************************
+ *
+ * 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.reflection.ParamInfo;
+import com.sun.star.reflection.ParamMode;
+import com.sun.star.reflection.XIdlClass;
+import com.sun.star.reflection.XIdlMethod;
+import com.sun.star.uno.TypeClass;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Vector;
+
+public class UnoMethodNode extends UnoNode{
+ XIdlMethod m_xIdlMethod = null;
+ Object[] m_oParamObjects = null;
+ Object m_oUnoReturnObject = null;
+ boolean m_bisInvoked = false;
+ XUnoMethodNode m_xUnoMethodNode = null;
+
+
+ /** Creates a new instance of UnoMethodNode */
+ public UnoMethodNode(XIdlMethod _xIdlMethod, Object _oUnoObject, XUnoMethodNode _xUnoMethodNode) {
+ super(_oUnoObject);
+ m_xIdlMethod = _xIdlMethod;
+ m_oParamObjects = new Object[m_xIdlMethod.getParameterInfos().length];
+ m_xUnoMethodNode = _xUnoMethodNode;
+ }
+
+ protected boolean isFoldable(){
+ return ((!this.isPrimitive()) && (getTypeClass().getValue() != TypeClass.VOID_value));
+ }
+
+ protected boolean isInvokable(){
+ boolean bisFoldable = true;
+ XIdlClass[] xIdlClasses = m_xIdlMethod.getParameterTypes();
+ for (int i = 0; i < xIdlClasses.length; i++){
+ bisFoldable = Introspector.isPrimitive(xIdlClasses[i].getTypeClass());
+ if (!bisFoldable){
+ return false;
+ }
+ }
+ return bisFoldable;
+ }
+
+ public XIdlMethod getXIdlMethod(){
+ return m_xIdlMethod;
+ }
+
+
+ public String getAnchor(){
+ return getXIdlMethod().getName();
+ }
+
+
+ public String getName(){
+ return getXIdlMethod().getName();
+ }
+
+
+ public Object invoke(){
+ Object oUnoReturnObject = null;
+ if (!hasParameters()){
+ oUnoReturnObject = invokeParameterlessMethod();
+ m_bisInvoked = true;
+ }
+ else{
+ Vector oUnoMethodObjects = m_xUnoMethodNode.getMethodObjects();
+ if (oUnoMethodObjects != null){
+ for (int i = 0; i < getXIdlMethod().getParameterInfos().length; i++){
+ this.m_oParamObjects[i] = oUnoMethodObjects.get(i);
+ }
+ if (oUnoMethodObjects.size() == m_oParamObjects.length + 1){
+ oUnoReturnObject = oUnoMethodObjects.get(oUnoMethodObjects.size()-1);
+ }
+ m_bisInvoked = (oUnoReturnObject != null);
+ }
+ }
+ m_oUnoReturnObject = oUnoReturnObject;
+ return oUnoReturnObject;
+ }
+
+
+ public boolean isInvoked(){
+ return m_bisInvoked;
+ }
+
+
+ protected String getNodeDescription(){
+ String sNodeDescription = "";
+ String sParameters = getParameterDescription();
+ if (m_xIdlMethod.getParameterInfos().length > 0){
+ sNodeDescription = getStandardMethodDescription();
+ }
+ else{
+ TypeClass typeClass = getTypeClass();
+ if (typeClass != TypeClass.VOID){
+ sNodeDescription = getStandardMethodDescription();
+ }
+ else{
+ sNodeDescription = getStandardMethodDescription();
+ }
+ }
+ return sNodeDescription;
+ }
+
+
+ public String getStandardMethodDescription(){
+ String sNodeDescription = m_xIdlMethod.getReturnType().getName() + " " + m_xIdlMethod.getName() + " (" + getParameterDescription() + " )";
+ if (isPrimitive()){
+ sNodeDescription += "";
+ }
+ return sNodeDescription;
+ }
+
+
+ public boolean hasParameters(){
+ return (m_xIdlMethod.getParameterInfos().length > 0);
+ }
+
+
+ public Object[] getLastParameterObjects(){
+ return m_oParamObjects;
+ }
+
+
+ public Object getLastUnoReturnObject(){
+ return m_oUnoReturnObject;
+ }
+
+
+ public String getParameterDescription(){
+ ParamInfo[] paramInfo = m_xIdlMethod.getParameterInfos();
+ String sParameters = "";
+ String sStandardMethodDisplayText = m_xIdlMethod.getReturnType().getName() + " " + m_xIdlMethod.getName() + " (" + sParameters + " )";
+ if (Introspector.isValid(paramInfo)) {
+ // get all parameters with type and mode
+ for ( int i = 0; i < paramInfo.length; i++ ) {
+ XIdlClass xIdlClass = paramInfo[ i ].aType;
+ if ( i == 0 ) {
+ // the first parameter has no leading comma
+ sParameters += "[" + getParamMode(paramInfo[ i ].aMode ) + "] " + xIdlClass.getName();
+ }
+ else {
+ // all other parameters are separated with comma
+ sParameters += ", [" + getParamMode(paramInfo[ i ].aMode ) + "] " + xIdlClass.getName();
+ }
+ }
+ }
+ return sParameters;
+ }
+
+
+ // return the parameter mode (IN, OUT, INOUT)
+ private static String getParamMode(ParamMode paramMode) {
+ String toReturn = "";
+ if ( paramMode == ParamMode.IN ) {
+ toReturn = "IN";
+ }
+ if ( paramMode == ParamMode.OUT ) {
+ toReturn = "OUT";
+ }
+ if ( paramMode == ParamMode.INOUT ) {
+ toReturn = "INOUT";
+ }
+ return( toReturn );
+ }
+
+ public TypeClass getTypeClass(){
+ XIdlClass xIdlClass = m_xIdlMethod.getReturnType();
+ return xIdlClass.getTypeClass();
+ }
+
+
+ private Object invokeParameterlessMethod(){
+ try {
+ Object[][] aParamInfo = new Object[1][];
+ aParamInfo[0] = new Object[] {};
+ return getXIdlMethod().invoke(getUnoObject(), aParamInfo);
+ } catch (Exception ex) {
+ ex.printStackTrace(System.out);
+ return null;
+ }}
+
+
+ public boolean isPrimitive(){
+ return Introspector.isObjectPrimitive(m_xIdlMethod.getClass(), getTypeClass());
+ }
+
+
+ protected Object invoke(Object _oUnoObject, Object[] oParameters) throws com.sun.star.uno.Exception{
+ Object[][] aParams = new Object[1][oParameters.length];
+ for ( int i = 0; i < oParameters.length; i++ ) {
+ aParams[0][i] = oParameters[i];
+ }
+ return m_xIdlMethod.invoke(_oUnoObject, aParams);
+ }
+}
diff --git a/odk/examples/java/Inspector/UnoNode.java b/odk/examples/java/Inspector/UnoNode.java
new file mode 100644
index 000000000000..50d6ec3243d5
--- /dev/null
+++ b/odk/examples/java/Inspector/UnoNode.java
@@ -0,0 +1,437 @@
+/*************************************************************************
+ *
+ * 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.beans.PropertyValue;
+import com.sun.star.frame.FrameSearchFlag;
+import com.sun.star.frame.XDesktop;
+import com.sun.star.frame.XDispatch;
+import com.sun.star.frame.XDispatchProvider;
+import com.sun.star.frame.XFrame;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.reflection.TypeDescriptionSearchDepth;
+import com.sun.star.reflection.XServiceTypeDescription;
+import com.sun.star.reflection.XTypeDescription;
+import com.sun.star.reflection.XTypeDescriptionEnumeration;
+import com.sun.star.reflection.XTypeDescriptionEnumerationAccess;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.uno.Type;
+import com.sun.star.uno.TypeClass;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.util.URL;
+import com.sun.star.util.XURLTransformer;
+import java.util.List;
+import java.util.Vector;
+
+public class UnoNode{
+
+ String sPath = null;
+ Object m_oUnoObject;
+ private XMultiComponentFactory m_xMultiComponentFactory;
+ private XComponentContext m_xComponentContext;
+ private Object[] m_oParamObjects = null;
+ private int m_nNodeType = XUnoNode.nOTHERS;
+ private Type aType = null;
+ private String sLabel = "";
+
+
+
+ /** Creates a new instance of UnoNode */
+ public UnoNode(Object _oUnoObject) {
+ m_xComponentContext = Introspector.getIntrospector().getXComponentContext();
+ m_xMultiComponentFactory = m_xComponentContext.getServiceManager();
+ m_oUnoObject = _oUnoObject;
+ }
+
+ public UnoNode(Object _oUnoObject, Type _aType) {
+ this(_oUnoObject);
+ aType = _aType;
+ m_nNodeType = XUnoNode.nINTERFACE;
+ }
+
+ public Object getUnoObject(){
+ return m_oUnoObject;
+ }
+
+
+ protected XComponentContext getXComponentContext(){
+ return m_xComponentContext;
+ }
+
+
+ protected XMultiComponentFactory getXMultiComponentFactory(){
+ return m_xMultiComponentFactory;
+ }
+
+
+ private static XTypeDescriptionEnumerationAccess getXTypeDescriptionEnumerationAccess(){
+ return Introspector.getIntrospector().getXTypeDescriptionEnumerationAccess();
+ }
+
+
+ public String getAnchor(){
+ return "";
+ }
+
+ public int getNodeType(){
+ return m_nNodeType;
+ }
+
+ public void setNodeType(int _nNodeType){
+ m_nNodeType = _nNodeType;
+ }
+
+ public String getClassName(){
+ String sClassName = "";
+ if (m_nNodeType == XUnoNode.nINTERFACE){
+ sClassName = aType.getTypeName();
+ }
+ else if(m_nNodeType == XUnoNode.nSERVICE){
+ sClassName = sLabel;
+ }
+ return sClassName;
+ }
+
+
+ public Type getUnoType(){
+ return aType;
+ }
+
+ protected void setLabel(String _sLabel){
+ sLabel = _sLabel;
+ }
+
+ public void openIdlDescription(String _sIDLUrl, String _sClassName, String _sAnchor){
+ try{
+ String sIDLUrl = _sIDLUrl;
+ String sAnchor = ""; // TODO find out how the Anchor may be set at the html file; //_sAnchor;
+ boolean bExists = Introspector.getIntrospector().getXSimpleFileAccess().exists(sIDLUrl);
+ if (sIDLUrl.equals("") || (!bExists)){
+ sIDLUrl = "http://api.openoffice.org/" + Inspector.sIDLDOCUMENTSUBFOLDER;
+ }
+ if (!sIDLUrl.endsWith("/")){
+ sIDLUrl += "/";
+ }
+ if (_sClassName.equals("")){
+ sIDLUrl += "com/sun/star/module-ix";
+ sAnchor = "";
+ }
+ else{
+ sIDLUrl += _sClassName.replace('.', '/');
+ }
+ if (sAnchor != null){
+ if (!sAnchor.equals("")){
+ sIDLUrl += "#" + sAnchor;
+ }
+ }
+ sIDLUrl += ".html";
+ URL openHyperlink = getDispatchURL(".uno:OpenHyperlink");
+ PropertyValue pv = new PropertyValue();
+ pv.Name = "URL";
+ pv.Value = sIDLUrl;
+ getXDispatcher(openHyperlink).dispatch(openHyperlink, new PropertyValue[] {pv});
+ } catch(Exception exception) {
+ exception.printStackTrace(System.out);
+ }}
+
+
+ private com.sun.star.util.URL getDispatchURL(String _sURL){
+ try {
+ Object oTransformer = getXMultiComponentFactory().createInstanceWithContext("com.sun.star.util.URLTransformer", getXComponentContext());
+ XURLTransformer xTransformer = (XURLTransformer) UnoRuntime.queryInterface(XURLTransformer.class, oTransformer);
+ com.sun.star.util.URL[] oURL = new com.sun.star.util.URL[1];
+ oURL[0] = new com.sun.star.util.URL();
+ oURL[0].Complete = _sURL;
+ xTransformer.parseStrict(oURL);
+ return oURL[0];
+ } catch (Exception e) {
+ e.printStackTrace(System.out);
+ }
+ return null;
+ }
+
+
+ private XFrame getCurrentFrame(){
+ try{
+ Object oDesktop = getXMultiComponentFactory().createInstanceWithContext("com.sun.star.frame.Desktop", getXComponentContext());
+ XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, oDesktop);
+ return xDesktop.getCurrentFrame();
+ } catch (Exception e) {
+ e.printStackTrace(System.out);
+ return null;
+ }}
+
+
+ private XDispatch getXDispatcher(com.sun.star.util.URL oURL) {
+ try {
+ com.sun.star.util.URL[] oURLArray = new com.sun.star.util.URL[1];
+ oURLArray[0] = oURL;
+ XDispatchProvider xDispatchProvider = (XDispatchProvider) UnoRuntime.queryInterface(XDispatchProvider.class, getCurrentFrame());
+ XDispatch xDispatch = xDispatchProvider.queryDispatch(oURLArray[0], "_top", FrameSearchFlag.ALL); // "_self"
+ return xDispatch;
+ } catch (Exception e) {
+ e.printStackTrace(System.out);
+ return null;
+ }}
+
+
+ private PropertyValue[] loadArgs(String url) {
+ PropertyValue pv = new PropertyValue();
+ pv.Name = "URL";
+ pv.Value = url;
+ return new PropertyValue[] {pv};
+ }
+
+
+
+ public boolean isFilterApplicable(String _sFilter, String _sName){
+ boolean bFilterDoesApply = true;
+ if (_sFilter.length() > 0){
+ if (_sName.indexOf(_sFilter) == -1){
+ bFilterDoesApply = false;
+ }
+ }
+ return bFilterDoesApply;
+ }
+
+
+// public static String getServiceDescription(Object _oUnoObject){
+// String sClassName = "";
+// XServiceInfo xServiceInfo = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, _oUnoObject);
+// if (xServiceInfo != null){
+// String[] sChildServiceNames = removeMandatoryServiceNames(xServiceInfo.getSupportedServiceNames());
+// if (sChildServiceNames.length > 0){
+// sClassName = sChildServiceNames[0];
+// }
+// }
+// return sClassName;
+// }
+
+
+
+ private static String[] getMandatoryServiceNames(String _sServiceName){
+ String[] sMandatoryServiceNames = new String[]{};
+ try {
+ TypeClass[] eTypeClasses = new com.sun.star.uno.TypeClass[1];
+ eTypeClasses[0] = com.sun.star.uno.TypeClass.SERVICE;
+ XTypeDescriptionEnumeration xTDEnumeration = getXTypeDescriptionEnumerationAccess().createTypeDescriptionEnumeration(Introspector.getModuleName(_sServiceName), eTypeClasses, TypeDescriptionSearchDepth.INFINITE);
+ while (xTDEnumeration.hasMoreElements()) {
+ XTypeDescription xTD = xTDEnumeration.nextTypeDescription();
+ if (xTD.getName().equals(_sServiceName)){
+ XServiceTypeDescription xServiceTypeDescription = (XServiceTypeDescription) UnoRuntime.queryInterface(XServiceTypeDescription.class, xTD);
+ XServiceTypeDescription[] xMandatoryServiceTypeDescriptions = xServiceTypeDescription.getMandatoryServices();
+ int nlength = xMandatoryServiceTypeDescriptions.length;
+ sMandatoryServiceNames = new String[nlength];
+ for (int i = 0; i < nlength; i++){
+ sMandatoryServiceNames[i] = xMandatoryServiceTypeDescriptions[i].getName();
+ }
+
+ }
+ }
+ } catch ( java.lang.Exception e) {
+ System.out.println(System.out);
+ }
+ return sMandatoryServiceNames;
+ }
+
+
+ private static String[] removeMandatoryServiceNames(String[] _sServiceNames){
+ try{
+ List aList = java.util.Arrays.asList(_sServiceNames);
+ Vector aVector = new Vector(aList);
+ for (int n = 0; n < _sServiceNames.length; n++){
+ String[] sDelServiceNames = getMandatoryServiceNames(_sServiceNames[n]);
+ for (int m = 0; m < sDelServiceNames.length; m++){
+ if (aVector.contains(sDelServiceNames[m])){
+ int nIndex = aVector.indexOf(sDelServiceNames[m]);
+ aVector.remove(nIndex);
+ }
+ }
+ }
+ String[] sRetArray = new String[aVector.size()];
+ aVector.toArray(sRetArray);
+ return sRetArray;
+ } catch (java.lang.Exception exception) {
+ exception.printStackTrace(System.out);
+ }
+ return new String[]{};
+ }
+
+
+ public static String getDisplayValueOfPrimitiveType(Object _objectElement){
+ String sValue ="";
+ try{
+ if (AnyConverter.isString(_objectElement)){
+ sValue = AnyConverter.toString(_objectElement);
+ }
+ else if (AnyConverter.isBoolean(_objectElement)){
+ sValue += AnyConverter.toBoolean(_objectElement);
+ }
+ else if (AnyConverter.isByte(_objectElement)){
+ sValue += AnyConverter.toByte(_objectElement);
+ }
+ else if (AnyConverter.isChar(_objectElement)){
+ sValue += AnyConverter.toChar(_objectElement);
+ }
+ else if (AnyConverter.isDouble(_objectElement)){
+ sValue += AnyConverter.toDouble(_objectElement);
+ }
+ else if (AnyConverter.isFloat(_objectElement)){
+ sValue += AnyConverter.toFloat(_objectElement);
+ }
+ else if (AnyConverter.isInt(_objectElement)){
+ sValue += AnyConverter.toInt(_objectElement);
+ }
+ else if (AnyConverter.isLong(_objectElement)){
+ sValue += AnyConverter.toLong(_objectElement);
+ }
+ else if (AnyConverter.isShort(_objectElement)){
+ sValue += AnyConverter.toShort(_objectElement);
+ }
+ }
+ catch( Exception e ) {
+ System.err.println( e );
+ }
+ return sValue;
+ }
+
+ protected static String[] getDisplayValuesofPrimitiveArray(Object _oUnoObject){
+ String[] sDisplayValues = null;
+ try{
+ Type aType = AnyConverter.getType(_oUnoObject);
+ TypeClass aTypeClass = aType.getTypeClass();
+ int nTypeValue = aTypeClass.getValue();
+ if (nTypeValue == TypeClass.SEQUENCE_value){
+ nTypeValue = (sequenceComponentType(aType)).getTypeClass().getValue();
+ }
+ switch (nTypeValue){
+ case TypeClass.BOOLEAN_value:
+ boolean[] bBooleans = (boolean[]) AnyConverter.toArray(_oUnoObject);
+ sDisplayValues = new String[bBooleans.length];
+ for (int i = 0; i < bBooleans.length; i++){
+ sDisplayValues[i] = Boolean.toString(bBooleans[i]);
+ }
+ break;
+ case TypeClass.BYTE_value:
+ byte[] bBytes = (byte[]) AnyConverter.toArray(_oUnoObject);
+ sDisplayValues = new String[bBytes.length];
+ for (int i = 0; i < bBytes.length; i++){
+ sDisplayValues[i] = "" + bBytes[i];
+ }
+ break;
+ case TypeClass.DOUBLE_value:
+ double[] fdoubles = (double[]) AnyConverter.toArray(_oUnoObject);
+ sDisplayValues = new String[fdoubles.length];
+ for (int i = 0; i < fdoubles.length; i++){
+ sDisplayValues[i] = String.valueOf(fdoubles[i]);
+ }
+ break;
+ case TypeClass.FLOAT_value:
+ float[] ffloats = (float[]) AnyConverter.toArray(_oUnoObject);
+ sDisplayValues = new String[ffloats.length];
+ for (int i = 0; i < ffloats.length; i++){
+ sDisplayValues[i] = String.valueOf(ffloats[i]);
+ }
+ break;
+ case TypeClass.LONG_value:
+ int[] nints = (int[]) AnyConverter.toArray(_oUnoObject);
+ sDisplayValues = new String[nints.length];
+ for (int i = 0; i < nints.length; i++){
+ sDisplayValues[i] = String.valueOf(nints[i]);
+ }
+ break;
+ case TypeClass.HYPER_value:
+ long[] nlongs = (long[]) AnyConverter.toArray(_oUnoObject);
+ sDisplayValues = new String[nlongs.length];
+ for (int i = 0; i < nlongs.length; i++){
+ sDisplayValues[i] = String.valueOf(nlongs[i]);
+ }
+ break;
+ case TypeClass.SHORT_value:
+ short[] nShorts = (short[]) AnyConverter.toArray(_oUnoObject);
+ sDisplayValues = new String[nShorts.length];
+ for (int i = 0; i < nShorts.length; i++){
+ sDisplayValues[i] = "" + nShorts[i];
+ }
+ break;
+ case TypeClass.CHAR_value:
+ break;
+ default:
+ System.out.println("Value could not be retrieved: " + aType.getTypeClass().getClass().getName());
+ }
+ return sDisplayValues;
+ }
+ catch( Exception e ) {
+ System.err.println( e );
+ return null;
+ }}
+
+
+ private static Type sequenceComponentType(Type sequenceType) {
+// assert sequenceType.getTypeClass() == TypeClass.SEQUENCE;
+ String n = sequenceType.getTypeName();
+ final String PREFIX = "[]";
+// assert n.startsWith(PREFIX);
+ return new Type(n.substring(PREFIX.length()));
+ }
+
+
+ public static String getNodeDescription(Object _oUnoObject, int _nIndex){
+ return getNodeDescription(_oUnoObject) + "[" + (_nIndex + 1) + "]";
+ }
+
+
+ public static String getNodeDescription(Object _oUnoObject){
+ XServiceInfo xServiceInfo = ( XServiceInfo ) UnoRuntime.queryInterface( XServiceInfo.class, _oUnoObject );
+ if ( xServiceInfo != null ) {
+ return xServiceInfo.getImplementationName();
+ }
+ String sClassName = _oUnoObject.getClass().getName();
+ if (Introspector.getIntrospector().isObjectPrimitive(_oUnoObject)){ //super.isO{sObjectClassName.equals("java.lang.String"))issClassName.equals("java.lang.String"))
+ return _oUnoObject.toString();
+ }
+ else{
+ return _oUnoObject.getClass().getName();
+ }
+ }
+
+ public void setParameterObjects(Object[] _oParamObjects){
+ m_oParamObjects = _oParamObjects;
+ }
+
+ public Object[] getParameterObjects(){
+ return m_oParamObjects;
+ }
+}
diff --git a/odk/examples/java/Inspector/UnoPropertyNode.java b/odk/examples/java/Inspector/UnoPropertyNode.java
new file mode 100644
index 000000000000..e9efe526a24b
--- /dev/null
+++ b/odk/examples/java/Inspector/UnoPropertyNode.java
@@ -0,0 +1,225 @@
+/*************************************************************************
+ *
+ * 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.beans.Property;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.reflection.TypeDescriptionSearchDepth;
+import com.sun.star.reflection.XConstantTypeDescription;
+import com.sun.star.reflection.XPropertyTypeDescription;
+import com.sun.star.reflection.XServiceTypeDescription;
+import com.sun.star.reflection.XTypeDescription;
+import com.sun.star.reflection.XTypeDescriptionEnumeration;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.uno.TypeClass;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+import javax.swing.tree.DefaultMutableTreeNode;
+
+public class UnoPropertyNode extends UnoNode{
+
+ Property aProperty;
+ PropertyValue aPropertyValue;
+ String m_sPropertyName;
+ Object m_oUnoReturnObject;
+ private int m_nPropertyType = XUnoPropertyNode.nDEFAULT;
+ private String sLabel = "";
+
+ private static XConstantTypeDescription[] xPropertyAttributesTypeDescriptions = null;
+
+
+ /** Creates a new instance of UnoMethodNode */
+ public UnoPropertyNode(Property _aProperty, Object _oUnoObject, Object _oUnoReturnObject) {
+ super(_oUnoObject);
+ aProperty = _aProperty;
+ m_sPropertyName = aProperty.Name;
+ m_oUnoReturnObject = _oUnoReturnObject;
+ }
+
+
+ public UnoPropertyNode(Property _aProperty){
+ super(null);
+ aProperty = _aProperty;
+ m_sPropertyName = aProperty.Name;
+ m_oUnoReturnObject = null;
+ }
+
+ public UnoPropertyNode(PropertyValue _aPropertyValue, Object _oUnoObject, Object _oUnoReturnObject) {
+ super(_oUnoObject);
+ m_oUnoReturnObject = _oUnoReturnObject;
+ aPropertyValue = _aPropertyValue;
+ m_sPropertyName = aPropertyValue.Name;
+ }
+
+
+ public int getPropertyNodeType(){
+ return m_nPropertyType;
+ }
+
+
+ public void setPropertyNodeType(int _nPropertyType){
+ m_nPropertyType = _nPropertyType;
+ }
+
+
+ public String getPropertyName(){
+ return m_sPropertyName;
+ }
+
+ public String getName(){
+ return this.m_sPropertyName;
+ }
+
+
+ public String getClassName(){
+ String sClassName = "";
+ if (m_oUnoObject != null){
+ XServiceInfo xServiceInfo = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, m_oUnoObject);
+ if (xServiceInfo != null){
+ String[] sServiceNames = xServiceInfo.getSupportedServiceNames();
+ for (int i = 0; i < sServiceNames.length; i++){
+ if (doesServiceSupportProperty(sServiceNames[i], m_sPropertyName)){
+ sClassName = sServiceNames[i];
+ break;
+ }
+ }
+ }
+ }
+ else{
+ sClassName = "com.sun.star.beans.Property";
+ }
+ return sClassName;
+ }
+
+
+ public String getAnchor(){
+ return m_sPropertyName;
+ }
+
+
+
+ protected boolean doesServiceSupportProperty(String _sServiceName, String _sPropertyName){
+ try {
+ XPropertyTypeDescription[] xPropertyTypeDescriptions = Introspector.getIntrospector().getPropertyDescriptionsOfService(_sServiceName);
+ for (int i = 0; i < xPropertyTypeDescriptions.length; i++){
+ if (xPropertyTypeDescriptions[i].getName().equals(_sServiceName + "." + _sPropertyName)){
+ return true;
+ }
+ }
+ } catch ( java.lang.Exception e) {
+ System.out.println(System.out);
+ }
+ return false;
+ }
+
+
+ public Object getUnoReturnObject(){
+ return m_oUnoReturnObject;
+ }
+
+
+ private boolean isPrimitive(){
+ boolean bIsPrimitive = true;
+ if (getUnoReturnObject() != null){
+ if (getProperty() != null){
+ bIsPrimitive = Introspector.isObjectPrimitive(getUnoReturnObject().getClass(), getProperty().Type.getTypeClass());
+ }
+ else{
+ bIsPrimitive = Introspector.isObjectPrimitive(getUnoReturnObject().getClass());
+ }
+ }
+ else{
+ bIsPrimitive = Introspector.isObjectPrimitive(aProperty.Type.getTypeClass());
+ }
+ return bIsPrimitive;
+ }
+
+
+ protected boolean isFoldable(){
+ boolean bIsFoldable = false;
+ if (! isPrimitive()){
+ String sTypeName = getUnoReturnObject().getClass().getName();
+ bIsFoldable = (!sTypeName.equals("com.sun.star.uno.Type"));
+ }
+ return bIsFoldable;
+ }
+
+
+ protected String getLabel(){
+ if (!sLabel.equals("")){
+ if (! isPrimitive()){
+ if (isFoldable()){
+ sLabel = getPropertyTypeDescription(aProperty, getUnoReturnObject());
+ }
+ else{
+ sLabel = getStandardPropertyDescription(aProperty, getUnoReturnObject());
+ }
+ }
+ else {
+ sLabel = getStandardPropertyDescription(aProperty, getUnoReturnObject());
+ }
+ }
+ return sLabel;
+ }
+
+ public Property getProperty(){
+ return aProperty;
+ }
+
+ protected static String getPropertyTypeDescription(Property _aProperty, Object _oUnoObject){
+ return _aProperty.Type.getTypeName() + " " + _aProperty.Name + " = " + _oUnoObject.toString();
+ }
+
+
+ protected static String getStandardPropertyDescription(Property _aProperty, Object _objectElement){
+ if (!Introspector.isObjectPrimitive(_objectElement)){
+ return _aProperty.Name + " = (" + _aProperty.Type.getTypeName() + ") ";
+ }
+ else{
+ return _aProperty.Name + " (" + _aProperty.Type.getTypeName() + ") = " + getDisplayValueOfPrimitiveType(_objectElement);
+ }
+ }
+
+
+ protected static String getStandardPropertyValueDescription(PropertyValue _aPropertyValue){
+ if (!Introspector.isObjectPrimitive(_aPropertyValue.Value)){
+ return _aPropertyValue.Name;
+ }
+ else{
+ return _aPropertyValue.Name + " : " + UnoNode.getDisplayValueOfPrimitiveType(_aPropertyValue.Value);
+ }
+ }
+}
+
+
diff --git a/odk/examples/java/Inspector/UnoTreeRenderer.java b/odk/examples/java/Inspector/UnoTreeRenderer.java
new file mode 100644
index 000000000000..9c2772124658
--- /dev/null
+++ b/odk/examples/java/Inspector/UnoTreeRenderer.java
@@ -0,0 +1,135 @@
+/*************************************************************************
+ *
+ * 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 java.awt.Color;
+import java.awt.Component;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.SystemColor;
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.JLabel;
+import javax.swing.JTree;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeCellRenderer;
+
+
+
+public class UnoTreeRenderer extends DefaultTreeCellRenderer{
+ private Icon m_oMethodIcon;
+ private Icon m_oPropertyIcon;
+ private Icon m_oContainerIcon;
+ private Icon m_oContentIcon;
+ private Icon m_oServiceIcon;
+ private Icon m_oInterfaceIcon;
+ private Icon m_oPropertyValueIcon;
+ private boolean bSelected;
+ private int nWidth = 0;
+
+
+ /** Creates a new instance of UnoTreeRenderer */
+ public UnoTreeRenderer(){
+ super();
+ try {
+
+ final ClassLoader loader = ClassLoader.getSystemClassLoader();
+ m_oMethodIcon = new ImageIcon(loader.getResource("images/methods_16.png"));
+ m_oPropertyIcon = new ImageIcon("images/properties_16.png");
+ m_oPropertyValueIcon = new ImageIcon("images/properties_16.png");
+ m_oContainerIcon = new ImageIcon("images/containers_16.png");
+ m_oServiceIcon = new ImageIcon("images/services_16.png");
+ m_oInterfaceIcon = new ImageIcon("images/interfaces_16.png");
+ m_oContentIcon = new ImageIcon("images/content_16.png");
+ } catch (RuntimeException e) {
+ System.out.println("Sorry, could not locate resourecs, treecell icons will not be displayed.");
+ }
+ }
+
+
+ public synchronized Component getTreeCellRendererComponent(JTree tree,Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus){
+ try{
+ bSelected = sel;
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
+ Component rc = super.getTreeCellRendererComponent( tree, value, sel,expanded, leaf, row,hasFocus);
+ String sLabelText = (String)node.getUserObject();
+ if (sLabelText != null){
+ if (sLabelText.equals(XUnoFacetteNode.SCONTAINERDESCRIPTION)){
+// setIcon(m_oContainerIcon);
+ } else if (sLabelText.equals(XUnoFacetteNode.SCONTENTDESCRIPTION)){
+// setIcon(m_oContentIcon);
+ } else if (sLabelText.equals(XUnoFacetteNode.SINTERFACEDESCRIPTION)){
+// setIcon(m_oInterfaceIcon);
+ } else if (sLabelText.equals(XUnoFacetteNode.SMETHODDESCRIPTION)){
+// setIcon(m_oMethodIcon);
+ } else if (sLabelText.equals(XUnoFacetteNode.SPROPERTYDESCRIPTION)){
+// setIcon(m_oPropertyIcon);
+ } else if (sLabelText.startsWith(XUnoFacetteNode.SPROPERTYINFODESCRIPTION)){
+// setIcon(m_oPropertyIcon);
+ } else if (sLabelText.equals(XUnoFacetteNode.SPROPERTYVALUEDESCRIPTION)){
+// setIcon(m_oPropertyValueIcon);
+ } else if (sLabelText.equals(XUnoFacetteNode.SSERVICEDESCRIPTION)){
+// setIcon(m_oServiceIcon);
+ } else{
+ setText(sLabelText);
+ rc.validate();
+ }
+ setSize(getPreferredSize()); //fm.stringWidth(sLabelText), (int) getSize().getHeight());
+ rc.validate();
+// nWidth = (int) rc.getPreferredSize().getWidth();
+ doLayout();
+ }
+ } catch (RuntimeException e) {
+ System.out.println("Sorry, icon for treecell could not be displayed.");
+ }
+ return this;
+ }
+
+
+
+ public void paintComponent(Graphics g) {
+ FontMetrics fm = getFontMetrics(getFont());
+ int x, y;
+ y = fm.getAscent() + 2;
+ if(getIcon() == null) {
+ x = 0;
+ } else {
+ x = getIcon().getIconWidth() + getIconTextGap();
+ }
+ g.setColor(getForeground());
+// g.fillRect(x,y,x + fm.stringWidth(getText()),y);
+// System.out.println("Text: " + getText());
+ super.paintComponent(g);
+ }
+}
+
+
diff --git a/odk/examples/java/Inspector/XDialogProvider.java b/odk/examples/java/Inspector/XDialogProvider.java
new file mode 100644
index 000000000000..fdf406273b7e
--- /dev/null
+++ b/odk/examples/java/Inspector/XDialogProvider.java
@@ -0,0 +1,65 @@
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+
+public interface XDialogProvider {
+
+ public static String SINVOKE = "Invoke";
+
+ public static String SADDTOSOURCECODE = "Add to Sourcecode";
+
+ public void enablePopupMenuItem(String _sMenuTitle, boolean _bdoEnable);
+
+ public void showPopUpMenu(Object invoker, int x, int y) throws java.lang.ClassCastException;
+
+ public InspectorPane getSelectedInspectorPage();
+
+ public void addInspectorPage(String _sTitle, Object _oContainer);
+
+ public InspectorPane getInspectorPage(int _nIndex);
+
+ public int getInspectorPageCount();
+
+ public void selectInspectorPageByIndex(int nTabIndex);
+
+ public void show(int _nPageIndex) throws java.lang.ClassCastException;
+
+ public void selectSourceCodeLanguage(int _nLanguage);
+
+ public void paint();
+
+ // returns one of the constants defined in XLanguageSourceCodeGenerator
+ public int getLanguage();
+
+ public String getIDLPath();
+}
diff --git a/odk/examples/java/Inspector/XInstanceInspector.idl b/odk/examples/java/Inspector/XInstanceInspector.idl
new file mode 100644
index 000000000000..2749535816b2
--- /dev/null
+++ b/odk/examples/java/Inspector/XInstanceInspector.idl
@@ -0,0 +1,56 @@
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+
+#ifndef INCLUDED_ORG_OPENOFFICE_XINSTANCEINSPECTOR_IDL
+#define INCLUDED_ORG_OPENOFFICE_XINSTANCEINSPECTOR_IDL
+
+#include <com/sun/star/uno/XInterface.idl>
+
+module org { module openoffice {
+
+ interface XInstanceInspector {
+ /**
+ * For a given instance this method displays all services, interfaces,
+ * methods, attributes, and contents in a tree. All dependend
+ * instances are also inspected and displayed, so the user could browse
+ * the tree. If you press the key "F1", the API-documentation from
+ * www.openoffice.org for the current instance will be displayed in a
+ * new window.
+ */
+ void inspect( [in] any aInstance, [in] string sTitle );
+ };
+
+}; };
+
+#endif
diff --git a/odk/examples/java/Inspector/XLanguageSourceCodeGenerator.java b/odk/examples/java/Inspector/XLanguageSourceCodeGenerator.java
new file mode 100644
index 000000000000..aaf424607a8a
--- /dev/null
+++ b/odk/examples/java/Inspector/XLanguageSourceCodeGenerator.java
@@ -0,0 +1,106 @@
+/*************************************************************************
+ *
+ * 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.TypeClass;
+import java.util.Vector;
+
+public interface XLanguageSourceCodeGenerator {
+
+ public static final int nJAVA = 0;
+ public static final int nCPLUSPLUS = 1;
+ public static final int nBASIC = 2;
+
+ public String getHeaderSourceCode(Object _oUnoObject, String _sClassName, TypeClass _aTypeClass);
+
+ public String getFinalHeaderStatements();
+
+ public void assignqueryInterfaceHeaderSourceCode();
+
+ public String getMainMethodSignatureSourceCode(XUnoNode _oUnoNode, String _soReturnObjectDescription);
+
+ public String getMethodTerminationSourceCode();
+
+ public String getStatementTerminationCharacter();
+
+ public boolean needsqueryInterface();
+
+ public String getqueryInterfaceSourceCode(String _sReturnValueDescription, String _sClassName, String _sObjectDescription);
+
+ public String getPropertyValueGetterSourceCode(String _sPropertyName, String _sReturnVariableName, String _sIncomingObjectName, TypeClass _aTypeClass, String _sTypeName);
+
+ public String getStructSourceCode(String _sReturnVariableDescription, String _sObjectDescription, String _sMember);
+
+ public String getObjectTypeDescription(String _sClassName, boolean _bAsHeader);
+
+ public String getbooleanTypeDescription();
+
+ public String getbyteTypeDescription();
+
+ public String getshortTypeDescription();
+
+ public String getunsignedshortTypeDescription();
+
+ public String getlongTypeDescription();
+
+ public String getunsignedlongTypeDescription();
+
+ public String gethyperTypeDescription();
+
+ public String getunsignedhyperTypeDescription();
+
+ public String getfloatTypeDescription();
+
+ public String getdoubleTypeDescription();
+
+ public String getcharTypeDescription();
+
+ public String getstringTypeDescription(boolean _bAsHeaderSourceCode);
+
+ public String gettypeTypeDescription(boolean _bAsHeaderSourceCode);
+
+ public String getanyTypeDescription(boolean _bAsHeaderSourceCode);
+
+ public String getArrayDeclaration(String sVariableDeclaration);
+
+ public String getVariableDeclaration(String _sTypeString, String _sVariableName, boolean _bIsArray, TypeClass aTypeClass, boolean _bInitialize);
+
+ public String getMethodSeparator();
+
+ public String getStringValue(String _sValue);
+
+ public String getConvertedSourceCodeValueOfObject(String _sReturnVariableName, String _sObjectDescription, TypeClass _aTypeClass, String _sTypeName);
+
+ public String castLiteral(String _sExpression, TypeClass _aTypeClass);
+
+ public String getCommentSign();
+}
diff --git a/odk/examples/java/Inspector/XMethodParametersDialog.java b/odk/examples/java/Inspector/XMethodParametersDialog.java
new file mode 100644
index 000000000000..d8fcdb13c9b1
--- /dev/null
+++ b/odk/examples/java/Inspector/XMethodParametersDialog.java
@@ -0,0 +1,37 @@
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+
+public interface XMethodParametersDialog {
+
+}
diff --git a/odk/examples/java/Inspector/XTreeControlProvider.java b/odk/examples/java/Inspector/XTreeControlProvider.java
new file mode 100644
index 000000000000..8f0d951e1a29
--- /dev/null
+++ b/odk/examples/java/Inspector/XTreeControlProvider.java
@@ -0,0 +1,93 @@
+/*************************************************************************
+ *
+ * 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.beans.Property;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.reflection.XIdlMethod;
+import com.sun.star.uno.Type;
+
+public interface XTreeControlProvider {
+
+ public static String sTitle = "User defined";
+
+ public String enableFilterElements(XUnoNode _oUnoNode);
+
+ public void setSourceCode(String _sSourceCode);
+
+ public Object inspect(java.lang.Object _oUserDefinedObject, String _sTitle) throws com.sun.star.uno.RuntimeException;
+
+ public void nodeInserted(XUnoNode _oParentNode, XUnoNode _oChildNode, int index);
+
+ public void nodeChanged(XUnoNode _oNode);
+
+ public boolean setNodeVisible(Object node, boolean v);
+
+ public XUnoNode getSelectedNode();
+
+ public XTreePathProvider getSelectedPath();
+
+ public void expandPath(XTreePathProvider xTreePathProvider) throws java.lang.ClassCastException;
+
+ public void addTreeExpandListener();
+
+ public void addInspectorPane(InspectorPane _oInspectorPane);
+
+ public boolean isPropertyNode(XUnoNode _oUnoNode);
+
+ public boolean isMethodNode(XUnoNode _oUnoNode);
+
+ public boolean isFacetteNode(XUnoNode _oUnoNode);
+
+ public XUnoNode addUnoNode(Object _oUnoObject);
+
+ public XUnoNode addUnoNode(Object _oUnoObject, Type _aType);
+
+ public XUnoFacetteNode addUnoFacetteNode(XUnoNode _oParentNode, String _sNodeDescription, Object _oUnoObject);
+
+ public XUnoMethodNode addMethodNode(Object _objectElement, XIdlMethod _xIdlMethod);
+
+ public XUnoPropertyNode addUnoPropertyNodeWithName(Property _aProperty);
+
+ public XUnoPropertyNode addUnoPropertyNodeWithHandle(Property _aProperty);
+
+ public XUnoPropertyNode addUnoPropertyNodeWithType(Property _aProperty);
+
+ public XUnoPropertyNode addUnoPropertyNodeWithAttributesDescription(Property _aProperty);
+
+ public XUnoPropertyNode addUnoPropertyNode(Object _oUnoObject, Property _aProperty);
+
+ public XUnoPropertyNode addUnoPropertyNode(Object _oUnoObject, PropertyValue _aPropertyValue, Object _oReturnObject);
+
+ public XUnoPropertyNode addUnoPropertyNode(Object _oUnoObject, Property _aProperty, Object _oUnoReturnObject);
+}
diff --git a/odk/examples/java/Inspector/XTreePathProvider.java b/odk/examples/java/Inspector/XTreePathProvider.java
new file mode 100644
index 000000000000..8a2f1ba58b59
--- /dev/null
+++ b/odk/examples/java/Inspector/XTreePathProvider.java
@@ -0,0 +1,25 @@
+/*
+ * xTreePathProvider.java
+ *
+ * Created on 12. Dezember 2006, 13:30
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+/**
+ *
+ * @author bc93774
+ */
+public interface XTreePathProvider {
+
+ public XUnoNode getLastPathComponent();
+
+ public XUnoNode getPathComponent(int i);
+
+ public int getPathCount();
+
+ public XTreePathProvider getParentPath();
+
+ public XTreePathProvider pathByAddingChild(XUnoNode _oUnoNode);
+}
diff --git a/odk/examples/java/Inspector/XUnoFacetteNode.java b/odk/examples/java/Inspector/XUnoFacetteNode.java
new file mode 100644
index 000000000000..9bf091b234f3
--- /dev/null
+++ b/odk/examples/java/Inspector/XUnoFacetteNode.java
@@ -0,0 +1,63 @@
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+
+
+
+public interface XUnoFacetteNode extends XUnoNode {
+
+ public static String SMETHODDESCRIPTION = "Methods";
+ public static String SPROPERTYDESCRIPTION = "Properties";
+ public static String SPROPERTYINFODESCRIPTION = "PropertyInfo";
+ public static String SCONTAINERDESCRIPTION = "Container";
+ public static String SSERVICEDESCRIPTION = "Services";
+ public static String SINTERFACEDESCRIPTION = "Interfaces";
+ public static String SCONTENTDESCRIPTION = "Content";
+ public static String SPROPERTYVALUEDESCRIPTION = "PropertyValues";
+
+
+ public boolean isMethodNode();
+
+ public boolean isPropertyNode();
+
+ public boolean isContainerNode();
+
+ public boolean isServiceNode();
+
+ public boolean isInterfaceNode();
+
+ public String getFilter();
+
+ public void setFilter(String _sFilter);
+
+}
diff --git a/odk/examples/java/Inspector/XUnoMethodNode.java b/odk/examples/java/Inspector/XUnoMethodNode.java
new file mode 100644
index 000000000000..93167840a978
--- /dev/null
+++ b/odk/examples/java/Inspector/XUnoMethodNode.java
@@ -0,0 +1,68 @@
+/*************************************************************************
+ *
+ * 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.reflection.XIdlMethod;
+import com.sun.star.uno.TypeClass;
+import java.util.Vector;
+
+
+public interface XUnoMethodNode extends XUnoNode {
+
+ public XIdlMethod getXIdlMethod();
+
+ public boolean isInvoked();
+
+ public Object invoke() throws com.sun.star.uno.Exception;
+
+ public Object invoke(Object _oUnoObject, Object[] _oParameters) throws com.sun.star.uno.Exception;
+
+ public boolean isInvokable();
+
+ public boolean hasParameters();
+
+ public Object[] getLastParameterObjects();
+
+ public Object getLastUnoReturnObject();
+
+ public TypeClass getTypeClass();
+
+ public boolean isPrimitive();
+
+ public Vector getMethodObjects();
+
+ public boolean isFoldable();
+
+ public String getStandardMethodDescription();
+
+}
diff --git a/odk/examples/java/Inspector/XUnoNode.java b/odk/examples/java/Inspector/XUnoNode.java
new file mode 100644
index 000000000000..a27c0aa3a4ab
--- /dev/null
+++ b/odk/examples/java/Inspector/XUnoNode.java
@@ -0,0 +1,84 @@
+import com.sun.star.uno.Type;
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+
+
+public interface XUnoNode {
+
+ public static final int nINTERFACE = 1;
+ public static final int nSERVICE = 2;
+ public static final int nOTHERS = 3;
+
+ public String getAnchor();
+
+ public String getClassName();
+
+ public void openIdlDescription(String _sIDLUrl);
+
+ public boolean isFilterApplicable(String _sFilter);
+
+ public void setVisible(String _sFilter);
+
+ public void setParameterObjects(Object[] _oParamObjects);
+
+ public Object[] getParameterObjects();
+
+ public String getName();
+
+ public void setFoldable(boolean _bIsFoldable);
+
+ public Object getUnoObject();
+
+ public XUnoNode getParentNode();
+
+ public void addChildNode(XUnoNode _xUnoNode);
+
+ public void setLabel(String _sLabel);
+
+ public String getLabel();
+
+ public int getChildCount();
+
+ public XUnoNode getChild(int _index);
+
+ public int getNodeType();
+
+ // possible values are nINTERFACE, nSERVICE, nOTHERS
+ public void setNodeType(int _nNodeType);
+
+ /** delivers only the Uno-Type when the NodeType is set to nINTERFACE
+ * otherwise (when the NodeType has not been set returns null
+ */
+ public Type getUnoType();
+}
diff --git a/odk/examples/java/Inspector/XUnoPropertyNode.java b/odk/examples/java/Inspector/XUnoPropertyNode.java
new file mode 100644
index 000000000000..27d6c5021e1d
--- /dev/null
+++ b/odk/examples/java/Inspector/XUnoPropertyNode.java
@@ -0,0 +1,51 @@
+/*************************************************************************
+ *
+ * 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.beans.Property;
+
+
+public interface XUnoPropertyNode extends XUnoNode {
+
+ public static int nDEFAULT = 0;
+ public static int nPROPERTYSETINFOTYPE = 1;
+ public static int nPROPERTYVALUETYPE = 2;
+
+ public Object getUnoReturnObject();
+
+ public int getPropertyNodeType();
+
+ public void setPropertyNodeType(int _nPropertyType);
+
+ public Property getProperty();
+
+}
diff --git a/odk/examples/java/Inspector/images/containers_16.png b/odk/examples/java/Inspector/images/containers_16.png
new file mode 100755
index 000000000000..0b4c62f11294
--- /dev/null
+++ b/odk/examples/java/Inspector/images/containers_16.png
Binary files differ
diff --git a/odk/examples/java/Inspector/images/content_16.png b/odk/examples/java/Inspector/images/content_16.png
new file mode 100755
index 000000000000..758169260f54
--- /dev/null
+++ b/odk/examples/java/Inspector/images/content_16.png
Binary files differ
diff --git a/odk/examples/java/Inspector/images/interfaces_16.png b/odk/examples/java/Inspector/images/interfaces_16.png
new file mode 100755
index 000000000000..cf633ac9c7c3
--- /dev/null
+++ b/odk/examples/java/Inspector/images/interfaces_16.png
Binary files differ
diff --git a/odk/examples/java/Inspector/images/methods_16.png b/odk/examples/java/Inspector/images/methods_16.png
new file mode 100755
index 000000000000..25cd8b45cf1c
--- /dev/null
+++ b/odk/examples/java/Inspector/images/methods_16.png
Binary files differ
diff --git a/odk/examples/java/Inspector/images/properties_16.png b/odk/examples/java/Inspector/images/properties_16.png
new file mode 100755
index 000000000000..4e22dd1d5ce7
--- /dev/null
+++ b/odk/examples/java/Inspector/images/properties_16.png
Binary files differ
diff --git a/odk/examples/java/Inspector/images/services_16.png b/odk/examples/java/Inspector/images/services_16.png
new file mode 100755
index 000000000000..024a16ed63d3
--- /dev/null
+++ b/odk/examples/java/Inspector/images/services_16.png
Binary files differ
diff --git a/odk/examples/java/Inspector/manifest.mf b/odk/examples/java/Inspector/manifest.mf
new file mode 100755
index 000000000000..328e8e5bc3b7
--- /dev/null
+++ b/odk/examples/java/Inspector/manifest.mf
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+X-COMMENT: Main-Class will be added automatically by build
+
diff --git a/odk/examples/java/MinimalComponent/BuildMinimalComponent.xml b/odk/examples/java/MinimalComponent/BuildMinimalComponent.xml
new file mode 100644
index 000000000000..a296f7f932c6
--- /dev/null
+++ b/odk/examples/java/MinimalComponent/BuildMinimalComponent.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ author: Bertram Nolte
+ created: 2001-10-11
+ revision: 1.0
+ -->
+<project name="MinimalComponent" basedir="." default="all">
+
+ <target name="init">
+ <!--
+ In this target you have to change all parts, so that the properties
+ fit to your odk installation and to your service
+ -->
+ <property name="ODKPATH" value="D:/cvs/api/odk"/>
+ <property name="OUTPUTPATH" value="D:/cvs/api/odk/WINexample.out"/>
+ <property name="PACKAGE_NAME" value="org.OpenOffice."/>
+ <property name="JAR_FILE_NAME" value="MinimalComponent"/>
+ <property name="INTERFACE_NAME" value="MinimalComponent"/>
+ <property name="RDB_NAME" value="MinimalComponent.rdb"/>
+ </target>
+ <target depends="init" name="unoidl">
+
+ <exec dir="${ODKPATH}/WINexample.out/misc/" executable="${ODKPATH}/windows/bin/idlc.exe" timeout="600">
+ <arg line="-I. -I${ODKPATH}/idl ${ODKPATH}/examples/java/MinimalComponent/${INTERFACE_NAME}.idl"/>
+ </exec>
+
+ <exec dir="." executable="${ODKPATH}/windows/bin/regmerge.exe" timeout="600">
+ <arg line="./${RDB_NAME} /UCR ./${INTERFACE_NAME}.urd"/>
+ </exec>
+
+ <exec dir="." executable="${ODKPATH}/windows/bin/regmerge.exe" timeout="600">
+ <arg line="./${RDB_NAME} / ${ODKPATH}/windows/bin/applicat.rdb"/>
+ </exec>
+
+ <exec dir="." executable="${ODKPATH}/windows/bin/javamaker.exe" timeout="600">
+ <arg line="-BUCR -O${OUTPUTPATH}/class/${INTERFACE_NAME} -nD ./${RDB_NAME}"/>
+<!--
+ <arg line="-BUCR -T${PACKAGE_NAME}${INTERFACE_NAME} -O${OUTPUTPATH}/class/${INTERFACE_NAME} -nD ./${INTERFACE_NAME}.urd"/>
+ -->
+ </exec>
+
+ </target>
+
+ <target depends="init,unoidl" name="compile">
+ <mkdir dir="classes"/>
+ <javac debug="on" destdir="./classes" srcdir="." >
+ <classpath>
+ <fileset dir="${ODKPATH}/classes/">
+ <include name="**/*.jar"/>
+ </fileset>
+ <pathelement location="./classes"/>
+ </classpath>
+ </javac>
+ </target>
+
+ <target depends="compile,init" name="jar">
+ <jar basedir="./classes" compress="true" jarfile="${JAR_FILE_NAME}.jar" manifest="Manifest">
+ </jar>
+ </target>
+
+ <target depends="compile,init,jar" name="all">
+ <!-- WRITEME -->
+ </target>
+</project>
diff --git a/odk/examples/java/MinimalComponent/Makefile b/odk/examples/java/MinimalComponent/Makefile
new file mode 100644
index 000000000000..8fd4ade8fb9d
--- /dev/null
+++ b/odk/examples/java/MinimalComponent/Makefile
@@ -0,0 +1,203 @@
+#*************************************************************************
+#
+# 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 Minimal component example of the SDK.
+
+PRJ=../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+
+# we use the sample directory name dor separating this example
+# from others in the output directory
+SAMPLE_NAME=MinimalComponent
+SAMPLE_CLASS_OUT=$(OUT_CLASS)/$(SAMPLE_NAME)
+SAMPLE_GEN_OUT=$(OUT_MISC)/$(SAMPLE_NAME)
+
+COMP_NAME=MinimalComponent
+COMP_CLASS_OUT=$(SAMPLE_CLASS_OUT)/$(COMP_NAME)
+COMP_GEN_OUT=$(SAMPLE_GEN_OUT)/$(COMP_NAME)
+COMP_RDB_NAME=$(COMP_NAME).uno.rdb
+COMP_RDB=$(COMP_GEN_OUT)/$(COMP_RDB_NAME)
+COMP_PACKAGE=$(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT)
+COMP_PACKAGE_URL=$(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)")
+COMP_JAR_NAME=$(COMP_NAME).uno.jar
+COMP_JAR=$(SAMPLE_CLASS_OUT)/$(COMP_JAR_NAME)
+COMP_JAR_MANIFEST=$(COMP_GEN_OUT)/$(COMP_NAME).uno.Manifest
+COMP_UNOPKG_MANIFEST = $(COMP_GEN_OUT)/META-INF/manifest.xml
+COMP_REGISTERFLAG=$(COMP_GEN_OUT)$(PS)java_$(COMP_NAME)_register_component.flag
+
+APP1_NAME=TestMinimalComponent
+APP1_CLASS_OUT=$(SAMPLE_CLASS_OUT)/$(APP1_NAME)
+APP1_GEN_OUT=$(SAMPLE_GEN_OUT)/$(APP1_NAME)
+APP1_JAR=$(SAMPLE_CLASS_OUT)/$(APP1_NAME).jar
+APP1_JAR_MANIFEST=$(APP1_GEN_OUT)/$(APP1_NAME).mf
+
+IDLFILES = MinimalComponent.idl
+
+# normally the idl file should be stored in a directory tree fitting the module structure,
+# for the example we know the module structure
+PACKAGE = org/openoffice
+
+COMP_JAVAFILES = MinimalComponent.java
+COMP_CLASSFILES = $(patsubst %.java,$(COMP_CLASS_OUT)/%.class,$(COMP_JAVAFILES))
+
+GEN_CLASSFILES = $(patsubst %.idl,$(SAMPLE_CLASS_OUT)/$(PACKAGE)/%.class,$(IDLFILES))
+GEN_TYPELIST = $(subst /,.,$(patsubst %.idl,-T$(PACKAGE)/% ,$(IDLFILES)))
+GEN_URDFILES = $(patsubst %.idl,$(SAMPLE_GEN_OUT)/%.urd,$(IDLFILES))
+
+# the generated types are necessary for the component and the application jar
+GEN_CLASSFILENAMES = $(subst $(SAMPLE_CLASS_OUT)/,,$(GEN_CLASSFILES))
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(SAMPLE_CLASS_OUT)\
+ $(PATH_SEPARATOR)$(COMP_CLASS_OUT)\
+ $(PATH_SEPARATOR)$(APP1_CLASS_OUT))
+
+
+# Targets
+.PHONY: ALL
+ALL : JavaMinimalComponentExample
+
+include $(SETTINGS)/stdtarget.mk
+
+$(COMP_GEN_OUT)/%.Manifest :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo UNO-Type-Path: $(basename $*).uno.jar> $@
+ @echo RegistrationClassName: $(basename $*)>> $@
+
+$(SAMPLE_GEN_OUT)/%.urd : %.idl
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(IDLC) -C -I. -I$(IDL_DIR) -O$(SAMPLE_GEN_OUT) $<
+
+$(COMP_GEN_OUT)/%.rdb : $(GEN_URDFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(REGMERGE) $@ /UCR $(GEN_URDFILES)
+
+$(GEN_CLASSFILES) : $(COMP_RDB)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(JAVAMAKER) -BUCR -nD $(GEN_TYPELIST) -O$(SAMPLE_CLASS_OUT) $(COMP_RDB) -X$(URE_TYPES) -X$(OFFICE_TYPES)
+
+# component as well as application are dependent from the generated types
+# rule for component class files
+$(COMP_CLASS_OUT)/%.class : %.java $(GEN_CLASSFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(COMP_CLASS_OUT) $<
+
+# rule for example application class files
+$(APP1_CLASS_OUT)/%.class : %.java $(GEN_CLASSFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(APP1_CLASS_OUT) $<
+
+# rule for client/example application manifest file
+$(APP1_GEN_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: $*>> $@
+
+# rule for client/example application jar file
+$(APP1_JAR) : $(APP1_JAR_MANIFEST) $(APP1_CLASS_OUT)/$(APP1_NAME).class $(GEN_CLASSFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAR) cvfm $@ $< -C $(APP1_CLASS_OUT) .
+ +cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_JAR) uvf $(@F) $(GEN_CLASSFILENAMES)
+ +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
+
+# rule for component jar file
+$(COMP_JAR) : $(COMP_JAR_MANIFEST) $(COMP_CLASSFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAR) cvfm $@ $< -C $(COMP_CLASS_OUT) .
+ +cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_JAR) uvf $(@F) $(GEN_CLASSFILENAMES)
+
+# rule for component package manifest
+$(COMP_GEN_OUT)/%/manifest.xml :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
+ @echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@
+ @echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-typelibrary;type=RDB$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(SAMPLE_GEN_OUT)/,,$(@D))).uno.rdb$(QM)"/$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-component;type=Java$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(SAMPLE_GEN_OUT)/,,$(@D))).uno.jar$(QM)"/$(CSEP) >> $@
+ @echo $(OSEP)/manifest:manifest$(CSEP) >> $@
+
+# rule for component package file
+$(COMP_PACKAGE) : $(COMP_RDB) $(COMP_JAR) $(COMP_UNOPKG_MANIFEST)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ cd $(subst /,$(PS),$(COMP_GEN_OUT)) && $(SDK_ZIP) ../../../bin/$(@F) $(COMP_RDB_NAME)
+ cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_ZIP) -u ../../bin/$(@F) $(COMP_JAR_NAME)
+ cd $(subst /,$(PS),$(COMP_GEN_OUT)) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
+
+$(COMP_REGISTERFLAG) : $(COMP_PACKAGE)
+ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES"
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(DEPLOYTOOL) $(COMP_PACKAGE_URL)
+ @echo flagged > $(subst /,$(PS),$@)
+else
+ @echo --------------------------------------------------------------------------------
+ @echo If you want to install your component automatically, please set the environment
+ @echo variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only
+ @echo possible if no office instance is running.
+ @echo --------------------------------------------------------------------------------
+endif
+
+JavaMinimalComponentExample : $(COMP_REGISTERFLAG) $(APP1_JAR)
+ @echo --------------------------------------------------------------------------------
+ @echo Please use the following command to execute the example!
+ @echo -
+ @echo $(MAKE) $(APP1_NAME).run
+ @echo ------
+ @echo The $(COMP_NAME) component was installed if SDK_AUTO_DEPLOYMENT = YES.
+ @echo You can use this component inside your office installation, see the example
+ @echo description.
+ @echo --------------------------------------------------------------------------------
+
+%.run: $(SAMPLE_CLASS_OUT)/%.jar
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $<
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_CLASS_OUT))
+ -$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_GEN_OUT))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL)))
diff --git a/odk/examples/java/MinimalComponent/MinimalComponent.idl b/odk/examples/java/MinimalComponent/MinimalComponent.idl
new file mode 100644
index 000000000000..41ee6c53c14f
--- /dev/null
+++ b/odk/examples/java/MinimalComponent/MinimalComponent.idl
@@ -0,0 +1,52 @@
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+
+#ifndef _org_openoffice_MinimalComponent_idl_
+#define _org_openoffice_MinimalComponent_idl_
+
+#include <com/sun/star/lang/XServiceInfo.idl>
+
+// org
+module org {
+ // openoffice
+ module openoffice {
+ // example service, XServiceInfo is implemented here for demonstration
+ // issues. XServiceInfo must be implemented by all components. But
+ // here it is used to show the new code generation feature for services.
+ // See the TestMinimalComponent.java how it can be used!
+ service MinimalComponent: ::com::sun::star::lang::XServiceInfo;
+ };
+};
+
+#endif
diff --git a/odk/examples/java/MinimalComponent/MinimalComponent.java b/odk/examples/java/MinimalComponent/MinimalComponent.java
new file mode 100644
index 000000000000..ef75cb287c1d
--- /dev/null
+++ b/odk/examples/java/MinimalComponent/MinimalComponent.java
@@ -0,0 +1,171 @@
+/*************************************************************************
+ *
+ * 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.lib.uno.helper.Factory;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.lang.XSingleComponentFactory;
+import com.sun.star.lib.uno.helper.WeakBase;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.registry.XRegistryKey;
+import com.sun.star.lang.XInitialization;
+import com.sun.star.lang.XTypeProvider;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.uno.Type;
+
+/** This class capsulates the class, that implements the minimal component, a
+ * factory for creating the service (<CODE>__getComponentFactory</CODE>) and a
+ * method, that writes the information into the given registry key
+ * (<CODE>__writeRegistryServiceInfo</CODE>).
+ */
+public class MinimalComponent {
+ /** This class implements the component. At least the interfaces XServiceInfo,
+ * XTypeProvider, and XInitialization should be provided by the service.
+ */
+ public static class _MinimalComponent extends WeakBase
+ implements XInitialization, XServiceInfo {
+ /** The service name, that must be used to get an instance of this service.
+ */
+ static private final String __serviceName =
+ "org.openoffice.MinimalComponent";
+
+ /** The initial component contextr, that gives access to
+ * the service manager, supported singletons, ...
+ * It's often later used
+ */
+ private XComponentContext m_cmpCtx;
+
+ /** The service manager, that gives access to all registered services.
+ * It's often later used
+ */
+ private XMultiComponentFactory m_xMCF;
+
+ /** The constructor of the inner class has a XMultiServiceFactory parameter.
+ * @param xmultiservicefactoryInitialization A special service factory
+ * could be introduced while initializing.
+ */
+ public _MinimalComponent(XComponentContext xCompContext) {
+ try {
+ m_cmpCtx = xCompContext;
+ m_xMCF = m_cmpCtx.getServiceManager();
+ }
+ catch( Exception e ) {
+ e.printStackTrace();
+ }
+ }
+
+ /** This method is a member of the interface for initializing an object
+ * directly after its creation.
+ * @param object This array of arbitrary objects will be passed to the
+ * component after its creation.
+ * @throws Exception Every exception will not be handled, but will be
+ * passed to the caller.
+ */
+ public void initialize( Object[] object )
+ throws com.sun.star.uno.Exception {
+ /* The component describes what arguments its expected and in which
+ * order!At this point you can read the objects and can intialize
+ * your component using these objects.
+ */
+ }
+
+ /** This method returns an array of all supported service names.
+ * @return Array of supported service names.
+ */
+ public String[] getSupportedServiceNames() {
+ return getServiceNames();
+ }
+
+ /** This method is a simple helper function to used in the
+ * static component initialisation functions as well as in
+ * getSupportedServiceNames.
+ */
+ public static String[] getServiceNames() {
+ String[] sSupportedServiceNames = { __serviceName };
+ return sSupportedServiceNames;
+ }
+
+ /** This method returns true, if the given service will be
+ * supported by the component.
+ * @param sServiceName Service name.
+ * @return True, if the given service name will be supported.
+ */
+ public boolean supportsService( String sServiceName ) {
+ return sServiceName.equals( __serviceName );
+ }
+
+ /** Return the class name of the component.
+ * @return Class name of the component.
+ */
+ public String getImplementationName() {
+ return _MinimalComponent.class.getName();
+ }
+ }
+
+
+ /**
+ * Gives a factory for creating the service.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return returns a <code>XSingleComponentFactory</code> for creating
+ * the component
+ * @param sImplName the name of the implementation for which a
+ * service is desired
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static XSingleComponentFactory __getComponentFactory(String sImplName)
+ {
+ XSingleComponentFactory xFactory = null;
+
+ if ( sImplName.equals( _MinimalComponent.class.getName() ) )
+ xFactory = Factory.createComponentFactory(_MinimalComponent.class,
+ _MinimalComponent.getServiceNames());
+
+ return xFactory;
+ }
+
+ /**
+ * Writes the service information into the given registry key.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return returns true if the operation succeeded
+ * @param regKey the registryKey
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
+ return Factory.writeRegistryServiceInfo(_MinimalComponent.class.getName(),
+ _MinimalComponent.getServiceNames(),
+ regKey);
+ }
+}
diff --git a/odk/examples/java/MinimalComponent/TestMinimalComponent.java b/odk/examples/java/MinimalComponent/TestMinimalComponent.java
new file mode 100644
index 000000000000..219eea7ca504
--- /dev/null
+++ b/odk/examples/java/MinimalComponent/TestMinimalComponent.java
@@ -0,0 +1,69 @@
+/*************************************************************************
+ *
+ * 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.lang.XSingleComponentFactory;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.container.XSet;
+import com.sun.star.lang.XServiceInfo;
+
+public class TestMinimalComponent {
+ public static void main(String args[]) {
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ try {
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ if( xContext != null )
+ System.out.println("Connected to a running office ...");
+
+ XServiceInfo xSIMinimalComponent =
+ org.openoffice.MinimalComponent.create(xContext);
+
+ System.out.println("\nXServiceInfo is used to get the implementation" +
+ " name: " +
+ xSIMinimalComponent.getImplementationName() +
+ "\nOk\n");
+ xContext = null;
+
+ System.exit(0);
+ }
+ catch( Exception e ) {
+ System.err.println( e );
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+}
diff --git a/odk/examples/java/NotesAccess/Makefile b/odk/examples/java/NotesAccess/Makefile
new file mode 100644
index 000000000000..87e41d3c1e7a
--- /dev/null
+++ b/odk/examples/java/NotesAccess/Makefile
@@ -0,0 +1,113 @@
+#*************************************************************************
+#
+# 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 NotesAccess example of the SDK.
+
+PRJ=../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+EXAMPLE_NAME=NotesAccessExample
+OUT_APP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME)
+
+APP_NAME=NotesAccess
+APP_JAR=$(OUT_APP_CLASS)/$(APP_NAME).jar
+
+JAVAFILES = \
+ NotesAccess.java
+
+CLASSFILES = $(patsubst %.java,$(OUT_APP_CLASS)/%.class,$(JAVAFILES))
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(OUT_APP_CLASS))
+
+
+# Targets
+.PHONY: ALL
+ALL : \
+ JavaNotesAccessExample
+
+include $(SETTINGS)/stdtarget.mk
+
+NotesAPIs :
+ @echo --------------------------------------------------------------------------------
+ @echo This example uses external APIs from Lotus Notes/Domino. You can download a
+ @echo trial version from "$(QM)http://www.lotus.com/downloads$(QM)". After installation
+ @echo please do the following:
+ @echo 1. Add the install path to the PATH or LD_LIBRARY_PATH of this shell.
+ @echo e.g "$(QM)PATH=C:\Program Files\lotus\notes;...$(QM)"
+ @echo 2. Add the "$(QM)Notes.jar$(QM)" to your CLASSPATH
+ @echo e.g. "$(QM)CLASSPATH=C:\Program Files\lotus\notes\Notes.jar;$(QM)"
+ @echo --------------------------------------------------------------------------------
+
+
+$(CLASSFILES) : $(JAVAFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_APP_CLASS) $(JAVAFILES)
+
+$(OUT_APP_CLASS)/%.mf :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo Class-Path: Notes.jar> $@
+ @echo Main-Class: com.sun.star.lib.loader.Loader>> $@
+ $(ECHOLINE)>> $@
+ @echo Name: com/sun/star/lib/loader/Loader.class>> $@
+ @echo Application-Class: $*>> $@
+
+$(APP_JAR) : $(OUT_APP_CLASS)/$(APP_NAME).mf $(OUT_APP_CLASS)/$(APP_NAME).class
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ +cd $(subst /,$(PS),$(OUT_APP_CLASS)) && $(SDK_JAR) cvfm $(@F) $(APP_NAME).mf $(APP_NAME).class
+ +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
+
+JavaNotesAccessExample : NotesAPIs $(APP_JAR)
+ @echo --------------------------------------------------------------------------------
+ @echo NOTE: Before you run this example make sure that the exaternal "$(QM)Notes.jar$(QM)" can
+ @echo be found besides "$(QM)$(APP_JAR)"$(QM)
+ @echo and that the PATH variable includes the Notes installation directory.
+ @echo -
+ @echo Please use the following command to execute the example!
+ @echo -
+ @echo $(MAKE) NotesAccess.run
+ @echo --------------------------------------------------------------------------------
+
+%.run: $(APP_JAR)
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $< "$(QM)$(QM)" "$(QM)$(QM)" "$(QM)$(QM)" Stocks.nsf
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst \\,\,$(subst /,$(PS),$(OUT_APP_CLASS)))
diff --git a/odk/examples/java/NotesAccess/NotesAccess.java b/odk/examples/java/NotesAccess/NotesAccess.java
new file mode 100644
index 000000000000..e989c9cfa760
--- /dev/null
+++ b/odk/examples/java/NotesAccess/NotesAccess.java
@@ -0,0 +1,288 @@
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+
+// Lotus Notes Domino API
+import lotus.domino.NotesThread;
+import lotus.domino.Session;
+import lotus.domino.Database;
+import lotus.domino.DocumentCollection;
+import lotus.domino.Document;
+import lotus.domino.NotesFactory;
+
+// OpenOffice.org API
+import com.sun.star.bridge.XUnoUrlResolver;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.frame.XComponentLoader;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.sheet.XSpreadsheetDocument;
+import com.sun.star.sheet.XSpreadsheets;
+import com.sun.star.sheet.XSpreadsheet;
+import com.sun.star.container.XIndexAccess;
+import com.sun.star.table.XCell;
+
+/** This class creates an OpenOffice.org Calc spreadsheet document and fills it
+ * with existing values of documents from a Lotus Notes database.
+ */
+public class NotesAccess implements Runnable {
+
+ /** Host server of the Domino Directory.
+ */
+ static String stringHost = "";
+
+ /** User in the host's Domino Directory.
+ */
+ static String stringUser = "";
+
+ /** Password for the user in the host's Domino Directory.
+ */
+ static String stringPassword = "";
+
+ /** Database with documents to get data from.
+ */
+ static String stringDatabase = "";
+
+ /** Reading the arguments and constructing the thread.
+ * @param argv Holding values for the host, user, and the password of the user.
+ */
+ public static void main( String args[] ) {
+ Thread thread;
+
+ if ( args.length < 4 ) {
+ System.out.println(
+ "usage: java -jar NotesAccess.jar \"<Domino Host>\" \"<User>\" " +
+ "\"<Password>\" \"<Database>\"" );
+ System.out.println( "\ne.g.:" );
+ System.out.println(
+ "java -jar NotesAccess.jar \"\" \"\" \"\" \"Stocks.nsf\"" );
+ System.exit( 1 );
+ }
+
+ if ( !args[ 0 ].trim().equals( "" ) ) {
+ stringHost = args[ 0 ].trim();
+ }
+ if ( !args[ 1 ].trim().equals( "" ) ) {
+ stringUser = args[ 1 ].trim();
+ }
+ stringPassword = args[ 2 ].trim();
+
+ try {
+ java.io.File sourceFile = new java.io.File(args[ 3 ].trim());
+ stringDatabase = sourceFile.getCanonicalPath();
+ } catch (java.io.IOException e) {
+ System.out.println("Error: Please check the name or path to your database file.");
+ e.printStackTrace();
+ System.exit( 1 );
+ }
+
+ if ( stringHost.equals( "" ) ) {
+ // Initializing.
+ NotesAccess notesaccess = new NotesAccess();
+
+ // Allowing only local calls to the Domino classes.
+ thread = new NotesThread( ( Runnable ) notesaccess );
+ }
+ else {
+ // Extracting the host, user, and password.
+ NotesAccess notesaccess = new NotesAccess();
+
+ // Allowing remote calls to the Domino classes.
+ thread = new Thread( ( Runnable ) notesaccess );
+ }
+
+ // Starting the thread.
+ thread.start();
+ }
+
+ /** This is the default constructor without arguments.
+ */
+ public NotesAccess() {
+ }
+
+ /** Reading all documents from the given database and writing the data to
+ * an OpenOffice.org Calc spreadsheet document.
+ */
+ public void run() {
+ try {
+ // get the remote office component context
+ XComponentContext xContext =
+ com.sun.star.comp.helper.Bootstrap.bootstrap();
+
+ System.out.println("Connected to a running office ...");
+
+ XMultiComponentFactory xMCF = xContext.getServiceManager();
+
+ /* A desktop environment contains tasks with one or more
+ frames in which components can be loaded. Desktop is the
+ environment for components which can instanciate within
+ frames. */
+ XComponentLoader xLoader = ( XComponentLoader )
+ UnoRuntime.queryInterface(XComponentLoader.class,
+ xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext));
+
+ // Load a Writer document, which will be automaticly displayed
+ XComponent xComponent = xLoader.loadComponentFromURL(
+ "private:factory/scalc", "_blank", 0,
+ new PropertyValue[0] );
+
+ // Querying for the interface XSpreadsheetDocument
+ XSpreadsheetDocument xSpreadsheetDoc =
+ (XSpreadsheetDocument) UnoRuntime.queryInterface(
+ XSpreadsheetDocument.class, xComponent);
+
+ // Getting all sheets from the spreadsheet document.
+ XSpreadsheets xSpreadsheets = xSpreadsheetDoc.getSheets() ;
+
+ // Querying for the interface XIndexAccess.
+ XIndexAccess xIndexAccess = (XIndexAccess) UnoRuntime.queryInterface(
+ XIndexAccess.class, xSpreadsheets);
+
+ // Getting the first spreadsheet.
+ XSpreadsheet xSpreadsheet = (XSpreadsheet) UnoRuntime.queryInterface(
+ XSpreadsheet.class, xIndexAccess.getByIndex(0));
+
+ Session session;
+ if ( !stringHost.equals( "" ) ) {
+ // Creating a Notes session for remote calls to the Domino classes.
+ session = NotesFactory.createSession(stringHost, stringUser,
+ stringPassword);
+ }
+ else {
+ // Creating a Notes session for only local calls to the
+ // Domino classes.
+ session = NotesFactory.createSession();
+ }
+
+ // Getting the specified Notes database.
+ Database database = session.getDatabase( "", stringDatabase );
+
+ // Getting a collection of all documents from the database.
+ DocumentCollection documentCollection = database.getAllDocuments();
+
+ // Getting the first document from the database
+ Document document = documentCollection.getFirstDocument();
+
+ // Start to write to cells at this row.
+ int intRowToStart = 0;
+
+ // The current row.
+ int intRow = intRowToStart;
+
+ // The current column.
+ int intColumn = 0;
+
+ // Process all documents
+ while ( document != null ) {
+ // Getting the name of the stock.
+ String stringName = document.getItemValueString("Name");
+
+ // Inserting the name to a specified cell.
+ insertIntoCell(intColumn, intRow, stringName, xSpreadsheet, "");
+
+ // Getting the number of stocks.
+ double intNumber = document.getItemValueInteger( "Number" );
+
+ // Inserting the number of stocks to a specified cell.
+ insertIntoCell( intColumn + 1, intRow, String.valueOf(intNumber),
+ xSpreadsheet, "V" );
+
+ // Getting current share price.
+ double doubleSharePrice = document.getItemValueDouble("SharePrice");
+
+ // Inserting the current share price to a specified cell.
+ insertIntoCell(intColumn + 2, intRow,
+ String.valueOf(doubleSharePrice),
+ xSpreadsheet, "V");
+
+ // Inserting the total value.
+ insertIntoCell(intColumn + 3, intRow, "=B"
+ + String.valueOf( intRow + 1 )
+ + "*C" + String.valueOf(intRow + 1),
+ xSpreadsheet, "");
+
+ // Increasing the current row.
+ intRow++;
+
+ // Getting the next document from the collection.
+ document = documentCollection.getNextDocument();
+ }
+
+ // Summing all specific amounts.
+ insertIntoCell(intColumn + 3, intRow, "=sum(D"
+ + String.valueOf( intRowToStart + 1 ) + ":D"
+ + String.valueOf( intRow ),
+ xSpreadsheet, "");
+
+ xContext = null;
+
+ // Leaving the program.
+ System.exit(0);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /** Inserting a value or formula to a cell defined by the row and column.
+ * @param intCellX Row.
+ * @param intCellY Column.
+ * @param stringValue This value will be written to the cell.
+ * @param xSpreadsheet Write the value to the cells of this spreadsheet.
+ * @param stringFlag If this string contains "V", the value will be written,
+ * otherwise the formula.
+ */
+ public static void insertIntoCell(int intCellX, int intCellY,
+ String stringValue,
+ XSpreadsheet xSpreadsheet,
+ String stringFlag)
+ {
+ XCell xCell = null;
+
+ try {
+ xCell = xSpreadsheet.getCellByPosition( intCellX, intCellY );
+ } catch ( com.sun.star.lang.IndexOutOfBoundsException exception ) {
+ System.out.println( "Could not get Cell" );
+ }
+ if ( stringFlag.equals( "V" )) {
+ xCell.setValue((new Float(stringValue)).floatValue());
+ }
+ else {
+ xCell.setFormula(stringValue);
+ }
+ }
+}
diff --git a/odk/examples/java/NotesAccess/Stocks.nsf b/odk/examples/java/NotesAccess/Stocks.nsf
new file mode 100644
index 000000000000..10ed138ed3b6
--- /dev/null
+++ b/odk/examples/java/NotesAccess/Stocks.nsf
Binary files differ
diff --git a/odk/examples/java/PropertySet/Makefile b/odk/examples/java/PropertySet/Makefile
new file mode 100644
index 000000000000..0a382d15042e
--- /dev/null
+++ b/odk/examples/java/PropertySet/Makefile
@@ -0,0 +1,134 @@
+#*************************************************************************
+#
+# 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 PropertySet component example of the SDK.
+
+PRJ=../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+COMP_NAME=PropTest
+COMP_CLASS_OUT=$(OUT_CLASS)/$(COMP_NAME)
+COMP_GEN_OUT=$(OUT_MISC)/$(COMP_NAME)
+COMP_PACKAGE=$(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT)
+COMP_PACKAGE_URL=$(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)")
+COMP_JAR_NAME=$(COMP_NAME).uno.jar
+COMP_JAR=$(COMP_CLASS_OUT)/$(COMP_JAR_NAME)
+COMP_JAR_MANIFEST=$(COMP_CLASS_OUT)/$(COMP_NAME).uno.Manifest
+COMP_UNOPKG_MANIFEST = $(COMP_GEN_OUT)/META-INF/manifest.xml
+COMP_REGISTERFLAG=$(COMP_GEN_OUT)$(PS)java_$(COMP_NAME)_register_component.flag
+
+COMP_JAVAFILES = PropTest.java
+
+COMP_CLASSFILES = $(patsubst %.java,$(COMP_CLASS_OUT)/%.class,$(COMP_JAVAFILES))
+
+$(COMP_NAME)_CLASSFILES = $(COMP_NAME).class
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(COMP_CLASS_OUT))
+
+
+# Targets
+.PHONY: ALL
+ALL : JavaPropertySetExample
+
+include $(SETTINGS)/stdtarget.mk
+
+$(COMP_CLASS_OUT)/%.Manifest :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo RegistrationClassName: $(basename $(basename $(@F)))> $@
+
+$(COMP_CLASSFILES) : $(COMP_JAVAFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(COMP_CLASS_OUT) $(COMP_JAVAFILES)
+
+# rule for component jar file
+$(COMP_JAR) : $(COMP_JAR_MANIFEST) $(COMP_CLASSFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ cd $(subst /,$(PS),$(COMP_CLASS_OUT)) && $(SDK_JAR) cvfm $(@F) $(<F) $($(basename $(basename $(@F)))_CLASSFILES)
+
+# rule for component package manifest
+$(COMP_GEN_OUT)/%/manifest.xml :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
+ @echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@
+ @echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-component;type=Java$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(OUT_MISC)/,,$(@D))).uno.jar$(QM)"/$(CSEP) >> $@
+ @echo $(OSEP)/manifest:manifest$(CSEP) >> $@
+
+# rule for component package file
+$(COMP_PACKAGE) : $(COMP_JAR) $(COMP_UNOPKG_MANIFEST)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ cd $(subst /,$(PS),$(COMP_CLASS_OUT)) && $(SDK_ZIP) ../../bin/$(@F) $(<F)
+ cd $(subst /,$(PS),$(COMP_GEN_OUT)) && $(SDK_ZIP) -u ../../bin/$(@F) META-INF/manifest.xml
+
+
+$(COMP_REGISTERFLAG) : $(COMP_PACKAGE)
+ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES"
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(DEPLOYTOOL) $(COMP_PACKAGE_URL)
+ @echo flagged > $(subst /,$(PS),$@)
+else
+ @echo --------------------------------------------------------------------------------
+ @echo If you want to install your component automatically, please set the environment
+ @echo variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only
+ @echo possible if no office instance is running.
+ @echo --------------------------------------------------------------------------------
+endif
+
+JavaPropertySetExample : $(COMP_REGISTERFLAG)
+ @echo --------------------------------------------------------------------------------
+ @echo The PropTest was installed if SDK_AUTO_DEPLOYMENT = YES.
+ @echo Load the "$(QM)PropertySet.odt$(QM)" document to see how this component works. You can
+ @echo use this component inside your office installation, see the example description.
+ @echo -
+ @echo $(MAKE) PropertySet.odt.load
+ @echo --------------------------------------------------------------------------------
+
+PropertySet.odt.load : $(COMP_REGISTERFLAG)
+ "$(OFFICE_PROGRAM_PATH)$(PS)soffice" $(basename $@)
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(COMP_CLASS_OUT))
+ -$(DELRECURSIVE) $(subst /,$(PS),$(COMP_GEN_OUT))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL)))
diff --git a/odk/examples/java/PropertySet/PropTest.java b/odk/examples/java/PropertySet/PropTest.java
new file mode 100644
index 000000000000..fded3c08c3ec
--- /dev/null
+++ b/odk/examples/java/PropertySet/PropTest.java
@@ -0,0 +1,265 @@
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+
+/*
+This example shows a UNO component that inherits com.sun.star.lib.uno.helper.PropertySet in
+order to provide implementations of these interfaces:
+
+ com.sun.star.beans.XPropertySet
+ com.sun.star.beans.XMultiPropertySet
+ com.sun.star.beans.XFastPropertySet
+ com.sun.star.lang.XComponent
+ com.sun.star.uno.XWeak
+ com.sun.star.lang.XTypeProvider
+*/
+import com.sun.star.lib.uno.helper.PropertySet;
+import com.sun.star.comp.loader.FactoryHelper;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+import com.sun.star.registry.XRegistryKey;
+import com.sun.star.uno.Any;
+import com.sun.star.uno.Type;
+import com.sun.star.uno.XInterface;
+import com.sun.star.lang.XTypeProvider;
+import com.sun.star.beans.PropertyAttribute;
+
+/**
+ This component contains the followin properties:
+ * <table border>
+ * <tr>
+ * <th> Property Name </th>
+ * <th> Type Name </th>
+ * <th> PropertyAttribute </th>
+ * <tr><td>boolA</td><td>BOOLEAN</td><td> - </td</tr>
+ * <tr><td>charA</td><td>CHAR</td><td> - </td></tr>
+ * <tr><td>byteA</td><td>BYTE</td><td> - </td></tr>
+ * <tr><td>shortA</td><td>SHORT</td><td> - </td></tr>
+ * <tr><td>intA</td><td>LONG</td><td> - </td></tr>
+ * <tr><td>longA</td><td>HYPER</td><td> - </td></tr>
+ * <tr><td>floatA</td><td>FLOAT</td><td> - </td></tr>
+ * <tr><td>doubleA</td><td>DOUBLE</td><td> - </td></tr>
+ * <tr><td>stringA</td><td>STRING</td><td> - </td></tr>
+ * <tr><td>objectA</td><td>ANY</td><td> - </td></tr>
+ * <tr><td>anyA</td><td>ANY</td><td> - </td></tr>
+ * <tr><td>typeA</td><td>TYPE</td><td> - </td></tr>
+ * <tr><td>xinterfaceA</td><td>INTERFACE</td><td> - </td></tr>
+ * <tr><td>xtypeproviderA</td><td>INTERFACE</td><td> - </td></tr>
+ * <tr><td>arBoolA</td><td>[]boolean</td><td> - </td></tr>
+ * <tr><td>arCharA</td><td>[]char</td><td> - </td></tr>
+ * <tr><td>arByteA</td><td>[]byte</td><td> - </td></tr>
+ * <tr><td>arShortA</td><td>[]short</td><td> - </td></tr>
+ * <tr><td>arIntA</td><td>[]long</td><td> - </td></tr>
+ * <tr><td>arLongA</td><td>[]hyper</td><td> - </td></tr>
+ * <tr><td>arFloatA</td><td>[]float</td><td> - </td></tr>
+ * <tr><td>arDoubleA</td><td>[]double</td><td> - </td></tr>
+ * <tr><td>arStringA</td><td>[]string</td><td> - </td></tr>
+ * <tr><td>arObjectA</td><td>[]any</td><td> - </td></tr>
+ * <tr><td>arXinterfaceA</td><td>[]com.sun.star.uno.XInterface</td><td> - </td></tr>
+ * <tr><td>ar2BoolA</td><td>[][]boolean</td><td> - </td></tr>
+ * <tr><td>boolClassA</td><td>boolean</td><td> - </td></tr>
+ * <tr><td>charClassA</td><td>char</td><td> - </td></tr>
+ * <tr><td>byteClassA</td><td>byte</td><td> - </td></tr>
+ * <tr><td>shortClassA</td><td>short</td><td> - </td></tr>
+ * <tr><td>intClassA</td><td>long</td><td> - </td></tr>
+ * <tr><td>longClassA</td><td>hyper</td><td> - </td></tr>
+ * <tr><td>floatClassA</td><td>float</td><td> - </td></tr>
+ * <tr><td>doubleClassA</td><td>double</td><td> - </td></tr>
+ * <tr><td>roIntA</td><td>long</td><td>READONLY</td></tr>
+ * <tr><td>roIntClassA</td><td>long</td><td>READONLY</td></tr>
+ * <tr><td>roObjectA</td><td>any</td><td>READONLY</td></tr>
+ * <tr><td>roAnyA</td><td>any</td><td>READONLY</td></tr>
+ * <tr><td>bcBoolA</td><td>boolean</td><td>BOUND,CONSTRAINED</td></tr>
+ * <tr><td>bcBoolClassA</td><td>boolean</td><td>BOUND,CONSTRAINED</td></tr>
+ * <tr><td>bcObjectA</td><td>any</td><td>BOUND,CONSTRAINED</td></tr>
+ * <tr><td>bcAnyA</td><td>any</td><td>BOUND,CONSTRAINED</td></tr>
+ * <tr><td>mvIntA</td><td>long</td><td>MAYBEVOID</td></tr>
+ * <tr><td>mvObjectA</td><td>any</td><td>MAYBEVOID</td></tr>
+ * <tr><td>mvAnyA</td><td>any</td><td>MAYBEVOID</td></tr>
+ * <tr><td>mvXinterfaceA</td><td>any</td><td>MAYBEVOID</td></tr>
+ </table>
+*/
+
+public class PropTest extends PropertySet implements XServiceInfo
+{
+
+ public boolean boolA;
+ public char charA;
+ public byte byteA;
+ public short shortA;
+ public int intA;
+ public long longA;
+ public float floatA;
+ public double doubleA;
+ public String stringA; // MAYBEVOID
+ public Object objectA; // MAYBEVOID
+ public Any anyA; // MAYBEVOID
+ public Type typeA;// MAYBEVOID
+ public XInterface xinterfaceA;// MAYBEVOID
+ public XTypeProvider xtypeproviderA;// MAYBEVOID
+ public boolean[] arBoolA; // MAYBEVOID
+ public char[] arCharA; // MAYBEVOID
+ public byte[] arByteA; // MAYBEVOID
+ public short[] arShortA; // MAYBEVOID
+ public int[] arIntA; // MAYBEVOID
+ public long[] arLongA; // MAYBEVOID
+ public float[] arFloatA; // MAYBEVOID
+ public double[] arDoubleA; // MAYBEVOID
+ public String[] arStringA; // MAYBEVOID
+ public Object[] arObjectA; // MAYBEVOID
+ public Any[] arAnyA; // MAYBEVOID
+ public XInterface[] arXinterfaceA; // MAYBEVOID
+ public boolean[][] ar2BoolA; // MAYBEVOID
+ public Boolean boolClassA; // MAYBEVOID
+ public Character charClassA; // MAYBEVOID
+ public Byte byteClassA; // MAYBEVOID
+ public Short shortClassA; // MAYBEVOID
+ public Integer intClassA; // MAYBEVOID
+ public Long longClassA; // MAYBEVOID
+ public Float floatClassA; // MAYBEVOID
+ public Double doubleClassA; // MAYBEVOID
+
+ // readonly
+ public int roIntA= 100;
+ public Integer roIntClassA= new Integer(100);
+ public Object roObjectA= new Integer(101);
+ public Any roAnyA= new Any( new Type(int.class), new Integer(102));
+
+ // BOUND & CONSTRAINED
+ public boolean bcBoolA;
+ public Boolean bcBoolClassA; // MAYBEVOID
+ public Object bcObjectA; // MAYBEVOID
+ public Any bcAnyA; // MAYBEVOID
+
+ // MAYBEVOID
+ public Integer mvIntA;
+ public Object mvObjectA;
+ public Any mvAnyA;
+ public XInterface mvXinterfaceA;
+
+ public static final String __serviceName="PropTest";
+
+ public PropTest() {
+ registerProperty("boolA", (short) 0);
+ registerProperty("charA", (short) 0);
+ registerProperty("byteA", (short) 0);
+ registerProperty("shortA", (short) 0);
+ registerProperty("intA", (short) 0);
+ registerProperty("longA", (short) 0);
+ registerProperty("floatA", (short) 0);
+ registerProperty("doubleA", (short) 0);
+ registerProperty("stringA", PropertyAttribute.MAYBEVOID);
+ registerProperty("objectA", PropertyAttribute.MAYBEVOID);
+ registerProperty("anyA", PropertyAttribute.MAYBEVOID);
+ registerProperty("typeA", PropertyAttribute.MAYBEVOID);
+ registerProperty("xinterfaceA", PropertyAttribute.MAYBEVOID);
+ registerProperty("xtypeproviderA", PropertyAttribute.MAYBEVOID);
+ registerProperty("arBoolA", PropertyAttribute.MAYBEVOID);
+ registerProperty("arCharA", PropertyAttribute.MAYBEVOID);
+ registerProperty("arByteA", PropertyAttribute.MAYBEVOID);
+ registerProperty("arShortA", PropertyAttribute.MAYBEVOID);
+ registerProperty("arIntA", PropertyAttribute.MAYBEVOID);
+ registerProperty("arLongA", PropertyAttribute.MAYBEVOID);
+ registerProperty("arFloatA", PropertyAttribute.MAYBEVOID);
+ registerProperty("arDoubleA", PropertyAttribute.MAYBEVOID);
+ registerProperty("arStringA", PropertyAttribute.MAYBEVOID);
+ registerProperty("arObjectA", PropertyAttribute.MAYBEVOID);
+ registerProperty("arAnyA", PropertyAttribute.MAYBEVOID);
+ registerProperty("arXinterfaceA", PropertyAttribute.MAYBEVOID);
+ registerProperty("ar2BoolA", PropertyAttribute.MAYBEVOID);
+ registerProperty("boolClassA", PropertyAttribute.MAYBEVOID);
+ registerProperty("charClassA", PropertyAttribute.MAYBEVOID);
+ registerProperty("byteClassA", PropertyAttribute.MAYBEVOID);
+ registerProperty("shortClassA", PropertyAttribute.MAYBEVOID);
+ registerProperty("intClassA", PropertyAttribute.MAYBEVOID);
+ registerProperty("longClassA", PropertyAttribute.MAYBEVOID);
+ registerProperty("floatClassA", PropertyAttribute.MAYBEVOID);
+ registerProperty("doubleClassA", PropertyAttribute.MAYBEVOID);
+ registerProperty("roIntA", PropertyAttribute.READONLY);
+ registerProperty("roIntClassA", PropertyAttribute.READONLY);
+ registerProperty("roObjectA", PropertyAttribute.READONLY);
+ registerProperty("roAnyA", PropertyAttribute.READONLY);
+ registerProperty("bcBoolA",(short) ( PropertyAttribute.BOUND | PropertyAttribute.CONSTRAINED));
+ registerProperty("bcBoolClassA", (short) (PropertyAttribute.BOUND | PropertyAttribute.CONSTRAINED | PropertyAttribute.MAYBEVOID));
+ registerProperty("bcObjectA", (short) (PropertyAttribute.BOUND | PropertyAttribute.CONSTRAINED | PropertyAttribute.MAYBEVOID));
+ registerProperty("bcAnyA", (short) (PropertyAttribute.BOUND | PropertyAttribute.CONSTRAINED |PropertyAttribute.MAYBEVOID));
+ registerProperty("mvIntA", PropertyAttribute.MAYBEVOID);
+ registerProperty("mvObjectA", PropertyAttribute.MAYBEVOID);
+ registerProperty("mvAnyA", PropertyAttribute.MAYBEVOID);
+ registerProperty("mvXinterfaceA", PropertyAttribute.MAYBEVOID);
+ }
+
+
+ // XServiceName
+ public String getImplementationName( )
+ {
+ return getClass().getName();
+ }
+
+ // XServiceName
+ public boolean supportsService( /*IN*/String name )
+ {
+ if (name.equals(__serviceName))
+ return true;
+ return false;
+ }
+
+ //XServiceName
+ public String[] getSupportedServiceNames( )
+ {
+ String[] retValue= new String[]{__serviceName};
+ return retValue;
+ }
+
+ public static XSingleServiceFactory __getServiceFactory(String implName,
+ XMultiServiceFactory multiFactory,
+ XRegistryKey regKey)
+ {
+ XSingleServiceFactory xSingleServiceFactory = null;
+
+ if (implName.equals( PropTest.class.getName()) )
+ xSingleServiceFactory = FactoryHelper.getServiceFactory( PropTest.class,
+ PropTest.__serviceName,
+ multiFactory,
+ regKey);
+
+ return xSingleServiceFactory;
+ }
+
+ public static boolean __writeRegistryServiceInfo(XRegistryKey regKey)
+ {
+ return FactoryHelper.writeRegistryServiceInfo( PropTest.class.getName(),
+ PropTest.__serviceName, regKey);
+ }
+}
diff --git a/odk/examples/java/PropertySet/PropertySet.odt b/odk/examples/java/PropertySet/PropertySet.odt
new file mode 100644
index 000000000000..31d326e4106f
--- /dev/null
+++ b/odk/examples/java/PropertySet/PropertySet.odt
Binary files differ
diff --git a/odk/examples/java/Spreadsheet/CalcAddins.java b/odk/examples/java/Spreadsheet/CalcAddins.java
new file mode 100644
index 000000000000..0f0fddad97d3
--- /dev/null
+++ b/odk/examples/java/Spreadsheet/CalcAddins.java
@@ -0,0 +1,304 @@
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+
+// Template for an Office Calc add-in Java implementation file.
+
+/** You can find more
+ * information on the following web page:
+ * http://api.openoffice.org/common/ref/com/sun/star/index.html
+ */
+import com.sun.star.comp.loader.FactoryHelper;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+import com.sun.star.registry.XRegistryKey;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.lib.uno.helper.WeakBase;
+import com.sun.star.lang.XInitialization;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.lang.XServiceName;
+import com.sun.star.sheet.XAddIn;
+import com.sun.star.lang.Locale;
+import com.sun.star.lang.XTypeProvider;
+import com.sun.star.uno.Type;
+
+import org.openoffice.sheet.addin.XCalcAddins;
+
+/** This outer class provides an inner class to implement the service
+ * description, a method to instantiate the
+ * component on demand (__getServiceFactory()), and a method to give
+ * information about the component (__writeRegistryServiceInfo()).
+ */
+public class CalcAddins {
+
+/** This inner class provides the component as a concrete implementation
+ * of the service description. It implements the needed interfaces.
+ * @implements XCalcAddins, XAddIn, XServiceName, XServiceInfo, XTypeProvider
+ */
+ static public class _CalcAddins extends WeakBase implements
+ XCalcAddins,
+ XAddIn,
+ XServiceName,
+ XServiceInfo
+ {
+
+/** The component will be registered under this name.
+ */
+ static private final String __serviceName = "org.openoffice.sheet.addin.CalcAddins";
+
+ static private final String ADDIN_SERVICE = "com.sun.star.sheet.AddIn";
+
+ private Locale aFuncLoc;
+
+ private static final String[] stringFunctionName = {
+/** TO DO:
+ * You should replace these method names by the method names of your interface.
+ */
+ "getMyFirstValue",
+ "getMySecondValue"
+ };
+
+ private static final short shortINVALID = -1;
+
+/** TO DO:
+ * For each of your methods you should make up a new constant with a different value.
+ */
+ private static final short shortGETMYFIRSTVALUE = 0;
+ private static final short shortGETMYSECONDVALUE = 1;
+
+
+/** TO DO:
+ * This is where you implement all methods of your interface. The parameters have to
+ * be the same as in your IDL file and their types have to be the correct
+ * IDL-to-Java mappings of their types in the IDL file.
+ */
+ public int getMyFirstValue(
+ com.sun.star.beans.XPropertySet xOptions
+ ) {
+ return (int) 1;
+ }
+
+ public int getMySecondValue(
+ com.sun.star.beans.XPropertySet xOptions,
+ int intDummy
+ ) {
+ return( (int) ( 2 + intDummy ) );
+ }
+
+
+ // Implement method from interface XServiceName
+ public String getServiceName() {
+ return( __serviceName );
+ }
+
+ // Implement methods from interface XServiceInfo
+ public boolean supportsService(String stringServiceName) {
+ return( stringServiceName.equals( ADDIN_SERVICE ) ||
+ stringServiceName.equals( __serviceName ) );
+ }
+
+ public String getImplementationName() {
+ return( _CalcAddins.class.getName() );
+ }
+
+ public String[] getSupportedServiceNames() {
+ String[] stringSupportedServiceNames = { ADDIN_SERVICE, __serviceName };
+ return( stringSupportedServiceNames );
+ }
+
+ // Implement methods from interface XAddIn
+ public String getDisplayArgumentName(String stringProgrammaticFunctionName,int intArgument) {
+ String stringReturn = "";
+
+ switch( this.getFunctionID( stringProgrammaticFunctionName ) ) {
+/** TO DO:
+ * You should list all argument names for each of your methods, here.
+ */
+ case shortGETMYFIRSTVALUE:
+ switch( intArgument ) {
+ case 0:
+ stringReturn = "(internal)";
+ break;
+ }
+ break;
+ case shortGETMYSECONDVALUE:
+ switch( intArgument ) {
+ case 0:
+ stringReturn = "(internal)";
+ break;
+ case 1:
+ stringReturn = "intDummy";
+ break;
+ }
+ break;
+ }
+ return( stringReturn );
+ }
+
+ public String getDisplayFunctionName(String stringProgrammaticName) {
+ String stringReturn = "";
+
+ switch( this.getFunctionID( stringProgrammaticName ) ) {
+/** TO DO:
+ * Assign the name of each of your methods.
+ */
+ case shortGETMYFIRSTVALUE:
+ stringReturn = "getMyFirstValue";
+ break;
+ case shortGETMYSECONDVALUE:
+ stringReturn = "getMySecondValue";
+ break;
+ }
+
+ return( stringReturn );
+ }
+
+ public String getProgrammaticCategoryName(String p1) {
+ return( "Add-In" );
+ }
+
+ public String getDisplayCategoryName(String p1) {
+ return( "Add-In" );
+ }
+
+ public String getFunctionDescription(String stringProgrammaticName) {
+ String stringReturn = "";
+
+ switch( this.getFunctionID( stringProgrammaticName ) ) {
+/** TO DO:
+ * Enter a description for each of your methods that office users will understand.
+ */
+ case shortGETMYFIRSTVALUE:
+ stringReturn = "This is your first method.";
+ break;
+ case shortGETMYSECONDVALUE:
+ stringReturn = "This is your second method.";
+ break;
+ }
+
+ return( stringReturn );
+ }
+
+ public String getArgumentDescription(String stringProgrammaticFunctionName,int intArgument) {
+ String stringReturn = "";
+
+ switch( this.getFunctionID( stringProgrammaticFunctionName ) ) {
+/** TO DO:
+ * Enter a description for every argument of every method. Make them so that office users will understand.
+ */
+ case shortGETMYFIRSTVALUE:
+ switch( intArgument ) {
+ case 0:
+ stringReturn = "(internal)";
+ break;
+ }
+ break;
+ case shortGETMYSECONDVALUE:
+ switch( intArgument ) {
+ case 0:
+ stringReturn = "(internal)";
+ break;
+ case 1:
+ stringReturn = "You can add this value.";
+ break;
+ }
+ break;
+ }
+ return( stringReturn );
+ }
+
+ public String getProgrammaticFuntionName(String p1) {
+ return( "" );
+ }
+
+ // Implement methods from interface XLocalizable
+ public Locale getLocale() {
+ return( aFuncLoc );
+ }
+
+ public void setLocale(Locale p1) {
+ aFuncLoc = p1;
+ }
+
+ // Auxiliary functions
+ private short getFunctionID( String stringProgrammaticName ) {
+ for ( int i = 0; i < stringFunctionName.length; i++ ) {
+ if ( stringProgrammaticName.equals( stringFunctionName[ i ] ) ) {
+ return( ( short ) i );
+ }
+ }
+
+ return( -1 );
+ }
+ }
+
+ /**
+ * Returns a factory for creating the service.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return returns a <code>XSingleServiceFactory</code> for creating the component
+ * @param implName the name of the implementation for which a service is desired
+ * @param multiFactory the service manager to be used if needed
+ * @param regKey the registryKey
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static XSingleServiceFactory __getServiceFactory(String implName,
+ XMultiServiceFactory multiFactory,
+ XRegistryKey regKey) {
+ XSingleServiceFactory xSingleServiceFactory = null;
+
+ if (implName.equals(_CalcAddins.class.getName()) )
+ xSingleServiceFactory = FactoryHelper.getServiceFactory(_CalcAddins.class,
+ _CalcAddins.__serviceName,
+ multiFactory,
+ regKey);
+
+ return xSingleServiceFactory;
+ }
+
+ /**
+ * Writes the service information into the given registry key.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return returns true if the operation succeeded
+ * @param regKey the registryKey
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
+ return FactoryHelper.writeRegistryServiceInfo(_CalcAddins.class.getName(),
+ _CalcAddins.__serviceName, regKey)
+ && FactoryHelper.writeRegistryServiceInfo(_CalcAddins.class.getName(),
+ _CalcAddins.ADDIN_SERVICE, regKey);
+ }
+}
diff --git a/odk/examples/java/Spreadsheet/CalcAddins.ods b/odk/examples/java/Spreadsheet/CalcAddins.ods
new file mode 100644
index 000000000000..133539d5a554
--- /dev/null
+++ b/odk/examples/java/Spreadsheet/CalcAddins.ods
Binary files differ
diff --git a/odk/examples/java/Spreadsheet/ChartTypeChange.java b/odk/examples/java/Spreadsheet/ChartTypeChange.java
new file mode 100644
index 000000000000..ab4e44bfdc4c
--- /dev/null
+++ b/odk/examples/java/Spreadsheet/ChartTypeChange.java
@@ -0,0 +1,355 @@
+/*************************************************************************
+ *
+ * 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.awt.Rectangle;
+
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.beans.XPropertySet;
+
+import com.sun.star.chart.XDiagram;
+import com.sun.star.chart.XChartDocument;
+
+import com.sun.star.container.XNameAccess;
+import com.sun.star.container.XIndexAccess;
+
+import com.sun.star.document.XEmbeddedObjectSupplier;
+
+import com.sun.star.frame.XComponentLoader;
+
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XMultiComponentFactory;
+
+import com.sun.star.sheet.XSpreadsheets;
+import com.sun.star.sheet.XSpreadsheet;
+import com.sun.star.sheet.XSpreadsheetDocument;
+import com.sun.star.sheet.XCellRangeAddressable;
+
+import com.sun.star.table.XTableChart;
+import com.sun.star.table.XTableCharts;
+import com.sun.star.table.XCell;
+import com.sun.star.table.XCellRange;
+import com.sun.star.table.XTableChartsSupplier;
+import com.sun.star.table.CellRangeAddress;
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XInterface;
+import com.sun.star.uno.XComponentContext;
+
+
+
+/** This class loads an OpenOffice.org Calc document and changes the type of the
+ * embedded chart.
+ * @author Bertram Nolte
+ */
+public class ChartTypeChange {
+
+ /** Table chart, which type will be changed.
+ */
+ private XTableChart xtablechart = null;
+
+ /** Service factory
+ */
+ private XMultiComponentFactory xMCF = null;
+
+ /** Component context
+ */
+ private XComponentContext xCompContext = null;
+
+ /** Beginning of the program.
+ * @param args No arguments will be passed to the class.
+ */
+ public static void main(String args[]) {
+ try {
+ ChartTypeChange charttypechange = new ChartTypeChange();
+
+ // Double array holding all values the chart should be based on.
+ String[][] stringValues = {
+ { "", "Jan", "Feb", "Mar", "Apr", "Mai" },
+ { "Profit", "12.3", "43.2", "5.1", "76", "56.8" },
+ { "Rival in business", "12.2", "12.6", "17.7", "20.4", "100" },
+ };
+
+ // Create the chart with
+ charttypechange.getChart( stringValues );
+
+ String[] stringChartType = {
+ "com.sun.star.chart.LineDiagram",
+ "com.sun.star.chart.BarDiagram",
+ "com.sun.star.chart.PieDiagram",
+ "com.sun.star.chart.NetDiagram",
+ "com.sun.star.chart.XYDiagram",
+ "com.sun.star.chart.StockDiagram",
+ "com.sun.star.chart.AreaDiagram"
+ };
+
+ for ( int intCounter = 0; intCounter < stringChartType.length;
+ intCounter++ ) {
+ charttypechange.changeChartType( stringChartType[ intCounter ],
+ false );
+ Thread.sleep( 3000 );
+ }
+
+ System.exit(0);
+ }
+ catch( Exception exception ) {
+ System.err.println( exception );
+ }
+ }
+
+ /** The constructor connects to the OpenOffice.org.
+ * @param args Parameters for this constructor (connection string).
+ * @throws Exception All exceptions are thrown from this method.
+ */
+ public ChartTypeChange()
+ throws Exception {
+
+ /* Bootstraps a component context. Component context to be granted
+ to a component for running. Arbitrary values can be retrieved
+ from the context. */
+ xCompContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+
+ /* Gets the service manager instance to be used (or null). This method has
+ been added for convenience, because the service manager is a often used
+ object. */
+ xMCF = xCompContext.getServiceManager();
+ }
+
+ /** This method will change the type of a specified chart.
+ * @param stringType The chart will be converted to this type.
+ * @param booleanIs3D If the chart should be displayed in 3D this parameter should be set to true.
+ * @throws Exception All exceptions are thrown from this method.
+ */
+ public void changeChartType( String stringType, boolean booleanIs3D )
+ throws Exception {
+ XEmbeddedObjectSupplier xEmbeddedObjSupplier = (XEmbeddedObjectSupplier)
+ UnoRuntime.queryInterface(XEmbeddedObjectSupplier.class, xtablechart);
+ XInterface xInterface = xEmbeddedObjSupplier.getEmbeddedObject();
+
+ XChartDocument xChartDoc = (XChartDocument)UnoRuntime.queryInterface(
+ XChartDocument.class, xInterface);
+ XDiagram xDiagram = (XDiagram) xChartDoc.getDiagram();
+ XMultiServiceFactory xMSF = (XMultiServiceFactory)
+ UnoRuntime.queryInterface( XMultiServiceFactory.class, xChartDoc );
+ Object object = xMSF.createInstance( stringType );
+ xDiagram = (XDiagram) UnoRuntime.queryInterface(XDiagram.class, object);
+
+ XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
+ XPropertySet.class, xDiagram );
+ xPropSet.setPropertyValue( "Dim3D", new Boolean( booleanIs3D ) );
+
+ xChartDoc.setDiagram(xDiagram);
+ }
+
+ /** Loading an OpenOffice.org Calc document and getting a chart by name.
+ * @param stringFileName Name of the OpenOffice.org Calc document which should
+ * be loaded.
+ * @param stringChartName Name of the chart which should get a new chart type.
+ */
+ public void getChart( String stringFileName, String stringChartName ) {
+ try {
+ /* A desktop environment contains tasks with one or more
+ frames in which components can be loaded. Desktop is the
+ environment for components which can instanciate within
+ frames. */
+ XComponentLoader xComponentloader = (XComponentLoader)
+ UnoRuntime.queryInterface( XComponentLoader.class,
+ xMCF.createInstanceWithContext("com.sun.star.frame.Desktop",
+ xCompContext ) );
+
+ // Load a Writer document, which will be automaticly displayed
+ XComponent xComponent = xComponentloader.loadComponentFromURL(
+ "file:///" + stringFileName, "_blank", 0,
+ new PropertyValue[0] );
+
+ // Query for the interface XSpreadsheetDocument
+ XSpreadsheetDocument xSpreadSheetDocument = ( XSpreadsheetDocument )
+ UnoRuntime.queryInterface( XSpreadsheetDocument.class, xComponent );
+
+ XSpreadsheets xSpreadsheets = xSpreadSheetDocument.getSheets() ;
+
+ XIndexAccess xIndexAccess = (XIndexAccess)
+ UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets );
+
+ XSpreadsheet xSpreadsheet = (XSpreadsheet) UnoRuntime.queryInterface(
+ XSpreadsheet.class, xIndexAccess.getByIndex(0));
+
+ XTableChartsSupplier xTableChartsSupplier = ( XTableChartsSupplier )
+ UnoRuntime.queryInterface( XTableChartsSupplier.class, xSpreadsheet );
+
+ xIndexAccess = (XIndexAccess) UnoRuntime.queryInterface(
+ XIndexAccess.class, xTableChartsSupplier.getCharts() );
+
+ this.xtablechart = (XTableChart) UnoRuntime.queryInterface(
+ XTableChart.class, xIndexAccess.getByIndex( 0 ) );
+ }
+ catch( Exception exception ) {
+ System.err.println( exception );
+ }
+ }
+
+ /** Creating an empty OpenOffice.org Calc document, inserting data, and getting a
+ * chart by name.
+ * @param stringValues Double array with the values for the chart.
+ */
+ public void getChart( String[][] stringValues ) {
+ try {
+ /* A desktop environment contains tasks with one or more
+ frames in which components can be loaded. Desktop is the
+ environment for components which can instanciate within
+ frames. */
+ XComponentLoader xcomponentloader = ( XComponentLoader )
+ UnoRuntime.queryInterface( XComponentLoader.class,
+ xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop",
+ xCompContext ) );
+
+ // Create an empty calc document, which will be automaticly displayed
+ XComponent xComponent = xcomponentloader.loadComponentFromURL(
+ "private:factory/scalc", "_blank", 0,
+ new PropertyValue[0] );
+
+ // Query for the interface XSpreadsheetDocument
+ XSpreadsheetDocument xspreadsheetdocument = ( XSpreadsheetDocument )
+ UnoRuntime.queryInterface( XSpreadsheetDocument.class, xComponent );
+
+ // Get all sheets of the spreadsheet document.
+ XSpreadsheets xspreadsheets = xspreadsheetdocument.getSheets() ;
+
+ // Get the index of the spreadsheet document.
+ XIndexAccess xindexaccess = (XIndexAccess) UnoRuntime.queryInterface(
+ XIndexAccess.class, xspreadsheets );
+
+ // Get the first spreadsheet.
+ XSpreadsheet xspreadsheet = (XSpreadsheet) UnoRuntime.queryInterface(
+ XSpreadsheet.class, xindexaccess.getByIndex(0));
+
+ // The double array will written to the spreadsheet
+ for ( int intY = 0; intY < stringValues.length; intY++ ) {
+ for ( int intX = 0; intX < stringValues[ intY ].length;
+ intX++ ) {
+ // Insert the value to the cell, specified by intY and intX.
+ this.insertIntoCell( intY, intX,
+ stringValues[ intY ][ intX ], xspreadsheet, "" );
+ }
+ }
+
+ // Create a rectangle, which holds the size of the chart.
+ Rectangle rectangle = new Rectangle();
+ rectangle.X = 500;
+ rectangle.Y = 3000;
+ rectangle.Width = 25000;
+ rectangle.Height = 11000;
+
+ // Get the cell range of the spreadsheet.
+ XCellRange xcellrange = ( XCellRange ) UnoRuntime.queryInterface(
+ XCellRange.class, xspreadsheet );
+
+ // Create the Unicode of the character for the column name.
+ char charRectangle = ( char ) ( 65 + stringValues.length - 1 );
+
+ // Get maximum length all rows in the double array.
+ int intMaximumWidthRow = 0;
+ for ( int intRow = 0; intRow < stringValues.length; intRow++ ) {
+ if ( stringValues[ intRow ].length > intMaximumWidthRow ) {
+ intMaximumWidthRow = stringValues[ intRow ].length;
+ }
+ }
+
+ // Get the cell range of the written values.
+ XCellRange xcellrangeChart = xcellrange.getCellRangeByName( "A1:" +
+ charRectangle + intMaximumWidthRow );
+
+ // Get the addressable cell range.
+ XCellRangeAddressable xcellrangeaddressable =
+ ( XCellRangeAddressable ) UnoRuntime.queryInterface(
+ XCellRangeAddressable.class, xcellrangeChart );
+
+ // Get the cell range address.
+ CellRangeAddress cellrangeaddress = xcellrangeaddressable.getRangeAddress();
+
+ // Create the cell range address for the chart.
+ CellRangeAddress[] cellrangeaddressChart =
+ new CellRangeAddress[ 1 ];
+ cellrangeaddressChart[ 0 ] = cellrangeaddress;
+
+ // Get the table charts supplier of the spreadsheet.
+ XTableChartsSupplier xtablechartssupplier = ( XTableChartsSupplier )
+ UnoRuntime.queryInterface( XTableChartsSupplier.class, xspreadsheet );
+
+ // Get all table charts of the spreadsheet.
+ XTableCharts xtablecharts = xtablechartssupplier.getCharts();
+
+ // Create a table chart with all written values.
+ xtablecharts.addNewByName( "Example", rectangle,
+ cellrangeaddressChart, true, true );
+
+ // Get the created table chart.
+ this.xtablechart = ( XTableChart ) UnoRuntime.queryInterface(
+ XTableChart.class, (( XNameAccess ) UnoRuntime.queryInterface(
+ XNameAccess.class, xtablecharts ) ).getByName( "Example" ));
+ }
+ catch( Exception exception ) {
+ System.err.println( exception );
+ }
+ }
+
+ /** Inserting a given value to a cell, that is specified by the parameters intX
+ * and intY.
+ * @param intX Column on the spreadsheet.
+ * @param intY Row on the spreadsheet.
+ * @param stringValue Value to be inserted to a cell.
+ * @param xspreadsheet Spreadsheet of the cell, which will be changed.
+ * @param stringFlag If the value of stringFlag is "V", the stringValue
+ * will be converted to the
+ * float type. Otherwise the stringValue will be written as a formula.
+ */
+ public static void insertIntoCell( int intX, int intY, String stringValue,
+ XSpreadsheet xspreadsheet, String stringFlag )
+ {
+ XCell xcell = null;
+
+ try {
+ xcell = xspreadsheet.getCellByPosition( intX, intY );
+ }
+ catch ( com.sun.star.lang.IndexOutOfBoundsException exception ) {
+ System.out.println( "Could not get cell." );
+ }
+ if ( stringFlag.equals( "V" ) ) {
+ xcell.setValue( ( new Float( stringValue ) ).floatValue() );
+ }
+ else {
+ xcell.setFormula( stringValue );
+ }
+ }
+}
diff --git a/odk/examples/java/Spreadsheet/EuroAdaption.java b/odk/examples/java/Spreadsheet/EuroAdaption.java
new file mode 100644
index 000000000000..43c2b47d138c
--- /dev/null
+++ b/odk/examples/java/Spreadsheet/EuroAdaption.java
@@ -0,0 +1,389 @@
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+
+//***************************************************************************
+// comment: Step 1: get the Desktop object from the office
+// Step 2: open an empty Calc document
+// Step 3: enter a example text, set the numberformat to DM
+// Step 4: change the numberformat to EUR (Euro)
+// Step 5: use the DM/EUR factor on each cell with a content
+//***************************************************************************
+
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.beans.XPropertySet;
+
+import com.sun.star.container.XEnumeration;
+import com.sun.star.container.XIndexAccess;
+import com.sun.star.container.XEnumerationAccess;
+
+import com.sun.star.document.XActionLockable;
+
+import com.sun.star.frame.XDesktop;
+import com.sun.star.frame.XComponentLoader;
+
+import com.sun.star.lang.Locale;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiComponentFactory;
+
+import com.sun.star.table.XCell;
+import com.sun.star.table.XCellRange;
+
+import com.sun.star.sheet.XSpreadsheet;
+import com.sun.star.sheet.XSpreadsheets;
+import com.sun.star.sheet.XSheetCellRanges;
+import com.sun.star.sheet.XCellRangesQuery;
+import com.sun.star.sheet.XCellFormatRangesSupplier;
+import com.sun.star.sheet.XCellRangesQuery;
+import com.sun.star.sheet.XSpreadsheetDocument;
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.uno.XInterface;
+import com.sun.star.uno.XComponentContext;
+
+import com.sun.star.util.NumberFormat;
+import com.sun.star.util.XNumberFormats;
+import com.sun.star.util.XNumberFormatsSupplier;
+
+
+public class EuroAdaption {
+
+ public static void main(String args[]) {
+ // You need the desktop to create a document
+ // The getDesktop method does the UNO bootstrapping, gets the
+ // remote servie manager and the desktop object.
+ com.sun.star.frame.XDesktop xDesktop = null;
+ xDesktop = getDesktop();
+
+ // create a sheet document
+ XSpreadsheetDocument xSheetdocument = null;
+ xSheetdocument = ( XSpreadsheetDocument ) createSheetdocument( xDesktop );
+ System.out.println( "Create a new Spreadsheet" );
+
+ // get the collection of all sheets from the document
+ XSpreadsheets xSheets = null;
+ xSheets = (XSpreadsheets) xSheetdocument.getSheets();
+
+ // the Action Interface provides methods to hide actions,
+ // like inserting data, on a sheet, that increase the performance
+ XActionLockable xActionInterface = null;
+ xActionInterface = (XActionLockable) UnoRuntime.queryInterface(
+ XActionLockable.class, xSheetdocument );
+
+ // lock all actions
+ xActionInterface.addActionLock();
+
+ com.sun.star.sheet.XSpreadsheet xSheet = null;
+ try {
+ // get via the index access the first sheet
+ XIndexAccess xElements = (XIndexAccess) UnoRuntime.queryInterface(
+ XIndexAccess.class, xSheets );
+
+ // specify the first sheet from the spreadsheet
+ xSheet = (XSpreadsheet) UnoRuntime.queryInterface(
+ XSpreadsheet.class, xElements.getByIndex( 0 ));
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ // get the interface to apply and create new numberformats
+ XNumberFormatsSupplier xNumberFormatSupplier = null;
+ xNumberFormatSupplier = (XNumberFormatsSupplier) UnoRuntime.queryInterface(
+ XNumberFormatsSupplier.class, xSheetdocument );
+ XNumberFormats xNumberFormats = null;
+ xNumberFormats = xNumberFormatSupplier.getNumberFormats();
+
+ // insert some example data in a sheet
+ createExampleData( xSheet, xNumberFormats );
+ System.out.println( "Insert example data and use the number format with the currency 'DM'" );
+
+ // Change the currency from the cells from DM to Euro
+ Convert( xSheet, xNumberFormats, "DM", "EUR", 1.95583f );
+ System.out.println( "Change the number format to EUR and divide the values with the factor 1.95583" );
+
+ // remove all locks, the user see all changes
+ xActionInterface.removeActionLock();
+
+ System.out.println("done");
+ System.exit(0);
+ }
+
+
+ public static void Convert( XSpreadsheet xSheet, XNumberFormats xNumberFormats,
+ String sOldSymbol, String sNewSymbol,
+ float fFactor ) {
+ try {
+ Locale xLanguage = new Locale();
+ xLanguage.Country = "de"; // Germany -> DM
+ xLanguage.Language = "de"; // German
+
+ // Numberformat string with sNewSymbol
+ String sSimple = "0 [$" + sNewSymbol + "]";
+ // create a number format key with the sNewSymbol
+ int iSimpleKey = NumberFormat( xNumberFormats, sSimple, xLanguage );
+
+ // you have to use the FormatSupplier interface to get the
+ // CellFormat enumeration
+ XCellFormatRangesSupplier xCellFormatSupplier =
+ (XCellFormatRangesSupplier)UnoRuntime.queryInterface(
+ XCellFormatRangesSupplier.class, xSheet );
+
+ // getCellFormatRanges() has the interfaces for the enumeration
+ XEnumerationAccess xEnumerationAccess =
+ (XEnumerationAccess)UnoRuntime.queryInterface(
+ XEnumerationAccess.class,
+ xCellFormatSupplier.getCellFormatRanges() );
+
+ XEnumeration xRanges = xEnumerationAccess.createEnumeration();
+
+ // create an AnyConverter for later use
+ AnyConverter aAnyConv = new AnyConverter();
+
+ while( xRanges.hasMoreElements() ) {
+ // the enumeration returns a cellrange
+ XCellRange xCellRange = (XCellRange) UnoRuntime.queryInterface(
+ XCellRange.class, xRanges.nextElement());
+
+ // the PropertySet the get and set the properties from the cellrange
+ XPropertySet xCellProp = (XPropertySet)UnoRuntime.queryInterface(
+ XPropertySet.class, xCellRange );
+
+ // getPropertyValue returns an Object, you have to cast it to
+ // type that you need
+ Object oNumberObject = xCellProp.getPropertyValue( "NumberFormat" );
+ int iNumberFormat = aAnyConv.toInt(oNumberObject);
+
+ // get the properties from the cellrange numberformat
+ XPropertySet xFormat = (XPropertySet)
+ xNumberFormats.getByKey(iNumberFormat );
+
+ short fType = aAnyConv.toShort(xFormat.getPropertyValue("Type"));
+ String sCurrencySymbol = aAnyConv.toString(
+ xFormat.getPropertyValue("CurrencySymbol"));
+
+ // change the numberformat only on cellranges with a
+ // currency numberformat
+ if( ( (fType & com.sun.star.util.NumberFormat.CURRENCY) > 0) &&
+ ( sCurrencySymbol.compareTo( sOldSymbol ) == 0 ) ) {
+ boolean bThousandSep = aAnyConv.toBoolean(
+ xFormat.getPropertyValue("ThousandsSeparator"));
+ boolean bNegativeRed = aAnyConv.toBoolean(
+ xFormat.getPropertyValue("NegativeRed"));
+ short fDecimals = aAnyConv.toShort(
+ xFormat.getPropertyValue("Decimals"));
+ short fLeadingZeros = aAnyConv.toShort(
+ xFormat.getPropertyValue("LeadingZeros"));
+ Locale oLocale = (Locale) aAnyConv.toObject(
+ new com.sun.star.uno.Type(Locale.class),
+ xFormat.getPropertyValue("Locale"));
+
+ // create a new numberformat string
+ String sNew = xNumberFormats.generateFormat( iSimpleKey,
+ oLocale, bThousandSep, bNegativeRed,
+ fDecimals, fLeadingZeros );
+
+ // get the NumberKey from the numberformat
+ int iNewNumberFormat = NumberFormat( xNumberFormats,
+ sNew, oLocale );
+
+ // set the new numberformat to the cellrange DM->EUR
+ xCellProp.setPropertyValue( "NumberFormat",
+ new Integer( iNewNumberFormat ) );
+
+ // interate over all cells from the cellrange with an
+ // content and use the DM/EUR factor
+ XCellRangesQuery xCellRangesQuery = (XCellRangesQuery)
+ UnoRuntime.queryInterface(
+ XCellRangesQuery.class, xCellRange );
+
+ XSheetCellRanges xSheetCellRanges =
+ xCellRangesQuery.queryContentCells(
+ (short) com.sun.star.sheet.CellFlags.VALUE );
+
+ if( xSheetCellRanges.getCount() > 0 ) {
+ XEnumerationAccess xCellEnumerationAccess =
+ xSheetCellRanges.getCells();
+ XEnumeration xCellEnumeration =
+ xCellEnumerationAccess.createEnumeration();
+
+ while( xCellEnumeration.hasMoreElements() ) {
+ XCell xCell = (XCell) UnoRuntime.queryInterface(
+ XCell.class, xCellEnumeration.nextElement());
+ xCell.setValue( (double) xCell.getValue() / fFactor );
+ }
+ }
+ }
+ }
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+ }
+
+
+ public static int NumberFormat( XNumberFormats xNumberFormat, String sFormat,
+ com.sun.star.lang.Locale xLanguage ) {
+ int nRetKey = 0;
+
+ try {
+ // exists the numberformat
+ nRetKey = xNumberFormat.queryKey( sFormat, xLanguage, true );
+
+ // if not, create a new one
+ if( nRetKey == -1 ) {
+ nRetKey = xNumberFormat.addNew( sFormat, xLanguage );
+ if( nRetKey == -1 )
+ nRetKey = 0;
+ }
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return( nRetKey );
+ }
+
+
+ public static void createExampleData( XSpreadsheet xSheet,
+ XNumberFormats xNumberFormat ) {
+
+ // enter in a cellrange numbers and change the numberformat to DM
+ XCell xCell = null;
+ XCellRange xCellRange = null;
+
+ try {
+ Locale xLanguage = new Locale();
+ xLanguage.Country = "de"; // Germany -> DM
+ xLanguage.Language = "de"; // German
+
+ // Numberformat string from DM
+ String sSimple = "0 [$DM]";
+
+ // get the numberformat key
+ int iNumberFormatKey = NumberFormat(xNumberFormat, sSimple, xLanguage);
+
+ for( int iCounter=1; iCounter < 10; iCounter++ ) {
+ // get one cell and insert a number
+ xCell = xSheet.getCellByPosition( 2, 1 + iCounter );
+ xCell.setValue( (double) iCounter * 2 );
+ xCellRange = xSheet.getCellRangeByPosition( 2, 1 + iCounter,
+ 2, 1 + iCounter );
+
+ // get the ProperySet from the cell, to change the numberformat
+ XPropertySet xCellProp = (XPropertySet)UnoRuntime.queryInterface(
+ XPropertySet.class, xCellRange );
+ xCellProp.setPropertyValue( "NumberFormat",
+ new Integer(iNumberFormatKey) );
+ }
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+ }
+
+ public static XDesktop getDesktop() {
+ XDesktop xDesktop = null;
+ XMultiComponentFactory xMCF = null;
+
+ try {
+ XComponentContext xContext = null;
+
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+
+ // get the remote office service manager
+ xMCF = xContext.getServiceManager();
+ if( xMCF != null ) {
+ System.out.println("Connected to a running office ...");
+
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext);
+ xDesktop = (XDesktop) UnoRuntime.queryInterface(
+ XDesktop.class, oDesktop);
+ }
+ else
+ System.out.println( "Can't create a desktop. No connection, no remote servicemanager available!" );
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+
+ return xDesktop;
+ }
+
+
+ public static XSpreadsheetDocument createSheetdocument( XDesktop xDesktop ) {
+ XSpreadsheetDocument aSheetDocument = null;
+
+ try {
+ XComponent xComponent = null;
+ xComponent = CreateNewDocument( xDesktop, "scalc" );
+
+ aSheetDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(
+ XSpreadsheetDocument.class, xComponent);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return aSheetDocument;
+ }
+
+ protected static XComponent CreateNewDocument( XDesktop xDesktop,
+ String sDocumentType ) {
+ String sURL = "private:factory/" + sDocumentType;
+
+ XComponent xComponent = null;
+ XComponentLoader xComponentLoader = null;
+ PropertyValue xValues[] = new PropertyValue[1];
+ PropertyValue xEmptyArgs[] = new PropertyValue[0];
+
+ try {
+ xComponentLoader = (XComponentLoader) UnoRuntime.queryInterface(
+ XComponentLoader.class, xDesktop );
+
+ xComponent = xComponentLoader.loadComponentFromURL(
+ sURL, "_blank", 0, xEmptyArgs);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return xComponent ;
+ }
+
+}
diff --git a/odk/examples/java/Spreadsheet/Makefile b/odk/examples/java/Spreadsheet/Makefile
new file mode 100644
index 000000000000..4a251ae2062b
--- /dev/null
+++ b/odk/examples/java/Spreadsheet/Makefile
@@ -0,0 +1,213 @@
+#*************************************************************************
+#
+# 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 Spreadsheet examples of the SDK.
+
+PRJ=../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+EXAMPLE_NAME=JavaSpreadsheetExamples
+OUT_COMP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME)
+OUT_COMP_GEN = $(OUT_MISC)/$(EXAMPLE_NAME)
+
+APP1_NAME=EuroAdaption
+APP1_JAR=$(OUT_COMP_CLASS)/$(APP1_NAME).jar
+APP2_NAME=SCalc
+APP2_JAR=$(OUT_COMP_CLASS)/$(APP2_NAME).jar
+APP3_NAME=ChartTypeChange
+APP3_JAR=$(OUT_COMP_CLASS)/$(APP3_NAME).jar
+
+COMPONENT_NAME=CalcAddins
+COMPONENT_RDB_NAME=$(COMPONENT_NAME).uno.rdb
+COMPONENT_RDB=$(OUT_COMP_GEN)/$(COMPONENT_RDB_NAME)
+COMPONENT_PACKAGE=$(OUT_BIN)/$(COMPONENT_NAME).$(UNOOXT_EXT)
+COMPONENT_PACKAGE_URL=$(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMPONENT_NAME).$(UNOOXT_EXT)")
+COMPONENT_JAR_NAME=$(COMPONENT_NAME).uno.jar
+COMPONENT_JAR=$(OUT_COMP_CLASS)/$(COMPONENT_JAR_NAME)
+COMPONENT_MANIFESTFILE=$(OUT_COMP_CLASS)/$(COMPONENT_NAME).uno.Manifest
+COMPONENT_UNOPKG_MANIFEST = $(OUT_COMP_CLASS)/$(COMPONENT_NAME)/META-INF/manifest.xml
+REGISTERFLAG=$(OUT_MISC)$(PS)java_$(COMPONENT_NAME)_register_component.flag
+
+IDLFILES = XCalcAddins.idl
+
+# normally the idl file should be stored in a directory tree fitting the module structure,
+# for the example we know the module structure
+PACKAGE = org/openoffice/sheet/addin
+
+COMPJAVAFILES = CalcAddins.java
+
+#GENJAVAFILES = $(patsubst %.idl,$(OUT_COMP_GEN)/$(PACKAGE)/%.java,$(IDLFILES))
+GENCLASSFILES = $(patsubst %.idl,$(OUT_COMP_CLASS)/$(PACKAGE)/%.class,$(IDLFILES))
+GENTYPELIST = $(subst /,.,$(patsubst %.idl,-T$(PACKAGE)/% ,$(IDLFILES)))
+GENURDFILES = $(patsubst %.idl,$(OUT_COMP_GEN)/%.urd,$(IDLFILES))
+
+COMPCLASSFILES = $(patsubst %.java,$(OUT_COMP_CLASS)/%.class,$(COMPJAVAFILES))
+#COMPCLASSFILES += $(subst $(OUT_COMP_GEN),$(OUT_COMP_CLASS),$(GENJAVAFILES:.java=.class))
+
+$(COMPONENT_NAME)_CLASSFILES = $(COMPONENT_NAME).class \
+ $(COMPONENT_NAME)$(QUOTE)$$_$(COMPONENT_NAME).class
+
+#$(COMPONENT_NAME)_CLASSFILES += $(subst $(OUT_COMP_GEN)/,,$(GENJAVAFILES:.java=.class))
+$(COMPONENT_NAME)_CLASSFILES += $(subst $(OUT_COMP_CLASS)/,,$(GENCLASSFILES))
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(OUT_COMP_CLASS))
+
+# Targets
+.PHONY: ALL
+ALL : $(EXAMPLE_NAME)
+
+include $(SETTINGS)/stdtarget.mk
+
+# rule for a component manifest file
+$(OUT_COMP_CLASS)/%.Manifest :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo UNO-Type-Path: $(basename $*).uno.jar> $@
+ @echo RegistrationClassName: $(basename $*)>> $@
+
+$(OUT_COMP_GEN)/%.urd : %.idl
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(IDLC) -C -I. -I$(IDL_DIR) -O$(OUT_COMP_GEN) $<
+
+$(OUT_COMP_GEN)/%.rdb : $(GENURDFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(REGMERGE) $@ /UCR $(GENURDFILES)
+
+#$(OUT_COMP_GEN)/%.java : $(COMPONENT_RDB)
+$(GENCLASSFILES) : $(COMPONENT_RDB)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(JAVAMAKER) -BUCR -nD $(GENTYPELIST) -O$(OUT_COMP_CLASS) $(COMPONENT_RDB) -X$(URE_TYPES) -X$(OFFICE_TYPES)
+
+$(OUT_COMP_CLASS)/%.class : %.java
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_COMP_CLASS) $<
+
+# only the component depends on the generated types
+$(COMPCLASSFILES) : $(JAVAFILES) $(GENCLASSFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_COMP_CLASS) $(COMPJAVAFILES)
+
+# rule for client/example application manifest file
+$(OUT_COMP_CLASS)/%.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: $*>> $@
+
+# rule for client/example application jar file
+$(OUT_COMP_CLASS)/%.jar : $(OUT_COMP_CLASS)/%.mf $(OUT_COMP_CLASS)/%.class
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ +cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_JAR) cvfm $(@F) $*.mf $*.class
+ +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
+
+# rule for component jar file
+$(COMPONENT_JAR) : $(COMPONENT_MANIFESTFILE) $(COMPCLASSFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_JAR) cvfm $(@F) $(<F) $($(basename $(basename $(@F)))_CLASSFILES)
+
+# rule for component package manifest
+$(OUT_COMP_CLASS)/%/manifest.xml :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
+ @echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@
+ @echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-typelibrary;type=RDB$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(OUT_COMP_CLASS)/,,$(@D))).uno.rdb$(QM)"/$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-component;type=Java$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(OUT_COMP_CLASS)/,,$(@D))).uno.jar$(QM)"/$(CSEP) >> $@
+ @echo $(OSEP)/manifest:manifest$(CSEP) >> $@
+
+# rule for component package file
+$(COMPONENT_PACKAGE) : $(COMPONENT_RDB) $(COMPONENT_JAR) $(COMPONENT_UNOPKG_MANIFEST)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(COPY) $(subst /,$(PS),$<) $(subst /,$(PS),$(OUT_COMP_CLASS))
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_ZIP) ../../bin/$(@F) $(COMPONENT_RDB_NAME) $(COMPONENT_JAR_NAME)
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
+ $(DEL) $(subst \\,\,$(subst /,$(PS),$(OUT_COMP_CLASS)/$(<F)))
+
+$(REGISTERFLAG) : $(COMPONENT_PACKAGE)
+ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES"
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(DEPLOYTOOL) $(COMPONENT_PACKAGE_URL)
+ @echo flagged > $(subst /,$(PS),$@)
+else
+ @echo --------------------------------------------------------------------------------
+ @echo If you want to install your component automatically, please set the environment
+ @echo variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only
+ @echo possible if no office instance is running.
+ @echo --------------------------------------------------------------------------------
+endif
+
+$(APP1_JAR) : $(OUT_COMP_CLASS)/$(APP1_NAME).mf $(OUT_COMP_CLASS)/$(APP1_NAME).class
+$(APP2_JAR) : $(OUT_COMP_CLASS)/$(APP2_NAME).mf $(OUT_COMP_CLASS)/$(APP2_NAME).class
+$(APP3_JAR) : $(OUT_COMP_CLASS)/$(APP3_NAME).mf $(OUT_COMP_CLASS)/$(APP3_NAME).class
+
+$(EXAMPLE_NAME) : $(REGISTERFLAG) $(APP1_JAR) $(APP2_JAR) $(APP3_JAR)
+ @echo --------------------------------------------------------------------------------
+ @echo Please use the following command to execute the examples!
+ @echo -
+ @echo $(MAKE) EuroAdaption.run
+ @echo $(MAKE) SCalc.run
+ @echo $(MAKE) ChartTypeChange.run
+ @echo --------------------------------------------------------------------------------
+ @echo The Calc add-in component was installed if SDK_AUTO_DEPLOYMENT = YES.
+ @echo You can use this component inside your office installation, see the example
+ @echo description. You can also load the "$(QM)CalcAddins.ods$(QM)" document to see
+ @echo how the add-in functions works.
+ @echo -
+ @echo $(MAKE) CalcAddins.ods.load
+ @echo --------------------------------------------------------------------------------
+
+%.run: $(OUT_COMP_CLASS)/%.jar
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $<
+
+CalcAddins.ods.load : $(REGISTERFLAG)
+ "$(OFFICE_PROGRAM_PATH)$(PS)soffice" $(basename $@)
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_CLASS))
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_GEN))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMPONENT_PACKAGE_URL)))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(REGISTERFLAG)))
diff --git a/odk/examples/java/Spreadsheet/SCalc.java b/odk/examples/java/Spreadsheet/SCalc.java
new file mode 100644
index 000000000000..1938244f5733
--- /dev/null
+++ b/odk/examples/java/Spreadsheet/SCalc.java
@@ -0,0 +1,412 @@
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+
+//***************************************************************************
+// comment: Step 1: get the remote component context from the office
+// Step 2: open an empty calc document
+// Step 3: create cell styles
+// Step 4: get the sheet an insert some data
+// Step 5: apply the created cell syles
+// Step 6: insert a 3D Chart
+//***************************************************************************
+
+import com.sun.star.awt.Rectangle;
+
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.beans.XPropertySet;
+
+import com.sun.star.chart.XDiagram;
+import com.sun.star.chart.XChartDocument;
+
+import com.sun.star.container.XIndexAccess;
+import com.sun.star.container.XNameAccess;
+import com.sun.star.container.XNameContainer;
+
+import com.sun.star.document.XEmbeddedObjectSupplier;
+
+import com.sun.star.frame.XDesktop;
+import com.sun.star.frame.XComponentLoader;
+
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XMultiComponentFactory;
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XInterface;
+import com.sun.star.uno.XComponentContext;
+
+import com.sun.star.sheet.XCellRangeAddressable;
+import com.sun.star.sheet.XSpreadsheet;
+import com.sun.star.sheet.XSpreadsheets;
+import com.sun.star.sheet.XSpreadsheetDocument;
+
+import com.sun.star.style.XStyleFamiliesSupplier;
+
+import com.sun.star.table.CellRangeAddress;
+import com.sun.star.table.XCell;
+import com.sun.star.table.XCellRange;
+import com.sun.star.table.XTableChart;
+import com.sun.star.table.XTableCharts;
+import com.sun.star.table.XTableChartsSupplier;
+
+
+public class SCalc {
+
+ public static void main(String args[]) {
+
+ //oooooooooooooooooooooooooooStep 1oooooooooooooooooooooooooooooooooooooooooo
+ // call UNO bootstrap method and get the remote component context form
+ // the a running office (office will be started if necessary)
+ //***************************************************************************
+ XComponentContext xContext = null;
+
+ // get the remote office component context
+ try {
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+ } catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+ //oooooooooooooooooooooooooooStep 2oooooooooooooooooooooooooooooooooooooooooo
+ // open an empty document. In this case it's a calc document.
+ // For this purpose an instance of com.sun.star.frame.Desktop
+ // is created. The desktop provides the XComponentLoader interface,
+ // which is used to open the document via loadComponentFromURL
+ //***************************************************************************
+
+ //Open document
+
+ //Calc
+ XSpreadsheetDocument myDoc = null;
+// XCell oCell = null;
+
+ System.out.println("Opening an empty Calc document");
+ myDoc = openCalc(xContext);
+
+ //***************************************************************************
+
+
+ //oooooooooooooooooooooooooooStep 3oooooooooooooooooooooooooooooooooooooooooo
+ // create cell styles.
+ // For this purpose get the StyleFamiliesSupplier and the the familiy
+ // CellStyle. Create an instance of com.sun.star.style.CellStyle and
+ // add it to the family. Now change some properties
+ //***************************************************************************
+
+ try {
+ XStyleFamiliesSupplier xSFS = (XStyleFamiliesSupplier)
+ UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, myDoc);
+ XNameAccess xSF = (XNameAccess) xSFS.getStyleFamilies();
+ XNameAccess xCS = (XNameAccess) UnoRuntime.queryInterface(
+ XNameAccess.class, xSF.getByName("CellStyles"));
+ XMultiServiceFactory oDocMSF = (XMultiServiceFactory)
+ UnoRuntime.queryInterface(XMultiServiceFactory.class, myDoc );
+ XNameContainer oStyleFamilyNameContainer = (XNameContainer)
+ UnoRuntime.queryInterface(
+ XNameContainer.class, xCS);
+ XInterface oInt1 = (XInterface) oDocMSF.createInstance(
+ "com.sun.star.style.CellStyle");
+ oStyleFamilyNameContainer.insertByName("My Style", oInt1);
+ XPropertySet oCPS1 = (XPropertySet)UnoRuntime.queryInterface(
+ XPropertySet.class, oInt1 );
+ oCPS1.setPropertyValue("IsCellBackgroundTransparent", new Boolean(false));
+ oCPS1.setPropertyValue("CellBackColor",new Integer(6710932));
+ oCPS1.setPropertyValue("CharColor",new Integer(16777215));
+ XInterface oInt2 = (XInterface) oDocMSF.createInstance(
+ "com.sun.star.style.CellStyle");
+ oStyleFamilyNameContainer.insertByName("My Style2", oInt2);
+ XPropertySet oCPS2 = (XPropertySet)UnoRuntime.queryInterface(
+ XPropertySet.class, oInt2 );
+ oCPS2.setPropertyValue("IsCellBackgroundTransparent", new Boolean(false));
+ oCPS2.setPropertyValue("CellBackColor",new Integer(13421823));
+ } catch (Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ //***************************************************************************
+
+ //oooooooooooooooooooooooooooStep 4oooooooooooooooooooooooooooooooooooooooooo
+ // get the sheet an insert some data.
+ // Get the sheets from the document and then the first from this container.
+ // Now some data can be inserted. For this purpose get a Cell via
+ // getCellByPosition and insert into this cell via setValue() (for floats)
+ // or setFormula() for formulas and Strings
+ //***************************************************************************
+
+
+ XSpreadsheet xSheet=null;
+
+ try {
+ System.out.println("Getting spreadsheet") ;
+ XSpreadsheets xSheets = myDoc.getSheets() ;
+ XIndexAccess oIndexSheets = (XIndexAccess) UnoRuntime.queryInterface(
+ XIndexAccess.class, xSheets);
+ xSheet = (XSpreadsheet) UnoRuntime.queryInterface(
+ XSpreadsheet.class, oIndexSheets.getByIndex(0));
+
+ } catch (Exception e) {
+ System.out.println("Couldn't get Sheet " +e);
+ e.printStackTrace(System.err);
+ }
+
+
+
+ System.out.println("Creating the Header") ;
+
+ insertIntoCell(1,0,"JAN",xSheet,"");
+ insertIntoCell(2,0,"FEB",xSheet,"");
+ insertIntoCell(3,0,"MAR",xSheet,"");
+ insertIntoCell(4,0,"APR",xSheet,"");
+ insertIntoCell(5,0,"MAI",xSheet,"");
+ insertIntoCell(6,0,"JUN",xSheet,"");
+ insertIntoCell(7,0,"JUL",xSheet,"");
+ insertIntoCell(8,0,"AUG",xSheet,"");
+ insertIntoCell(9,0,"SEP",xSheet,"");
+ insertIntoCell(10,0,"OCT",xSheet,"");
+ insertIntoCell(11,0,"NOV",xSheet,"");
+ insertIntoCell(12,0,"DEC",xSheet,"");
+ insertIntoCell(13,0,"SUM",xSheet,"");
+
+
+ System.out.println("Fill the lines");
+
+ insertIntoCell(0,1,"Smith",xSheet,"");
+ insertIntoCell(1,1,"42",xSheet,"V");
+ insertIntoCell(2,1,"58.9",xSheet,"V");
+ insertIntoCell(3,1,"-66.5",xSheet,"V");
+ insertIntoCell(4,1,"43.4",xSheet,"V");
+ insertIntoCell(5,1,"44.5",xSheet,"V");
+ insertIntoCell(6,1,"45.3",xSheet,"V");
+ insertIntoCell(7,1,"-67.3",xSheet,"V");
+ insertIntoCell(8,1,"30.5",xSheet,"V");
+ insertIntoCell(9,1,"23.2",xSheet,"V");
+ insertIntoCell(10,1,"-97.3",xSheet,"V");
+ insertIntoCell(11,1,"22.4",xSheet,"V");
+ insertIntoCell(12,1,"23.5",xSheet,"V");
+ insertIntoCell(13,1,"=SUM(B2:M2)",xSheet,"");
+
+
+ insertIntoCell(0,2,"Jones",xSheet,"");
+ insertIntoCell(1,2,"21",xSheet,"V");
+ insertIntoCell(2,2,"40.9",xSheet,"V");
+ insertIntoCell(3,2,"-57.5",xSheet,"V");
+ insertIntoCell(4,2,"-23.4",xSheet,"V");
+ insertIntoCell(5,2,"34.5",xSheet,"V");
+ insertIntoCell(6,2,"59.3",xSheet,"V");
+ insertIntoCell(7,2,"27.3",xSheet,"V");
+ insertIntoCell(8,2,"-38.5",xSheet,"V");
+ insertIntoCell(9,2,"43.2",xSheet,"V");
+ insertIntoCell(10,2,"57.3",xSheet,"V");
+ insertIntoCell(11,2,"25.4",xSheet,"V");
+ insertIntoCell(12,2,"28.5",xSheet,"V");
+ insertIntoCell(13,2,"=SUM(B3:M3)",xSheet,"");
+
+ insertIntoCell(0,3,"Brown",xSheet,"");
+ insertIntoCell(1,3,"31.45",xSheet,"V");
+ insertIntoCell(2,3,"-20.9",xSheet,"V");
+ insertIntoCell(3,3,"-117.5",xSheet,"V");
+ insertIntoCell(4,3,"23.4",xSheet,"V");
+ insertIntoCell(5,3,"-114.5",xSheet,"V");
+ insertIntoCell(6,3,"115.3",xSheet,"V");
+ insertIntoCell(7,3,"-171.3",xSheet,"V");
+ insertIntoCell(8,3,"89.5",xSheet,"V");
+ insertIntoCell(9,3,"41.2",xSheet,"V");
+ insertIntoCell(10,3,"71.3",xSheet,"V");
+ insertIntoCell(11,3,"25.4",xSheet,"V");
+ insertIntoCell(12,3,"38.5",xSheet,"V");
+ insertIntoCell(13,3,"=SUM(A4:L4)",xSheet,"");
+
+ //***************************************************************************
+
+ //oooooooooooooooooooooooooooStep 5oooooooooooooooooooooooooooooooooooooooooo
+ // apply the created cell style.
+ // For this purpose get the PropertySet of the Cell and change the
+ // property CellStyle to the appropriate value.
+ //***************************************************************************
+
+ // change backcolor
+ chgbColor( 1 , 0, 13, 0, "My Style", xSheet );
+ chgbColor( 0 , 1, 0, 3, "My Style", xSheet );
+ chgbColor( 1 , 1, 13, 3, "My Style2", xSheet );
+
+ //***************************************************************************
+
+ //oooooooooooooooooooooooooooStep 6oooooooooooooooooooooooooooooooooooooooooo
+ // insert a 3D chart.
+ // get the CellRange which holds the data for the chart and its RangeAddress
+ // get the TableChartSupplier from the sheet and then the TableCharts from it.
+ // add a new chart based on the data to the TableCharts.
+ // get the ChartDocument, which provide the Diagramm. Change the properties
+ // Dim3D (3 dimension) and String (the title) of the diagramm.
+ //***************************************************************************
+
+ // insert a chart
+
+ Rectangle oRect = new Rectangle();
+ oRect.X = 500;
+ oRect.Y = 3000;
+ oRect.Width = 25000;
+ oRect.Height = 11000;
+
+ XCellRange oRange = (XCellRange)UnoRuntime.queryInterface(
+ XCellRange.class, xSheet);
+ XCellRange myRange = oRange.getCellRangeByName("A1:N4");
+ XCellRangeAddressable oRangeAddr = (XCellRangeAddressable)
+ UnoRuntime.queryInterface(XCellRangeAddressable.class, myRange);
+ CellRangeAddress myAddr = oRangeAddr.getRangeAddress();
+
+ CellRangeAddress[] oAddr = new CellRangeAddress[1];
+ oAddr[0] = myAddr;
+ XTableChartsSupplier oSupp = (XTableChartsSupplier)UnoRuntime.queryInterface(
+ XTableChartsSupplier.class, xSheet);
+
+ XTableChart oChart = null;
+
+ System.out.println("Insert Chart");
+
+ XTableCharts oCharts = oSupp.getCharts();
+ oCharts.addNewByName("Example", oRect, oAddr, true, true);
+
+ // get the diagramm and Change some of the properties
+
+ try {
+ oChart = (XTableChart) (UnoRuntime.queryInterface(
+ XTableChart.class, ((XNameAccess)UnoRuntime.queryInterface(
+ XNameAccess.class, oCharts)).getByName("Example")));
+ XEmbeddedObjectSupplier oEOS = (XEmbeddedObjectSupplier)
+ UnoRuntime.queryInterface(XEmbeddedObjectSupplier.class, oChart);
+ XInterface oInt = oEOS.getEmbeddedObject();
+ XChartDocument xChart = (XChartDocument) UnoRuntime.queryInterface(
+ XChartDocument.class,oInt);
+ XDiagram oDiag = (XDiagram) xChart.getDiagram();
+ System.out.println("Change Diagramm to 3D");
+ XPropertySet oCPS = (XPropertySet)UnoRuntime.queryInterface(
+ XPropertySet.class, oDiag );
+ oCPS.setPropertyValue("Dim3D", new Boolean(true));
+ System.out.println("Change the title");
+ Thread.sleep(200);
+ XPropertySet oTPS = (XPropertySet)UnoRuntime.queryInterface(
+ XPropertySet.class, xChart.getTitle() );
+ oTPS.setPropertyValue("String","The new title");
+ //oDiag.Dim3D();
+ } catch (Exception e){
+ System.err.println("Changin Properties failed "+e);
+ e.printStackTrace(System.err);
+ }
+
+ System.out.println("done");
+ System.exit(0);
+ }
+
+ public static XSpreadsheetDocument openCalc(XComponentContext xContext)
+ {
+ //define variables
+ XMultiComponentFactory xMCF = null;
+ XComponentLoader xCLoader;
+ XSpreadsheetDocument xSpreadSheetDoc = null;
+ XComponent xComp = null;
+
+ try {
+ // get the servie manager rom the office
+ xMCF = xContext.getServiceManager();
+
+ // create a new instance of the the desktop
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext );
+
+ // query the desktop object for the XComponentLoader
+ xCLoader = ( XComponentLoader ) UnoRuntime.queryInterface(
+ XComponentLoader.class, oDesktop );
+
+ PropertyValue [] szEmptyArgs = new PropertyValue [0];
+ String strDoc = "private:factory/scalc";
+
+ xComp = xCLoader.loadComponentFromURL(strDoc, "_blank", 0, szEmptyArgs );
+ xSpreadSheetDoc = (XSpreadsheetDocument) UnoRuntime.queryInterface(
+ XSpreadsheetDocument.class, xComp);
+
+ } catch(Exception e){
+ System.err.println(" Exception " + e);
+ e.printStackTrace(System.err);
+ }
+
+ return xSpreadSheetDoc;
+ }
+
+
+ public static void insertIntoCell(int CellX, int CellY, String theValue,
+ XSpreadsheet TT1, String flag)
+ {
+ XCell xCell = null;
+
+ try {
+ xCell = TT1.getCellByPosition(CellX, CellY);
+ } catch (com.sun.star.lang.IndexOutOfBoundsException ex) {
+ System.err.println("Could not get Cell");
+ ex.printStackTrace(System.err);
+ }
+
+ if (flag.equals("V")) {
+ xCell.setValue((new Float(theValue)).floatValue());
+ } else {
+ xCell.setFormula(theValue);
+ }
+
+ }
+
+ public static void chgbColor( int x1, int y1, int x2, int y2,
+ String template, XSpreadsheet TT )
+ {
+ XCellRange xCR = null;
+ try {
+ xCR = TT.getCellRangeByPosition(x1,y1,x2,y2);
+ } catch (com.sun.star.lang.IndexOutOfBoundsException ex) {
+ System.err.println("Could not get CellRange");
+ ex.printStackTrace(System.err);
+ }
+
+ XPropertySet xCPS = (XPropertySet)UnoRuntime.queryInterface(
+ XPropertySet.class, xCR );
+
+ try {
+ xCPS.setPropertyValue("CellStyle", template);
+ } catch (Exception e) {
+ System.err.println("Can't change colors chgbColor" + e);
+ e.printStackTrace(System.err);
+ }
+ }
+
+}
diff --git a/odk/examples/java/Spreadsheet/XCalcAddins.idl b/odk/examples/java/Spreadsheet/XCalcAddins.idl
new file mode 100644
index 000000000000..403c1f138ef4
--- /dev/null
+++ b/odk/examples/java/Spreadsheet/XCalcAddins.idl
@@ -0,0 +1,100 @@
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+#ifndef INCLUDED_ORG_OPENOFFICE_SHEET_ADDIN_XCALCADDIN_IDL
+#define INCLUDED_ORG_OPENOFFICE_SHEET_ADDIN_XCALCADDIN_IDL
+
+#include <com/sun/star/beans/XPropertySet.idl>
+#include <com/sun/star/sheet/AddIn.idl>
+
+
+module org {
+ module openoffice {
+ module sheet {
+ module addin {
+ /** Interface with your additional methods.
+
+ You may declare several methods. Each method may have
+ any number of arguments after xOptions.
+ Furthermore, you could replace the name of the service and
+ the interface, but only if you want to replace this name in all
+ your project files. This example will work with tNeccessaryhe default
+ names.
+ Interface names should start with an X prefix.
+ */
+ interface XCalcAddins
+ {
+ /** Declare your methods:
+ This is where you could add the declarations of your methods.
+ If you want to learn more about
+ the IDL syntax including the base types, you could
+ visit the following web page:
+ http://www.openoffice.org/project/udk/common/man/idl_syntax.html .
+ */
+ long getMyFirstValue(
+ /** Parameters:
+ You could insert further arguments after the
+ parameter xOptions.
+ */
+ [in] com::sun::star::beans::XPropertySet xOptions
+ );
+
+ long getMySecondValue(
+ /** Parameters:
+ You could insert further arguments after the
+ parameter xOptions.
+ */
+ [in] com::sun::star::beans::XPropertySet xOptions,
+ [in] long intDummy
+ );
+ };
+
+ service CalcAddins
+ {
+ /** Exported interfaces:
+ This is where you put all interfaces that this service exports. The service
+ supports its main interface only.
+ */
+ interface XCalcAddins;
+
+ /** Necessary base service.
+ All add-ins must implement this service
+ */
+ service com::sun::star::sheet::AddIn;
+ };
+ };
+ };
+ };
+};
+
+#endif
diff --git a/odk/examples/java/Storage/Makefile b/odk/examples/java/Storage/Makefile
new file mode 100644
index 000000000000..663f22dfe3e7
--- /dev/null
+++ b/odk/examples/java/Storage/Makefile
@@ -0,0 +1,58 @@
+# Builds the Java Storage test example of the SDK.
+
+PRJ=../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+COMPONENT_NAME=JavaStorageTestExample
+OUT_COMP_CLASS = $(OUT_CLASS)/$(COMPONENT_NAME)
+
+JAVAFILES = \
+ StorageFunctionality.java \
+ TestHelper.java \
+ StorageTest.java \
+ Test01.java \
+ Test02.java \
+ Test03.java \
+ Test04.java \
+ Test05.java \
+ Test06.java \
+ Test07.java \
+ Test08.java \
+ Test09.java
+
+CLASSFILES = $(patsubst %.java,$(OUT_COMP_CLASS)/%.class,$(JAVAFILES))
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(OUT_COMP_CLASS))
+
+
+# Targets
+.PHONY: ALL
+ALL : \
+ JavaStorageTestExample
+
+include $(SETTINGS)/stdtarget.mk
+
+$(CLASSFILES) : $(JAVAFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_COMP_CLASS) $(JAVAFILES)
+
+JavaStorageTestExample : $(CLASSFILES)
+ @echo --------------------------------------------------------------------------------
+ @echo Please use following command to execute the example!
+ @echo ------
+ @echo $(MAKE) StorageFunctionality.run
+ @echo --------------------------------------------------------------------------------
+
+%.run: $(OUT_COMP_CLASS)/%.class
+ $(SDK_JAVA) -classpath "$(SDK_CLASSPATH)" $(basename $@)
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_CLASS))
+
diff --git a/odk/examples/java/Storage/StorageFunctionality.java b/odk/examples/java/Storage/StorageFunctionality.java
new file mode 100644
index 000000000000..01708044f80f
--- /dev/null
+++ b/odk/examples/java/Storage/StorageFunctionality.java
@@ -0,0 +1,147 @@
+import com.sun.star.comp.servicemanager.ServiceManager;
+
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.connection.XConnector;
+import com.sun.star.connection.XConnection;
+
+import com.sun.star.bridge.XUnoUrlResolver;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XInterface;
+import com.sun.star.uno.XNamingService;
+import com.sun.star.uno.XComponentContext;
+
+import com.sun.star.container.*;
+import com.sun.star.beans.*;
+import com.sun.star.lang.*;
+
+import storagetesting.*;
+
+public class StorageFunctionality {
+
+ public static void main( String args[] )
+ {
+ // connect to the office
+ String sConnectionString = "uno:socket,host=localhost,port=8100;urp;StarOffice.NamingService";
+
+ // It is possible to use a different connection string, passed as argument
+ if ( args.length == 1 ) {
+ sConnectionString = args[0];
+ }
+
+ XMultiServiceFactory xMSF = null;
+
+ // create connection(s) and get multiservicefactory
+ try {
+ xMSF = connect( sConnectionString );
+
+ if ( xMSF == null )
+ {
+ System.out.println( "Error: Couldn't get MSF!" );
+ return;
+ }
+ } catch( Exception e ) {
+ System.out.println( "Error: Couldn't get MSF, exception: " + e );
+ return;
+ }
+
+ XSingleServiceFactory xStorageFactory = null;
+ try
+ {
+ Object oStorageFactory = xMSF.createInstance( "com.sun.star.embed.StorageFactory" );
+ xStorageFactory = (XSingleServiceFactory)UnoRuntime.queryInterface( XSingleServiceFactory.class,
+ oStorageFactory );
+
+ if ( xStorageFactory == null )
+ {
+ System.out.println( "Error: Can not get storage factory!" );
+ return;
+ }
+ }
+ catch ( Exception e )
+ {
+ System.out.println( "Error: Can't get storage factory, exception: " + e + "!" );
+ return;
+ }
+
+ boolean bTestsPassed = true;
+
+ final int nNumTests = 9;
+ StorageTest pTests[] = new StorageTest[nNumTests];
+ pTests[0] = (StorageTest) new Test01( xMSF, xStorageFactory );
+ pTests[1] = (StorageTest) new Test02( xMSF, xStorageFactory );
+ pTests[2] = (StorageTest) new Test03( xMSF, xStorageFactory );
+ pTests[3] = (StorageTest) new Test04( xMSF, xStorageFactory );
+ pTests[4] = (StorageTest) new Test05( xMSF, xStorageFactory );
+ pTests[5] = (StorageTest) new Test06( xMSF, xStorageFactory );
+ pTests[6] = (StorageTest) new Test07( xMSF, xStorageFactory );
+ pTests[7] = (StorageTest) new Test08( xMSF, xStorageFactory );
+ pTests[8] = (StorageTest) new Test09( xMSF, xStorageFactory );
+
+ System.out.println( "\nstart testing\n" );
+
+ for ( int nInd = 0; nInd < nNumTests; nInd++ )
+ {
+ String sTestName = "Test" + ( ( nInd < 9 ) ? "0" : "" ) + ( nInd + 1 );
+
+ System.out.println( "======= Storage test " + sTestName + " started!" );
+ if ( pTests[nInd].test() )
+ System.out.println( "======= Storage test " + sTestName + " passed!" );
+ else
+ {
+ System.out.println( "======= Storage test " + sTestName + " failed!" );
+ bTestsPassed = false;
+ }
+ }
+
+ if ( bTestsPassed )
+ System.out.println( "\ntesting passed" );
+ else
+ System.out.println( "\ntesting failed" );
+
+ System.out.println( "done" );
+
+ System.exit( 0 );
+ }
+
+
+ public static XMultiServiceFactory connect( String sConnectStr )
+ throws com.sun.star.uno.Exception,
+ com.sun.star.uno.RuntimeException,
+ Exception
+ {
+ // Get component context
+ XComponentContext xComponentContext =
+ com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(
+ null );
+
+ // initial serviceManager
+ XMultiComponentFactory xLocalServiceManager =
+ xComponentContext.getServiceManager();
+
+ // create a connector, so that it can contact the office
+ Object oUrlResolver = xLocalServiceManager.createInstanceWithContext(
+ "com.sun.star.bridge.UnoUrlResolver", xComponentContext );
+ XUnoUrlResolver xUrlResolver = (XUnoUrlResolver)UnoRuntime.queryInterface(
+ XUnoUrlResolver.class, oUrlResolver );
+
+ Object oInitialObject = xUrlResolver.resolve( sConnectStr );
+ XNamingService xName = (XNamingService)UnoRuntime.queryInterface(
+ XNamingService.class, oInitialObject );
+
+ XMultiServiceFactory xMSF = null;
+ if( xName != null ) {
+ System.err.println( "got the remote naming service !" );
+ Object oMSF = xName.getRegisteredObject("StarOffice.ServiceManager" );
+
+ xMSF = (XMultiServiceFactory)
+ UnoRuntime.queryInterface( XMultiServiceFactory.class, oMSF );
+ }
+ else
+ System.out.println( "Error: Can't get XNamingService interface from url resolver!" );
+
+ return xMSF;
+ }
+
+}
+
diff --git a/odk/examples/java/Storage/StorageTest.java b/odk/examples/java/Storage/StorageTest.java
new file mode 100644
index 000000000000..3d748d045109
--- /dev/null
+++ b/odk/examples/java/Storage/StorageTest.java
@@ -0,0 +1,7 @@
+package storagetesting;
+
+public interface StorageTest
+{
+ boolean test();
+}
+
diff --git a/odk/examples/java/Storage/Test01.java b/odk/examples/java/Storage/Test01.java
new file mode 100644
index 000000000000..7c9de41c37be
--- /dev/null
+++ b/odk/examples/java/Storage/Test01.java
@@ -0,0 +1,158 @@
+package storagetesting;
+
+import com.sun.star.uno.XInterface;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+
+import com.sun.star.bridge.XUnoUrlResolver;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XInterface;
+
+import com.sun.star.embed.*;
+
+import storagetesting.TestHelper;
+import storagetesting.StorageTest;
+
+public class Test01 implements StorageTest {
+
+ XMultiServiceFactory m_xMSF;
+ XSingleServiceFactory m_xStorageFactory;
+ TestHelper m_aTestHelper;
+
+ public Test01( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory )
+ {
+ m_xMSF = xMSF;
+ m_xStorageFactory = xStorageFactory;
+ m_aTestHelper = new TestHelper( "Test01: " );
+ }
+
+ public boolean test()
+ {
+ try
+ {
+ String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF );
+ if ( sTempFileURL == null || sTempFileURL == "" )
+ {
+ m_aTestHelper.Error( "No valid temporary file was created!" );
+ return false;
+ }
+
+ // create temporary storage based on arbitrary medium
+ // after such a storage is closed it is lost
+ Object oTempStorage = m_xStorageFactory.createInstance();
+ XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
+ if ( xTempStorage == null )
+ {
+ m_aTestHelper.Error( "Can't create temporary storage representation!" );
+ return false;
+ }
+
+ // open a new substorage
+ XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
+ "SubStorage1",
+ ElementModes.ELEMENT_WRITE );
+ if ( xTempSubStorage == null )
+ {
+ m_aTestHelper.Error( "Can't create substorage!" );
+ return false;
+ }
+
+ byte pBytes1[] = { 1, 1, 1, 1, 1 };
+
+ // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
+ if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream1", "MediaType1", true, pBytes1 ) )
+ return false;
+
+ byte pBytes2[] = { 2, 2, 2, 2, 2 };
+
+ // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
+ if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream2", "MediaType2", false, pBytes2 ) )
+ return false;
+
+ // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
+ if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
+ "MediaType3",
+ true,
+ ElementModes.ELEMENT_READWRITE ) )
+ return false;
+
+ // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
+ if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
+ "MediaType4",
+ false,
+ ElementModes.ELEMENT_WRITE ) )
+ return false;
+
+ // create temporary storage based on a previously created temporary file
+ Object pArgs[] = new Object[2];
+ pArgs[0] = (Object) sTempFileURL;
+ pArgs[1] = new Integer( ElementModes.ELEMENT_WRITE );
+
+ Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage );
+ if ( xTempFileStorage == null )
+ {
+ m_aTestHelper.Error( "Can't create storage based on temporary file!" );
+ return false;
+ }
+
+ // copy xTempStorage to xTempFileStorage
+ // xTempFileStorage will be automatically commited
+ if ( !m_aTestHelper.copyStorage( xTempStorage, xTempFileStorage ) )
+ return false;
+
+ // dispose used storages to free resources
+ if ( !m_aTestHelper.disposeStorage( xTempStorage ) || !m_aTestHelper.disposeStorage( xTempFileStorage ) )
+ return false;
+
+ // ================================================
+ // now check all the written and copied information
+ // ================================================
+
+ // the temporary file must not be locked any more after storage disposing
+ pArgs[1] = new Integer( ElementModes.ELEMENT_READWRITE );
+ Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage );
+ if ( xResultStorage == null )
+ {
+ m_aTestHelper.Error( "Can't reopen storage based on temporary file!" );
+ return false;
+ }
+
+ if ( !m_aTestHelper.checkStorageProperties( xResultStorage, "MediaType3", true, ElementModes.ELEMENT_READWRITE ) )
+ return false;
+
+ // open existing substorage
+ XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage,
+ "SubStorage1",
+ ElementModes.ELEMENT_READ );
+ if ( xResultSubStorage == null )
+ {
+ m_aTestHelper.Error( "Can't open existing substorage!" );
+ return false;
+ }
+
+ if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, "MediaType4", false, ElementModes.ELEMENT_READ ) )
+ return false;
+
+ if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream1", "MediaType1", pBytes1 ) )
+ return false;
+
+ if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream2", "MediaType2", pBytes2 ) )
+ return false;
+
+ // dispose used storages to free resources
+ if ( !m_aTestHelper.disposeStorage( xResultStorage ) )
+ return false;
+
+ return true;
+ }
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Exception: " + e );
+ return false;
+ }
+ }
+
+}
+
diff --git a/odk/examples/java/Storage/Test02.java b/odk/examples/java/Storage/Test02.java
new file mode 100644
index 000000000000..b258f10ca999
--- /dev/null
+++ b/odk/examples/java/Storage/Test02.java
@@ -0,0 +1,152 @@
+package storagetesting;
+
+import com.sun.star.uno.XInterface;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+
+import com.sun.star.bridge.XUnoUrlResolver;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XInterface;
+import com.sun.star.io.XStream;
+import com.sun.star.io.XInputStream;
+
+import com.sun.star.embed.*;
+
+import storagetesting.TestHelper;
+import storagetesting.StorageTest;
+
+public class Test02 implements StorageTest {
+
+ XMultiServiceFactory m_xMSF;
+ XSingleServiceFactory m_xStorageFactory;
+ TestHelper m_aTestHelper;
+
+ public Test02( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory )
+ {
+ m_xMSF = xMSF;
+ m_xStorageFactory = xStorageFactory;
+ m_aTestHelper = new TestHelper( "Test02: " );
+ }
+
+ public boolean test()
+ {
+ try
+ {
+ XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF );
+ if ( xTempFileStream == null )
+ return false;
+
+ // create storage based on the temporary stream
+ Object pArgs[] = new Object[2];
+ pArgs[0] = (Object) xTempFileStream;
+ pArgs[1] = new Integer( ElementModes.ELEMENT_WRITE );
+
+ Object oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
+ if ( xTempStorage == null )
+ {
+ m_aTestHelper.Error( "Can't create temporary storage representation!" );
+ return false;
+ }
+
+ // open a new substorage
+ XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
+ "SubStorage1",
+ ElementModes.ELEMENT_WRITE );
+ if ( xTempSubStorage == null )
+ {
+ m_aTestHelper.Error( "Can't create substorage!" );
+ return false;
+ }
+
+ byte pBytes1[] = { 1, 1, 1, 1, 1 };
+
+ // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
+ if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream1", "MediaType1", true, pBytes1 ) )
+ return false;
+
+ // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
+ if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
+ "MediaType2",
+ true,
+ ElementModes.ELEMENT_WRITE ) )
+ return false;
+
+ // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
+ if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
+ "MediaType3",
+ false,
+ ElementModes.ELEMENT_WRITE ) )
+ return false;
+
+ // commit substorage first
+ if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
+ return false;
+
+ // commit the root storage so the contents must be stored now
+ if ( !m_aTestHelper.commitStorage( xTempStorage ) )
+ return false;
+
+ // dispose used storage to free resources
+ // the substorage dispose will be triggered by this call
+ if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
+ return false;
+
+
+ // ================================================
+ // now check all the written information
+ // ================================================
+
+ // close the output part of the temporary stream
+ // the output part must present since we already wrote to the stream
+ if ( !m_aTestHelper.closeOutput( xTempFileStream ) )
+ return false;
+
+ XInputStream xTempInStream = m_aTestHelper.getInputStream( xTempFileStream );
+ if ( xTempInStream == null )
+ return false;
+
+
+ // open input stream
+ // since no mode is provided the result storage must be opened readonly
+ Object pOneArg[] = new Object[1];
+ pOneArg[0] = (Object) xTempInStream;
+
+ Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pOneArg );
+ XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage );
+ if ( xResultStorage == null )
+ {
+ m_aTestHelper.Error( "Can't open storage based on input stream!" );
+ return false;
+ }
+
+ if ( !m_aTestHelper.checkStorageProperties( xResultStorage, "MediaType2", true, ElementModes.ELEMENT_READ ) )
+ return false;
+
+ // open existing substorage
+ XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage,
+ "SubStorage1",
+ ElementModes.ELEMENT_READ );
+ if ( xResultSubStorage == null )
+ {
+ m_aTestHelper.Error( "Can't open existing substorage!" );
+ return false;
+ }
+
+ if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, "MediaType3", false, ElementModes.ELEMENT_READ ) )
+ return false;
+
+ if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream1", "MediaType1", pBytes1 ) )
+ return false;
+
+ return true;
+ }
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Exception: " + e );
+ return false;
+ }
+ }
+
+}
+
diff --git a/odk/examples/java/Storage/Test03.java b/odk/examples/java/Storage/Test03.java
new file mode 100644
index 000000000000..f1d5d415067f
--- /dev/null
+++ b/odk/examples/java/Storage/Test03.java
@@ -0,0 +1,209 @@
+package storagetesting;
+
+import com.sun.star.uno.XInterface;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+
+import com.sun.star.bridge.XUnoUrlResolver;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XInterface;
+
+import com.sun.star.embed.*;
+import com.sun.star.container.XNameAccess;
+
+import storagetesting.TestHelper;
+import storagetesting.StorageTest;
+
+public class Test03 implements StorageTest {
+
+ XMultiServiceFactory m_xMSF;
+ XSingleServiceFactory m_xStorageFactory;
+ TestHelper m_aTestHelper;
+
+ public Test03( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory )
+ {
+ m_xMSF = xMSF;
+ m_xStorageFactory = xStorageFactory;
+ m_aTestHelper = new TestHelper( "Test03: " );
+ }
+
+ public boolean test()
+ {
+ try
+ {
+ // create temporary storage based on arbitrary medium
+ // after such a storage is closed it is lost
+ Object oTempStorage = m_xStorageFactory.createInstance();
+ XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
+ if ( xTempStorage == null )
+ {
+ m_aTestHelper.Error( "Can't create temporary storage representation!" );
+ return false;
+ }
+
+ // open a new substorage
+ XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
+ "SubStorage1",
+ ElementModes.ELEMENT_WRITE );
+ if ( xTempSubStorage == null )
+ {
+ m_aTestHelper.Error( "Can't create substorage!" );
+ return false;
+ }
+
+ byte pBytes1[] = { 1, 1, 1, 1, 1 };
+
+ // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
+ if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage, "SubStream1", "MediaType1", true, pBytes1 ) )
+ return false;
+
+ byte pBytes2[] = { 2, 2, 2, 2, 2 };
+
+ // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
+ if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream2", "MediaType2", false, pBytes2 ) )
+ return false;
+
+ // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
+ if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
+ "MediaType3",
+ false,
+ ElementModes.ELEMENT_WRITE ) )
+ return false;
+
+ if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
+ return false;
+
+ if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
+ return false;
+
+ // ================================================
+ // check storage hyerarchy tree
+ // ================================================
+
+ // check that isStorageElement() and isStreamElement reacts to nonexisting object correctly
+ try {
+ xTempStorage.isStorageElement( "does not exist" );
+ m_aTestHelper.Error( "Nonexisting element doesn't detected by isStorageElement() call!" );
+ return false;
+ }
+ catch( com.sun.star.container.NoSuchElementException ne )
+ {
+ }
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Wrong exception is thrown by isStorageElement() call: " + e );
+ return false;
+ }
+
+ try {
+ xTempStorage.isStreamElement( "does not exist" );
+ m_aTestHelper.Error( "Nonexisting element doesn't detected by isStreamElement() call!" );
+ return false;
+ }
+ catch( com.sun.star.container.NoSuchElementException ne )
+ {
+ }
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Wrong exception is thrown by isStreamElement() call: " + e );
+ return false;
+ }
+
+ XNameAccess xRootNameAccess = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xTempStorage );
+ if ( xRootNameAccess == null )
+ {
+ m_aTestHelper.Error( "Root storage doesn't support XNameAccess!" );
+ return false;
+ }
+
+ try {
+ if ( !xTempStorage.isStorageElement( "SubStorage1" ) || xTempStorage.isStreamElement( "SubStorage1" ) )
+ {
+ m_aTestHelper.Error( "Child 'SubStorage1' can not be detected as storage!" );
+ return false;
+ }
+
+ if ( xTempStorage.isStorageElement( "SubStream1" ) || !xTempStorage.isStreamElement( "SubStream1" ) )
+ {
+ m_aTestHelper.Error( "Child 'SubStream1' can not be detected as stream!" );
+ return false;
+ }
+ }
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Child's type can not be detected, exception: " + e );
+ return false;
+ }
+
+
+ // check that root storage contents are represented correctly
+ String sRootCont[] = xRootNameAccess.getElementNames();
+
+ if ( sRootCont.length != 2 )
+ {
+ m_aTestHelper.Error( "Root storage contains wrong amount of children!" );
+ return false;
+ }
+
+ if ( !( sRootCont[0].equals( "SubStorage1" ) && sRootCont[1].equals( "SubStream1" )
+ || sRootCont[0].equals( "SubStream1" ) && sRootCont[1].equals( "SubStorage1" ) )
+ || !( xRootNameAccess.hasByName( "SubStream1" ) && xRootNameAccess.hasByName( "SubStorage1" ) ) )
+ {
+ m_aTestHelper.Error( "Root storage contains wrong list of children!" );
+ return false;
+ }
+
+ // get storage through XNameAccess
+ XStorage xResultSubStorage = getStorageFromNameAccess( xRootNameAccess, "SubStorage1" );
+ if ( xResultSubStorage == null )
+ return false;
+
+ if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, "MediaType3", false, ElementModes.ELEMENT_READ ) )
+ return false;
+
+ XNameAccess xChildAccess = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xResultSubStorage );
+ if ( xChildAccess == null )
+ {
+ m_aTestHelper.Error( "Child storage doesn't support XNameAccess!" );
+ return false;
+ }
+
+ if ( !xChildAccess.hasByName( "SubStream2" )
+ || !xResultSubStorage.isStreamElement( "SubStream2" )
+ || xResultSubStorage.isStorageElement( "SubStream2" ) )
+ {
+ m_aTestHelper.Error( "'SubStream2' can not be detected as child stream element of 'SubStorage1'!" );
+ return false;
+ }
+
+ return true;
+ }
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Exception: " + e );
+ return false;
+ }
+ }
+
+ public XStorage getStorageFromNameAccess( XNameAccess xAccess, String sName )
+ {
+ try
+ {
+ Object oStorage = xAccess.getByName( sName );
+ XStorage xResult = (XStorage) UnoRuntime.queryInterface( XStorage.class, oStorage );
+
+ if ( xResult != null )
+ return xResult;
+ else
+ m_aTestHelper.Error( "Can't retrieve substorage '" + sName + "' through XNameAccess!" );
+ }
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Can't retrieve substorage '" + sName + "' through XNameAccess, exception: " + e );
+ }
+
+ return null;
+ }
+
+}
+
diff --git a/odk/examples/java/Storage/Test04.java b/odk/examples/java/Storage/Test04.java
new file mode 100644
index 000000000000..943fcfff8a38
--- /dev/null
+++ b/odk/examples/java/Storage/Test04.java
@@ -0,0 +1,273 @@
+package storagetesting;
+
+import com.sun.star.uno.XInterface;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+import com.sun.star.lang.DisposedException;
+
+import com.sun.star.bridge.XUnoUrlResolver;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XInterface;
+
+import com.sun.star.container.XNameAccess;
+
+import com.sun.star.embed.*;
+
+import storagetesting.TestHelper;
+import storagetesting.StorageTest;
+
+public class Test04 implements StorageTest {
+
+ XMultiServiceFactory m_xMSF;
+ XSingleServiceFactory m_xStorageFactory;
+ TestHelper m_aTestHelper;
+
+ public Test04( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory )
+ {
+ m_xMSF = xMSF;
+ m_xStorageFactory = xStorageFactory;
+ m_aTestHelper = new TestHelper( "Test04: " );
+ }
+
+ public boolean test()
+ {
+ try
+ {
+ String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF );
+ if ( sTempFileURL == null || sTempFileURL == "" )
+ {
+ m_aTestHelper.Error( "No valid temporary file was created!" );
+ return false;
+ }
+
+ // create temporary storage based on arbitrary medium
+ // after such a storage is closed it is lost
+ Object oTempStorage = m_xStorageFactory.createInstance();
+ XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
+ if ( xTempStorage == null )
+ {
+ m_aTestHelper.Error( "Can't create temporary storage representation!" );
+ return false;
+ }
+
+ // open substorages and create streams there
+
+ // first substorage of the root storage
+ XStorage xTempSubStorage1 = m_aTestHelper.openSubStorage( xTempStorage,
+ "SubStorage1",
+ ElementModes.ELEMENT_WRITE );
+ if ( xTempSubStorage1 == null )
+ {
+ m_aTestHelper.Error( "Can't create substorage!" );
+ return false;
+ }
+
+ byte pBytes1[] = { 1, 1, 1, 1, 1 };
+
+ // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
+ if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage1, "SubStream1", "MediaType1", true, pBytes1 ) )
+ return false;
+
+ // second substorage of the root storage
+ XStorage xTempSubStorage2 = m_aTestHelper.openSubStorage( xTempStorage,
+ "SubStorage2",
+ ElementModes.ELEMENT_WRITE );
+ if ( xTempSubStorage2 == null )
+ {
+ m_aTestHelper.Error( "Can't create substorage!" );
+ return false;
+ }
+
+ byte pBytes2[] = { 2, 2, 2, 2, 2 };
+
+ // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
+ if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage2, "SubStream2", "MediaType2", false, pBytes2 ) )
+ return false;
+
+ // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
+ if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
+ "MediaType3",
+ true,
+ ElementModes.ELEMENT_READWRITE ) )
+ return false;
+
+ // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
+ if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage1,
+ "MediaType4",
+ false,
+ ElementModes.ELEMENT_WRITE ) )
+ return false;
+
+ // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
+ if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage2,
+ "MediaType5",
+ false,
+ ElementModes.ELEMENT_WRITE ) )
+ return false;
+
+ // create temporary storage based on a previously created temporary file
+ Object pArgs[] = new Object[2];
+ pArgs[0] = (Object) sTempFileURL;
+ pArgs[1] = new Integer( ElementModes.ELEMENT_WRITE );
+
+ Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage );
+ if ( xTempFileStorage == null )
+ {
+ m_aTestHelper.Error( "Can't create storage based on temporary file!" );
+ return false;
+ }
+
+ if ( !m_aTestHelper.copyElementTo( xTempStorage, "SubStorage1", xTempFileStorage ) )
+ return false;
+
+ // if storage is not commited before disposing all the changes will be lost
+ if ( !m_aTestHelper.commitStorage( xTempSubStorage2 ) )
+ return false;
+
+ // a storage must be disposed before moving/removing otherwise the access will be denied
+ if ( !m_aTestHelper.disposeStorage( xTempSubStorage2 ) )
+ return false;
+
+ if ( !m_aTestHelper.moveElementTo( xTempStorage, "SubStorage2", xTempFileStorage ) )
+ return false;
+
+ // SubStorage2 must be removed and disposed now
+ try
+ {
+ xTempSubStorage2.isStreamElement( "SubStream2" );
+ m_aTestHelper.Error( "SubStorage2 must be disposed already!" );
+ return false;
+ }
+ catch( com.sun.star.lang.DisposedException de )
+ {
+ }
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Wrong exception in case of disposed storage, exception: " + e );
+ return false;
+ }
+
+ if ( !m_aTestHelper.copyElementTo( xTempSubStorage1, "SubStream1", xTempFileStorage ) )
+ return false;
+
+ if ( !m_aTestHelper.renameElement( xTempFileStorage, "SubStream1", "SubStream1_copy" ) )
+ return false;
+
+ if ( !m_aTestHelper.moveElementTo( xTempSubStorage1, "SubStream1", xTempFileStorage ) )
+ return false;
+
+ if ( !m_aTestHelper.commitStorage( xTempFileStorage ) )
+ return false;
+
+ // dispose used storages to free resources
+ if ( !m_aTestHelper.disposeStorage( xTempStorage ) || !m_aTestHelper.disposeStorage( xTempFileStorage ) )
+ return false;
+
+ // ================================================
+ // now check all the written and copied information
+ // ================================================
+
+ // the temporary file must not be locked any more after storage disposing
+ pArgs[1] = new Integer( ElementModes.ELEMENT_READWRITE );
+ Object oResStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xResStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResStorage );
+ if ( xResStorage == null )
+ {
+ m_aTestHelper.Error( "Can't reopen storage based on temporary file!" );
+ return false;
+ }
+
+ // open and check SubStorage1
+ XStorage xResSubStorage1 = m_aTestHelper.openSubStorage( xResStorage,
+ "SubStorage1",
+ ElementModes.ELEMENT_READ );
+ if ( xResSubStorage1 == null )
+ {
+ m_aTestHelper.Error( "Can't open existing substorage!" );
+ return false;
+ }
+
+ if ( !m_aTestHelper.checkStorageProperties( xResSubStorage1, "MediaType4", false, ElementModes.ELEMENT_READ ) )
+ return false;
+
+
+ // open and check SubStorage2
+ XStorage xResSubStorage2 = m_aTestHelper.openSubStorage( xResStorage,
+ "SubStorage2",
+ ElementModes.ELEMENT_READ );
+ if ( xResSubStorage2 == null )
+ {
+ m_aTestHelper.Error( "Can't open existing substorage!" );
+ return false;
+ }
+
+ if ( !m_aTestHelper.checkStorageProperties( xResSubStorage2, "MediaType5", false, ElementModes.ELEMENT_READ ) )
+ return false;
+
+
+ // check all the result streams
+
+ if ( !m_aTestHelper.checkStream( xResStorage, "SubStream1", "MediaType1", pBytes1 ) )
+ return false;
+
+ if ( !m_aTestHelper.checkStream( xResStorage, "SubStream1_copy", "MediaType1", pBytes1 ) )
+ return false;
+
+ if ( !m_aTestHelper.checkStream( xResSubStorage1, "SubStream1", "MediaType1", pBytes1 ) )
+ return false;
+
+ if ( !m_aTestHelper.checkStream( xResSubStorage2, "SubStream2", "MediaType2", pBytes2 ) )
+ return false;
+
+ // the storage must be disposed before removing
+ if ( !m_aTestHelper.disposeStorage( xResSubStorage2 ) )
+ return false;
+
+ // remove element and check that it was removed completelly
+ if ( !m_aTestHelper.removeElement( xResStorage, "SubStorage2" ) )
+ return false;
+
+ try
+ {
+ XNameAccess xResAccess = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xResStorage );
+ if ( xResAccess.hasByName( "SubStorage2" ) )
+ m_aTestHelper.Error( "SubStorage2 must be removed already!" );
+ }
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Can't get access to root storage, exception: " + e );
+ return false;
+ }
+
+ try
+ {
+ xResSubStorage2.isStreamElement( "SubStream2" );
+
+ m_aTestHelper.Error( "SubStorage2 must be disposed already!" );
+ return false;
+ }
+ catch( com.sun.star.lang.DisposedException de )
+ {
+ }
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Wrong exception in case of disposed storage, exception: " + e );
+ return false;
+ }
+
+ // dispose used storages to free resources
+ if ( !m_aTestHelper.disposeStorage( xResStorage ) )
+ return false;
+
+ return true;
+ }
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Exception: " + e );
+ return false;
+ }
+ }
+
+}
+
diff --git a/odk/examples/java/Storage/Test05.java b/odk/examples/java/Storage/Test05.java
new file mode 100644
index 000000000000..263e2d2561c7
--- /dev/null
+++ b/odk/examples/java/Storage/Test05.java
@@ -0,0 +1,268 @@
+package storagetesting;
+
+import com.sun.star.uno.XInterface;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+
+import com.sun.star.bridge.XUnoUrlResolver;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XInterface;
+import com.sun.star.io.XStream;
+
+import com.sun.star.embed.*;
+
+import storagetesting.TestHelper;
+import storagetesting.StorageTest;
+
+public class Test05 implements StorageTest {
+
+ XMultiServiceFactory m_xMSF;
+ XSingleServiceFactory m_xStorageFactory;
+ TestHelper m_aTestHelper;
+
+ public Test05( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory )
+ {
+ m_xMSF = xMSF;
+ m_xStorageFactory = xStorageFactory;
+ m_aTestHelper = new TestHelper( "Test05: " );
+ }
+
+ public boolean test()
+ {
+ try
+ {
+ String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF );
+ if ( sTempFileURL == null || sTempFileURL == "" )
+ {
+ m_aTestHelper.Error( "No valid temporary file was created!" );
+ return false;
+ }
+
+ // create temporary storage based on a previously created temporary file
+ Object pArgs[] = new Object[2];
+ pArgs[0] = (Object) sTempFileURL;
+ pArgs[1] = new Integer( ElementModes.ELEMENT_WRITE );
+
+ Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage );
+ if ( xTempFileStorage == null )
+ {
+ m_aTestHelper.Error( "Can't create storage based on temporary file!" );
+ return false;
+ }
+
+ // open a new substorage
+ XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempFileStorage,
+ "SubStorage1",
+ ElementModes.ELEMENT_WRITE );
+ if ( xTempSubStorage == null )
+ {
+ m_aTestHelper.Error( "Can't create substorage!" );
+ return false;
+ }
+
+ // open a new substorage
+ XStorage xSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage,
+ "SubSubStorage1",
+ ElementModes.ELEMENT_WRITE );
+ if ( xSubSubStorage == null )
+ {
+ m_aTestHelper.Error( "Can't create substorage!" );
+ return false;
+ }
+
+
+ byte pBytes1[] = { 1, 1, 1, 1, 1 };
+
+ // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
+ if ( !m_aTestHelper.WriteBytesToSubstream( xSubSubStorage, "SubStream1", "MediaType1", true, pBytes1 ) )
+ return false;
+
+ byte pBytes2[] = { 2, 2, 2, 2, 2 };
+
+ // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
+ if ( !m_aTestHelper.WriteBytesToSubstream( xSubSubStorage, "SubStream2", "MediaType2", false, pBytes2 ) )
+ return false;
+
+ // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
+ if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempFileStorage,
+ "MediaType3",
+ true,
+ ElementModes.ELEMENT_WRITE ) )
+ return false;
+
+ // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
+ if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
+ "MediaType4",
+ false,
+ ElementModes.ELEMENT_WRITE ) )
+ return false;
+
+ // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
+ if ( !m_aTestHelper.setStorageTypeAndCheckProps( xSubSubStorage,
+ "MediaType5",
+ false,
+ ElementModes.ELEMENT_WRITE ) )
+ return false;
+
+
+ // commit all the storages
+ if ( !m_aTestHelper.commitStorage( xSubSubStorage ) )
+ return false;
+
+ if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
+ return false;
+
+ if ( !m_aTestHelper.commitStorage( xTempFileStorage ) )
+ return false;
+
+ // try to open an opened substorage, open call must fail
+ if ( !m_aTestHelper.cantOpenStorage( xTempFileStorage, "SubStorage1" ) )
+ return false;
+
+
+ // reopen created streams
+ XStream xSubStream1 = m_aTestHelper.OpenStream( xSubSubStorage,
+ "SubStream1",
+ ElementModes.ELEMENT_READWRITE | ElementModes.ELEMENT_NOCREATE );
+ XStream xSubStream2 = m_aTestHelper.OpenStream( xSubSubStorage,
+ "SubStream2",
+ ElementModes.ELEMENT_READ | ElementModes.ELEMENT_NOCREATE );
+ if ( xSubStream1 == null || xSubStream2 == null )
+ return false;
+
+ // it should be possible to have more then one copy of stream for reading
+ XStream xSubStream2clone = m_aTestHelper.OpenStream( xSubSubStorage,
+ "SubStream2",
+ ElementModes.ELEMENT_READ | ElementModes.ELEMENT_NOCREATE );
+ if ( xSubStream2 == null )
+ return false;
+
+
+ // so now the first stream can not be open neither for reading nor for writing
+ if ( !m_aTestHelper.cantOpenStream( xSubSubStorage, "SubStream1", ElementModes.ELEMENT_WRITE )
+ || !m_aTestHelper.cantOpenStream( xSubSubStorage, "SubStream1", ElementModes.ELEMENT_READ ) )
+ return false;
+
+ // the second stream can not be open for writing
+ if ( !m_aTestHelper.cantOpenStream( xSubSubStorage, "SubStream2", ElementModes.ELEMENT_WRITE ) )
+ return false;
+
+
+ // dispose xTestSubStorage, all the subtree must be disposed
+ if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
+ return false;
+
+ // check that subtree was disposed correctly
+ try
+ {
+ xSubSubStorage.isStreamElement( "SubStream1" );
+ m_aTestHelper.Error( "Substorage was not disposed!" );
+ return false;
+ }
+ catch ( com.sun.star.lang.DisposedException de )
+ {}
+ catch ( Exception e )
+ {
+ m_aTestHelper.Error( "Wrong exception is thrown by disposed storage: " + e );
+ return false;
+ }
+
+ try
+ {
+ xSubStream1.getInputStream();
+ m_aTestHelper.Error( "Writeable substream was not disposed!" );
+ return false;
+ }
+ catch ( com.sun.star.lang.DisposedException de )
+ {}
+ catch ( Exception e )
+ {
+ m_aTestHelper.Error( "Wrong exception is thrown by disposed stream: " + e );
+ return false;
+ }
+
+ try
+ {
+ xSubStream2.getInputStream();
+ m_aTestHelper.Error( "Readonly substream was not disposed!" );
+ return false;
+ }
+ catch ( com.sun.star.lang.DisposedException de )
+ {}
+ catch ( Exception e )
+ {
+ m_aTestHelper.Error( "Wrong exception is thrown by disposed stream: " + e );
+ return false;
+ }
+
+
+ // dispose root storage
+ if ( !m_aTestHelper.disposeStorage( xTempFileStorage ) )
+ return false;
+
+
+ // ================================================
+ // now check all the written and copied information
+ // ================================================
+
+ pArgs[1] = new Integer( ElementModes.ELEMENT_READ );
+ Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage );
+ if ( xResultStorage == null )
+ {
+ m_aTestHelper.Error( "Can't reopen storage based on temporary file!" );
+ return false;
+ }
+
+ if ( !m_aTestHelper.checkStorageProperties( xResultStorage, "MediaType3", true, ElementModes.ELEMENT_READ ) )
+ return false;
+
+ // open existing substorage
+ XStorage xResSubStorage = m_aTestHelper.openSubStorage( xResultStorage,
+ "SubStorage1",
+ ElementModes.ELEMENT_READ );
+ if ( xResSubStorage == null )
+ {
+ m_aTestHelper.Error( "Can't open existing substorage 'SubSubStorage'!" );
+ return false;
+ }
+
+ if ( !m_aTestHelper.checkStorageProperties( xResSubStorage, "MediaType4", false, ElementModes.ELEMENT_READ ) )
+ return false;
+
+ // open existing substorage
+ XStorage xResSubSubStorage = m_aTestHelper.openSubStorage( xResSubStorage,
+ "SubSubStorage1",
+ ElementModes.ELEMENT_READ );
+ if ( xResSubSubStorage == null )
+ {
+ m_aTestHelper.Error( "Can't open existing substorage 'SubSubStorage'!" );
+ return false;
+ }
+
+ if ( !m_aTestHelper.checkStorageProperties( xResSubSubStorage, "MediaType5", false, ElementModes.ELEMENT_READ ) )
+ return false;
+
+ // check substreams
+ if ( !m_aTestHelper.checkStream( xResSubSubStorage, "SubStream1", "MediaType1", pBytes1 ) )
+ return false;
+
+ if ( !m_aTestHelper.checkStream( xResSubSubStorage, "SubStream2", "MediaType2", pBytes2 ) )
+ return false;
+
+ // dispose used storages to free resources
+ if ( !m_aTestHelper.disposeStorage( xResultStorage ) )
+ return false;
+
+ return true;
+ }
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Exception: " + e );
+ return false;
+ }
+ }
+
+}
+
diff --git a/odk/examples/java/Storage/Test06.java b/odk/examples/java/Storage/Test06.java
new file mode 100644
index 000000000000..7ee3a832b5f3
--- /dev/null
+++ b/odk/examples/java/Storage/Test06.java
@@ -0,0 +1,278 @@
+package storagetesting;
+
+import com.sun.star.uno.XInterface;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+
+import com.sun.star.bridge.XUnoUrlResolver;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XInterface;
+
+import com.sun.star.lang.IllegalArgumentException;
+import com.sun.star.container.NoSuchElementException;
+import com.sun.star.container.ElementExistException;
+
+import com.sun.star.embed.*;
+
+import storagetesting.TestHelper;
+import storagetesting.StorageTest;
+
+public class Test06 implements StorageTest {
+
+ XMultiServiceFactory m_xMSF;
+ XSingleServiceFactory m_xStorageFactory;
+ TestHelper m_aTestHelper;
+
+ public Test06( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory )
+ {
+ m_xMSF = xMSF;
+ m_xStorageFactory = xStorageFactory;
+ m_aTestHelper = new TestHelper( "Test06: " );
+ }
+
+ public boolean test()
+ {
+ try
+ {
+ // create temporary storage based on arbitrary medium
+ // after such a storage is closed it is lost
+ Object oTempStorage = m_xStorageFactory.createInstance();
+ XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
+ if ( xTempStorage == null )
+ {
+ m_aTestHelper.Error( "Can't create temporary storage representation!" );
+ return false;
+ }
+
+ try
+ {
+ xTempStorage.copyToStorage( null );
+ m_aTestHelper.Error( "The method must throw an exception because of illegal parameter!" );
+ return false;
+ }
+ catch( com.sun.star.lang.IllegalArgumentException iae )
+ {}
+ catch( com.sun.star.uno.Exception ue )
+ {}
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Unexpected excepion because of illegal parameter : " + e );
+ return false;
+ }
+
+ // open new substorages
+ XStorage xTempSubStorage1 = m_aTestHelper.openSubStorage( xTempStorage,
+ "SubStorage1",
+ ElementModes.ELEMENT_WRITE );
+ XStorage xTempSubStorage2 = m_aTestHelper.openSubStorage( xTempStorage,
+ "SubStorage2",
+ ElementModes.ELEMENT_WRITE );
+ if ( xTempSubStorage1 == null || xTempSubStorage2 == null )
+ {
+ m_aTestHelper.Error( "Can't create substorage!" );
+ return false;
+ }
+
+ // in case stream is open for reading it must exist
+ try
+ {
+ xTempSubStorage1.openStreamElement( "NonExistingStream", ElementModes.ELEMENT_READ );
+ m_aTestHelper.Error( "The method must throw an exception in case of try to open nonexistent stream for reading!" );
+ return false;
+ }
+ catch( com.sun.star.uno.Exception ue )
+ {}
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Unexpected excepion in case of try to open nonexistent stream for reading : " + e );
+ return false;
+ }
+
+ // in case a storage is open for reading it must exist
+ try
+ {
+ xTempSubStorage1.openStreamElement( "NonExistingStorage", ElementModes.ELEMENT_READ );
+ m_aTestHelper.Error( "The method must throw an exception in case of try to open nonexistent storage for reading!" );
+ return false;
+ }
+ catch( com.sun.star.uno.Exception ue )
+ {}
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Unexpected excepion in case of try to open nonexistent storage for reading : " + e );
+ return false;
+ }
+
+ // in case of removing nonexistent element an exception must be thrown
+ try
+ {
+ xTempSubStorage1.removeElement( "NonExistingElement" );
+ m_aTestHelper.Error( "An exception must be thrown in case of removing nonexistent element!" );
+ return false;
+ }
+ catch( com.sun.star.container.NoSuchElementException ne )
+ {}
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Unexpected excepion in case of try to remove nonexistent element : " + e );
+ return false;
+ }
+
+ // in case of renaming of nonexistent element an exception must be thrown
+ try
+ {
+ xTempSubStorage1.renameElement( "NonExistingElement", "NewName" );
+ m_aTestHelper.Error( "An exception must be thrown in case of renaming nonexistent element!" );
+ return false;
+ }
+ catch( com.sun.star.container.NoSuchElementException ne )
+ {}
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Unexpected excepion in case of try to rename nonexistent element : " + e );
+ return false;
+ }
+
+ // in case of renaming to a name of existent element an exception must be thrown
+ try
+ {
+ xTempStorage.renameElement( "SubStorage1", "SubStorage2" );
+ m_aTestHelper.Error( "An exception must be thrown in case of renaming to the name of existent element!" );
+ return false;
+ }
+ catch( com.sun.star.container.ElementExistException ee )
+ {}
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Unexpected excepion in case of try to rename to the name of existent element : " + e );
+ return false;
+ }
+
+ // in case of copying target storage must be provided
+ try
+ {
+ xTempStorage.copyElementTo( "SubStorage1", null, "SubStorage1" );
+ m_aTestHelper.Error( "An exception must be thrown in case empty reference is provided as target for copying!" );
+ return false;
+ }
+ catch( com.sun.star.lang.IllegalArgumentException iae )
+ {}
+ catch( com.sun.star.uno.Exception ue )
+ {}
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Unexpected excepion in case empty reference is provieded as target for copying : " + e );
+ return false;
+ }
+
+ // in case of moving target storage must be provided
+ try
+ {
+ xTempStorage.moveElementTo( "SubStorage1", null, "SubStorage1" );
+ m_aTestHelper.Error( "An exception must be thrown in case empty reference is provided as target for moving!" );
+ return false;
+ }
+ catch( com.sun.star.lang.IllegalArgumentException iae )
+ {}
+ catch( com.sun.star.uno.Exception ue )
+ {}
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Unexpected excepion in case empty reference is provieded as target for moving : " + e );
+ return false;
+ }
+
+
+ // prepare target for further testings
+
+ // create new temporary storage based on arbitrary medium
+ Object oTargetStorage = m_xStorageFactory.createInstance();
+ XStorage xTargetStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTargetStorage );
+ if ( xTargetStorage == null )
+ {
+ m_aTestHelper.Error( "Can't create temporary storage representation!" );
+ return false;
+ }
+
+ // open a new substorage
+ XStorage xTargetSubStorage = m_aTestHelper.openSubStorage( xTargetStorage,
+ "SubStorage1",
+ ElementModes.ELEMENT_WRITE );
+ if ( xTargetSubStorage == null )
+ {
+ m_aTestHelper.Error( "Can't create substorage!" );
+ return false;
+ }
+
+ // in case of copying of nonexistent element an exception must be thrown
+ try
+ {
+ xTempStorage.copyElementTo( "Nonexistent element", xTargetStorage, "Target" );
+ m_aTestHelper.Error( "An exception must be thrown in case of copying of nonexisting element!" );
+ return false;
+ }
+ catch( com.sun.star.container.NoSuchElementException ne )
+ {}
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Unexpected excepion in case of copying of nonexistent element: " + e );
+ return false;
+ }
+
+ // in case of moving of nonexistent element an exception must be thrown
+ try
+ {
+ xTempStorage.moveElementTo( "Nonexistent element", xTargetStorage, "Target" );
+ m_aTestHelper.Error( "An exception must be thrown in case of moving of nonexisting element!" );
+ return false;
+ }
+ catch( com.sun.star.container.NoSuchElementException ne )
+ {}
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Unexpected excepion in case of moving of nonexistent element: " + e );
+ return false;
+ }
+
+ // in case target for copying already exists an exception must be thrown
+ try
+ {
+ xTempStorage.copyElementTo( "SubStorage1", xTargetStorage, "SubStorage1" );
+ m_aTestHelper.Error( "An exception must be thrown in case target for copying already exists!" );
+ return false;
+ }
+ catch( com.sun.star.container.ElementExistException ee )
+ {}
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Unexpected excepion in case target for copying already exists: " + e );
+ return false;
+ }
+
+ // in case target for moving already exists an exception must be thrown
+ try
+ {
+ xTempStorage.moveElementTo( "SubStorage1", xTargetStorage, "SubStorage1" );
+ m_aTestHelper.Error( "An exception must be thrown in case target for moving already exists!" );
+ return false;
+ }
+ catch( com.sun.star.container.ElementExistException ee )
+ {}
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Unexpected excepion in case target for moving already exists: " + e );
+ return false;
+ }
+
+
+ return true;
+ }
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Exception: " + e );
+ return false;
+ }
+ }
+
+}
+
diff --git a/odk/examples/java/Storage/Test07.java b/odk/examples/java/Storage/Test07.java
new file mode 100644
index 000000000000..25e3fedf4df3
--- /dev/null
+++ b/odk/examples/java/Storage/Test07.java
@@ -0,0 +1,137 @@
+package storagetesting;
+
+import com.sun.star.uno.XInterface;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+
+import com.sun.star.bridge.XUnoUrlResolver;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XInterface;
+
+import com.sun.star.embed.*;
+
+import storagetesting.TestHelper;
+import storagetesting.StorageTest;
+
+public class Test07 implements StorageTest {
+
+ XMultiServiceFactory m_xMSF;
+ XSingleServiceFactory m_xStorageFactory;
+ TestHelper m_aTestHelper;
+
+ public Test07( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory )
+ {
+ m_xMSF = xMSF;
+ m_xStorageFactory = xStorageFactory;
+ m_aTestHelper = new TestHelper( "Test07: " );
+ }
+
+ public boolean test()
+ {
+ try
+ {
+ String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF );
+ if ( sTempFileURL == null || sTempFileURL == "" )
+ {
+ m_aTestHelper.Error( "No valid temporary file was created!" );
+ return false;
+ }
+
+ // create temporary storage based on arbitrary medium
+ // after such a storage is closed it is lost
+ Object oTempStorage = m_xStorageFactory.createInstance();
+ XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
+ if ( xTempStorage == null )
+ {
+ m_aTestHelper.Error( "Can't create temporary storage representation!" );
+ return false;
+ }
+
+ byte pBytes1[] = { 1, 1, 1, 1, 1 };
+ byte pPass1[] = { 1, 2, 3, 4, 5 };
+
+ // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
+ if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempStorage, "SubStream1", "MediaType1", true, pBytes1, pPass1 ) )
+ return false;
+
+ byte pBytes2[] = { 2, 2, 2, 2, 2 };
+ byte pPass2[] = { 5, 4, 3, 2, 1 };
+
+ // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
+ if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempStorage, "SubStream2", "MediaType2", false, pBytes2, pPass2 ) )
+ return false;
+
+ // create temporary storage based on a previously created temporary file
+ Object pArgs[] = new Object[2];
+ pArgs[0] = (Object) sTempFileURL;
+ pArgs[1] = new Integer( ElementModes.ELEMENT_WRITE );
+
+ Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage );
+ if ( xTempFileStorage == null )
+ {
+ m_aTestHelper.Error( "Can't create storage based on temporary file!" );
+ return false;
+ }
+
+ // copy xTempStorage to xTempFileStorage
+ // xTempFileStorage will be automatically commited
+ if ( !m_aTestHelper.copyStorage( xTempStorage, xTempFileStorage ) )
+ return false;
+
+ // dispose used storages to free resources
+ if ( !m_aTestHelper.disposeStorage( xTempStorage ) || !m_aTestHelper.disposeStorage( xTempFileStorage ) )
+ return false;
+
+ // ================================================
+ // now check all the written and copied information
+ // ================================================
+
+ // the temporary file must not be locked any more after storage disposing
+ pArgs[1] = new Integer( ElementModes.ELEMENT_READWRITE );
+ Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage );
+ if ( xResultStorage == null )
+ {
+ m_aTestHelper.Error( "Can't reopen storage based on temporary file!" );
+ return false;
+ }
+
+ Object o2CopyStorage = m_xStorageFactory.createInstance();
+ XStorage x2CopyStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, o2CopyStorage );
+ if ( x2CopyStorage == null )
+ {
+ m_aTestHelper.Error( "Can't create temporary storage representation!" );
+ return false;
+ }
+
+ if ( !m_aTestHelper.copyStorage( xResultStorage, x2CopyStorage ) )
+ return false;
+
+ if ( !m_aTestHelper.checkEncrStream( xResultStorage, "SubStream1", "MediaType1", pBytes1, pPass1 ) )
+ return false;
+
+ if ( !m_aTestHelper.checkEncrStream( xResultStorage, "SubStream2", "MediaType2", pBytes2, pPass2 ) )
+ return false;
+
+ if ( !m_aTestHelper.checkEncrStream( x2CopyStorage, "SubStream1", "MediaType1", pBytes1, pPass1 ) )
+ return false;
+
+ if ( !m_aTestHelper.checkEncrStream( x2CopyStorage, "SubStream2", "MediaType2", pBytes2, pPass2 ) )
+ return false;
+
+ // dispose used storages to free resources
+ if ( !m_aTestHelper.disposeStorage( xResultStorage ) )
+ return false;
+
+ return true;
+ }
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Exception: " + e );
+ return false;
+ }
+ }
+
+}
+
diff --git a/odk/examples/java/Storage/Test08.java b/odk/examples/java/Storage/Test08.java
new file mode 100644
index 000000000000..147f57262992
--- /dev/null
+++ b/odk/examples/java/Storage/Test08.java
@@ -0,0 +1,213 @@
+package storagetesting;
+
+import com.sun.star.uno.XInterface;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+
+import com.sun.star.bridge.XUnoUrlResolver;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XInterface;
+
+import com.sun.star.embed.*;
+
+import storagetesting.TestHelper;
+import storagetesting.StorageTest;
+
+public class Test08 implements StorageTest {
+
+ XMultiServiceFactory m_xMSF;
+ XSingleServiceFactory m_xStorageFactory;
+ TestHelper m_aTestHelper;
+
+ public Test08( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory )
+ {
+ m_xMSF = xMSF;
+ m_xStorageFactory = xStorageFactory;
+ m_aTestHelper = new TestHelper( "Test08: " );
+ }
+
+ public boolean test()
+ {
+ try
+ {
+
+ // create temporary storage based on arbitrary medium
+ // after such a storage is closed it is lost
+ Object oTempStorage = m_xStorageFactory.createInstance();
+ XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
+ if ( xTempStorage == null )
+ {
+ m_aTestHelper.Error( "Can't create temporary storage representation!" );
+ return false;
+ }
+
+ // set the global password for the root storage
+ XEncryptionProtectedSource xTempStorageEncryption =
+ (XEncryptionProtectedSource) UnoRuntime.queryInterface( XEncryptionProtectedSource.class, xTempStorage );
+
+ if ( xTempStorageEncryption == null )
+ {
+ m_aTestHelper.Message( "Optional interface XEncryptionProtectedSource is not implemented, feature can not be tested!" );
+ return true;
+ }
+
+ byte pPass1[] = { 1, 2, 3 };
+ byte pPass2[] = { 3, 2, 1 };
+
+ try {
+ xTempStorageEncryption.setEncryptionKey( pPass1 );
+ }
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Can't set a common encryption key for the storage, exception:" + e );
+ return false;
+ }
+
+ // open a new substorage
+ XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
+ "SubStorage1",
+ ElementModes.ELEMENT_WRITE );
+ if ( xTempSubStorage == null )
+ {
+ m_aTestHelper.Error( "Can't create substorage!" );
+ return false;
+ }
+
+ // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
+ // the stream will be encrypted with common password
+ byte pBytes1[] = { 1, 1, 1, 1, 1 };
+ if ( !m_aTestHelper.WBToSubstrOfEncr( xTempSubStorage, "SubStream1", "MediaType1", true, pBytes1, true ) )
+ return false;
+
+ // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
+ // the stream will not be encrypted
+ byte pBytes2[] = { 2, 2, 2, 2, 2 };
+ if ( !m_aTestHelper.WBToSubstrOfEncr( xTempSubStorage, "SubStream2", "MediaType2", false, pBytes2, false ) )
+ return false;
+
+ // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
+ // the stream will be compressed with own password
+ byte pBytes3[] = { 3, 3, 3, 3, 3 };
+
+ // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
+ // the stream will not be encrypted
+ if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempSubStorage, "SubStream3", "MediaType3", false, pBytes3, pPass2 ) )
+ return false;
+
+ // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
+ if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
+ "MediaType4",
+ true,
+ ElementModes.ELEMENT_READWRITE ) )
+ return false;
+
+ // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
+ if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
+ "MediaType5",
+ false,
+ ElementModes.ELEMENT_WRITE ) )
+ return false;
+
+ // create temporary file
+ String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF );
+ if ( sTempFileURL == null || sTempFileURL == "" )
+ {
+ m_aTestHelper.Error( "No valid temporary file was created!" );
+ return false;
+ }
+
+ // create temporary storage based on a previously created temporary file
+ Object pArgs[] = new Object[2];
+ pArgs[0] = (Object) sTempFileURL;
+ pArgs[1] = new Integer( ElementModes.ELEMENT_WRITE );
+
+ Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage );
+ if ( xTempFileStorage == null )
+ {
+ m_aTestHelper.Error( "Can't create storage based on temporary file!" );
+ return false;
+ }
+
+ // copy xTempStorage to xTempFileStorage
+ // xTempFileStorage will be automatically commited
+ if ( !m_aTestHelper.copyStorage( xTempStorage, xTempFileStorage ) )
+ return false;
+
+ // dispose used storages to free resources
+ if ( !m_aTestHelper.disposeStorage( xTempStorage ) || !m_aTestHelper.disposeStorage( xTempFileStorage ) )
+ return false;
+
+ // ================================================
+ // now check all the written and copied information
+ // ================================================
+
+ // the temporary file must not be locked any more after storage disposing
+ pArgs[1] = new Integer( ElementModes.ELEMENT_READ );
+ Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage );
+ if ( xResultStorage == null )
+ {
+ m_aTestHelper.Error( "Can't reopen storage based on temporary file!" );
+ return false;
+ }
+
+ if ( !m_aTestHelper.checkStorageProperties( xResultStorage, "MediaType4", true, ElementModes.ELEMENT_READ ) )
+ return false;
+
+ // open existing substorage
+ XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage,
+ "SubStorage1",
+ ElementModes.ELEMENT_READ );
+ if ( xResultSubStorage == null )
+ {
+ m_aTestHelper.Error( "Can't open existing substorage!" );
+ return false;
+ }
+
+ if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, "MediaType5", false, ElementModes.ELEMENT_READ ) )
+ return false;
+
+ // set the global password for the root storage
+ XEncryptionProtectedSource xResultStorageEncryption =
+ (XEncryptionProtectedSource) UnoRuntime.queryInterface( XEncryptionProtectedSource.class, xResultStorage );
+
+ if ( xResultStorageEncryption == null )
+ {
+ m_aTestHelper.Error( "XEncryptionProtectedSource was successfully used already, so it must be supported!" );
+ return false;
+ }
+
+ try {
+ xResultStorageEncryption.setEncryptionKey( pPass2 );
+ }
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Can't set a common encryption key for the storage, exception:" + e );
+ return false;
+ }
+
+ if ( !m_aTestHelper.checkEncrStream( xResultSubStorage, "SubStream1", "MediaType1", pBytes1, pPass1 ) )
+ return false;
+
+ if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream2", "MediaType2", pBytes2 ) )
+ return false;
+
+ // the common root storage password should allow to open this stream
+ if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream3", "MediaType3", pBytes3 ) )
+ return false;
+
+ // dispose used storages to free resources
+ if ( !m_aTestHelper.disposeStorage( xResultStorage ) )
+ return false;
+
+ return true;
+ }
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Exception: " + e );
+ return false;
+ }
+ }
+}
+
diff --git a/odk/examples/java/Storage/Test09.java b/odk/examples/java/Storage/Test09.java
new file mode 100644
index 000000000000..f4ae8ee879f3
--- /dev/null
+++ b/odk/examples/java/Storage/Test09.java
@@ -0,0 +1,123 @@
+package storagetesting;
+
+import com.sun.star.uno.XInterface;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+
+import com.sun.star.bridge.XUnoUrlResolver;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XInterface;
+
+import com.sun.star.embed.*;
+
+import storagetesting.TestHelper;
+import storagetesting.StorageTest;
+
+public class Test09 implements StorageTest {
+
+ XMultiServiceFactory m_xMSF;
+ XSingleServiceFactory m_xStorageFactory;
+ TestHelper m_aTestHelper;
+
+ public Test09( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory )
+ {
+ m_xMSF = xMSF;
+ m_xStorageFactory = xStorageFactory;
+ m_aTestHelper = new TestHelper( "Test09: " );
+ }
+
+ public boolean test()
+ {
+ try
+ {
+
+ // create temporary storage based on arbitrary medium
+ // after such a storage is closed it is lost
+ Object oTempStorage = m_xStorageFactory.createInstance();
+ XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
+ if ( xTempStorage == null )
+ {
+ m_aTestHelper.Error( "Can't create temporary storage representation!" );
+ return false;
+ }
+
+ byte pPass1[] = { 1, 2, 3 };
+ byte pPass2[] = { 3, 2, 1 };
+ byte pBytes[] = { 1, 1, 1, 1, 1 };
+
+ // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
+ // the stream will not be encrypted
+ if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempStorage, "SubStream1", "MediaType1", false, pBytes, pPass1 ) )
+ return false;
+
+ // create temporary file
+ String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF );
+ if ( sTempFileURL == null || sTempFileURL == "" )
+ {
+ m_aTestHelper.Error( "No valid temporary file was created!" );
+ return false;
+ }
+
+ // create temporary storage based on a previously created temporary file
+ Object pArgs[] = new Object[2];
+ pArgs[0] = (Object) sTempFileURL;
+ pArgs[1] = new Integer( ElementModes.ELEMENT_WRITE );
+
+ Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage );
+ if ( xTempFileStorage == null )
+ {
+ m_aTestHelper.Error( "Can't create storage based on temporary file!" );
+ return false;
+ }
+
+ // copy xTempStorage to xTempFileStorage
+ // xTempFileStorage will be automatically commited
+ if ( !m_aTestHelper.copyStorage( xTempStorage, xTempFileStorage ) )
+ return false;
+
+ // change password of the substream of new storage based on file
+ int nResult = m_aTestHelper.ChangeStreamPass( xTempFileStorage, "SubStream1", pPass1, pPass2 );
+ if ( nResult == 0 )
+ return false; // test failed
+ else if ( nResult == -1 )
+ return true; // tested optional feature is not supported
+
+ if ( !m_aTestHelper.commitStorage( xTempFileStorage ) )
+ return false;
+
+ // dispose used storages to free resources
+ if ( !m_aTestHelper.disposeStorage( xTempStorage ) || !m_aTestHelper.disposeStorage( xTempFileStorage ) )
+ return false;
+
+ // ================================================
+ // now check all the written and copied information
+ // ================================================
+
+ // the temporary file must not be locked any more after storage disposing
+ pArgs[1] = new Integer( ElementModes.ELEMENT_READ );
+ Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage );
+ if ( xResultStorage == null )
+ {
+ m_aTestHelper.Error( "Can't reopen storage based on temporary file!" );
+ return false;
+ }
+
+ if ( !m_aTestHelper.checkEncrStream( xResultStorage, "SubStream1", "MediaType1", pBytes, pPass2 ) )
+ return false;
+
+ // dispose used storages to free resources
+ if ( !m_aTestHelper.disposeStorage( xResultStorage ) )
+ return false;
+
+ return true;
+ }
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Exception: " + e );
+ return false;
+ }
+ }
+}
+
diff --git a/odk/examples/java/Storage/TestHelper.java b/odk/examples/java/Storage/TestHelper.java
new file mode 100644
index 000000000000..2868de481f81
--- /dev/null
+++ b/odk/examples/java/Storage/TestHelper.java
@@ -0,0 +1,864 @@
+package storagetesting;
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XInterface;
+import com.sun.star.uno.AnyConverter;
+
+import com.sun.star.lang.*;
+import com.sun.star.embed.*;
+import com.sun.star.packages.*;
+import com.sun.star.io.*;
+import com.sun.star.beans.*;
+
+public class TestHelper {
+
+ String m_sTestPrefix;
+
+ public TestHelper( String sTestPrefix )
+ {
+ m_sTestPrefix = sTestPrefix;
+ }
+
+ public boolean WriteBytesToStream( XStream xStream,
+ String sStreamName,
+ String sMediaType,
+ boolean bCompressed,
+ byte[] pBytes )
+ {
+ // get output stream of substream
+ XOutputStream xOutput = xStream.getOutputStream();
+ if ( xOutput == null )
+ {
+ Error( "Can't get XOutputStream implementation from substream '" + sStreamName + "'!" );
+ return false;
+ }
+
+ // get XTrucate implementation from output stream
+ XTruncate xTruncate = (XTruncate) UnoRuntime.queryInterface( XTruncate.class, xOutput );
+ if ( xTruncate == null )
+ {
+ Error( "Can't get XTruncate implementation from substream '" + sStreamName + "'!" );
+ return false;
+ }
+
+ // write requested byte sequence
+ try
+ {
+ xTruncate.truncate();
+ xOutput.writeBytes( pBytes );
+ }
+ catch( Exception e )
+ {
+ Error( "Can't write to stream '" + sStreamName + "', exception: " + e );
+ return false;
+ }
+
+ // get access to the XPropertySet interface
+ XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStream );
+ if ( xPropSet == null )
+ {
+ Error( "Can't get XPropertySet implementation from substream '" + sStreamName + "'!" );
+ return false;
+ }
+
+ // set properties to the stream
+ try
+ {
+ xPropSet.setPropertyValue( "MediaType", sMediaType );
+ xPropSet.setPropertyValue( "Compressed", new Boolean( bCompressed ) );
+ }
+ catch( Exception e )
+ {
+ Error( "Can't set properties to substream '" + sStreamName + "', exception: " + e );
+ return false;
+ }
+
+ // check size property of the stream
+ try
+ {
+ int nSize = AnyConverter.toInt( xPropSet.getPropertyValue( "Size" ) );
+ if ( nSize != pBytes.length )
+ {
+ Error( "The 'Size' property of substream '" + sStreamName + "' contains wrong value!" );
+ return false;
+ }
+ }
+ catch( Exception e )
+ {
+ Error( "Can't get 'Size' property from substream '" + sStreamName + "', exception: " + e );
+ return false;
+ }
+
+ // free the stream resources, garbage collector may remove the object too late
+ XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, xStream );
+ if ( xComponent == null )
+ {
+ Error( "Can't get XComponent implementation from substream '" + sStreamName + "'!" );
+ return false;
+ }
+ xComponent.dispose();
+
+ return true;
+ }
+
+
+ public boolean WriteBytesToSubstream( XStorage xStorage,
+ String sStreamName,
+ String sMediaType,
+ boolean bCompressed,
+ byte[] pBytes )
+ {
+ // open substream element
+ XStream xSubStream = null;
+ try
+ {
+ Object oSubStream = xStorage.openStreamElement( sStreamName, ElementModes.ELEMENT_WRITE );
+ xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream );
+ if ( xSubStream == null )
+ {
+ Error( "Can't create substream '" + sStreamName + "'!" );
+ return false;
+ }
+ }
+ catch( Exception e )
+ {
+ Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" );
+ return false;
+ }
+
+ return WriteBytesToStream( xSubStream, sStreamName, sMediaType, bCompressed, pBytes );
+ }
+
+ public boolean WriteBytesToEncrSubstream( XStorage xStorage,
+ String sStreamName,
+ String sMediaType,
+ boolean bCompressed,
+ byte[] pBytes,
+ byte[] pPass )
+ {
+ // open substream element
+ XStream xSubStream = null;
+ try
+ {
+ Object oSubStream = xStorage.openEncryptedStreamElement( sStreamName, ElementModes.ELEMENT_WRITE, pPass );
+ xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream );
+ if ( xSubStream == null )
+ {
+ Error( "Can't create substream '" + sStreamName + "'!" );
+ return false;
+ }
+ }
+ catch( Exception e )
+ {
+ Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" );
+ return false;
+ }
+
+ return WriteBytesToStream( xSubStream, sStreamName, sMediaType, bCompressed, pBytes );
+ }
+
+ public boolean WBToSubstrOfEncr( XStorage xStorage,
+ String sStreamName,
+ String sMediaType,
+ boolean bCompressed,
+ byte[] pBytes,
+ boolean bEncrypted )
+ {
+ // open substream element
+ XStream xSubStream = null;
+ try
+ {
+ Object oSubStream = xStorage.openStreamElement( sStreamName, ElementModes.ELEMENT_WRITE );
+ xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream );
+ if ( xSubStream == null )
+ {
+ Error( "Can't create substream '" + sStreamName + "'!" );
+ return false;
+ }
+ }
+ catch( Exception e )
+ {
+ Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" );
+ return false;
+ }
+
+ // get access to the XPropertySet interface
+ XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xSubStream );
+ if ( xPropSet == null )
+ {
+ Error( "Can't get XPropertySet implementation from substream '" + sStreamName + "'!" );
+ return false;
+ }
+
+ // set properties to the stream
+ try
+ {
+ xPropSet.setPropertyValue( "Encrypted", new Boolean( bEncrypted ) );
+ }
+ catch( Exception e )
+ {
+ Error( "Can't set 'Encrypted' property to substream '" + sStreamName + "', exception: " + e );
+ return false;
+ }
+
+ return WriteBytesToStream( xSubStream, sStreamName, sMediaType, bCompressed, pBytes );
+ }
+
+ public int ChangeStreamPass( XStorage xStorage,
+ String sStreamName,
+ byte[] pOldPass,
+ byte[] pNewPass )
+ {
+ // open substream element
+ XStream xSubStream = null;
+ try
+ {
+ Object oSubStream = xStorage.openEncryptedStreamElement( sStreamName, ElementModes.ELEMENT_WRITE, pOldPass );
+ xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream );
+ if ( xSubStream == null )
+ {
+ Error( "Can't open substream '" + sStreamName + "'!" );
+ return 0;
+ }
+ }
+ catch( Exception e )
+ {
+ Error( "Can't open substream '" + sStreamName + "', exception : " + e + "!" );
+ return 0;
+ }
+
+
+ // change the password for the stream
+ XEncryptionProtectedSource xStreamEncryption =
+ (XEncryptionProtectedSource) UnoRuntime.queryInterface( XEncryptionProtectedSource.class, xSubStream );
+
+ if ( xStreamEncryption == null )
+ {
+ Message( "Optional interface XEncryptionProtectedSource is not implemented, feature can not be tested!" );
+ return -1;
+ }
+
+ try {
+ xStreamEncryption.setEncryptionKey( pNewPass );
+ }
+ catch( Exception e )
+ {
+ Error( "Can't change encryption key of the substream '" + sStreamName + "', exception:" + e );
+ return 0;
+ }
+
+ // free the stream resources, garbage collector may remove the object too late
+ XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, xSubStream );
+ if ( xComponent == null )
+ {
+ Error( "Can't get XComponent implementation from substream '" + sStreamName + "'!" );
+ return 0;
+ }
+ xComponent.dispose();
+
+ return 1;
+ }
+
+ public boolean setStorageTypeAndCheckProps( XStorage xStorage, String sMediaType, boolean bIsRoot, int nMode )
+ {
+ boolean bOk = false;
+
+ // get access to the XPropertySet interface
+ XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStorage );
+ if ( xPropSet != null )
+ {
+ try
+ {
+ // set "MediaType" property to the stream
+ xPropSet.setPropertyValue( "MediaType", sMediaType );
+
+ // get "IsRoot" and "OpenMode" properties and control there values
+ boolean bPropIsRoot = AnyConverter.toBoolean( xPropSet.getPropertyValue( "IsRoot" ) );
+ int nPropMode = AnyConverter.toInt( xPropSet.getPropertyValue( "OpenMode" ) );
+
+ bOk = true;
+ if ( bPropIsRoot != bIsRoot )
+ {
+ Error( "'IsRoot' property contains wrong value!" );
+ bOk = false;
+ }
+
+ if ( ( bIsRoot && ( nPropMode | ElementModes.ELEMENT_READ ) != ( nMode | ElementModes.ELEMENT_READ ) )
+ || ( !bIsRoot && ( nPropMode & nMode ) != nMode ) )
+ {
+ Error( "'OpenMode' property contains wrong value!" );
+ bOk = false;
+ }
+ }
+ catch( Exception e )
+ {
+ Error( "Can't control properties of substorage, exception: " + e );
+ }
+ }
+ else
+ {
+ Error( "Can't get XPropertySet implementation from storage!" );
+ }
+
+ return bOk;
+ }
+
+ public boolean checkStorageProperties( XStorage xStorage, String sMediaType, boolean bIsRoot, int nMode )
+ {
+ boolean bOk = false;
+
+ // get access to the XPropertySet interface
+ XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStorage );
+ if ( xPropSet != null )
+ {
+ try
+ {
+ // get "MediaType", "IsRoot" and "OpenMode" properties and control there values
+ String sPropMediaType = AnyConverter.toString( xPropSet.getPropertyValue( "MediaType" ) );
+ boolean bPropIsRoot = AnyConverter.toBoolean( xPropSet.getPropertyValue( "IsRoot" ) );
+ int nPropMode = AnyConverter.toInt( xPropSet.getPropertyValue( "OpenMode" ) );
+
+ bOk = true;
+ if ( !sPropMediaType.equals( sMediaType ) )
+ {
+ Error( "'MediaType' property contains wrong value, expected '"
+ + sMediaType + "', set '" + sPropMediaType + "' !" );
+ bOk = false;
+ }
+
+ if ( bPropIsRoot != bIsRoot )
+ {
+ Error( "'IsRoot' property contains wrong value!" );
+ bOk = false;
+ }
+
+ if ( ( bIsRoot && ( nPropMode | ElementModes.ELEMENT_READ ) != ( nMode | ElementModes.ELEMENT_READ ) )
+ || ( !bIsRoot && ( nPropMode & nMode ) != nMode ) )
+ {
+ Error( "'OpenMode' property contains wrong value!" );
+ bOk = false;
+ }
+ }
+ catch( Exception e )
+ {
+ Error( "Can't get properties of substorage, exception: " + e );
+ }
+ }
+ else
+ {
+ Error( "Can't get XPropertySet implementation from storage!" );
+ }
+
+ return bOk;
+ }
+
+ public boolean InternalCheckStream( XStream xStream,
+ String sName,
+ String sMediaType,
+ byte[] pBytes )
+ {
+ // get input stream of substream
+ XInputStream xInput = xStream.getInputStream();
+ if ( xInput == null )
+ {
+ Error( "Can't get XInputStream implementation from substream '" + sName + "'!" );
+ return false;
+ }
+
+ byte pContents[][] = new byte[1][]; // ???
+
+ // read contents
+ try
+ {
+ xInput.readBytes( pContents, pBytes.length + 1 );
+ }
+ catch( Exception e )
+ {
+ Error( "Can't read from stream '" + sName + "', exception: " + e );
+ return false;
+ }
+
+ // check size of stream data
+ if ( pContents.length == 0 )
+ {
+ Error( "SubStream '" + sName + "' reading produced disaster!" );
+ return false;
+ }
+
+ if ( pBytes.length != pContents[0].length )
+ {
+ Error( "SubStream '" + sName + "' contains wrong amount of data! (" + pContents[0].length + "/" + pBytes.length + ")" );
+ return false;
+ }
+
+ // check stream data
+ for ( int ind = 0; ind < pBytes.length; ind++ )
+ {
+ if ( pBytes[ind] != pContents[0][ind] )
+ {
+ Error( "SubStream '" + sName + "' contains wrong data!" );
+ return false;
+ }
+ }
+
+
+ // check properties
+ boolean bOk = false;
+
+ // get access to the XPropertySet interface
+ XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStream );
+ if ( xPropSet != null )
+ {
+ try
+ {
+ // get "MediaType" and "Size" properties and control there values
+ String sPropMediaType = AnyConverter.toString( xPropSet.getPropertyValue( "MediaType" ) );
+ int nPropSize = AnyConverter.toInt( xPropSet.getPropertyValue( "Size" ) );
+
+ bOk = true;
+ if ( !sPropMediaType.equals( sMediaType ) )
+ {
+ Error( "'MediaType' property contains wrong value for stream '" + sName + "',\nexpected: '"
+ + sMediaType + "', set: '" + sPropMediaType + "'!" );
+ bOk = false;
+ }
+
+ if ( nPropSize != pBytes.length )
+ {
+ Error( "'Size' property contains wrong value for stream'" + sName + "'!" );
+ bOk = false;
+ }
+ }
+ catch( Exception e )
+ {
+ Error( "Can't get properties of substream '" + sName + "', exception: " + e );
+ }
+ }
+ else
+ {
+ Error( "Can't get XPropertySet implementation from stream '" + sName + "'!" );
+ }
+
+ return bOk;
+ }
+
+ public boolean checkStream( XStorage xParentStorage,
+ String sName,
+ String sMediaType,
+ byte[] pBytes )
+ {
+ // open substream element first
+ XStream xSubStream = null;
+ try
+ {
+ Object oSubStream = xParentStorage.openStreamElement( sName, ElementModes.ELEMENT_READ );
+ xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream );
+ if ( xSubStream == null )
+ {
+ Error( "Can't open substream '" + sName + "'!" );
+ return false;
+ }
+ }
+ catch( Exception e )
+ {
+ Error( "Can't open substream '" + sName + "', exception : " + e + "!" );
+ return false;
+ }
+
+ return InternalCheckStream( xSubStream, sName, sMediaType, pBytes );
+ }
+
+ public boolean checkEncrStream( XStorage xParentStorage,
+ String sName,
+ String sMediaType,
+ byte[] pBytes,
+ byte[] pPass )
+ {
+ // Important: a common password for any of parent storage should not be set or
+ // should be different from pPass
+
+ if ( pPass.length == 0 )
+ {
+ Error( "Wrong password is used in the test!" );
+ return false;
+ }
+
+ try
+ {
+ Object oSubStream = xParentStorage.openStreamElement( sName, ElementModes.ELEMENT_READ );
+ Error( "Encrypted stream '" + sName + "' was opened without password!" );
+ return false;
+ }
+ catch( WrongPasswordException wpe )
+ {}
+ catch( Exception e )
+ {
+ Error( "Unexpected exception in case of opening of encrypted stream '" + sName + "' without password: " + e + "!" );
+ return false;
+ }
+
+ byte pWrongPass[] = { 1, 1 };
+ pWrongPass[0] += pPass[0];
+ try
+ {
+ Object oSubStream = xParentStorage.openEncryptedStreamElement( sName, ElementModes.ELEMENT_READ, pWrongPass );
+ Error( "Encrypted stream '" + sName + "' was opened with wrong password!" );
+ return false;
+ }
+ catch( WrongPasswordException wpe )
+ {}
+ catch( Exception e )
+ {
+ Error( "Unexpected exception in case of opening of encrypted stream '" + sName + "' with wrong password: " + e + "!" );
+ return false;
+ }
+
+ XStream xSubStream = null;
+ try
+ {
+ Object oSubStream = xParentStorage.openEncryptedStreamElement( sName, ElementModes.ELEMENT_READ, pPass );
+ xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream );
+ if ( xSubStream == null )
+ {
+ Error( "Can't open encrypted substream '" + sName + "'!" );
+ return false;
+ }
+ }
+ catch( Exception e )
+ {
+ Error( "Can't open encrypted substream '" + sName + "', exception : " + e + "!" );
+ return false;
+ }
+
+ return InternalCheckStream( xSubStream, sName, sMediaType, pBytes );
+ }
+
+ public boolean copyStorage( XStorage xSourceStorage, XStorage xDestStorage )
+ {
+ // copy xSourceStorage to xDestStorage
+ try
+ {
+ xSourceStorage.copyToStorage( xDestStorage );
+ }
+ catch( Exception e )
+ {
+ Error( "Storage copying failed, exception: " + e );
+ return false;
+ }
+
+ return true;
+ }
+
+ public boolean commitStorage( XStorage xStorage )
+ {
+ // XTransactedObject must be supported by storages
+ XTransactedObject xTransact = (XTransactedObject) UnoRuntime.queryInterface( XTransactedObject.class, xStorage );
+ if ( xTransact == null )
+ {
+ Error( "Storage doesn't implement transacted access!" );
+ return false;
+ }
+
+ try
+ {
+ xTransact.commit();
+ }
+ catch( Exception e )
+ {
+ Error( "Storage commit failed, exception:" + e );
+ return false;
+ }
+
+ return true;
+ }
+
+ public boolean disposeStorage( XStorage xStorage )
+ {
+ // dispose the storage
+ XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, xStorage );
+ if ( xComponent == null )
+ {
+ Error( "Can't retrieve XComponent implementation from storage!" );
+ return false;
+ }
+
+ try
+ {
+ xComponent.dispose();
+ }
+ catch( Exception e )
+ {
+ Error( "Storage disposing failed!" );
+ return false;
+ }
+
+ return true;
+ }
+
+ public XInputStream getInputStream( XStream xStream )
+ {
+ XInputStream xInTemp = null;
+ try
+ {
+ xInTemp = xStream.getInputStream();
+ if ( xInTemp == null )
+ Error( "Can't get the input part of a stream!" );
+ }
+ catch ( Exception e )
+ {
+ Error( "Can't get the input part of a stream, exception :" + e );
+ }
+
+ return xInTemp;
+ }
+
+ public boolean closeOutput( XStream xStream )
+ {
+ XOutputStream xOutTemp = null;
+ try
+ {
+ xOutTemp = xStream.getOutputStream();
+ if ( xOutTemp == null )
+ {
+ Error( "Can't get the output part of a stream!" );
+ return false;
+ }
+ }
+ catch ( Exception e )
+ {
+ Error( "Can't get the output part of a stream, exception :" + e );
+ return false;
+ }
+
+ try
+ {
+ xOutTemp.closeOutput();
+ }
+ catch ( Exception e )
+ {
+ Error( "Can't close output part of a stream, exception :" + e );
+ return false;
+ }
+
+ return true;
+ }
+
+ public XStorage openSubStorage( XStorage xStorage, String sName, int nMode )
+ {
+ // open existing substorage
+ try
+ {
+ Object oSubStorage = xStorage.openStorageElement( sName, nMode );
+ XStorage xSubStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oSubStorage );
+ return xSubStorage;
+ }
+ catch( Exception e )
+ {
+ Error( "Can't open substorage '" + sName + "', exception: " + e );
+ }
+
+ return null;
+ }
+
+ public XStream CreateTempFileStream( XMultiServiceFactory xMSF )
+ {
+ // try to get temporary file representation
+ XStream xTempFileStream = null;
+ try
+ {
+ Object oTempFile = xMSF.createInstance( "com.sun.star.io.TempFile" );
+ xTempFileStream = (XStream)UnoRuntime.queryInterface( XStream.class, oTempFile );
+ }
+ catch( Exception e )
+ {}
+
+ if ( xTempFileStream == null )
+ Error( "Can't create temporary file!" );
+
+ return xTempFileStream;
+ }
+
+ public String CreateTempFile( XMultiServiceFactory xMSF )
+ {
+ String sResult = null;
+
+ // try to get temporary file representation
+ XPropertySet xTempFileProps = null;
+ try
+ {
+ Object oTempFile = xMSF.createInstance( "com.sun.star.io.TempFile" );
+ xTempFileProps = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, oTempFile );
+ }
+ catch( Exception e )
+ {}
+
+ if ( xTempFileProps != null )
+ {
+ try
+ {
+ xTempFileProps.setPropertyValue( "RemoveFile", new Boolean( false ) );
+ sResult = AnyConverter.toString( xTempFileProps.getPropertyValue( "Uri" ) );
+ }
+ catch( Exception e )
+ {
+ Error( "Can't control TempFile properties, exception: " + e );
+ }
+ }
+ else
+ {
+ Error( "Can't create temporary file representation!" );
+ }
+
+ // close temporary file explicitly
+ try
+ {
+ XStream xStream = (XStream)UnoRuntime.queryInterface( XStream.class, xTempFileProps );
+ if ( xStream != null )
+ {
+ XOutputStream xOut = xStream.getOutputStream();
+ if ( xOut != null )
+ xOut.closeOutput();
+
+ XInputStream xIn = xStream.getInputStream();
+ if ( xIn != null )
+ xIn.closeInput();
+ }
+ else
+ Error( "Can't close TempFile!" );
+ }
+ catch( Exception e )
+ {
+ Error( "Can't close TempFile, exception: " + e );
+ }
+
+ return sResult;
+ }
+
+ public boolean copyElementTo( XStorage xSource, String sName, XStorage xDest )
+ {
+ // copy element with name sName from xSource to xDest
+ try
+ {
+ xSource.copyElementTo( sName, xDest, sName );
+ }
+ catch( Exception e )
+ {
+ Error( "Element copying failed, exception: " + e );
+ return false;
+ }
+
+ return true;
+ }
+
+ public boolean moveElementTo( XStorage xSource, String sName, XStorage xDest )
+ {
+ // move element with name sName from xSource to xDest
+ try
+ {
+ xSource.moveElementTo( sName, xDest, sName );
+ }
+ catch( Exception e )
+ {
+ Error( "Element moving failed, exception: " + e );
+ return false;
+ }
+
+ return true;
+ }
+
+ public boolean renameElement( XStorage xStorage, String sOldName, String sNewName )
+ {
+ // rename element with name sOldName to sNewName
+ try
+ {
+ xStorage.renameElement( sOldName, sNewName );
+ }
+ catch( Exception e )
+ {
+ Error( "Element renaming failed, exception: " + e );
+ return false;
+ }
+
+ return true;
+ }
+
+ public boolean removeElement( XStorage xStorage, String sName )
+ {
+ // remove element with name sName
+ try
+ {
+ xStorage.removeElement( sName );
+ }
+ catch( Exception e )
+ {
+ Error( "Element removing failed, exception: " + e );
+ return false;
+ }
+
+ return true;
+ }
+
+ public XStream OpenStream( XStorage xStorage,
+ String sStreamName,
+ int nMode )
+ {
+ // open substream element
+ XStream xSubStream = null;
+ try
+ {
+ Object oSubStream = xStorage.openStreamElement( sStreamName, nMode );
+ xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream );
+ if ( xSubStream == null )
+ Error( "Can't create substream '" + sStreamName + "'!" );
+ }
+ catch( Exception e )
+ {
+ Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" );
+ }
+
+ return xSubStream;
+ }
+
+ public boolean cantOpenStorage( XStorage xStorage, String sName )
+ {
+ // try to open an opened substorage, open call must fail
+ try
+ {
+ Object oDummyStorage = xStorage.openStorageElement( sName, ElementModes.ELEMENT_READ );
+ Error( "The trying to reopen opened substorage '" + sName + "' must fail!" );
+ }
+ catch( Exception e )
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ public boolean cantOpenStream( XStorage xStorage, String sName, int nMode )
+ {
+ // try to open the substream with specified mode must fail
+ try
+ {
+ Object oDummyStream = xStorage.openStreamElement( sName, nMode );
+ Error( "The trying to open substoream '" + sName + "' must fail!" );
+ }
+ catch( Exception e )
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ public void Error( String sError )
+ {
+ System.out.println( m_sTestPrefix + "Error: " + sError );
+ }
+
+ public void Message( String sError )
+ {
+ System.out.println( m_sTestPrefix + sError );
+ }
+}
+
diff --git a/odk/examples/java/Text/BookmarkInsertion.java b/odk/examples/java/Text/BookmarkInsertion.java
new file mode 100644
index 000000000000..03c9cb24340d
--- /dev/null
+++ b/odk/examples/java/Text/BookmarkInsertion.java
@@ -0,0 +1,284 @@
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+
+//***************************************************************************
+// comment: Step 1: get the Desktop object from the office
+// Step 2: open an empty text document
+// Step 3: enter a example text
+// Step 4: insert some bookmarks
+//
+// Chapter 5.1.1.4 Inserting bookmarks
+//***************************************************************************
+
+import com.sun.star.uno.UnoRuntime;
+
+public class BookmarkInsertion {
+
+ public static void main(String args[]) {
+ // You need the desktop to create a document
+ // The getDesktop method does the UNO bootstrapping, gets the
+ // remote servie manager and the desktop object.
+ com.sun.star.frame.XDesktop xDesktop = null;
+ xDesktop = getDesktop();
+
+ // create text document
+ com.sun.star.text.XTextDocument xTextDocument = null;
+ xTextDocument = createTextdocument(xDesktop);
+
+ // put example text in document
+ createExampleData(xTextDocument);
+
+
+ String mOffending[] = { "negro(e|es)?","bor(ed|ing)?",
+ "bloody?", "bleed(ing)?" };
+ String mBad[] = { "possib(le|ilit(y|ies))", "real(ly)+", "brilliant" };
+
+ String sOffendPrefix = "Offending";
+ String sBadPrefix = "BadStyle";
+
+ markList(xTextDocument, mOffending, sOffendPrefix);
+ markList(xTextDocument, mBad, sBadPrefix);
+
+ System.out.println("Done");
+
+ System.exit(0);
+ }
+
+ public static void markList(com.sun.star.text.XTextDocument xTextDocument,
+ String mList[], String sPrefix) {
+ int iCounter=0;
+ com.sun.star.uno.XInterface xSearchInterface = null;
+ com.sun.star.text.XTextRange xSearchTextRange = null;
+
+ try {
+ for( iCounter = 0; iCounter < mList.length; iCounter++ ) {
+ // the findfirst returns a XInterface
+ xSearchInterface = (com.sun.star.uno.XInterface)FindFirst(
+ xTextDocument, mList[ iCounter ] );
+
+ if( xSearchInterface != null ) {
+ // get the TextRange form the XInterface
+ xSearchTextRange = (com.sun.star.text.XTextRange)
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XTextRange.class, xSearchInterface);
+
+ InsertBookmark(xTextDocument, xSearchTextRange,
+ sPrefix + iCounter);
+ }
+ }
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+ }
+
+
+ public static void InsertBookmark(com.sun.star.text.XTextDocument xTextDocument,
+ com.sun.star.text.XTextRange xTextRange,
+ String sBookName) {
+ // create a bookmark on a TextRange
+ try {
+ // get the MultiServiceFactory from the text document
+ com.sun.star.lang.XMultiServiceFactory xDocMSF;
+ xDocMSF = (com.sun.star.lang.XMultiServiceFactory)
+ UnoRuntime.queryInterface(
+ com.sun.star.lang.XMultiServiceFactory.class, xTextDocument);
+
+ // the bookmark service is a context dependend service, you need
+ // the MultiServiceFactory from the document
+ Object xObject = xDocMSF.createInstance("com.sun.star.text.Bookmark");
+
+ // set the name from the bookmark
+ com.sun.star.container.XNamed xNameAccess = null;
+ xNameAccess = (com.sun.star.container.XNamed)
+ UnoRuntime.queryInterface(
+ com.sun.star.container.XNamed.class, xObject);
+
+ xNameAccess.setName(sBookName);
+
+ // create a XTextContent, for the method 'insertTextContent'
+ com.sun.star.text.XTextContent xTextContent = null;
+ xTextContent = (com.sun.star.text.XTextContent)
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XTextContent.class, xNameAccess);
+
+ // insertTextContent need a TextRange not a cursor to specify the
+ // position from the bookmark
+ xTextDocument.getText().insertTextContent(xTextRange, xTextContent, true);
+
+ System.out.println("Insert bookmark: " + sBookName);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+ }
+
+ protected static com.sun.star.uno.XInterface FindFirst(
+ com.sun.star.text.XTextDocument xTextDocument, String sSearchString)
+ {
+ com.sun.star.util.XSearchDescriptor xSearchDescriptor = null;
+ com.sun.star.util.XSearchable xSearchable = null;
+ com.sun.star.uno.XInterface xSearchInterface = null;
+
+ try {
+ xSearchable = (com.sun.star.util.XSearchable)
+ UnoRuntime.queryInterface(
+ com.sun.star.util.XSearchable.class, xTextDocument);
+ xSearchDescriptor = (com.sun.star.util.XSearchDescriptor)
+ xSearchable.createSearchDescriptor();
+
+ xSearchDescriptor.setSearchString(sSearchString);
+
+ com.sun.star.beans.XPropertySet xPropertySet = null;
+ xPropertySet = (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xSearchDescriptor);
+
+ xPropertySet.setPropertyValue("SearchRegularExpression",
+ new Boolean( true ) );
+
+ xSearchInterface = (com.sun.star.uno.XInterface)
+ xSearchable.findFirst(xSearchDescriptor);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return xSearchInterface;
+ }
+
+ protected static void createExampleData(
+ com.sun.star.text.XTextDocument xTextDocument )
+ {
+ com.sun.star.text.XTextCursor xTextCursor = null;
+
+ try {
+ xTextCursor = (com.sun.star.text.XTextCursor)
+ xTextDocument.getText().createTextCursor();
+
+ xTextCursor.setString( "He heard quiet steps behind him. That didn't bode well. Who could be following him this late at night and in this deadbeat part of town? And at this particular moment, just after he pulled off the big time and was making off with the greenbacks. Was there another crook who'd had the same idea, and was now watching him and waiting for a chance to grab the fruit of his labor?" );
+ xTextCursor.collapseToEnd();
+ xTextCursor.setString( "Or did the steps behind him mean that one of many bloody officers in town was on to him and just waiting to pounce and snap those cuffs on his wrists? He nervously looked all around. Suddenly he saw the alley. Like lightening he darted off to the left and disappeared between the two warehouses almost falling over the trash can lying in the middle of the sidewalk. He tried to nervously tap his way along in the inky darkness and suddenly stiffened: it was a dead-end, he would have to go back the way he had come" );
+ xTextCursor.collapseToEnd();
+ xTextCursor.setString( "The steps got louder and louder, he saw the black outline of a figure coming around the corner. Is this the end of the line? he thought pressing himself back against the wall trying to make himself invisible in the dark, was all that planning and energy wasted? He was dripping with sweat now, cold and wet, he could smell the brilliant fear coming off his clothes. Suddenly next to him, with a barely noticeable squeak, a door swung quietly to and fro in the night's breeze." );
+
+ xTextCursor.gotoStart(false);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ }
+
+ public static com.sun.star.frame.XDesktop getDesktop() {
+ com.sun.star.frame.XDesktop xDesktop = null;
+ com.sun.star.lang.XMultiComponentFactory xMCF = null;
+
+ try {
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+
+ // get the remote office service manager
+ xMCF = xContext.getServiceManager();
+ if( xMCF != null ) {
+ System.out.println("Connected to a running office ...");
+
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext);
+ xDesktop = (com.sun.star.frame.XDesktop) UnoRuntime.queryInterface(
+ com.sun.star.frame.XDesktop.class, oDesktop);
+ }
+ else
+ System.out.println( "Can't create a desktop. No connection, no remote office servicemanager available!" );
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+
+ return xDesktop;
+ }
+
+ public static com.sun.star.text.XTextDocument createTextdocument(
+ com.sun.star.frame.XDesktop xDesktop )
+ {
+ com.sun.star.text.XTextDocument aTextDocument = null;
+
+ try {
+ com.sun.star.lang.XComponent xComponent = CreateNewDocument(xDesktop,
+ "swriter");
+ aTextDocument = (com.sun.star.text.XTextDocument)
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XTextDocument.class, xComponent);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return aTextDocument;
+ }
+
+
+ protected static com.sun.star.lang.XComponent CreateNewDocument(
+ com.sun.star.frame.XDesktop xDesktop,
+ String sDocumentType )
+ {
+ String sURL = "private:factory/" + sDocumentType;
+
+ com.sun.star.lang.XComponent xComponent = null;
+ com.sun.star.frame.XComponentLoader xComponentLoader = null;
+ com.sun.star.beans.PropertyValue xValues[] =
+ new com.sun.star.beans.PropertyValue[1];
+ com.sun.star.beans.PropertyValue xEmptyArgs[] =
+ new com.sun.star.beans.PropertyValue[0];
+
+ try {
+ xComponentLoader = (com.sun.star.frame.XComponentLoader)
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class, xDesktop);
+
+ xComponent = xComponentLoader.loadComponentFromURL(
+ sURL, "_blank", 0, xEmptyArgs);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.out);
+ }
+
+ return xComponent ;
+ }
+}
diff --git a/odk/examples/java/Text/GraphicsInserter.java b/odk/examples/java/Text/GraphicsInserter.java
new file mode 100644
index 000000000000..a42ccaabf119
--- /dev/null
+++ b/odk/examples/java/Text/GraphicsInserter.java
@@ -0,0 +1,179 @@
+/*************************************************************************
+ *
+ * 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.PrintWriter;
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+
+
+public class GraphicsInserter {
+ public static void main(String args[]) {
+ if ( args.length < 1 )
+ {
+ System.out.println(
+ "usage: java -jar GraphicsInserter.jar \"<Graphic URL|path>\"" );
+ System.out.println( "\ne.g.:" );
+ System.out.println(
+ "java -jar GraphicsInserter.jar \"file:///f:/TestGraphics.gif\"" );
+ System.exit( 1 );
+ }
+
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ try {
+
+ // bootstrap UNO and get the remote component context. The context can
+ // be used to get the service manager
+ 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();
+
+ /* A desktop environment contains tasks with one or more
+ frames in which components can be loaded. Desktop is the
+ environment for components which can instanciate within
+ frames. */
+ com.sun.star.frame.XDesktop xDesktop = (com.sun.star.frame.XDesktop)
+ UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class,
+ xMCF.createInstanceWithContext("com.sun.star.frame.Desktop",
+ xContext ) );
+
+ com.sun.star.frame.XComponentLoader xCompLoader =
+ (com.sun.star.frame.XComponentLoader)UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class, xDesktop);
+
+ // Load a Writer document, which will be automaticly displayed
+ com.sun.star.lang.XComponent xComp = xCompLoader.loadComponentFromURL(
+ "private:factory/swriter", "_blank", 0,
+ new com.sun.star.beans.PropertyValue[0]);
+
+ // Querying for the interface XTextDocument on the xcomponent
+ com.sun.star.text.XTextDocument xTextDoc =
+ (com.sun.star.text.XTextDocument)UnoRuntime.queryInterface(
+ com.sun.star.text.XTextDocument.class, xComp);
+
+ // Querying for the interface XMultiServiceFactory on the xtextdocument
+ com.sun.star.lang.XMultiServiceFactory xMSFDoc =
+ (com.sun.star.lang.XMultiServiceFactory)UnoRuntime.queryInterface(
+ com.sun.star.lang.XMultiServiceFactory.class, xTextDoc);
+
+ // Providing a log file for output
+ PrintWriter printwriterLog = new PrintWriter(
+ new BufferedWriter( new FileWriter("log.txt") ) );
+
+ Object oGraphic = null;
+ try {
+ // Creating the service GraphicObject
+ oGraphic =
+ xMSFDoc.createInstance("com.sun.star.text.TextGraphicObject");
+ }
+ catch ( Exception exception ) {
+ System.out.println( "Could not create instance" );
+ exception.printStackTrace( printwriterLog );
+ }
+
+ // Getting the text
+ com.sun.star.text.XText xText = xTextDoc.getText();
+
+ // Getting the cursor on the document
+ com.sun.star.text.XTextCursor xTextCursor = xText.createTextCursor();
+
+ // Querying for the interface XTextContent on the GraphicObject
+ com.sun.star.text.XTextContent xTextContent =
+ (com.sun.star.text.XTextContent)UnoRuntime.queryInterface(
+ com.sun.star.text.XTextContent.class, oGraphic );
+
+ // Printing information to the log file
+ printwriterLog.println( "inserting graphic" );
+ try {
+ // Inserting the content
+ xText.insertTextContent(xTextCursor, xTextContent, true);
+ } catch ( Exception exception ) {
+ System.out.println( "Could not insert Content" );
+ exception.printStackTrace(System.err);
+ }
+
+ // Printing information to the log file
+ printwriterLog.println( "adding graphic" );
+
+ // Querying for the interface XPropertySet on GraphicObject
+ com.sun.star.beans.XPropertySet xPropSet =
+ (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, oGraphic);
+ try {
+ // Creating a string for the graphic url
+ java.io.File sourceFile = new java.io.File(args[0]);
+ StringBuffer sUrl = new StringBuffer("file:///");
+ sUrl.append(sourceFile.getCanonicalPath().replace('\\', '/'));
+ System.out.println( "insert graphic \"" + sUrl + "\"");
+
+ // Setting the anchor type
+ xPropSet.setPropertyValue("AnchorType",
+ com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH );
+
+ // Setting the graphic url
+ xPropSet.setPropertyValue( "GraphicURL", sUrl.toString() );
+
+ // Setting the horizontal position
+ xPropSet.setPropertyValue( "HoriOrientPosition",
+ new Integer( 5500 ) );
+
+ // Setting the vertical position
+ xPropSet.setPropertyValue( "VertOrientPosition",
+ new Integer( 4200 ) );
+
+ // Setting the width
+ xPropSet.setPropertyValue( "Width", new Integer( 4400 ) );
+
+ // Setting the height
+ xPropSet.setPropertyValue( "Height", new Integer( 4000 ) );
+ } catch ( Exception exception ) {
+ System.out.println( "Couldn't set property 'GraphicURL'" );
+ exception.printStackTrace( printwriterLog );
+ }
+
+ xContext = null;
+
+ System.exit(0);
+ }
+ catch( Exception e ) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+ }
+}
diff --git a/odk/examples/java/Text/HardFormatting.java b/odk/examples/java/Text/HardFormatting.java
new file mode 100644
index 000000000000..7d8bf94f5971
--- /dev/null
+++ b/odk/examples/java/Text/HardFormatting.java
@@ -0,0 +1,286 @@
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+
+//***************************************************************************
+// comment: Step 1: get the Desktop object from the office
+// Step 2: open an empty text document
+// Step 3: enter a example text
+// Step 4: get some text attributes
+// Step 5: check the PropertyState from the selection
+//
+// Chapter 4.1.4 Hard formatting
+//***************************************************************************
+
+import com.sun.star.uno.UnoRuntime;
+
+public class HardFormatting {
+
+ public static void main(String args[]) {
+ // You need the desktop to create a document
+ // The getDesktop method does the UNO bootstrapping, gets the
+ // remote servie manager and the desktop object.
+ com.sun.star.frame.XDesktop xDesktop = null;
+ xDesktop = getDesktop();
+
+ try {
+ // create text document
+ com.sun.star.text.XTextDocument xTextDocument = null;
+ xTextDocument = createTextdocument(xDesktop);
+
+ // the text interface contains all methods and properties to
+ // manipulate the content from a text document
+ com.sun.star.text.XText xText = null;
+ xText = xTextDocument.getText();
+
+ String sMyText = "A very short paragraph for illustration only";
+
+ // you can travel with the cursor throught the text document.
+ // you travel only at the model, not at the view. The cursor that you can
+ // see on the document doesn't change the position
+ com.sun.star.text.XTextCursor xTextCursor = null;
+ xTextCursor = (com.sun.star.text.XTextCursor)
+ xTextDocument.getText().createTextCursor();
+
+ xText.insertString( xTextCursor, "Headline", false );
+ xText.insertControlCharacter(xTextCursor,
+ com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false);
+
+ xText.insertString(xTextCursor, sMyText, false);
+
+ com.sun.star.text.XTextRange xTextRange = null;
+ com.sun.star.beans.XPropertySet xPropertySet = null;
+
+ // BEGIN: 'Hard formating'
+ // the text range not the cursor contains the 'parastyle' property
+ xTextRange = xText.getEnd();
+ xPropertySet = (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xTextRange);
+
+ // create a paragraph cursor to travel throught the paragraphs
+ com.sun.star.text.XParagraphCursor xParagraphCursor = null;
+ xParagraphCursor = (com.sun.star.text.XParagraphCursor)
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XParagraphCursor.class, xTextRange);
+
+ xParagraphCursor.gotoStart( false );
+ xParagraphCursor.gotoEndOfParagraph( true );
+ xTextRange = xParagraphCursor.getText().getStart();
+
+ // create a WordCursor to travel into the paragraph
+ com.sun.star.text.XWordCursor xWordCursor = null;
+ xWordCursor = (com.sun.star.text.XWordCursor) UnoRuntime.queryInterface(
+ com.sun.star.text.XWordCursor.class, xTextRange);
+
+ // the PropertySet from the cursor contains the text attributes
+ xPropertySet = (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xWordCursor);
+ System.out.println(
+ "Parastyle : "
+ +xPropertySet.getPropertyValue("ParaStyleName").toString()
+ + "\nFontname : "
+ + xPropertySet.getPropertyValue("CharFontName").toString()
+ + "\nWeight : "
+ + xPropertySet.getPropertyValue("CharWeight").toString() );
+
+ xWordCursor.gotoNextWord(false);
+ xWordCursor.gotoNextWord(false);
+ xWordCursor.gotoEndOfWord(true);
+
+ xPropertySet = (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xWordCursor);
+ xPropertySet.setPropertyValue("CharWeight",
+ new Float(com.sun.star.awt.FontWeight.BOLD));
+ xPropertySet.setPropertyValue("CharColor", new Integer( 255 ) );
+
+ System.out.println(
+ "Parastyle : "
+ + xPropertySet.getPropertyValue("ParaStyleName").toString()
+ + "\nFontname : "
+ + xPropertySet.getPropertyValue("CharFontName").toString()
+ + "\nWeight : "
+ + xPropertySet.getPropertyValue("CharWeight").toString() );
+
+ // the PropertyState contains information where the attribute is set,
+ // is a text part hard formated or not.
+ com.sun.star.beans.XPropertyState xPropertyState = null;
+ xPropertyState = (com.sun.star.beans.XPropertyState)
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertyState.class, xWordCursor);
+
+ com.sun.star.beans.PropertyState xPropertyStateValue =
+ xPropertyState.getPropertyState("CharWeight");
+
+ checkPropertyState( xWordCursor, xPropertyStateValue );
+
+ xWordCursor.goRight( (short) 3 , true );
+ xPropertyStateValue = xPropertyState.getPropertyState("CharWeight");
+
+ System.out.println("Increase the selection with three characters");
+ checkPropertyState(xWordCursor, xPropertyStateValue);
+
+ xPropertyState.setPropertyToDefault("CharWeight");
+
+ System.out.println("Set the default value on the selection");
+ xPropertyStateValue = xPropertyState.getPropertyState("CharWeight");
+ checkPropertyState(xWordCursor, xPropertyStateValue);
+
+ // END: 'Hard formating' Section from the Cookbook
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+
+ System.out.println("Done");
+
+ System.exit(0);
+
+ }
+
+
+ public static void checkPropertyState(
+ com.sun.star.text.XWordCursor xWordCursor,
+ com.sun.star.beans.PropertyState xPropertyStateValue )
+ {
+ switch( xPropertyStateValue.getValue() ) {
+ case com.sun.star.beans.PropertyState.DIRECT_VALUE_value: {
+ System.out.println( "-> The selection '"
+ + xWordCursor.getString()
+ + "' completly hard formated" );
+ break;
+ }
+
+ case com.sun.star.beans.PropertyState.DEFAULT_VALUE_value: {
+ System.out.println( "-> The selection '"
+ + xWordCursor.getString()
+ + "' isn't hard formated" );
+ break;
+ }
+
+ case com.sun.star.beans.PropertyState.AMBIGUOUS_VALUE_value: {
+ System.out.println( "-> The selection '"
+ + xWordCursor.getString()
+ + "' isn't completly hard formated" );
+ break;
+ }
+
+ default:
+ System.out.println( "No PropertyState found" );
+ }
+ }
+
+ public static com.sun.star.frame.XDesktop getDesktop() {
+ com.sun.star.frame.XDesktop xDesktop = null;
+ com.sun.star.lang.XMultiComponentFactory xMCF = null;
+
+ try {
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+
+ // get the remote office service manager
+ xMCF = xContext.getServiceManager();
+ if( xMCF != null ) {
+ System.out.println("Connected to a running office ...");
+
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext);
+ xDesktop = (com.sun.star.frame.XDesktop) UnoRuntime.queryInterface(
+ com.sun.star.frame.XDesktop.class, oDesktop);
+ }
+ else
+ System.out.println( "Can't create a desktop. No connection, no remote office servicemanager available!" );
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+
+ return xDesktop;
+ }
+
+ public static com.sun.star.text.XTextDocument createTextdocument(
+ com.sun.star.frame.XDesktop xDesktop )
+ {
+ com.sun.star.text.XTextDocument aTextDocument = null;
+
+ try {
+ com.sun.star.lang.XComponent xComponent = CreateNewDocument(xDesktop,
+ "swriter");
+ aTextDocument = (com.sun.star.text.XTextDocument)
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XTextDocument.class, xComponent);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return aTextDocument;
+ }
+
+
+ protected static com.sun.star.lang.XComponent CreateNewDocument(
+ com.sun.star.frame.XDesktop xDesktop,
+ String sDocumentType )
+ {
+ String sURL = "private:factory/" + sDocumentType;
+
+ com.sun.star.lang.XComponent xComponent = null;
+ com.sun.star.frame.XComponentLoader xComponentLoader = null;
+ com.sun.star.beans.PropertyValue xValues[] =
+ new com.sun.star.beans.PropertyValue[1];
+ com.sun.star.beans.PropertyValue xEmptyArgs[] =
+ new com.sun.star.beans.PropertyValue[0];
+
+ try {
+ xComponentLoader = (com.sun.star.frame.XComponentLoader)
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class, xDesktop);
+
+ xComponent = xComponentLoader.loadComponentFromURL(
+ sURL, "_blank", 0, xEmptyArgs);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return xComponent ;
+ }
+}
diff --git a/odk/examples/java/Text/Makefile b/odk/examples/java/Text/Makefile
new file mode 100644
index 000000000000..9fb4b6226407
--- /dev/null
+++ b/odk/examples/java/Text/Makefile
@@ -0,0 +1,136 @@
+#*************************************************************************
+#
+# 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 Text examples of the SDK.
+
+PRJ=../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+EXAMPLE_NAME=JavaTextExamples
+OUT_APP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME)
+
+APP1_NAME=BookmarkInsertion
+APP1_JAR=$(OUT_APP_CLASS)/$(APP1_NAME).jar
+APP2_NAME=HardFormatting
+APP2_JAR=$(OUT_APP_CLASS)/$(APP2_NAME).jar
+APP3_NAME=StyleCreation
+APP3_JAR=$(OUT_APP_CLASS)/$(APP3_NAME).jar
+APP4_NAME=StyleInitialization
+APP4_JAR=$(OUT_APP_CLASS)/$(APP4_NAME).jar
+APP5_NAME=SWriter
+APP5_JAR=$(OUT_APP_CLASS)/$(APP5_NAME).jar
+APP6_NAME=TextDocumentStructure
+APP6_JAR=$(OUT_APP_CLASS)/$(APP6_NAME).jar
+APP7_NAME=TextReplace
+APP7_JAR=$(OUT_APP_CLASS)/$(APP7_NAME).jar
+APP8_NAME=WriterSelector
+APP8_JAR=$(OUT_APP_CLASS)/$(APP8_NAME).jar
+APP9_NAME=GraphicsInserter
+APP9_JAR=$(OUT_APP_CLASS)/$(APP9_NAME).jar
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(OUT_APP_CLASS))
+
+# Targets
+.PHONY: ALL
+ALL : \
+ $(EXAMPLE_NAME)
+
+include $(SETTINGS)/stdtarget.mk
+
+$(OUT_APP_CLASS)/%.class : %.java
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_APP_CLASS) $<
+
+$(OUT_APP_CLASS)/%.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: $*>> $@
+
+$(OUT_APP_CLASS)/%.jar : $(OUT_APP_CLASS)/%.mf $(OUT_APP_CLASS)/%.class
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ +cd $(subst /,$(PS),$(OUT_APP_CLASS)) && $(SDK_JAR) cvfm $(@F) $*.mf $*.class
+ +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
+
+
+$(APP1_JAR) : $(OUT_APP_CLASS)/$(APP1_NAME).mf $(OUT_APP_CLASS)/$(APP1_NAME).class
+$(APP2_JAR) : $(OUT_APP_CLASS)/$(APP2_NAME).mf $(OUT_APP_CLASS)/$(APP2_NAME).class
+$(APP3_JAR) : $(OUT_APP_CLASS)/$(APP3_NAME).mf $(OUT_APP_CLASS)/$(APP3_NAME).class
+$(APP4_JAR) : $(OUT_APP_CLASS)/$(APP4_NAME).mf $(OUT_APP_CLASS)/$(APP4_NAME).class
+$(APP5_JAR) : $(OUT_APP_CLASS)/$(APP5_NAME).mf $(OUT_APP_CLASS)/$(APP5_NAME).class
+$(APP6_JAR) : $(OUT_APP_CLASS)/$(APP6_NAME).mf $(OUT_APP_CLASS)/$(APP6_NAME).class
+$(APP7_JAR) : $(OUT_APP_CLASS)/$(APP7_NAME).mf $(OUT_APP_CLASS)/$(APP7_NAME).class
+$(APP8_JAR) : $(OUT_APP_CLASS)/$(APP8_NAME).mf $(OUT_APP_CLASS)/$(APP8_NAME).class
+$(APP9_JAR) : $(OUT_APP_CLASS)/$(APP9_NAME).mf $(OUT_APP_CLASS)/$(APP9_NAME).class
+
+$(EXAMPLE_NAME) : $(APP1_JAR) $(APP2_JAR) $(APP3_JAR) $(APP4_JAR) $(APP5_JAR) $(APP6_JAR) $(APP7_JAR) $(APP8_JAR) $(APP9_JAR)
+ @echo --------------------------------------------------------------------------------
+ @echo The GraphicsInserter example loads the graphic "$(QM)./oo_smiley.gif$(QM)" into a
+ @echo new document.
+ @echo -
+ @echo Please use one of the following commands to execute the examples!
+ @echo ------
+ @echo $(MAKE) BookmarkInsertion.run
+ @echo $(MAKE) HardFormatting.run
+ @echo $(MAKE) StyleCreation.run
+ @echo $(MAKE) StyleInitialization.run
+ @echo $(MAKE) SWriter.run
+ @echo $(MAKE) TextDocumentStructure.run
+ @echo $(MAKE) TextReplace.run
+ @echo $(MAKE) WriterSelector.run
+ @echo $(MAKE) GraphicsInserter.run
+ @echo --------
+ @echo The GraphicsInserter needs parameters. Please use the following command 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 --- GraphicsInserter ---
+ @echo java -jar GraphicsInserter.jar "$(QM)graphic Url|path$(QM)"
+ @echo --------------------------------------------------------------------------------
+
+%.run: $(OUT_APP_CLASS)/%.jar
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $<
+
+GraphicsInserter.run: $(OUT_APP_CLASS)/GraphicsInserter.jar
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $< oo_smiley.gif
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_CLASS))
diff --git a/odk/examples/java/Text/SWriter.java b/odk/examples/java/Text/SWriter.java
new file mode 100644
index 000000000000..ca7696b4cf4b
--- /dev/null
+++ b/odk/examples/java/Text/SWriter.java
@@ -0,0 +1,397 @@
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+
+//***************************************************************************
+// comment: Step 1: bootstrap UNO and get the remote component context
+// Step 2: open an empty text document
+// Step 3: enter some text
+// Step 4: insert a text table
+// Step 5: insert colored text
+// Step 6: insert a text frame
+//***************************************************************************
+
+import com.sun.star.uno.UnoRuntime;
+
+public class SWriter {
+
+ public static void main(String args[]) {
+
+
+ //oooooooooooooooooooooooooooStep 1oooooooooooooooooooooooooooooooooooooooo
+ // bootstrap UNO and get the remote component context. The context can
+ // be used to get the service manager
+ //*************************************************************************
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ try {
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ if( xContext != null )
+ System.out.println("Connected to a running office ...");
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+ //oooooooooooooooooooooooooooStep 2oooooooooooooooooooooooooooooooooooooooo
+ // open an empty document. In this case it's a writer document.
+ // For this purpose an instance of com.sun.star.frame.Desktop
+ // is created. It's interface XDesktop provides the XComponentLoader,
+ // which is used to open the document via loadComponentFromURL
+ //*************************************************************************
+
+ //Open Writer document
+
+ System.out.println("Opening an empty Writer document");
+ com.sun.star.text.XTextDocument myDoc = openWriter(xContext);
+
+ //*************************************************************************
+
+
+ //oooooooooooooooooooooooooooStep 3oooooooooooooooooooooooooooooooooooooooo
+ // insert some text.
+ // For this purpose get the Text-Object of the document an create the
+ // cursor. Now it is possible to insert a text at the cursor-position
+ // via insertString
+ //*************************************************************************
+
+
+ //getting the text object
+ com.sun.star.text.XText xText = myDoc.getText();
+
+ //create a cursor object
+ com.sun.star.text.XTextCursor xTCursor = xText.createTextCursor();
+
+ //inserting some Text
+ xText.insertString( xTCursor, "The first line in the newly created text document.\n", false );
+
+ //inserting a second line
+ xText.insertString( xTCursor, "Now we're in the second line\n", false );
+
+ //*************************************************************************
+
+
+ //oooooooooooooooooooooooooooStep 4oooooooooooooooooooooooooooooooooooooooo
+ // insert a text table.
+ // For this purpose get MultiServiceFactory of the document, create an
+ // instance of com.sun.star.text.TextTable and initialize it. Now it can
+ // be inserted at the cursor position via insertTextContent.
+ // After that some properties are changed and some data is inserted.
+ //*************************************************************************
+
+ //inserting a text table
+ System.out.println("Inserting a text table");
+
+ //getting MSF of the document
+ com.sun.star.lang.XMultiServiceFactory xDocMSF =
+ (com.sun.star.lang.XMultiServiceFactory) UnoRuntime.queryInterface(
+ com.sun.star.lang.XMultiServiceFactory.class, myDoc);
+
+ //create instance of a text table
+ com.sun.star.text.XTextTable xTT = null;
+
+ try {
+ Object oInt = xDocMSF.createInstance("com.sun.star.text.TextTable");
+ xTT = (com.sun.star.text.XTextTable)
+ UnoRuntime.queryInterface(com.sun.star.text.XTextTable.class,oInt);
+ } catch (Exception e) {
+ System.err.println("Couldn't create instance "+ e);
+ e.printStackTrace(System.err);
+ }
+
+ //initialize the text table with 4 columns an 4 rows
+ xTT.initialize(4,4);
+
+ com.sun.star.beans.XPropertySet xTTRowPS = null;
+
+ //insert the table
+ try {
+ xText.insertTextContent(xTCursor, xTT, false);
+ // get first Row
+ com.sun.star.container.XIndexAccess xTTRows = xTT.getRows();
+ xTTRowPS = (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xTTRows.getByIndex(0));
+
+ } catch (Exception e) {
+ System.err.println("Couldn't insert the table " + e);
+ e.printStackTrace(System.err);
+ }
+
+
+ // get the property set of the text table
+
+ com.sun.star.beans.XPropertySet xTTPS = (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, xTT);
+
+ // Change the BackColor
+ try {
+ xTTPS.setPropertyValue("BackTransparent", new Boolean(false));
+ xTTPS.setPropertyValue("BackColor",new Integer(13421823));
+ xTTRowPS.setPropertyValue("BackTransparent", new Boolean(false));
+ xTTRowPS.setPropertyValue("BackColor",new Integer(6710932));
+
+ } catch (Exception e) {
+ System.err.println("Couldn't change the color " + e);
+ e.printStackTrace(System.err);
+ }
+
+ // write Text in the Table headers
+ System.out.println("Write text in the table headers");
+
+ insertIntoCell("A1","FirstColumn", xTT);
+ insertIntoCell("B1","SecondColumn", xTT) ;
+ insertIntoCell("C1","ThirdColumn", xTT) ;
+ insertIntoCell("D1","SUM", xTT) ;
+
+
+ //Insert Something in the text table
+ System.out.println("Insert something in the text table");
+
+ (xTT.getCellByName("A2")).setValue(22.5);
+ (xTT.getCellByName("B2")).setValue(5615.3);
+ (xTT.getCellByName("C2")).setValue(-2315.7);
+ (xTT.getCellByName("D2")).setFormula("sum <A2:C2>");
+
+ (xTT.getCellByName("A3")).setValue(21.5);
+ (xTT.getCellByName("B3")).setValue(615.3);
+ (xTT.getCellByName("C3")).setValue(-315.7);
+ (xTT.getCellByName("D3")).setFormula("sum <A3:C3>");
+
+ (xTT.getCellByName("A4")).setValue(121.5);
+ (xTT.getCellByName("B4")).setValue(-615.3);
+ (xTT.getCellByName("C4")).setValue(415.7);
+ (xTT.getCellByName("D4")).setFormula("sum <A4:C4>");
+
+
+ //oooooooooooooooooooooooooooStep 5oooooooooooooooooooooooooooooooooooooooo
+ // insert a colored text.
+ // Get the propertySet of the cursor, change the CharColor and add a
+ // shadow. Then insert the Text via InsertString at the cursor position.
+ //*************************************************************************
+
+ // get the property set of the cursor
+ com.sun.star.beans.XPropertySet xTCPS = (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,
+ xTCursor);
+
+ Object oldValue = null;
+
+ // Change the CharColor and add a Shadow
+ try {
+ xTCPS.setPropertyValue("CharColor",new Integer(255));
+ xTCPS.setPropertyValue("CharShadowed", new Boolean(true));
+ } catch (Exception e) {
+ System.err.println("Couldn't change the color " + e);
+ e.printStackTrace(System.err);
+ }
+
+ //create a paragraph break
+ try {
+ xText.insertControlCharacter(xTCursor,
+ com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false);
+
+ } catch (Exception e) {
+ System.err.println("Couldn't insert break "+ e);
+ e.printStackTrace(System.err);
+ }
+
+ //inserting colored Text
+ System.out.println("Inserting colored Text");
+
+ xText.insertString(xTCursor, " This is a colored Text - blue with shadow\n",
+ false );
+
+ //create a paragraph break
+ try {
+ xText.insertControlCharacter(xTCursor,
+ com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false);
+
+ } catch (Exception e) {
+ System.err.println("Couldn't insert break "+ e);
+ e.printStackTrace(System.err);
+ }
+
+ //oooooooooooooooooooooooooooStep 6oooooooooooooooooooooooooooooooooooooooo
+ // insert a text frame.
+ // create an instance of com.sun.star.text.TextFrame using the MSF of the
+ // document. Change some properties an insert it.
+ // Now get the text-Object of the frame an the corresponding cursor.
+ // Insert some text via insertString.
+ //*************************************************************************
+
+ // Create a TextFrame
+ com.sun.star.text.XTextFrame xTF = null;
+ com.sun.star.drawing.XShape xTFS = null;
+
+ try {
+ Object oInt = xDocMSF.createInstance("com.sun.star.text.TextFrame");
+ xTF = (com.sun.star.text.XTextFrame) UnoRuntime.queryInterface(
+ com.sun.star.text.XTextFrame.class,oInt);
+ xTFS = (com.sun.star.drawing.XShape) UnoRuntime.queryInterface(
+ com.sun.star.drawing.XShape.class,oInt);
+
+ com.sun.star.awt.Size aSize = new com.sun.star.awt.Size();
+ aSize.Height = 400;
+ aSize.Width = 15000;
+
+ xTFS.setSize(aSize);
+ } catch (Exception e) {
+ System.err.println("Couldn't create instance "+ e);
+ e.printStackTrace(System.err);
+ }
+
+ // get the property set of the text frame
+ com.sun.star.beans.XPropertySet xTFPS = (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, xTF);
+
+ // Change the AnchorType
+ try {
+ xTFPS.setPropertyValue("AnchorType",
+ com.sun.star.text.TextContentAnchorType.AS_CHARACTER);
+ } catch (Exception e) {
+ System.err.println("Couldn't change the color " + e);
+ e.printStackTrace(System.err);
+ }
+
+ //insert the frame
+ System.out.println("Insert the text frame");
+
+ try {
+ xText.insertTextContent(xTCursor, xTF, false);
+ } catch (Exception e) {
+ System.err.println("Couldn't insert the frame " + e);
+ e.printStackTrace(System.err);
+ }
+
+ //getting the text object of Frame
+ com.sun.star.text.XText xTextF = xTF.getText();
+
+ //create a cursor object
+ com.sun.star.text.XTextCursor xTCF = xTextF.createTextCursor();
+
+ //inserting some Text
+ xTextF.insertString(xTCF,
+ "The first line in the newly created text frame.", false);
+
+
+ xTextF.insertString(xTCF,
+ "\nWith this second line the height of the frame raises.", false);
+
+ //insert a paragraph break
+ try {
+ xText.insertControlCharacter(xTCursor,
+ com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false );
+
+ } catch (Exception e) {
+ System.err.println("Couldn't insert break "+ e);
+ e.printStackTrace(System.err);
+ }
+
+ // Change the CharColor and add a Shadow
+ try {
+ xTCPS.setPropertyValue("CharColor",new Integer(65536));
+ xTCPS.setPropertyValue("CharShadowed", new Boolean(false));
+ } catch (Exception e) {
+ System.err.println("Couldn't change the color " + e);
+ e.printStackTrace(System.err);
+ }
+
+ xText.insertString(xTCursor, " That's all for now !!", false );
+
+ System.out.println("done");
+
+ System.exit(0);
+ }
+
+
+ public static com.sun.star.text.XTextDocument openWriter(
+ com.sun.star.uno.XComponentContext xContext)
+ {
+ //define variables
+ com.sun.star.frame.XComponentLoader xCLoader;
+ com.sun.star.text.XTextDocument xDoc = null;
+ com.sun.star.lang.XComponent xComp = null;
+
+ try {
+ // get the remote office service manager
+ com.sun.star.lang.XMultiComponentFactory xMCF =
+ xContext.getServiceManager();
+
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext);
+
+ xCLoader = (com.sun.star.frame.XComponentLoader)
+ UnoRuntime.queryInterface(com.sun.star.frame.XComponentLoader.class,
+ oDesktop);
+ com.sun.star.beans.PropertyValue [] szEmptyArgs =
+ new com.sun.star.beans.PropertyValue [0];
+ String strDoc = "private:factory/swriter";
+ xComp = xCLoader.loadComponentFromURL(strDoc, "_blank", 0, szEmptyArgs);
+ xDoc = (com.sun.star.text.XTextDocument)
+ UnoRuntime.queryInterface(com.sun.star.text.XTextDocument.class,
+ xComp);
+
+ } catch(Exception e){
+ System.err.println(" Exception " + e);
+ e.printStackTrace(System.err);
+ }
+ return xDoc;
+ }
+
+ public static void insertIntoCell(String CellName, String theText,
+ com.sun.star.text.XTextTable xTTbl) {
+
+ com.sun.star.text.XText xTableText = (com.sun.star.text.XText)
+ UnoRuntime.queryInterface(com.sun.star.text.XText.class,
+ xTTbl.getCellByName(CellName));
+
+ //create a cursor object
+ com.sun.star.text.XTextCursor xTC = xTableText.createTextCursor();
+
+ com.sun.star.beans.XPropertySet xTPS = (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, xTC);
+
+ try {
+ xTPS.setPropertyValue("CharColor",new Integer(16777215));
+ } catch (Exception e) {
+ System.err.println(" Exception " + e);
+ e.printStackTrace(System.err);
+ }
+
+ //inserting some Text
+ xTableText.setString( theText );
+
+ }
+}
diff --git a/odk/examples/java/Text/StyleCreation.java b/odk/examples/java/Text/StyleCreation.java
new file mode 100644
index 000000000000..362604af6311
--- /dev/null
+++ b/odk/examples/java/Text/StyleCreation.java
@@ -0,0 +1,226 @@
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+
+//***************************************************************************
+// comment: Step 1: get the Desktop object from the office
+// Step 2: open an empty text document
+// Step 3: create a new Paragraph style
+// Step 4: apply the Paragraph style
+//
+// Chapter 4.1.3 Defining Your Own Style
+//***************************************************************************
+
+import com.sun.star.uno.UnoRuntime;
+
+
+public class StyleCreation {
+ public static void main(String args[]) {
+ // You need the desktop to create a document
+ // The getDesktop method does the UNO bootstrapping, gets the
+ // remote servie manager and the desktop object.
+ com.sun.star.frame.XDesktop xDesktop = null;
+ xDesktop = getDesktop();
+
+ try {
+ // create text document
+ com.sun.star.text.XTextDocument xTextDocument = null;
+ xTextDocument = createTextdocument(xDesktop);
+
+ // the service '..ParagraphStyle' is context dependend, you need
+ // the multi service factory from the document to use the service
+ com.sun.star.lang.XMultiServiceFactory xDocMSF =
+ (com.sun.star.lang.XMultiServiceFactory)UnoRuntime.queryInterface(
+ com.sun.star.lang.XMultiServiceFactory.class, xTextDocument);
+
+ // use the service 'com.sun.star.style.ParagraphStyle'
+ com.sun.star.uno.XInterface xInterface = (com.sun.star.uno.XInterface)
+ xDocMSF.createInstance("com.sun.star.style.ParagraphStyle");
+
+ // create a supplier to get the Style family collection
+ com.sun.star.style.XStyleFamiliesSupplier xSupplier =
+ (com.sun.star.style.XStyleFamiliesSupplier)UnoRuntime.queryInterface(
+ com.sun.star.style.XStyleFamiliesSupplier.class, xTextDocument );
+
+ // get the NameAccess interface from the Style family collection
+ com.sun.star.container.XNameAccess xNameAccess =
+ xSupplier.getStyleFamilies();
+
+ // select the Paragraph styles, you get the Paragraph style collection
+ com.sun.star.container.XNameContainer xParaStyleCollection =
+ (com.sun.star.container.XNameContainer) UnoRuntime.queryInterface(
+ com.sun.star.container.XNameContainer.class,
+ xNameAccess.getByName("ParagraphStyles"));
+
+ // create a PropertySet to set the properties for the new Paragraphstyle
+ com.sun.star.beans.XPropertySet xPropertySet =
+ (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xInterface );
+ System.out.println( "create a PropertySet to set the properties for the new Paragraphstyle" );
+
+ // set some properties from the Paragraph style
+ xPropertySet.setPropertyValue("CharFontName", new String( "Helvetica" ) );
+ System.out.println( "set name of the font to 'Helvetica'" );
+
+ xPropertySet.setPropertyValue("CharHeight", new Float( 36 ) );
+ System.out.println( "Change the height of th font to 36" );
+
+ xPropertySet.setPropertyValue("CharWeight",
+ new Float( com.sun.star.awt.FontWeight.BOLD ) );
+ System.out.println( "set the font attribute 'Bold'" );
+
+ xPropertySet.setPropertyValue("CharAutoKerning", new Boolean( true ) );
+ System.out.println( "set the paragraph attribute 'AutoKerning'" );
+ xPropertySet.setPropertyValue("ParaAdjust",
+ new Integer( com.sun.star.style.ParagraphAdjust.CENTER_value ) );
+ System.out.println( "set the paragraph adjust to LEFT" );
+
+ xPropertySet.setPropertyValue("ParaFirstLineIndent", new Integer( 0 ) );
+ System.out.println( "set the first line indent to 0 cm" );
+
+ xPropertySet.setPropertyValue("BreakType",
+ com.sun.star.style.BreakType.PAGE_AFTER );
+ System.out.println( "set the paragraph attribute Breaktype to PageAfter" );
+
+ // insert the new Paragraph style in the Paragraph style collection
+ xParaStyleCollection.insertByName( "myheading", xPropertySet );
+ System.out.println( "create new paragraph style, with the values from the Propertyset");
+
+ // get the Textrange from the document
+ com.sun.star.text.XTextRange xTextRange =
+ xTextDocument.getText().getStart();
+
+ // get the PropertySet from the current paragraph
+ com.sun.star.beans.XPropertySet xParagraphPropertySet =
+ (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xTextRange );
+ // change the value from the property 'ParaStyle' to apply the
+ // Paragraph style
+ // To run the sample with StarOffice 5.2 you'll have to change
+ // 'ParaStyleName' to 'ParaStyle' in the next line
+ xParagraphPropertySet.setPropertyValue("ParaStyleName",
+ new String( "myheading" ) );
+ System.out.println( "apply the new paragraph style");
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+ System.out.println("done");
+
+ System.exit(0);
+ }
+
+
+ public static com.sun.star.frame.XDesktop getDesktop() {
+ com.sun.star.frame.XDesktop xDesktop = null;
+ com.sun.star.lang.XMultiComponentFactory xMCF = null;
+
+ try {
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+
+ // get the remote office service manager
+ xMCF = xContext.getServiceManager();
+ if( xMCF != null ) {
+ System.out.println("Connected to a running office ...");
+
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext);
+ xDesktop = (com.sun.star.frame.XDesktop) UnoRuntime.queryInterface(
+ com.sun.star.frame.XDesktop.class, oDesktop);
+ }
+ else
+ System.out.println( "Can't create a desktop. No connection, no remote office servicemanager available!" );
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+
+ return xDesktop;
+ }
+
+ public static com.sun.star.text.XTextDocument createTextdocument(
+ com.sun.star.frame.XDesktop xDesktop )
+ {
+ com.sun.star.text.XTextDocument aTextDocument = null;
+
+ try {
+ com.sun.star.lang.XComponent xComponent = CreateNewDocument(xDesktop,
+ "swriter");
+ aTextDocument = (com.sun.star.text.XTextDocument)
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XTextDocument.class, xComponent);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return aTextDocument;
+ }
+
+
+ protected static com.sun.star.lang.XComponent CreateNewDocument(
+ com.sun.star.frame.XDesktop xDesktop,
+ String sDocumentType )
+ {
+ String sURL = "private:factory/" + sDocumentType;
+
+ com.sun.star.lang.XComponent xComponent = null;
+ com.sun.star.frame.XComponentLoader xComponentLoader = null;
+ com.sun.star.beans.PropertyValue xValues[] =
+ new com.sun.star.beans.PropertyValue[1];
+ com.sun.star.beans.PropertyValue xEmptyArgs[] =
+ new com.sun.star.beans.PropertyValue[0];
+
+ try {
+ xComponentLoader = (com.sun.star.frame.XComponentLoader)
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class, xDesktop);
+
+ xComponent = xComponentLoader.loadComponentFromURL(
+ sURL, "_blank", 0, xEmptyArgs);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return xComponent ;
+ }
+}
+
diff --git a/odk/examples/java/Text/StyleInitialization.java b/odk/examples/java/Text/StyleInitialization.java
new file mode 100644
index 000000000000..22d8eb4d063e
--- /dev/null
+++ b/odk/examples/java/Text/StyleInitialization.java
@@ -0,0 +1,320 @@
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+
+//***************************************************************************
+// comment: Step 1: get the Desktop object from the office
+// Step 2: open an empty text document
+// Step 3: enter a example text
+// Step 4: use the paragraph collection
+// Step 5: apply a different paragraph style on the paragraphs
+//***************************************************************************
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.AnyConverter;
+
+public class StyleInitialization {
+
+ public static void main(String args[]) {
+ // You need the desktop to create a document
+ // The getDesktop method does the UNO bootstrapping, gets the
+ // remote servie manager and the desktop object.
+ com.sun.star.frame.XDesktop xDesktop = null;
+ xDesktop = getDesktop();
+
+ try {
+ // BEGIN: 'Style basics' Section from the Tutorial
+
+ // create text document
+ com.sun.star.text.XTextDocument xTextDocument = null;
+ xTextDocument = createTextdocument( xDesktop );
+
+ // the text interface contains all methods and properties to
+ // manipulate the content from a text document
+ com.sun.star.text.XText xText = null;
+ xText = xTextDocument.getText();
+
+ String sMyText = "A very short paragraph for illustration only";
+
+ // you can travel with the cursor throught the text document.
+ // you travel only at the model, not at the view. The cursor that you can
+ // see on the document doesn't change the position
+ com.sun.star.text.XTextCursor xTextCursor = null;
+ xTextCursor = (com.sun.star.text.XTextCursor)
+ xTextDocument.getText().createTextCursor();
+
+ com.sun.star.beans.XPropertySet oCPS = (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xTextCursor);
+ try {
+ oCPS.setPropertyValue("CharFontName","Helvetica");
+ }
+ catch (Exception ex) {
+
+ }
+
+ xText.insertString( xTextCursor, "Headline", false );
+
+ try {
+ oCPS.setPropertyValue("CharFontName","Times");
+ }
+ catch (Exception ex) {
+
+ }
+ xText.insertControlCharacter(xTextCursor,
+ com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false);
+
+ xText.insertString( xTextCursor, sMyText, false );
+
+ com.sun.star.text.XTextRange xTextRange = null;
+ com.sun.star.beans.XPropertySet xPropertySet = null;
+
+ // the text range not the cursor contains the 'parastyle' property
+ xTextRange = xText.getEnd();
+ xPropertySet = (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xTextRange );
+
+ // To run the sample with StarOffice 5.2 you'll have to change
+ // 'ParaStyleName' to 'ParaStyle' in the next line
+ System.out.println( "Current Parastyle : "
+ + xPropertySet.getPropertyValue("ParaStyleName") );
+
+ // END: 'Style basics' Section from the Tutorial
+
+ // There are two way to travel throught the paragraphs, with a
+ // paragraph cursor, or a enumeration.
+ // You find both ways in this example
+
+ // The first way, with the paragraph cursor
+ com.sun.star.text.XParagraphCursor xParagraphCursor = null;
+ xParagraphCursor = (com.sun.star.text.XParagraphCursor)
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XParagraphCursor.class, xTextRange );
+
+ xParagraphCursor.gotoStart( false );
+ xParagraphCursor.gotoEndOfParagraph( true );
+
+ // The second way, with the paragraph enumeration
+ com.sun.star.container.XEnumerationAccess xEnumerationAccess = null;
+ xEnumerationAccess = (com.sun.star.container.XEnumerationAccess)
+ UnoRuntime.queryInterface(
+ com.sun.star.container.XEnumerationAccess.class, xText );
+
+ // the enumeration contains all paragraph form the document
+ com.sun.star.container.XEnumeration xParagraphEnumeration = null;
+ xParagraphEnumeration = xEnumerationAccess.createEnumeration();
+
+ com.sun.star.text.XTextContent xParagraph = null;
+ com.sun.star.text.XTextRange xWord = null;
+
+ com.sun.star.container.XEnumerationAccess xParaEnumerationAccess = null;
+ com.sun.star.container.XEnumeration xPortionEnumeration = null;
+
+ // check if a paragraph is available
+ while ( xParagraphEnumeration.hasMoreElements() ) {
+ // get the next paragraph
+ xParagraph = (com.sun.star.text.XTextContent)
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XTextContent.class,
+ xParagraphEnumeration.nextElement());
+
+ // you need the method getAnchor to a TextRange -> to manipulate
+ // the paragraph
+ String sText = xParagraph.getAnchor().getString();
+
+ // create a cursor from this paragraph
+ com.sun.star.text.XTextCursor xParaCursor = null;
+ xParaCursor = xParagraph.getAnchor().getText().createTextCursor();
+
+ // goto the start and end of the paragraph
+ xParaCursor.gotoStart( false );
+ xParaCursor.gotoEnd( true );
+
+ // The enumeration from the paragraphs contain parts from the
+ // paragraph with a different attributes.
+ xParaEnumerationAccess = (com.sun.star.container.XEnumerationAccess)
+ UnoRuntime.queryInterface(
+ com.sun.star.container.XEnumerationAccess.class, xParagraph);
+ xPortionEnumeration = xParaEnumerationAccess.createEnumeration();
+
+ while ( xPortionEnumeration.hasMoreElements() ) {
+ // output of all parts from the paragraph with different attributes
+ xWord = (com.sun.star.text.XTextRange) UnoRuntime.queryInterface(
+ com.sun.star.text.XTextRange.class,
+ xPortionEnumeration.nextElement());
+ String sWordString = xWord.getString();
+ System.out.println( "Content of the paragraph : " + sWordString );
+ }
+ }
+
+ // BEGIN: 'Finding a suitable style' Section from the Tutorial
+
+ // craete a supplier to get the styles-collection
+ com.sun.star.style.XStyleFamiliesSupplier xSupplier = null;
+ xSupplier = ( com.sun.star.style.XStyleFamiliesSupplier ) UnoRuntime.queryInterface(
+ com.sun.star.style.XStyleFamiliesSupplier.class, xTextDocument );
+
+ // use the name access from the collection
+ com.sun.star.container.XNameAccess xNameAccess = null;
+ xNameAccess = xSupplier.getStyleFamilies();
+
+ com.sun.star.container.XNameContainer xParaStyleCollection = null;
+ xParaStyleCollection = (com.sun.star.container.XNameContainer) UnoRuntime.queryInterface(
+ com.sun.star.container.XNameContainer.class, xNameAccess.getByName( "ParagraphStyles" ));
+
+ // create a array from strings with the name of all paragraph styles from the text document
+ String[] sElementNames = xParaStyleCollection.getElementNames();
+ int iElementCount = sElementNames.length;
+
+ for( int iCounter = 0; iCounter < iElementCount; iCounter++ ) {
+ // specify one paragraph style
+ com.sun.star.style.XStyle xStyle = null;
+ xStyle = (com.sun.star.style.XStyle) UnoRuntime.queryInterface(
+ com.sun.star.style.XStyle.class,
+ xParaStyleCollection.getByName( sElementNames[iCounter] ));
+
+ // create a property set of all properties from the style
+ xPropertySet = (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xStyle );
+
+ AnyConverter aAnyConv = new AnyConverter();
+ String sFontname = aAnyConv.toString(xPropertySet.getPropertyValue("CharFontName"));
+ sFontname = sFontname.toLowerCase();
+
+ // if the style use the font 'Albany', apply it to the current paragraph
+ if( sFontname.compareTo("albany") == 0 ) {
+ // create a property set from the current paragraph, to change the paragraph style
+ xPropertySet = (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xTextRange );
+
+ // To run the sample with StarOffice 5.2 you'll have to change 'ParaStyleName'
+ // to 'ParaStyle' in the next line
+ xPropertySet.setPropertyValue("ParaStyleName", new String( sElementNames[iCounter] ) );
+ System.out.println( "Apply the paragraph style : " + sElementNames[iCounter] );
+ break;
+ }
+ }
+ // END: 'Finding a suitable style' Section from the Tutorial
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+
+ System.out.println("Done");
+
+ System.exit(0);
+
+ }
+
+ public static com.sun.star.frame.XDesktop getDesktop() {
+ com.sun.star.frame.XDesktop xDesktop = null;
+ com.sun.star.lang.XMultiComponentFactory xMCF = null;
+
+ try {
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+
+ // get the remote office service manager
+ xMCF = xContext.getServiceManager();
+ if( xMCF != null ) {
+ System.out.println("Connected to a running office ...");
+
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext);
+ xDesktop = (com.sun.star.frame.XDesktop) UnoRuntime.queryInterface(
+ com.sun.star.frame.XDesktop.class, oDesktop);
+ }
+ else
+ System.out.println( "Can't create a desktop. No connection, no remote office servicemanager available!" );
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+
+ return xDesktop;
+ }
+
+ public static com.sun.star.text.XTextDocument createTextdocument(
+ com.sun.star.frame.XDesktop xDesktop )
+ {
+ com.sun.star.text.XTextDocument aTextDocument = null;
+
+ try {
+ com.sun.star.lang.XComponent xComponent = CreateNewDocument(xDesktop,
+ "swriter");
+ aTextDocument = (com.sun.star.text.XTextDocument)
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XTextDocument.class, xComponent);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return aTextDocument;
+ }
+
+
+ protected static com.sun.star.lang.XComponent CreateNewDocument(
+ com.sun.star.frame.XDesktop xDesktop,
+ String sDocumentType )
+ {
+ String sURL = "private:factory/" + sDocumentType;
+
+ com.sun.star.lang.XComponent xComponent = null;
+ com.sun.star.frame.XComponentLoader xComponentLoader = null;
+ com.sun.star.beans.PropertyValue xValues[] =
+ new com.sun.star.beans.PropertyValue[1];
+ com.sun.star.beans.PropertyValue xEmptyArgs[] =
+ new com.sun.star.beans.PropertyValue[0];
+
+ try {
+ xComponentLoader = (com.sun.star.frame.XComponentLoader)
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class, xDesktop);
+
+ xComponent = xComponentLoader.loadComponentFromURL(
+ sURL, "_blank", 0, xEmptyArgs);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return xComponent ;
+ }
+}
diff --git a/odk/examples/java/Text/TextDocumentStructure.java b/odk/examples/java/Text/TextDocumentStructure.java
new file mode 100644
index 000000000000..1d91f6f1f44c
--- /dev/null
+++ b/odk/examples/java/Text/TextDocumentStructure.java
@@ -0,0 +1,205 @@
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+
+//***************************************************************************
+// comment: Step 1: bootstrap UNO and get the remote component context
+// Step 2: open an empty text document
+// Step 3: create an enumeration of all paragraphs
+// Step 4: create an enumeration of all text portions
+//***************************************************************************
+
+import com.sun.star.uno.UnoRuntime;
+
+public class TextDocumentStructure {
+
+ public static void main(String args[]) {
+ 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 rmeote service manger
+ com.sun.star.lang.XMultiComponentFactory xMCF =
+ xContext.getServiceManager();
+
+ // create a new instance of the desktop
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext);
+
+ // get the component laoder from the desktop to create a new
+ // text document
+ com.sun.star.frame.XComponentLoader xCLoader =
+ (com.sun.star.frame.XComponentLoader)
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class,oDesktop);
+ com.sun.star.beans.PropertyValue [] szEmptyArgs =
+ new com.sun.star.beans.PropertyValue [0];
+ String strDoc = "private:factory/swriter";
+
+ System.out.println("create new text document");
+
+ com.sun.star.lang.XComponent xComp = xCLoader.loadComponentFromURL(
+ strDoc, "_blank", 0, szEmptyArgs);
+
+ // query the new document for the XTextDocument interface
+ com.sun.star.text.XTextDocument xTextDocument =
+ (com.sun.star.text.XTextDocument)UnoRuntime.queryInterface(
+ com.sun.star.text.XTextDocument.class, xComp);
+
+ // create some example data
+ com.sun.star.text.XText xText = xTextDocument.getText();
+ createExampleData( xText );
+
+ // Begin section 'The structure of text documents' of the Tutorial
+
+ com.sun.star.container.XEnumeration xParagraphEnumeration = null;
+ com.sun.star.container.XEnumerationAccess xParaEnumerationAccess = null;
+ com.sun.star.container.XEnumeration xPortionEnumeration = null;
+ com.sun.star.container.XEnumeration xTextPortionEnum;
+ com.sun.star.text.XTextContent xTextElement = null;
+
+ System.out.println("create an enumeration of all paragraphs");
+ // create an enumeration access of all paragraphs of a document
+ com.sun.star.container.XEnumerationAccess xEnumerationAccess =
+ (com.sun.star.container.XEnumerationAccess)
+ UnoRuntime.queryInterface(
+ com.sun.star.container.XEnumerationAccess.class, xText);
+ xParagraphEnumeration = xEnumerationAccess.createEnumeration();
+
+ // Loop through all paragraphs of the document
+ while ( xParagraphEnumeration.hasMoreElements() ) {
+ xTextElement = (com.sun.star.text.XTextContent)
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XTextContent.class,
+ xParagraphEnumeration.nextElement());
+ com.sun.star.lang.XServiceInfo xServiceInfo =
+ (com.sun.star.lang.XServiceInfo)UnoRuntime.queryInterface(
+ com.sun.star.lang.XServiceInfo.class, xTextElement);
+
+ // check ifs the current paragraph really a paragraph or an
+ // anchor of a frame or picture
+ if( xServiceInfo.supportsService("com.sun.star.text.Paragraph") ) {
+ com.sun.star.text.XTextRange xTextRange =
+ xTextElement.getAnchor();
+ System.out.println( "This is a Paragraph" );
+
+ // create another enumeration to get all text portions of
+ // the paragraph
+ xParaEnumerationAccess =
+ (com.sun.star.container.XEnumerationAccess)
+ UnoRuntime.queryInterface(
+ com.sun.star.container.XEnumerationAccess.class,
+ xTextElement);
+ xTextPortionEnum = xParaEnumerationAccess.createEnumeration();
+
+ while ( xTextPortionEnum.hasMoreElements() ) {
+ com.sun.star.text.XTextRange xTextPortion =
+ (com.sun.star.text.XTextRange)UnoRuntime.queryInterface(
+ com.sun.star.text.XTextRange.class,
+ xTextPortionEnum.nextElement());
+ System.out.println( "Text from the portion : "
+ + xTextPortion.getString() );
+
+ com.sun.star.beans.XPropertySet xPropertySet =
+ (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class,
+ xTextPortion);
+ System.out.println( "Name of the font : "
+ + xPropertySet.getPropertyValue( "CharFontName" ) );
+
+ // PropertyState status of each text portion.
+ com.sun.star.beans.XPropertyState xPropertyState =
+ (com.sun.star.beans.XPropertyState)
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertyState.class,
+ xTextPortion);
+
+ if( xPropertyState.getPropertyState("CharWeight").equals(
+ com.sun.star.beans.PropertyState.AMBIGUOUS_VALUE) )
+ System.out.println( "- The text range contains more than one different attributes" );
+
+ if( xPropertyState.getPropertyState( "CharWeight" ).equals(
+ com.sun.star.beans.PropertyState.DIRECT_VALUE ) )
+ System.out.println( " - The text range contains hard formats" );
+
+ if( xPropertyState.getPropertyState( "CharWeight" ).equals(
+ com.sun.star.beans.PropertyState.DEFAULT_VALUE ) )
+ System.out.println( " - The text range doesn't contains hard formats" );
+ }
+ }
+ else
+ System.out.println( "The text portion isn't a text paragraph" );
+ // End section 'The structure of text documents' of the Tutorial
+ }
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+ System.out.println("done");
+ System.exit(0);
+ }
+
+ public static void createExampleData( com.sun.star.text.XText xText ) {
+
+ try {
+ xText.setString( "This is an example sentence" );
+
+ com.sun.star.text.XWordCursor xWordCursor =
+ (com.sun.star.text.XWordCursor)UnoRuntime.queryInterface(
+ com.sun.star.text.XWordCursor.class, xText.getStart());
+
+ xWordCursor.gotoNextWord(false);
+ xWordCursor.gotoNextWord(false);
+ xWordCursor.gotoEndOfWord(true);
+
+ com.sun.star.beans.XPropertySet xPropertySet =
+ (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xWordCursor );
+ xPropertySet.setPropertyValue("CharWeight",
+ new Float( com.sun.star.awt.FontWeight.BOLD ));
+
+ System.out.println("create example data");
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+
+ }
+}
diff --git a/odk/examples/java/Text/TextReplace.java b/odk/examples/java/Text/TextReplace.java
new file mode 100644
index 000000000000..0194d79b9825
--- /dev/null
+++ b/odk/examples/java/Text/TextReplace.java
@@ -0,0 +1,231 @@
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+
+//***************************************************************************
+// comment: Step 1: get the Desktop object from the office
+// Step 2: open an empty text document
+// Step 3: enter a example text
+// Step 4: replace some english spelled words with US spelled
+//***************************************************************************
+
+
+import com.sun.star.uno.UnoRuntime;
+
+public class TextReplace {
+
+ public static void main(String args[]) {
+ // You need the desktop to create a document
+ // The getDesktop method does the UNO bootstrapping, gets the
+ // remote servie manager and the desktop object.
+ com.sun.star.frame.XDesktop xDesktop = null;
+ xDesktop = getDesktop();
+
+ com.sun.star.text.XTextDocument xTextDocument =
+ createTextdocument( xDesktop );
+
+ createExampleData( xTextDocument );
+
+ String mBritishWords[] = {"colour", "neighbour", "centre", "behaviour",
+ "metre", "through" };
+ String mUSWords[] = { "color", "neighbor", "center", "behavior",
+ "meter", "thru" };
+
+ try {
+ com.sun.star.util.XReplaceDescriptor xReplaceDescr = null;
+ com.sun.star.util.XSearchDescriptor xSearchDescriptor = null;
+ com.sun.star.util.XReplaceable xReplaceable = null;
+
+ xReplaceable = (com.sun.star.util.XReplaceable)
+ UnoRuntime.queryInterface(
+ com.sun.star.util.XReplaceable.class, xTextDocument);
+
+ // You need a descriptor to set properies for Replace
+ xReplaceDescr = (com.sun.star.util.XReplaceDescriptor)
+ xReplaceable.createReplaceDescriptor();
+
+ System.out.println("Change all occurrences of ...");
+ for( int iArrayCounter = 0; iArrayCounter < mBritishWords.length;
+ iArrayCounter++ )
+ {
+ System.out.println(mBritishWords[iArrayCounter] +
+ " -> " + mUSWords[iArrayCounter]);
+ // Set the properties the replace method need
+ xReplaceDescr.setSearchString(mBritishWords[iArrayCounter] );
+ xReplaceDescr.setReplaceString(mUSWords[iArrayCounter] );
+
+ // Replace all words
+ xReplaceable.replaceAll( xReplaceDescr );
+ }
+
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ System.out.println("Done");
+
+ System.exit(0);
+
+ }
+
+ protected static void createExampleData(
+ com.sun.star.text.XTextDocument xTextDocument )
+ {
+ // Create textdocument and insert example text
+ com.sun.star.text.XTextCursor xTextCursor = null;
+
+ try {
+ xTextCursor = (com.sun.star.text.XTextCursor)
+ xTextDocument.getText().createTextCursor();
+ com.sun.star.text.XText xText = (com.sun.star.text.XText)
+ xTextDocument.getText();
+
+ xText.insertString( xTextCursor,
+ "He nervously looked all around. Suddenly he saw his ", false );
+
+ xText.insertString( xTextCursor, "neighbour ", true );
+ com.sun.star.beans.XPropertySet xCPS = (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xTextCursor);
+ // Set the word blue
+ xCPS.setPropertyValue( "CharColor", new Integer( 255 ) );
+ // Go to last character
+ xTextCursor.gotoEnd(false);
+ xCPS.setPropertyValue( "CharColor", new Integer( 0 ) );
+
+ xText.insertString( xTextCursor, "in the alley. Like lightening he darted off to the left and disappeared between the two warehouses almost falling over the trash can lying in the ", false );
+
+ xText.insertString( xTextCursor, "centre ", true );
+ xCPS = (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xTextCursor);
+ // Set the word blue
+ xCPS.setPropertyValue( "CharColor", new Integer( 255 ) );
+ // Go to last character
+ xTextCursor.gotoEnd(false);
+ xCPS.setPropertyValue( "CharColor", new Integer( 0 ) );
+
+ xText.insertString( xTextCursor, "of the sidewalk.", false );
+
+ xText.insertControlCharacter( xTextCursor,
+ com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false );
+ xText.insertString( xTextCursor, "He tried to nervously tap his way along in the inky darkness and suddenly stiffened: it was a dead-end, he would have to go back the way he had come.", false );
+
+ xTextCursor.gotoStart(false);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ }
+
+ public static com.sun.star.frame.XDesktop getDesktop() {
+ com.sun.star.frame.XDesktop xDesktop = null;
+ com.sun.star.lang.XMultiComponentFactory xMCF = null;
+
+ try {
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+
+ // get the remote office service manager
+ xMCF = xContext.getServiceManager();
+ if( xMCF != null ) {
+ System.out.println("Connected to a running office ...");
+
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext);
+ xDesktop = (com.sun.star.frame.XDesktop) UnoRuntime.queryInterface(
+ com.sun.star.frame.XDesktop.class, oDesktop);
+ }
+ else
+ System.out.println( "Can't create a desktop. No connection, no remote office servicemanager available!" );
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+
+ return xDesktop;
+ }
+
+ public static com.sun.star.text.XTextDocument createTextdocument(
+ com.sun.star.frame.XDesktop xDesktop )
+ {
+ com.sun.star.text.XTextDocument aTextDocument = null;
+
+ try {
+ com.sun.star.lang.XComponent xComponent = CreateNewDocument(xDesktop,
+ "swriter");
+ aTextDocument = (com.sun.star.text.XTextDocument)
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XTextDocument.class, xComponent);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return aTextDocument;
+ }
+
+
+ protected static com.sun.star.lang.XComponent CreateNewDocument(
+ com.sun.star.frame.XDesktop xDesktop,
+ String sDocumentType )
+ {
+ String sURL = "private:factory/" + sDocumentType;
+
+ com.sun.star.lang.XComponent xComponent = null;
+ com.sun.star.frame.XComponentLoader xComponentLoader = null;
+ com.sun.star.beans.PropertyValue xValues[] =
+ new com.sun.star.beans.PropertyValue[1];
+ com.sun.star.beans.PropertyValue xEmptyArgs[] =
+ new com.sun.star.beans.PropertyValue[0];
+
+ try {
+ xComponentLoader = (com.sun.star.frame.XComponentLoader)
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class, xDesktop);
+
+ xComponent = xComponentLoader.loadComponentFromURL(
+ sURL, "_blank", 0, xEmptyArgs);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return xComponent ;
+ }
+}
diff --git a/odk/examples/java/Text/WriterSelector.java b/odk/examples/java/Text/WriterSelector.java
new file mode 100644
index 000000000000..5c90aabc62dd
--- /dev/null
+++ b/odk/examples/java/Text/WriterSelector.java
@@ -0,0 +1,162 @@
+/*************************************************************************
+ *
+ * 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 gives you information on the selected objects (text range, text
+ * frame, or graphics) at an OpenOffice.org Server. The Office must be started in
+ * advance and you must have selected something (text, graphics, ...)
+ */
+public class WriterSelector {
+ /**
+ * @param args No arguments.
+ */
+ public static void main(String args[]) {
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ try {
+
+ // bootstrap UNO and get the remote component context. The context can
+ // be used to get the service manager
+ 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();
+
+ // get a new instance of the desktop
+ com.sun.star.frame.XDesktop xDesktop = (com.sun.star.frame.XDesktop)
+ UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class,
+ xMCF.createInstanceWithContext("com.sun.star.frame.Desktop",
+ xContext ) );
+
+ com.sun.star.frame.XComponentLoader xCompLoader =
+ (com.sun.star.frame.XComponentLoader)UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class, xDesktop);
+
+ com.sun.star.lang.XComponent xComponent =
+ xCompLoader.loadComponentFromURL("private:factory/swriter",
+ "_blank", 0, new com.sun.star.beans.PropertyValue[0]);
+ {
+ com.sun.star.text.XTextDocument xDoc =(com.sun.star.text.XTextDocument)
+ UnoRuntime.queryInterface(com.sun.star.text.XTextDocument.class,
+ xComponent);
+ xDoc.getText().setString("Please select something in this text and press then \"return\" in the shell where you have started the example.\n");
+
+ // ensure that the document content is optimal visible
+ com.sun.star.frame.XModel xModel =
+ (com.sun.star.frame.XModel)UnoRuntime.queryInterface(
+ com.sun.star.frame.XModel.class, xDoc);
+
+ com.sun.star.view.XViewSettingsSupplier xViewSettings =
+ (com.sun.star.view.XViewSettingsSupplier)UnoRuntime.queryInterface(
+ com.sun.star.view.XViewSettingsSupplier.class, xModel.getCurrentController());
+ xViewSettings.getViewSettings().setPropertyValue(
+ "ZoomType", new Short((short)0));
+ }
+ // test document will be closed later
+
+ System.out.println("\nPlease select something in the test document and press then \"return\" to continues the example ...");
+ char c = 'X';
+ do{
+ c = (char) System.in.read();
+ }while ((c != 13) && (c != 10));
+
+ // Getting the current frame from the OpenOffice.org Server.
+ com.sun.star.frame.XFrame xframe = xDesktop.getCurrentFrame();
+
+ // Getting the controller.
+ com.sun.star.frame.XController xController = xframe.getController();
+
+ com.sun.star.view.XSelectionSupplier xSelSupplier =
+ (com.sun.star.view.XSelectionSupplier)UnoRuntime.queryInterface(
+ com.sun.star.view.XSelectionSupplier.class, xController );
+
+ Object oSelection = xSelSupplier.getSelection();
+
+ com.sun.star.lang.XServiceInfo xServInfo =
+ (com.sun.star.lang.XServiceInfo)UnoRuntime.queryInterface(
+ com.sun.star.lang.XServiceInfo.class, oSelection );
+
+ if ( xServInfo.supportsService("com.sun.star.text.TextRanges") )
+ {
+ com.sun.star.container.XIndexAccess xIndexAccess =
+ (com.sun.star.container.XIndexAccess)UnoRuntime.queryInterface(
+ com.sun.star.container.XIndexAccess.class, oSelection);
+
+ int count = xIndexAccess.getCount();
+ com.sun.star.text.XTextRange xTextRange = null;
+ for ( int i = 0; i < count; i++ ) {
+ xTextRange = (com.sun.star.text.XTextRange)
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XTextRange.class,
+ xIndexAccess.getByIndex(i));
+
+ System.out.println( "You have selected a text range: \""
+ + xTextRange.getString() + "\"." );
+ }
+ }
+
+ if ( xServInfo.supportsService("com.sun.star.text.TextGraphicObject") )
+ {
+ System.out.println( "You have selected a graphics." );
+ }
+
+ if ( xServInfo.supportsService("com.sun.star.text.TextTableCursor") )
+ {
+ System.out.println( "You have selected a text table." );
+ }
+
+
+ // close test document
+ com.sun.star.util.XCloseable xCloseable = (com.sun.star.util.XCloseable)
+ UnoRuntime.queryInterface(com.sun.star.util.XCloseable.class,
+ xComponent );
+
+ if (xCloseable != null ) {
+ xCloseable.close(false);
+ } else
+ {
+ xComponent.dispose();
+ }
+
+ System.exit(0);
+ }
+ catch( Exception e ) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+ }
+}
diff --git a/odk/examples/java/Text/oo_smiley.gif b/odk/examples/java/Text/oo_smiley.gif
new file mode 100644
index 000000000000..f9fc08d5090c
--- /dev/null
+++ b/odk/examples/java/Text/oo_smiley.gif
Binary files differ
diff --git a/odk/examples/java/ToDo/Makefile b/odk/examples/java/ToDo/Makefile
new file mode 100644
index 000000000000..476ff6620dbc
--- /dev/null
+++ b/odk/examples/java/ToDo/Makefile
@@ -0,0 +1,166 @@
+#*************************************************************************
+#
+# 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 Calc Addin example of the SDK.
+
+PRJ=../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+COMP_NAME=ToDo
+COMP_CLASS_OUT=$(OUT_CLASS)/$(COMP_NAME)
+COMP_GEN_OUT=$(OUT_MISC)/$(COMP_NAME)
+COMP_RDB_NAME=$(COMP_NAME).uno.rdb
+COMP_RDB=$(COMP_GEN_OUT)/$(COMP_RDB_NAME)
+COMP_PACKAGE=$(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT)
+COMP_PACKAGE_URL=$(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)")
+COMP_JAR_NAME=$(COMP_NAME).uno.jar
+COMP_JAR=$(COMP_CLASS_OUT)/$(COMP_JAR_NAME)
+COMP_JAR_MANIFEST=$(COMP_CLASS_OUT)/$(COMP_NAME).uno.Manifest
+COMP_UNOPKG_MANIFEST = $(COMP_GEN_OUT)/META-INF/manifest.xml
+COMP_REGISTERFLAG=$(COMP_GEN_OUT)$(PS)java_$(COMP_NAME)_register_component.flag
+
+IDLFILES = XToDo.idl \
+ ToDo.idl
+
+# normally the idl file should be stored in a directory tree fitting the module
+# structure, for the example we know the module structure
+PACKAGE = org/openoffice
+
+COMP_JAVAFILES = ToDo.java
+COMP_CLASSFILES = $(patsubst %.java,$(COMP_CLASS_OUT)/%.class,$(COMP_JAVAFILES))
+
+GEN_CLASSFILES = $(patsubst %.idl,$(COMP_CLASS_OUT)/$(PACKAGE)/%.class,$(IDLFILES))
+GEN_TYPELIST = $(subst /,.,$(patsubst %.idl,-T$(PACKAGE)/% ,$(IDLFILES)))
+GEN_URDFILES = $(patsubst %.idl,$(COMP_GEN_OUT)/%.urd,$(IDLFILES))
+
+
+$(COMP_NAME)_CLASSFILES = $(COMP_NAME).class \
+ $(COMP_NAME)$(QUOTE)$$$(COMP_NAME)Impl.class
+
+$(COMP_NAME)_CLASSFILES += $(subst $(COMP_CLASS_OUT)/,,$(GEN_CLASSFILES))
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(COMP_CLASS_OUT))
+
+
+# Targets
+.PHONY: ALL
+ALL : JavaToDoExample
+
+include $(SETTINGS)/stdtarget.mk
+
+$(COMP_CLASS_OUT)/%.Manifest :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo UNO-Type-Path: $(basename $*).uno.jar> $@
+ @echo RegistrationClassName: $(basename $(basename $(@F)))>> $@
+
+$(COMP_GEN_OUT)/%.urd : %.idl
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(IDLC) -C -I. -I$(IDL_DIR) -O$(COMP_GEN_OUT) $<
+
+$(COMP_GEN_OUT)/%.rdb : $(GEN_URDFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(REGMERGE) $@ /UCR $(GEN_URDFILES)
+
+$(GEN_CLASSFILES) : $(COMP_RDB)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(JAVAMAKER) -BUCR -nD $(GEN_TYPELIST) -O$(COMP_CLASS_OUT) $(COMP_RDB) -X$(URE_TYPES) -X$(OFFICE_TYPES)
+
+$(COMP_CLASSFILES) : $(COMP_JAVAFILES) $(GEN_CLASSFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(COMP_CLASS_OUT) $(COMP_JAVAFILES)
+
+# rule for component jar file
+$(COMP_JAR) : $(COMP_JAR_MANIFEST) $(COMP_CLASSFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ cd $(subst /,$(PS),$(COMP_CLASS_OUT)) && $(SDK_JAR) cvfm $(@F) $(<F) $($(basename $(basename $(@F)))_CLASSFILES)
+
+# rule for component package manifest
+$(COMP_GEN_OUT)/%/manifest.xml :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
+ @echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@
+ @echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-typelibrary;type=RDB$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(OUT_MISC)/,,$(@D))).uno.rdb$(QM)"/$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-component;type=Java$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(OUT_MISC)/,,$(@D))).uno.jar$(QM)"/$(CSEP) >> $@
+ @echo $(OSEP)/manifest:manifest$(CSEP) >> $@
+
+# rule for component package file
+$(COMP_PACKAGE) : $(COMP_RDB) $(COMP_JAR) $(COMP_UNOPKG_MANIFEST)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ cd $(subst /,$(PS),$(COMP_GEN_OUT)) && $(SDK_ZIP) ../../bin/$(@F) $(COMP_RDB_NAME)
+ cd $(subst /,$(PS),$(COMP_CLASS_OUT)) && $(SDK_ZIP) -u ../../bin/$(@F) $(COMP_JAR_NAME)
+ cd $(subst /,$(PS),$(COMP_GEN_OUT)) && $(SDK_ZIP) -u ../../bin/$(@F) META-INF/manifest.xml
+
+$(COMP_REGISTERFLAG) : $(COMP_PACKAGE)
+ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES"
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(DEPLOYTOOL) $(COMP_PACKAGE_URL)
+ @echo flagged > $(subst /,$(PS),$@)
+else
+ @echo --------------------------------------------------------------------------------
+ @echo If you want to install your component automatically, please set the environment
+ @echo variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only
+ @echo possible if no office instance is running.
+ @echo --------------------------------------------------------------------------------
+endif
+
+JavaToDoExample : $(COMP_REGISTERFLAG)
+ @echo --------------------------------------------------------------------------------
+ @echo The $(COMP_NAME) Java component was installed if SDK_AUTO_DEPLOYMENT = YES.
+ @echo Please load the "$(QM)ToDo.ods$(QM)" document to see how this component works, see
+ @echo the example description.
+ @echo -
+ @echo $(MAKE) ToDo.ods.load
+ @echo --------------------------------------------------------------------------------
+
+ToDo.ods.load : $(COMP_REGISTERFLAG)
+ "$(OFFICE_PROGRAM_PATH)$(PS)soffice" $(basename $@)
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(COMP_CLASS_OUT))
+ -$(DELRECURSIVE) $(subst /,$(PS),$(COMP_GEN_OUT))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL)))
diff --git a/odk/examples/java/ToDo/ToDo.idl b/odk/examples/java/ToDo/ToDo.idl
new file mode 100644
index 000000000000..317671d1bf7e
--- /dev/null
+++ b/odk/examples/java/ToDo/ToDo.idl
@@ -0,0 +1,50 @@
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+
+#ifndef INCLUDED_ORG_OPENOFFICE_TODO_IDL
+#define INCLUDED_ORG_OPENOFFICE_TODO_IDL
+
+#include <XToDo.idl>
+
+/// org
+module org {
+ /// openoffice
+ module openoffice {
+
+ /// example service
+ service ToDo: XToDo;
+ };
+};
+
+#endif
diff --git a/odk/examples/java/ToDo/ToDo.java b/odk/examples/java/ToDo/ToDo.java
new file mode 100644
index 000000000000..df6310b360d3
--- /dev/null
+++ b/odk/examples/java/ToDo/ToDo.java
@@ -0,0 +1,965 @@
+/*************************************************************************
+ *
+ * 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.lib.uno.helper.Factory;
+import com.sun.star.lang.XInitialization;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.lang.XSingleComponentFactory;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.lang.XTypeProvider;
+import com.sun.star.lib.uno.helper.WeakBase;
+import com.sun.star.registry.XRegistryKey;
+import com.sun.star.uno.Type;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XInterface;
+import com.sun.star.uno.XWeak;
+import com.sun.star.uno.XComponentContext;
+import org.openoffice.*;
+
+// addintional interfaces used by the implementation
+import com.sun.star.sheet.XSpreadsheetDocument;
+import com.sun.star.sheet.XSpreadsheet;
+import com.sun.star.sheet.XCellRangeMovement;
+import com.sun.star.sheet.XFunctionAccess;
+import com.sun.star.container.XIndexAccess;
+import com.sun.star.table.XCellRange;
+import com.sun.star.table.XCell;
+import com.sun.star.table.CellAddress;
+import com.sun.star.table.CellRangeAddress;
+import com.sun.star.table.XColumnRowRange;
+import com.sun.star.table.XTableRows;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.text.XTextRange;
+import com.sun.star.text.XSimpleText;
+import com.sun.star.text.XTextCursor;
+import com.sun.star.text.XText;
+import com.sun.star.text.XTextField;
+
+import java.util.GregorianCalendar;
+import java.util.Calendar;
+import java.util.Vector;
+import java.util.Arrays;
+
+/** This class capsulates the class, that implements the minimal component, a
+ * factory for creating the service (<CODE>__getServiceFactory</CODE>) and a
+ * method, that writes the information into the given registry key
+ * (<CODE>__writeRegistryServiceInfo</CODE>).
+ */
+public class ToDo {
+
+ /** This class implements the component. At least the interfaces
+ * XInterface, XTypeProvider, and XWeak implemented by the helper class
+ * WeakBase and XServiceInfo should be provided by the service.
+ */
+ public static class ToDoImpl extends WeakBase implements XServiceInfo, XToDo {
+
+ /** The service name, that must be used to get an instance of this service.
+ */
+ private static final String __serviceName = "org.openoffice.ToDo";
+
+ /** The initial component contextr, that gives access to
+ * the service manager, supported singletons, ...
+ * It's often later used
+ */
+ private XComponentContext m_cmpCtx;
+
+ /** The service manager, that gives access to all registered services.
+ * It's often later used
+ */
+ private XMultiComponentFactory m_xMCF;
+
+ // Implementation helper variables
+ static private final int INT_COLUMN_FEATURE = 0;
+ static private final int INT_COLUMN_COMMENT = 1;
+ static private final int INT_COLUMN_NEEDEDDAYS = 2;
+ static private final int INT_COLUMN_STARTDATE = 3;
+ static private final int INT_COLUMN_START_DAY_OF_WEEK = 4;
+ static private final int INT_COLUMN_ENDDATE = 5;
+ static private final int INT_COLUMN_END_DAY_OF_WEEK = 6;
+ static private final int INT_COLUMN_DUEDATE = 7;
+ static private final int INT_COLUMN_STATUS = 8;
+
+ static private final int INT_ROW_FROM = 14; // 8
+
+ static private final int INT_ROW_HOLIDAYS_START = 4;
+ static private final int INT_COLUMN_HOLIDAYS_START = 7; // 10
+
+ static private final String STRING_SEPARATOR = "/";
+
+
+ /** The constructor of the inner class has a XComponenContext parameter.
+ * @param xCompContext the initial component context
+ */
+ public ToDoImpl(XComponentContext xCompContext) {
+ try {
+ m_cmpCtx = xCompContext;
+ m_xMCF = m_cmpCtx.getServiceManager();
+ }
+ catch( Exception e ) {
+ e.printStackTrace(System.err);
+ }
+ }
+
+ /** This method returns an array of all supported service names.
+ * @return Array of supported service names.
+ */
+ public String[] getSupportedServiceNames() {
+ return getServiceNames();
+ }
+
+ public static String[] getServiceNames() {
+ String[] sSupportedServiceNames = { __serviceName };
+ return sSupportedServiceNames;
+ }
+
+ /** This method returns true, if the given service will be
+ * supported by the component.
+ * @param sService Service name.
+ * @return True, if the given service name will be supported.
+ */
+ public boolean supportsService(String sServiceName) {
+ return sServiceName.equals( __serviceName );
+ }
+
+ /** Return the class name of the component.
+ * @return Class name of the component.
+ */
+ public String getImplementationName() {
+ return ToDoImpl.class.getName();
+ }
+
+ /** For every bug/feature listed in a spreadsheet document this method
+ * calculates the start date, day of week of the start date, the end date
+ * and the day of week of the end date. All calculations are dependent
+ * on the values of "Needed Days", "Due Date" and "Status". The columns
+ * "Needed Days" and "Status" are mandatory. The first feature/bug should
+ * be placed in row nine. The date to start the calculation should be
+ * placed in cell C6. The private holidays should be placed in cell K4/K5
+ * and below. All rows will be calculated up to the first empty cell in
+ * the first column. If a cell in the column "Due Date" will be colored
+ * red, you should take a look at your entries.
+ * @param aInstance Spreadsheet document.
+ * @throws com.sun.star.uno.RuntimeException This exception could occur
+ * at every interface method.
+ */
+ public void recalc( java.lang.Object aInstance )
+ throws com.sun.star.uno.RuntimeException {
+ try {
+ // Querying for the interface XSpreadsheetDocument
+ XSpreadsheetDocument xspreadsheetdocument =
+ ( XSpreadsheetDocument ) UnoRuntime.queryInterface(
+ XSpreadsheetDocument.class, aInstance );
+
+ // Querying for the interface XIndexAccess
+ XIndexAccess xindexaccess = ( XIndexAccess )
+ UnoRuntime.queryInterface( XIndexAccess.class,
+ xspreadsheetdocument.getSheets() );
+
+ // Getting the first XSpreadsheet
+ XSpreadsheet xspreadsheet = (XSpreadsheet)UnoRuntime.queryInterface(
+ XSpreadsheet.class, xindexaccess.getByIndex( 0 ));
+
+ // Querying for the interface XCellRange on the XSpeadsheet
+ XCellRange xcellrange = ( XCellRange )
+ UnoRuntime.queryInterface( XCellRange.class, xspreadsheet );
+
+ /* Getting the gregorian calendar with the date on which to start
+ the calculation */
+ GregorianCalendar gregCalAbsoluteStartDate =
+ this.getGregorianCalendarFromString(this.getStringFromCell(
+ xcellrange, 5, 2 ) );
+ gregCalAbsoluteStartDate.add( Calendar.DATE, -1 );
+
+ // Set the start date with the absolute start date
+ GregorianCalendar gregCalStartDate =
+ (GregorianCalendar) gregCalAbsoluteStartDate.clone();
+
+ /* Creating the service FunctionAccess, which allows generic
+ access to all spreadsheet functions */
+ Object objectFunctionAccess =
+ m_xMCF.createInstanceWithContext(
+ "com.sun.star.sheet.FunctionAccess", m_cmpCtx );
+
+ // Querying for the interface XFunctionAccess on service
+ // FunctionAccess
+ XFunctionAccess xfunctionaccess = (XFunctionAccess)
+ UnoRuntime.queryInterface(XFunctionAccess.class,
+ objectFunctionAccess );
+
+ // Creating vector for holidays
+ Vector vectorHolidays = new Vector();
+
+ // Get the Official Holidays
+ this.getOfficialHolidays( vectorHolidays, xcellrange,
+ xfunctionaccess,
+ gregCalStartDate.get(
+ Calendar.YEAR ) );
+
+ // Get the private holidays
+ this.getPrivateHolidays(vectorHolidays, xcellrange,
+ xfunctionaccess);
+
+ // Getting the object array of holidays
+ Object[] objectSortedHolidays = vectorHolidays.toArray();
+
+ // Sorting the holidays
+ Arrays.sort( objectSortedHolidays );
+
+ // Collect the Official Holidays and the private holidays
+ Object [][]objectHolidays =
+ new Object[][] { objectSortedHolidays };
+
+ // Row index
+ int intRowTo = this.INT_ROW_FROM - 1;
+
+ // Getting the feature of the first cell
+ String sFeature = this.getStringFromCell(xcellrange,
+ intRowTo + 1,
+ this.INT_COLUMN_FEATURE);
+
+ // Determine the last row with an entry in the first column
+ while ( ( sFeature != null ) &&
+ ( !sFeature.equals( "" ) ) ) {
+ intRowTo++;
+ sFeature = this.getStringFromCell( xcellrange,
+ intRowTo + 1, this.INT_COLUMN_FEATURE );
+ }
+
+ // Setting the last row to be calculated
+ final int INT_ROW_TO = intRowTo + 1;
+
+ // Deleting cells which will be recalculated
+ for ( int intRow = this.INT_ROW_FROM; intRow < INT_ROW_TO + 5;
+ intRow++ ) {
+ for ( int intColumn = this.INT_COLUMN_STARTDATE;
+ intColumn <= this.INT_COLUMN_END_DAY_OF_WEEK;
+ intColumn++ ) {
+ this.setStringToCell(xcellrange, intRow, intColumn, "");
+ }
+ }
+
+ /* Clearing the background color of the due date cells and setting
+ the hyperlink to the bugtracker */
+ for (int intRow = this.INT_ROW_FROM; intRow < INT_ROW_TO; intRow++)
+ {
+ // Querying for the interface XPropertySet for the cell
+ // providing the due date
+ XPropertySet xpropertyset = ( XPropertySet )
+ UnoRuntime.queryInterface(XPropertySet.class,
+ xcellrange.getCellByPosition(
+ this.INT_COLUMN_DUEDATE,
+ intRow ));
+
+ // Changing the background color of the cell to white
+ xpropertyset.setPropertyValue( "CellBackColor",
+ new Integer( 16777215 ) );
+
+ // Getting the cell of the bug id
+ XCell xcell = xcellrange.getCellByPosition(
+ this.INT_COLUMN_FEATURE, intRow );
+
+ // Querying for the interface XSimpleText
+ XSimpleText xsimpletext = ( XSimpleText )
+ UnoRuntime.queryInterface( XSimpleText.class, xcell );
+
+ // Getting the text cursor
+ XTextCursor xtextcursor = xsimpletext.createTextCursor();
+
+ // Querying for the interface XTextRange
+ XTextRange xtextrange = ( XTextRange )
+ UnoRuntime.queryInterface( XTextRange.class, xtextcursor );
+
+ // Getting the bug ID from the cell
+ String sBugID = xtextrange.getString();
+ if ( !sBugID.startsWith(
+ "http://www.openoffice.org/issues/show_bug.cgi?id=") ) {
+ String sBugIDLink =
+ "http://www.openoffice.org/issues/show_bug.cgi?id=" + sBugID;
+
+ // Querying for the interface XMultiServiceFactory
+ XMultiServiceFactory xMSFTextField =
+ (XMultiServiceFactory)UnoRuntime.queryInterface(
+ XMultiServiceFactory.class, aInstance );
+
+ // Creating an instance of the text field URL
+ Object objectTextField =
+ xMSFTextField.createInstance(
+ "com.sun.star.text.TextField.URL" );
+
+ // Querying for the interface XTextField
+ XTextField xtextfield = ( XTextField )
+ UnoRuntime.queryInterface( XTextField.class,
+ objectTextField );
+
+ // Querying for the interface XPropertySet
+ XPropertySet xpropertysetTextField = ( XPropertySet )
+ UnoRuntime.queryInterface( XPropertySet.class,
+ xtextfield );
+
+ // Setting the URL
+ xpropertysetTextField.setPropertyValue( "URL",
+ sBugIDLink );
+
+ // Setting the representation of the URL
+ xpropertysetTextField.setPropertyValue( "Representation",
+ sBugID );
+
+ // Querying for the interface XText
+ XText xtext = ( XText )UnoRuntime.queryInterface(
+ XText.class, xcell );
+
+ // Delete cell content
+ xtextrange.setString( "" );
+
+ // Inserting the text field URL to the cell
+ xtext.insertTextContent( xtextrange, xtextfield, false );
+ }
+ }
+
+ // Processing all features/bugs in the table
+ for (int intRow = this.INT_ROW_FROM; intRow < INT_ROW_TO; intRow++)
+ {
+ // Getting the cell of the column "Needed Days" in the
+ // current row
+ XCell xcell = xcellrange.getCellByPosition(
+ INT_COLUMN_NEEDEDDAYS, intRow );
+
+ // Getting the number of needed days to perform the feature
+ int intNeededDays = (int) Math.round( xcell.getValue() );
+
+ // Getting the content of a specified cell
+ String sStatus = this.getStringFromCell( xcellrange,
+ intRow, this.INT_COLUMN_STATUS );
+
+ /* Testing if the number of needed days is greater than
+ zero and if
+ the status is not "done" */
+ if ( ( intNeededDays > 0 )
+ && !( sStatus.toLowerCase().trim().equals("done")) ) {
+ // Getting the start date after a specified number of
+ // workdays
+ gregCalStartDate = this.getWorkday(
+ gregCalStartDate, 1, objectHolidays,
+ xfunctionaccess );
+
+ // Getting a string with the date format jjjj-mm-dd from
+ // the gregorian calendar
+ String sDate = this.getStringFromGregorianCalendar(
+ gregCalStartDate );
+
+ // Set the start date in the specified cell of the table
+ this.setStringToCell(xcellrange, intRow,
+ this.INT_COLUMN_STARTDATE, sDate);
+
+ // For the start day set the day of week in the specified
+ // cell of the table
+ this.setDayOfWeek( gregCalStartDate,
+ xcellrange, intRow,
+ this.INT_COLUMN_START_DAY_OF_WEEK );
+
+ // Getting the end date after a specified number of workdays
+ GregorianCalendar gregCalEndDate =
+ this.getWorkday( gregCalStartDate,
+ intNeededDays - 1,
+ objectHolidays, xfunctionaccess );
+
+ // Creating a string with the date format jjjj-mm-dd
+ sDate = this.getStringFromGregorianCalendar(
+ gregCalEndDate );
+
+ // Set the end date in the specified cell of the table
+ this.setStringToCell( xcellrange, intRow,
+ this.INT_COLUMN_ENDDATE, sDate );
+
+ // For the end day set the day of week in the specified
+ // cell of the table
+ this.setDayOfWeek(gregCalEndDate, xcellrange,
+ intRow, this.INT_COLUMN_END_DAY_OF_WEEK);
+
+ // Set the initial date for the next loop
+ gregCalStartDate = ( GregorianCalendar )
+ gregCalEndDate.clone();
+
+ // Get the due date from the table
+ String sDueDate = this.getStringFromCell(
+ xcellrange, intRow, this.INT_COLUMN_DUEDATE );
+
+ // Testing if the due date is not empty
+ if ( !sDueDate.equals( "" ) ) {
+ GregorianCalendar gregCalDueDate =
+ this.getGregorianCalendarFromString(sDueDate);
+
+ // Testing if the due date is before the calculated
+ // end date
+ if ( gregCalDueDate.before(
+ gregCalEndDate ) ) {
+ /* Getting the date when the processing of the
+ feature/bug should
+ be started at the latest */
+ GregorianCalendar gregCalLatestDateToStart =
+ this.getWorkday(gregCalDueDate,
+ -( intNeededDays - 1 ),
+ objectHolidays,
+ xfunctionaccess);
+
+ // Begin with the current row
+ int intRowToInsert = intRow;
+
+ // Get the start date for the feature/bug in the
+ // current row
+ GregorianCalendar gregCalPreviousStartDate =
+ this.getGregorianCalendarFromString(
+ this.getStringFromCell(
+ xcellrange, intRowToInsert,
+ this.INT_COLUMN_STARTDATE ) );
+
+ // Testing if we have to search for an earlier date
+ // to begin
+ while ((gregCalLatestDateToStart.before(
+ gregCalPreviousStartDate)) &&
+ (INT_ROW_FROM != intRowToInsert)) {
+ // Decrease the row
+ intRowToInsert--;
+
+ // Get the start date for the feature/bug in
+ // the current row
+ String sStartDate = this.getStringFromCell(
+ xcellrange, intRowToInsert,
+ this.INT_COLUMN_STARTDATE );
+
+ // Search until a valid start date is found
+ while ( sStartDate.equals( "" ) ) {
+ // Decrease the row
+ intRowToInsert--;
+
+ // Get the start date for the feature/bug
+ // in the current row
+ sStartDate = this.getStringFromCell(
+ xcellrange, intRowToInsert,
+ this.INT_COLUMN_STARTDATE );
+ }
+
+ // Get the GregorianCalender format for the
+ // start date
+ gregCalPreviousStartDate =
+ this.getGregorianCalendarFromString(
+ sStartDate );
+ }
+
+ // Getting the cell of the column "Needed Days"
+ // in the row where to insert
+ XCell xcellNeededDaysWhereToInsert =
+ xcellrange.getCellByPosition(
+ INT_COLUMN_NEEDEDDAYS, intRowToInsert );
+ // Getting the number of needed days to perform
+ // the feature
+ int intNeededDaysWhereToInsert = (int)
+ Math.round(
+ xcellNeededDaysWhereToInsert.getValue());
+
+ GregorianCalendar gregCalPreviousNewEndDate =
+ this.getWorkday(gregCalPreviousStartDate,
+ intNeededDays - 1 +
+ intNeededDaysWhereToInsert,
+ objectHolidays,
+ xfunctionaccess);
+ String sPreviousDueDate = this.getStringFromCell(
+ xcellrange, intRowToInsert,
+ this.INT_COLUMN_DUEDATE );
+
+ GregorianCalendar gregCalPreviousDueDate = null;
+
+ if ( !sPreviousDueDate.equals( "" ) ) {
+ gregCalPreviousDueDate =
+ this.getGregorianCalendarFromString(
+ sPreviousDueDate );
+ }
+
+ if ( ( intRowToInsert == intRow ) ||
+ ( gregCalPreviousNewEndDate.after(
+ gregCalPreviousDueDate ) ) ) {
+ // Querying for the interface XPropertySet for
+ // the cell providing the due date
+ XPropertySet xpropertyset = ( XPropertySet )
+ UnoRuntime.queryInterface(
+ XPropertySet.class,
+ xcellrange.getCellByPosition(
+ this.INT_COLUMN_DUEDATE,
+ intRow ) );
+
+ // Changing the background color of the cell
+ // to red
+ xpropertyset.setPropertyValue(
+ "CellBackColor", new Integer( 16711680 ) );
+ } else {
+ // Querying for the interface XColumnRowRange
+ // on the XCellRange
+ XColumnRowRange xcolumnrowrange =
+ ( XColumnRowRange)UnoRuntime.queryInterface(
+ XColumnRowRange.class, xcellrange );
+ // Inserting one row to the table
+ XTableRows xTableRows =
+ xcolumnrowrange.getRows();
+ xTableRows.insertByIndex( intRowToInsert, 1 );
+
+ // Querying for the interface
+ // XCellRangeMovement on XCellRange
+ XCellRangeMovement xcellrangemovement =
+ (XCellRangeMovement)UnoRuntime.queryInterface(
+ XCellRangeMovement.class, xcellrange );
+
+ // Creating the cell address of the destination
+ CellAddress celladdress = new CellAddress();
+ celladdress.Sheet = 0;
+ celladdress.Column = 0;
+ celladdress.Row = intRowToInsert;
+
+ // Creating the cell range of the source
+ CellRangeAddress cellrangeaddress =
+ new CellRangeAddress();
+ cellrangeaddress.Sheet = 0;
+ cellrangeaddress.StartColumn = 0;
+ cellrangeaddress.StartRow = intRow + 1;
+ cellrangeaddress.EndColumn = 8;
+ cellrangeaddress.EndRow = intRow + 1;
+
+ // Moves the cell range to another position in
+ // the document
+ xcellrangemovement.moveRange(celladdress,
+ cellrangeaddress);
+
+ // Removing the row not needed anymore
+ xcolumnrowrange.getRows().removeByIndex(intRow
+ + 1, 1);
+
+ // Set the current row, because we want to
+ // recalculate all rows below
+ intRow = intRowToInsert - 1;
+
+ // Tests at which line we want to insert
+ if ( intRow >= this.INT_ROW_FROM ) {
+ // Get the start date
+ gregCalStartDate =
+ this.getGregorianCalendarFromString(
+ this.getStringFromCell( xcellrange,
+ intRow,this.INT_COLUMN_ENDDATE));
+ }
+ else {
+ // Set the start date with the absolute s
+ // tart date
+ gregCalStartDate = (GregorianCalendar)
+ gregCalAbsoluteStartDate.clone();
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ catch( Exception exception ) {
+ showExceptionMessage( exception );
+ }
+ }
+
+ /** Getting a string from a gregorian calendar.
+ * @param gregCal Date to be converted.
+ * @return string (converted gregorian calendar).
+ */
+ public String getStringFromGregorianCalendar( GregorianCalendar gregCal ) {
+ String sDate = ( gregCal.get( Calendar.MONTH ) + 1 )
+ + STRING_SEPARATOR + gregCal.get( Calendar.DATE )
+// + STRING_SEPARATOR + ( gregCal.get( Calendar.MONTH ) + 1 )
+ + STRING_SEPARATOR + gregCal.get( Calendar.YEAR );
+
+ return sDate;
+ }
+
+ /** Getting a GregorianCalendar from a string.
+ * @param sDate String to be converted.
+ * @return The result of the converting of the string.
+ */
+ public GregorianCalendar getGregorianCalendarFromString( String sDate ) {
+ int []intDateValue = this.getDateValuesFromString( sDate );
+
+ return( new GregorianCalendar( intDateValue[ 2 ], intDateValue[ 0 ],
+ intDateValue[ 1 ] ) );
+ }
+
+ /** Getting the day, month and year from a string.
+ * @param sDate String to be parsed.
+ * @return Returns an array of integer variables.
+ */
+ public int[] getDateValuesFromString( String sDate) {
+ int[] intDateValues = new int[ 3 ];
+
+ int intPositionFirstTag = sDate.indexOf( STRING_SEPARATOR );
+ int intPositionSecondTag = sDate.indexOf(STRING_SEPARATOR,
+ intPositionFirstTag + 1);
+
+ // Getting the value of the month
+ intDateValues[ 0 ] = Integer.parseInt(
+ sDate.substring(0, intPositionFirstTag)) - 1;
+ // Getting the value of the day
+ intDateValues[ 1 ] = Integer.parseInt(
+ sDate.substring(intPositionFirstTag + 1, intPositionSecondTag));
+ // Getting the value of the year
+ intDateValues[ 2 ] = Integer.parseInt(
+ sDate.substring(intPositionSecondTag + 1, sDate.length()));
+
+ return intDateValues;
+ }
+
+ /** Getting a content from a specified cell.
+ * @param xcellrange Providing access to cells.
+ * @param intRow Number of row.
+ * @param intColumn Number of column.
+ * @return String from the specified cell.
+ */
+ public String getStringFromCell( XCellRange xcellrange, int intRow,
+ int intColumn ) {
+ XTextRange xtextrangeStartDate = null;
+
+ try {
+ // Getting the cell holding the information about the start date
+ XCell xcellStartDate = xcellrange.getCellByPosition(intColumn,
+ intRow);
+ // Querying for the interface XTextRange on the XCell
+ xtextrangeStartDate = (XTextRange)
+ UnoRuntime.queryInterface(XTextRange.class, xcellStartDate);
+ }
+ catch( Exception exception ) {
+ this.showExceptionMessage( exception );
+ }
+
+ // Getting the start date
+ return xtextrangeStartDate.getString().trim();
+ }
+
+ /** Writing a specified string to a specified cell.
+ * @param xcellrange Providing access to the cells.
+ * @param intRow Number of row.
+ * @param intColumn Number of column.
+ * @param sDate Date to write to the cell.
+ */
+ public void setStringToCell( XCellRange xcellrange, int intRow,
+ int intColumn, String sDate ) {
+ try {
+ // Getting the cell holding the information on the day to start
+ XCell xcellStartDate = xcellrange.getCellByPosition(intColumn,
+ intRow);
+ // Querying for the interface XTextRange on the XCell
+ XTextRange xtextrange = (XTextRange)
+ UnoRuntime.queryInterface(XTextRange.class, xcellStartDate);
+ // Setting the new start date
+ xtextrange.setString( sDate );
+ }
+ catch( Exception exception ) {
+ this.showExceptionMessage( exception );
+ }
+ }
+
+ /** Calculates the week of day and calls the method "setStringToCell".
+ * @param gregCal Day to be written to the cell.
+ * @param xcellrange Providing access to the cells.
+ * @param intRow Number of row.
+ * @param intColumn Number of column.
+ */
+ public void setDayOfWeek( GregorianCalendar gregCal,
+ XCellRange xcellrange, int intRow,
+ int intColumn) {
+ int intDayOfWeek = gregCal.get( Calendar.DAY_OF_WEEK );
+ String sDayOfWeek = "";
+ if ( intDayOfWeek == Calendar.MONDAY ) {
+ sDayOfWeek = "MON";
+ } else if ( intDayOfWeek == Calendar.TUESDAY ) {
+ sDayOfWeek = "TUE";
+ } else if ( intDayOfWeek == Calendar.WEDNESDAY ) {
+ sDayOfWeek = "WED";
+ } else if ( intDayOfWeek == Calendar.THURSDAY ) {
+ sDayOfWeek = "THU";
+ } else if ( intDayOfWeek == Calendar.FRIDAY ) {
+ sDayOfWeek = "FRI";
+ }
+
+ this.setStringToCell( xcellrange, intRow, intColumn,
+ sDayOfWeek );
+ }
+
+ /** Calculates the dates of the official holidays with help of Calc
+ * functions.
+ * @param vectorHolidays Holding all holidays.
+ * @param xcellrange Providing the cells.
+ * @param xfunctionaccess Provides access to functions of the Calc.
+ * @param intYear Year to calculate the official holidays.
+ */
+ public void getOfficialHolidays(
+ Vector vectorHolidays,
+ XCellRange xcellrange,
+ XFunctionAccess xfunctionaccess,
+ int intYear ) {
+ try {
+ // Official Holidays for how many years?
+ final int intHowManyYears = 2;
+
+ // Get the Official Holiday for two years
+ for ( int intNumberOfYear = 0;
+ intNumberOfYear <= ( intHowManyYears - 1 );
+ intNumberOfYear++ ) {
+ intYear += intNumberOfYear;
+
+ // Getting the Easter sunday
+ Double dEasterSunday = ( Double )
+ xfunctionaccess.callFunction(
+ "EASTERSUNDAY", new Object[] { new Integer(intYear) });
+
+ int intEasterSunday = (int)Math.round(
+ dEasterSunday.doubleValue());
+
+ // New-year
+ vectorHolidays.addElement( xfunctionaccess.callFunction(
+ "DATE",
+ new Object[] {
+ new Integer( intYear ),
+ new Integer( 1 ),
+ new Integer( 1 ) } ));
+
+ // Good Friday
+ vectorHolidays.addElement(
+ new Double( intEasterSunday - 2 ) );
+
+ // Easter monday
+ vectorHolidays.addElement(
+ new Double( intEasterSunday + 1 ) );
+
+ // Labour Day
+ vectorHolidays.addElement( xfunctionaccess.callFunction(
+ "DATE",
+ new Object[] {
+ new Integer( intYear ),
+ new Integer( 5 ),
+ new Integer( 1 ) } ));
+
+ // Ascension Day
+ vectorHolidays.addElement(new Double(intEasterSunday + 39 ));
+
+ // Pentecost monday
+ vectorHolidays.addElement(new Double(intEasterSunday + 50 ));
+
+ // German Unification
+ vectorHolidays.addElement( xfunctionaccess.callFunction(
+ "DATE",
+ new Object[] {
+ new Integer( intYear ),
+ new Integer( 10 ),
+ new Integer( 3 ) } ));
+
+ // Christmas Day First
+ vectorHolidays.addElement( xfunctionaccess.callFunction(
+ "DATE",
+ new Object[] {
+ new Integer( intYear ),
+ new Integer( 12 ),
+ new Integer( 25 ) } ));
+
+ // Christmas Day Second
+ vectorHolidays.addElement( xfunctionaccess.callFunction(
+ "DATE",
+ new Object[] {
+ new Integer( intYear ),
+ new Integer( 12 ),
+ new Integer( 26 ) } ));
+ }
+ }
+ catch( Exception exception ) {
+ this.showExceptionMessage( exception );
+ }
+ }
+
+ /** Returns the serial number of the date before or after a specified
+ * number of workdays.
+ * @param gregCalStartDate Date to start with the calculation.
+ * @param intDays Number of workdays (e.g. 5 or -3).
+ * @param objectHolidays Private and public holidays to take into account.
+ * @param xfunctionaccess Allows to call functions from the Calc.
+ * @return The gregorian date before or after a specified number of
+ * workdays.
+ */
+ public GregorianCalendar getWorkday(
+ GregorianCalendar gregCalStartDate,
+ int intDays, Object[][] objectHolidays,
+ XFunctionAccess xfunctionaccess ) {
+ GregorianCalendar gregCalWorkday = null;
+
+ try {
+ // Getting the value of the start date
+ Double dDate = ( Double ) xfunctionaccess.callFunction(
+ "DATE",
+ new Object[] {
+ new Integer( gregCalStartDate.get( Calendar.YEAR ) ),
+ new Integer( gregCalStartDate.get( Calendar.MONTH ) + 1 ),
+ new Integer( gregCalStartDate.get( Calendar.DATE ) )
+ } );
+
+ Double dWorkday = ( Double ) xfunctionaccess.callFunction(
+ "com.sun.star.sheet.addin.Analysis.getWorkday",
+ new Object[] { dDate, new Integer( intDays ), objectHolidays } );
+
+ Double dYear = ( Double ) xfunctionaccess.callFunction(
+ "YEAR", new Object[] { dWorkday } );
+ Double dMonth = ( Double ) xfunctionaccess.callFunction(
+ "MONTH", new Object[] { dWorkday } );
+ Double dDay = ( Double ) xfunctionaccess.callFunction(
+ "DAY", new Object[] { dWorkday } );
+
+ gregCalWorkday = new GregorianCalendar(
+ dYear.intValue(),
+ dMonth.intValue() - 1,
+ dDay.intValue() );
+ }
+ catch( Exception exception ) {
+ this.showExceptionMessage( exception );
+ }
+
+ return gregCalWorkday;
+ }
+
+ /** Getting the holidays from the spreadsheet.
+ * @param vectorHolidays Holding all holidays.
+ * @param xcellrange Providing the cells.
+ * @param xfunctionaccess Provides the access to functions of the Calc.
+ */
+ public void getPrivateHolidays( Vector vectorHolidays,
+ XCellRange xcellrange,
+ XFunctionAccess xfunctionaccess ) {
+ try {
+ int intRow = this.INT_ROW_HOLIDAYS_START;
+ int intColumn = this.INT_COLUMN_HOLIDAYS_START;
+
+ double dHolidayStart = xcellrange.getCellByPosition(
+ intColumn, intRow ).getValue();
+
+ double dHolidayEnd = xcellrange.getCellByPosition(
+ intColumn + 1, intRow ).getValue();
+
+ while ( dHolidayStart != 0 ) {
+ if ( dHolidayEnd == 0 ) {
+ vectorHolidays.addElement(
+ new Integer( (int) Math.round(
+ dHolidayStart ) ) );
+ }
+ else {
+ for ( int intHoliday = (int) Math.round(
+ dHolidayStart );
+ intHoliday <= (int) Math.round( dHolidayEnd );
+ intHoliday++ ) {
+ vectorHolidays.addElement( new Double( intHoliday ) );
+ }
+ }
+
+ intRow++;
+ dHolidayStart = xcellrange.getCellByPosition(
+ intColumn, intRow).getValue();
+ dHolidayEnd = xcellrange.getCellByPosition(
+ intColumn + 1, intRow).getValue();
+ }
+ }
+ catch( Exception exception ) {
+ this.showExceptionMessage( exception );
+ }
+ }
+
+ /** Showing the stack trace in a JOptionPane.
+ * @param sMessage The message to show.
+ */
+ public void showMessage( String sMessage ) {
+ javax.swing.JFrame jframe = new javax.swing.JFrame();
+ jframe.setLocation(100, 100);
+ jframe.setSize(300, 200);
+ jframe.setVisible(true);
+ javax.swing.JOptionPane.showMessageDialog(
+ jframe, sMessage, "Debugging information",
+ javax.swing.JOptionPane.INFORMATION_MESSAGE);
+ jframe.dispose();
+ }
+
+ /** Writing the stack trace from an exception to a string and calling
+ * the method showMessage() with this string.
+ * @param exception The occured exception.
+ * @see showMessage
+ */
+ public void showExceptionMessage( Exception exception ) {
+ java.io.StringWriter swriter = new java.io.StringWriter();
+ java.io.PrintWriter printwriter =
+ new java.io.PrintWriter( swriter );
+ exception.printStackTrace( printwriter);
+ System.err.println( exception );
+ this.showMessage( swriter.getBuffer().substring(0) );
+ }
+ }
+
+ /**
+ * Gives a factory for creating the service.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return returns a <code>XSingleComponentFactory</code> for creating
+ * the component
+ * @param sImplName the name of the implementation for which a
+ * service is desired
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static XSingleComponentFactory __getComponentFactory(String sImplName) {
+ XSingleComponentFactory xFactory = null;
+
+ if ( sImplName.equals( ToDoImpl.class.getName() ) )
+ xFactory = Factory.createComponentFactory(ToDoImpl.class,
+ ToDoImpl.getServiceNames());
+
+ return xFactory;
+ }
+
+ /**
+ * Writes the service information into the given registry key.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return returns true if the operation succeeded
+ * @param regKey the registryKey
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
+ return Factory.writeRegistryServiceInfo(ToDoImpl.class.getName(),
+ ToDoImpl.getServiceNames(), regKey);
+ }
+}
+
diff --git a/odk/examples/java/ToDo/ToDo.ods b/odk/examples/java/ToDo/ToDo.ods
new file mode 100644
index 000000000000..344a5c2e9f47
--- /dev/null
+++ b/odk/examples/java/ToDo/ToDo.ods
Binary files differ
diff --git a/odk/examples/java/ToDo/XToDo.idl b/odk/examples/java/ToDo/XToDo.idl
new file mode 100644
index 000000000000..10d592f77aad
--- /dev/null
+++ b/odk/examples/java/ToDo/XToDo.idl
@@ -0,0 +1,50 @@
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+
+#ifndef INCLUDED_ORG_OPENOFFICE_XTODO_IDL
+#define INCLUDED_ORG_OPENOFFICE_XTODO_IDL
+
+
+/// org
+module org {
+ /// openoffice
+ module openoffice {
+ /// example interface
+ interface XToDo {
+ void recalc( [in] any aInstance );
+ };
+ };
+};
+
+#endif
diff --git a/odk/examples/java/makefile.mk b/odk/examples/java/makefile.mk
new file mode 100644
index 000000000000..564b615e9356
--- /dev/null
+++ b/odk/examples/java/makefile.mk
@@ -0,0 +1,155 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org 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 version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+PRJ=..$/..
+PRJNAME=odk
+TARGET=copying
+
+#----------------------------------------------------------------
+.INCLUDE: settings.mk
+.INCLUDE: $(PRJ)$/util$/makefile.pmk
+#----------------------------------------------------------------
+
+#----------------------------------------------------
+# this makefile is only used for copying the example
+# files into the SDK
+#----------------------------------------------------
+
+DRAWING_FILES= \
+ $(DESTDIRJAVAEXAMPLES)$/Drawing$/SDraw.java \
+ $(DESTDIRJAVAEXAMPLES)$/Drawing$/Makefile
+
+SPREADSHEET_FILES= \
+ $(DESTDIRJAVAEXAMPLES)$/Spreadsheet$/SCalc.java \
+ $(DESTDIRJAVAEXAMPLES)$/Spreadsheet$/EuroAdaption.java \
+ $(DESTDIRJAVAEXAMPLES)$/Spreadsheet$/ChartTypeChange.java \
+ $(DESTDIRJAVAEXAMPLES)$/Spreadsheet$/CalcAddins.java \
+ $(DESTDIRJAVAEXAMPLES)$/Spreadsheet$/CalcAddins.ods \
+ $(DESTDIRJAVAEXAMPLES)$/Spreadsheet$/XCalcAddins.idl \
+ $(DESTDIRJAVAEXAMPLES)$/Spreadsheet$/Makefile
+
+TEXT_FILES= \
+ $(DESTDIRJAVAEXAMPLES)$/Text$/SWriter.java \
+ $(DESTDIRJAVAEXAMPLES)$/Text$/StyleInitialization.java \
+ $(DESTDIRJAVAEXAMPLES)$/Text$/TextDocumentStructure.java \
+ $(DESTDIRJAVAEXAMPLES)$/Text$/TextReplace.java \
+ $(DESTDIRJAVAEXAMPLES)$/Text$/BookmarkInsertion.java \
+ $(DESTDIRJAVAEXAMPLES)$/Text$/HardFormatting.java \
+ $(DESTDIRJAVAEXAMPLES)$/Text$/StyleCreation.java \
+ $(DESTDIRJAVAEXAMPLES)$/Text$/WriterSelector.java \
+ $(DESTDIRJAVAEXAMPLES)$/Text$/GraphicsInserter.java \
+ $(DESTDIRJAVAEXAMPLES)$/Text$/oo_smiley.gif \
+ $(DESTDIRJAVAEXAMPLES)$/Text$/Makefile
+
+DOCUMENTHANDLING_FILES= \
+ $(DESTDIRJAVAEXAMPLES)$/DocumentHandling$/DocumentConverter.java \
+ $(DESTDIRJAVAEXAMPLES)$/DocumentHandling$/DocumentLoader.java \
+ $(DESTDIRJAVAEXAMPLES)$/DocumentHandling$/DocumentPrinter.java \
+ $(DESTDIRJAVAEXAMPLES)$/DocumentHandling$/DocumentSaver.java \
+ $(DESTDIRJAVAEXAMPLES)$/DocumentHandling$/Makefile \
+ $(DESTDIRJAVAEXAMPLES)$/DocumentHandling$/test$/test1.odt
+
+CONVERTERSERVLET_FILES= \
+ $(DESTDIRJAVAEXAMPLES)$/ConverterServlet$/ConverterServlet.html \
+ $(DESTDIRJAVAEXAMPLES)$/ConverterServlet$/ConverterServlet.java \
+ $(DESTDIRJAVAEXAMPLES)$/ConverterServlet$/web.xml \
+ $(DESTDIRJAVAEXAMPLES)$/ConverterServlet$/Makefile \
+ $(DESTDIRJAVAEXAMPLES)$/ConverterServlet$/README
+
+EMBEDDEDOBJECT_FILES= \
+ $(DESTDIRJAVAEXAMPLES)$/EmbedDocument$/EmbeddedObject$/EmbeddedObject.xcu \
+ $(DESTDIRJAVAEXAMPLES)$/EmbedDocument$/EmbeddedObject$/OwnEmbeddedObject.java \
+ $(DESTDIRJAVAEXAMPLES)$/EmbedDocument$/EmbeddedObject$/EditorFrame.java \
+ $(DESTDIRJAVAEXAMPLES)$/EmbedDocument$/EmbeddedObject$/Makefile \
+ $(DESTDIRJAVAEXAMPLES)$/EmbedDocument$/EmbeddedObject$/OwnEmbeddedObjectFactory.java
+
+INSPECTOR_FILES= \
+ $(DESTDIRJAVAEXAMPLES)$/Inspector$/Inspector.jpg \
+ $(DESTDIRJAVAEXAMPLES)$/Inspector$/InspectorThumbnail.jpg \
+ $(DESTDIRJAVAEXAMPLES)$/Inspector$/Inspector.uno.xml \
+ $(DESTDIRJAVAEXAMPLES)$/Inspector$/Inspector.java \
+ $(DESTDIRJAVAEXAMPLES)$/Inspector$/Makefile \
+ $(DESTDIRJAVAEXAMPLES)$/Inspector$/TestInspector.java \
+ $(DESTDIRJAVAEXAMPLES)$/Inspector$/XInstanceInspector.idl \
+ $(DESTDIRJAVAEXAMPLES)$/Inspector$/InstanceInspector.idl \
+ $(DESTDIRJAVAEXAMPLES)$/Inspector$/InstanceInspectorTest.odt
+
+NOTESACCESS_FILES= \
+ $(DESTDIRJAVAEXAMPLES)$/NotesAccess$/NotesAccess.java \
+ $(DESTDIRJAVAEXAMPLES)$/NotesAccess$/Makefile \
+ $(DESTDIRJAVAEXAMPLES)$/NotesAccess$/Stocks.nsf
+
+TODO_FILES= \
+ $(DESTDIRJAVAEXAMPLES)$/ToDo$/ToDo.java \
+ $(DESTDIRJAVAEXAMPLES)$/ToDo$/ToDo.ods \
+ $(DESTDIRJAVAEXAMPLES)$/ToDo$/ToDo.uno.xml \
+ $(DESTDIRJAVAEXAMPLES)$/ToDo$/ToDo.idl \
+ $(DESTDIRJAVAEXAMPLES)$/ToDo$/XToDo.idl \
+ $(DESTDIRJAVAEXAMPLES)$/ToDo$/Makefile
+
+MINIMALCOMPONENT_FILES= \
+ $(DESTDIRJAVAEXAMPLES)$/MinimalComponent$/MinimalComponent.idl \
+ $(DESTDIRJAVAEXAMPLES)$/MinimalComponent$/MinimalComponent.java\
+ $(DESTDIRJAVAEXAMPLES)$/MinimalComponent$/MinimalComponent.uno.xml \
+ $(DESTDIRJAVAEXAMPLES)$/MinimalComponent$/TestMinimalComponent.java\
+ $(DESTDIRJAVAEXAMPLES)$/MinimalComponent$/Makefile
+
+PROPERTYSET_FILES= \
+ $(DESTDIRJAVAEXAMPLES)$/PropertySet$/PropTest.java \
+ $(DESTDIRJAVAEXAMPLES)$/PropertySet$/PropertySet.odt \
+ $(DESTDIRJAVAEXAMPLES)$/PropertySet$/Makefile
+
+DIR_FILE_LIST= \
+ $(DRAWING_FILES) \
+ $(SPREADSHEET_FILES) \
+ $(TEXT_FILES) \
+ $(DOCUMENTHANDLING_FILES) \
+ $(CONVERTERSERVLET_FILES) \
+ $(EMBEDDEDOBJECT_FILES) \
+ $(INSPECTOR_FILES) \
+ $(NOTESACCESS_FILES) \
+ $(TODO_FILES) \
+ $(MINIMALCOMPONENT_FILES) \
+ $(PROPERTYSET_FILES)
+
+DIR_DIRECTORY_LIST=$(uniq $(DIR_FILE_LIST:d))
+DIR_CREATE_FLAG=$(MISC)$/ex_java_dirs_created.txt
+DIR_FILE_FLAG=$(MISC)$/ex_java_files.txt
+
+#--------------------------------------------------
+# TARGETS
+#--------------------------------------------------
+all : \
+ $(DIR_FILE_LIST) \
+ $(DIR_FILE_FLAG)
+
+#--------------------------------------------------
+# use global rules
+#--------------------------------------------------
+.INCLUDE: $(PRJ)$/util$/odk_rules.pmk
+
+