summaryrefslogtreecommitdiffstats
path: root/odk/examples/java
diff options
context:
space:
mode:
Diffstat (limited to 'odk/examples/java')
-rw-r--r--odk/examples/java/ConverterServlet/ConverterServlet.html64
-rw-r--r--odk/examples/java/ConverterServlet/ConverterServlet.java325
-rw-r--r--odk/examples/java/ConverterServlet/Makefile93
-rw-r--r--odk/examples/java/ConverterServlet/README38
-rw-r--r--odk/examples/java/ConverterServlet/web.xml40
-rw-r--r--odk/examples/java/DocumentHandling/DocumentConverter.java226
-rw-r--r--odk/examples/java/DocumentHandling/DocumentLoader.java94
-rw-r--r--odk/examples/java/DocumentHandling/DocumentPrinter.java111
-rw-r--r--odk/examples/java/DocumentHandling/DocumentSaver.java131
-rw-r--r--odk/examples/java/DocumentHandling/Makefile144
-rw-r--r--odk/examples/java/DocumentHandling/test/test1.odtbin0 -> 397817 bytes
-rw-r--r--odk/examples/java/Drawing/Makefile91
-rw-r--r--odk/examples/java/Drawing/SDraw.java266
-rw-r--r--odk/examples/java/EmbedDocument/Container1/EmbedContApp.java1044
-rw-r--r--odk/examples/java/EmbedDocument/Container1/EmbedContFrame.java128
-rw-r--r--odk/examples/java/EmbedDocument/Container1/Makefile65
-rw-r--r--odk/examples/java/EmbedDocument/EmbeddedObject/EditorFrame.java134
-rw-r--r--odk/examples/java/EmbedDocument/EmbeddedObject/EmbeddedObject.odtbin0 -> 9975 bytes
-rw-r--r--odk/examples/java/EmbedDocument/EmbeddedObject/EmbeddedObject.xcu45
-rw-r--r--odk/examples/java/EmbedDocument/EmbeddedObject/Makefile148
-rw-r--r--odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObject.components8
-rw-r--r--odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObject.java1123
-rw-r--r--odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObjectFactory.java106
-rw-r--r--odk/examples/java/Inspector/Addons.xcu40
-rw-r--r--odk/examples/java/Inspector/HideableMutableTreeNode.java106
-rw-r--r--odk/examples/java/Inspector/HideableTreeModel.java258
-rw-r--r--odk/examples/java/Inspector/Inspector.java459
-rw-r--r--odk/examples/java/Inspector/InspectorAddon.java224
-rw-r--r--odk/examples/java/Inspector/InspectorPane.java577
-rw-r--r--odk/examples/java/Inspector/InstanceInspectorTest.odtbin0 -> 12272 bytes
-rw-r--r--odk/examples/java/Inspector/Introspector.java643
-rw-r--r--odk/examples/java/Inspector/Makefile186
-rw-r--r--odk/examples/java/Inspector/MethodParametersDialog.java351
-rw-r--r--odk/examples/java/Inspector/ObjectInspector.xcs34
-rw-r--r--odk/examples/java/Inspector/ObjectInspector.xcu31
-rw-r--r--odk/examples/java/Inspector/ProtocolHandler.xcu28
-rw-r--r--odk/examples/java/Inspector/ProtocolHandlerAddon.java273
-rw-r--r--odk/examples/java/Inspector/SourceCodeGenerator.java1635
-rw-r--r--odk/examples/java/Inspector/SwingDialogProvider.java444
-rw-r--r--odk/examples/java/Inspector/SwingTreeControlProvider.java423
-rw-r--r--odk/examples/java/Inspector/SwingTreePathProvider.java60
-rw-r--r--odk/examples/java/Inspector/SwingUnoFacetteNode.java84
-rw-r--r--odk/examples/java/Inspector/SwingUnoMethodNode.java144
-rw-r--r--odk/examples/java/Inspector/SwingUnoNode.java160
-rw-r--r--odk/examples/java/Inspector/SwingUnoPropertyNode.java102
-rw-r--r--odk/examples/java/Inspector/TDocSupplier.java166
-rw-r--r--odk/examples/java/Inspector/TestInspector.java88
-rw-r--r--odk/examples/java/Inspector/UnoMethodNode.java228
-rw-r--r--odk/examples/java/Inspector/UnoNode.java351
-rw-r--r--odk/examples/java/Inspector/UnoPropertyNode.java218
-rw-r--r--odk/examples/java/Inspector/UnoTreeRenderer.java122
-rw-r--r--odk/examples/java/Inspector/XDialogProvider.java68
-rw-r--r--odk/examples/java/Inspector/XLanguageSourceCodeGenerator.java108
-rw-r--r--odk/examples/java/Inspector/XTreeControlProvider.java96
-rw-r--r--odk/examples/java/Inspector/XTreePathProvider.java33
-rw-r--r--odk/examples/java/Inspector/XUnoFacetteNode.java66
-rw-r--r--odk/examples/java/Inspector/XUnoMethodNode.java70
-rw-r--r--odk/examples/java/Inspector/XUnoNode.java87
-rw-r--r--odk/examples/java/Inspector/XUnoPropertyNode.java54
-rw-r--r--odk/examples/java/Inspector/description.xml15
-rw-r--r--odk/examples/java/Inspector/images/containers_16.pngbin0 -> 233 bytes
-rw-r--r--odk/examples/java/Inspector/images/content_16.pngbin0 -> 370 bytes
-rw-r--r--odk/examples/java/Inspector/images/interfaces_16.pngbin0 -> 433 bytes
-rw-r--r--odk/examples/java/Inspector/images/methods_16.pngbin0 -> 380 bytes
-rw-r--r--odk/examples/java/Inspector/images/properties_16.pngbin0 -> 242 bytes
-rw-r--r--odk/examples/java/Inspector/images/services_16.pngbin0 -> 258 bytes
-rw-r--r--odk/examples/java/Inspector/manifest.mf3
-rw-r--r--odk/examples/java/Inspector/org/openoffice/InstanceInspector.idl55
-rw-r--r--odk/examples/java/Inspector/org/openoffice/XInstanceInspector.idl59
-rw-r--r--odk/examples/java/MinimalComponent/Makefile199
-rw-r--r--odk/examples/java/MinimalComponent/MinimalComponent.components8
-rw-r--r--odk/examples/java/MinimalComponent/MinimalComponent.idl55
-rw-r--r--odk/examples/java/MinimalComponent/MinimalComponent.java156
-rw-r--r--odk/examples/java/MinimalComponent/TestMinimalComponent.java67
-rw-r--r--odk/examples/java/MinimalComponent/description.xml15
-rw-r--r--odk/examples/java/NotesAccess/Makefile112
-rw-r--r--odk/examples/java/NotesAccess/NotesAccess.java282
-rw-r--r--odk/examples/java/NotesAccess/Stocks.nsfbin0 -> 262144 bytes
-rw-r--r--odk/examples/java/PropertySet/Makefile135
-rw-r--r--odk/examples/java/PropertySet/PropTest.components8
-rw-r--r--odk/examples/java/PropertySet/PropTest.java262
-rw-r--r--odk/examples/java/PropertySet/PropertySet.odtbin0 -> 8391 bytes
-rw-r--r--odk/examples/java/Spreadsheet/CalcAddins.components9
-rw-r--r--odk/examples/java/Spreadsheet/CalcAddins.java283
-rw-r--r--odk/examples/java/Spreadsheet/CalcAddins.odsbin0 -> 8653 bytes
-rw-r--r--odk/examples/java/Spreadsheet/ChartTypeChange.java347
-rw-r--r--odk/examples/java/Spreadsheet/EuroAdaption.java383
-rw-r--r--odk/examples/java/Spreadsheet/Makefile209
-rw-r--r--odk/examples/java/Spreadsheet/SCalc.java408
-rw-r--r--odk/examples/java/Spreadsheet/XCalcAddins.idl103
-rw-r--r--odk/examples/java/Spreadsheet/description.xml15
-rw-r--r--odk/examples/java/Storage/Makefile75
-rw-r--r--odk/examples/java/Storage/StorageFunctionality.java156
-rw-r--r--odk/examples/java/Storage/StorageTest.java25
-rw-r--r--odk/examples/java/Storage/Test01.java169
-rw-r--r--odk/examples/java/Storage/Test02.java165
-rw-r--r--odk/examples/java/Storage/Test03.java220
-rw-r--r--odk/examples/java/Storage/Test04.java282
-rw-r--r--odk/examples/java/Storage/Test05.java278
-rw-r--r--odk/examples/java/Storage/Test06.java285
-rw-r--r--odk/examples/java/Storage/Test07.java148
-rw-r--r--odk/examples/java/Storage/Test08.java224
-rw-r--r--odk/examples/java/Storage/Test09.java134
-rw-r--r--odk/examples/java/Storage/TestHelper.java881
-rw-r--r--odk/examples/java/Text/BookmarkInsertion.java275
-rw-r--r--odk/examples/java/Text/GraphicsInserter.java195
-rw-r--r--odk/examples/java/Text/HardFormatting.java279
-rw-r--r--odk/examples/java/Text/Makefile135
-rw-r--r--odk/examples/java/Text/SWriter.java390
-rw-r--r--odk/examples/java/Text/StyleCreation.java224
-rw-r--r--odk/examples/java/Text/StyleInitialization.java311
-rw-r--r--odk/examples/java/Text/TextDocumentStructure.java201
-rw-r--r--odk/examples/java/Text/TextReplace.java224
-rw-r--r--odk/examples/java/Text/WriterSelector.java161
-rw-r--r--odk/examples/java/Text/oo_smiley.gifbin0 -> 46109 bytes
-rw-r--r--odk/examples/java/ToDo/Makefile160
-rw-r--r--odk/examples/java/ToDo/ToDo.components8
-rw-r--r--odk/examples/java/ToDo/ToDo.java932
-rw-r--r--odk/examples/java/ToDo/ToDo.odsbin0 -> 13276 bytes
-rw-r--r--odk/examples/java/ToDo/description.xml15
-rw-r--r--odk/examples/java/ToDo/org/openoffice/ToDo.idl53
-rw-r--r--odk/examples/java/ToDo/org/openoffice/XToDo.idl53
122 files changed, 22287 insertions, 0 deletions
diff --git a/odk/examples/java/ConverterServlet/ConverterServlet.html b/odk/examples/java/ConverterServlet/ConverterServlet.html
new file mode 100644
index 000000000..7ef0a0db3
--- /dev/null
+++ b/odk/examples/java/ConverterServlet/ConverterServlet.html
@@ -0,0 +1,64 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+-->
+<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 000000000..91380ab86
--- /dev/null
+++ b/odk/examples/java/ConverterServlet/ConverterServlet.java
@@ -0,0 +1,325 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// JDK API
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.File;
+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;
+// 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 static final String stringHost = "localhost";
+
+ /** Specifies the port for the office server.
+ */
+ private static final 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.
+ */
+ @Override
+ 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 Message:</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 an 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 = 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 = UnoRuntime.queryInterface( XMultiComponentFactory.class, objectInitial );
+
+ // Query for the XPropertySet interface.
+ XPropertySet xpropertysetMultiComponentFactory = UnoRuntime.queryInterface( XPropertySet.class, xmulticomponentfactory );
+
+ // Get the default context from the office server.
+ Object objectDefaultContext =
+ xpropertysetMultiComponentFactory.getPropertyValue( "DefaultContext" );
+
+ // Query for the interface 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 instantiate within
+ frames. */
+ 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 to hide the open document
+ propertyvalue[ 0 ] = new PropertyValue();
+ propertyvalue[ 0 ].Name = "Hidden";
+ propertyvalue[ 0 ].Value = 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 =
+ 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 = 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 = 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 = UnoRuntime.queryInterface(
+ XComponent.class, xstorable );
+ xComponent.dispose();
+ }
+
+ if ( stringConvertedFile.startsWith( "file:///" ) ) {
+ // Truncating the beginning of the file name
+ stringConvertedFile = stringConvertedFile.substring( 8 );
+ }
+
+ // Returning the name of the converted file
+ return stringConvertedFile;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/ConverterServlet/Makefile b/odk/examples/java/ConverterServlet/Makefile
new file mode 100644
index 000000000..2dff683c3
--- /dev/null
+++ b/odk/examples/java/ConverterServlet/Makefile
@@ -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.
+#
+#**************************************************************************
+
+# Builds the Java ConverterServlet example of the SDK.
+
+PRJ=../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.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 000000000..ea59b80b4
--- /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 000000000..a0f36c7b2
--- /dev/null
+++ b/odk/examples/java/ConverterServlet/web.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+-->
+
+<!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 000000000..386af9f1f
--- /dev/null
+++ b/odk/examples/java/DocumentHandling/DocumentConverter.java
@@ -0,0 +1,226 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.uno.UnoRuntime;
+
+import java.io.File;
+
+
+/** The class <CODE>DocumentConverter</CODE> allows you to convert all documents
+ * in a given directory and in its subdirectories to a given type. A converted
+ * document will be created in the same directory as the origin document.
+ *
+ */
+public class DocumentConverter {
+ /** Containing the loaded documents
+ */
+ static com.sun.star.frame.XComponentLoader xCompLoader = null;
+ /** Containing the given type to convert to
+ */
+ static String sConvertType = "";
+ /** Containing the given extension
+ */
+ static String sExtension = "";
+ /** Containing the current file or directory
+ */
+ static String sIndent = "";
+ /** Containing the directory where the converted files are saved
+ */
+ static String sOutputDir = "";
+
+ /** Traversing the given directory recursively and converting their files to
+ * the favoured type if possible
+ * @param fileDirectory Containing the directory
+ */
+ static void traverse( File fileDirectory ) {
+ // Testing, if the file is a directory, and if so, it throws an exception
+ if ( !fileDirectory.isDirectory() ) {
+ throw new IllegalArgumentException(
+ "not a directory: " + fileDirectory.getName()
+ );
+ }
+
+ // Prepare Url for the output directory
+ File outdir = new File(DocumentConverter.sOutputDir);
+ String sOutUrl = "file:///" + outdir.getAbsolutePath().replace( '\\', '/' );
+
+ System.out.println("\nThe converted documents will stored in \""
+ + outdir.getPath() + "!");
+
+ System.out.println(sIndent + "[" + fileDirectory.getName() + "]");
+ sIndent += " ";
+
+ // Getting all files and directories in the current directory
+ File[] entries = fileDirectory.listFiles();
+
+
+ // Iterating for each file and directory
+ for ( int i = 0; i < entries.length; ++i ) {
+ // Testing, if the entry in the list is a directory
+ if ( entries[ i ].isDirectory() ) {
+ // Recursive call for the new directory
+ traverse( entries[ i ] );
+ } else {
+ // Converting the document to the favoured type
+ try {
+ // Composing the URL by replacing all backslashes
+ String sUrl = "file:///"
+ + entries[ i ].getAbsolutePath().replace( '\\', '/' );
+
+ // Loading the wanted document
+ com.sun.star.beans.PropertyValue propertyValues[] =
+ new com.sun.star.beans.PropertyValue[1];
+ propertyValues[0] = new com.sun.star.beans.PropertyValue();
+ propertyValues[0].Name = "Hidden";
+ propertyValues[0].Value = Boolean.TRUE;
+
+ Object oDocToStore =
+ DocumentConverter.xCompLoader.loadComponentFromURL(
+ sUrl, "_blank", 0, propertyValues);
+
+ // Getting an object that will offer a simple way to store
+ // a document to a URL.
+ com.sun.star.frame.XStorable xStorable =
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XStorable.class, oDocToStore );
+
+ // Preparing properties for converting the document
+ propertyValues = new com.sun.star.beans.PropertyValue[2];
+ // Setting the flag for overwriting
+ propertyValues[0] = new com.sun.star.beans.PropertyValue();
+ propertyValues[0].Name = "Overwrite";
+ propertyValues[0].Value = Boolean.TRUE;
+ // Setting the filter name
+ propertyValues[1] = new com.sun.star.beans.PropertyValue();
+ propertyValues[1].Name = "FilterName";
+ propertyValues[1].Value = DocumentConverter.sConvertType;
+
+ // Appending the favoured extension to the origin document name
+ int index1 = sUrl.lastIndexOf('/');
+ int index2 = sUrl.lastIndexOf('.');
+ String sStoreUrl = sOutUrl + sUrl.substring(index1, index2 + 1)
+ + DocumentConverter.sExtension;
+
+ // Storing and converting the document
+ xStorable.storeAsURL(sStoreUrl, propertyValues);
+
+ // Closing the converted document. Use XCloseable.close if the
+ // interface is supported, otherwise use XComponent.dispose
+ com.sun.star.util.XCloseable xCloseable =
+ UnoRuntime.queryInterface(
+ com.sun.star.util.XCloseable.class, xStorable);
+
+ if ( xCloseable != null ) {
+ xCloseable.close(false);
+ } else {
+ com.sun.star.lang.XComponent xComp =
+ UnoRuntime.queryInterface(
+ com.sun.star.lang.XComponent.class, xStorable);
+
+ xComp.dispose();
+ }
+ }
+ catch( Exception e ) {
+ e.printStackTrace(System.err);
+ }
+
+ System.out.println(sIndent + entries[ i ].getName());
+ }
+ }
+
+ sIndent = sIndent.substring(2);
+ }
+
+ /** Bootstrap UNO, getting the remote component context, getting a new instance
+ * of the desktop (used interface XComponentLoader) and calling the
+ * static method traverse
+ * @param args The array of the type String contains the directory, in which
+ * all files should be converted, the favoured converting type
+ * and the wanted extension
+ */
+ public static void main( String args[] ) {
+ if ( args.length < 3 ) {
+ System.out.println("usage: java -jar DocumentConverter.jar " +
+ "\"<directory to convert>\" \"<type to convert to>\" " +
+ "\"<extension>\" \"<output_directory>\"");
+ System.out.println("\ne.g.:");
+ System.out.println("usage: java -jar DocumentConverter.jar " +
+ "\"c:/myoffice\" \"swriter: MS Word 97\" \"doc\"");
+ System.exit(1);
+ }
+
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ try {
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+
+ // get the remote office service manager
+ com.sun.star.lang.XMultiComponentFactory xMCF =
+ xContext.getServiceManager();
+
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext);
+
+ xCompLoader = UnoRuntime.queryInterface(com.sun.star.frame.XComponentLoader.class,
+ oDesktop);
+
+ // Getting the given starting directory
+ File file = new File(args[0]);
+
+ // Getting the given type to convert to
+ sConvertType = args[1];
+
+ // Getting the given extension that should be appended to the
+ // origin document
+ sExtension = args[2];
+
+ // Getting the given type to convert to
+ sOutputDir = args[3];
+
+ // Starting the conversion of documents in the given directory
+ // and subdirectories
+ traverse(file);
+
+ System.exit(0);
+ } catch( Exception e ) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/DocumentHandling/DocumentLoader.java b/odk/examples/java/DocumentHandling/DocumentLoader.java
new file mode 100644
index 000000000..63d8dc66e
--- /dev/null
+++ b/odk/examples/java/DocumentHandling/DocumentLoader.java
@@ -0,0 +1,94 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.uno.UnoRuntime;
+
+
+/** This class opens a new or an existing office document.
+ */
+public class DocumentLoader {
+ public static void main(String args[]) {
+ if ( args.length < 1 ) {
+ System.out.println(
+ "usage: java -jar DocumentLoader.jar \"<URL|path>\"" );
+ System.out.println( "\ne.g.:" );
+ System.out.println(
+ "java -jar DocumentLoader.jar \"private:factory/swriter\"" );
+ System.exit(1);
+ }
+
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ try {
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+
+ // get the remote office service manager
+ com.sun.star.lang.XMultiComponentFactory xMCF =
+ xContext.getServiceManager();
+
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext);
+
+ com.sun.star.frame.XComponentLoader xCompLoader =
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class, oDesktop);
+
+ String sUrl = args[0];
+ if ( sUrl.indexOf("private:") != 0) {
+ java.io.File sourceFile = new java.io.File(args[0]);
+ StringBuffer sbTmp = new StringBuffer("file:///");
+ sbTmp.append(sourceFile.getCanonicalPath().replace('\\', '/'));
+ sUrl = sbTmp.toString();
+ }
+
+ // Load a Writer document, which will be automatically displayed
+ com.sun.star.lang.XComponent xComp = xCompLoader.loadComponentFromURL(
+ sUrl, "_blank", 0, new com.sun.star.beans.PropertyValue[0]);
+
+ if ( xComp != null )
+ System.exit(0);
+ else
+ System.exit(1);
+ }
+ catch( Exception e ) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/DocumentHandling/DocumentPrinter.java b/odk/examples/java/DocumentHandling/DocumentPrinter.java
new file mode 100644
index 000000000..dfa35aedd
--- /dev/null
+++ b/odk/examples/java/DocumentHandling/DocumentPrinter.java
@@ -0,0 +1,111 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.uno.UnoRuntime;
+
+
+public class DocumentPrinter {
+ public static void main(String args[]) {
+ if ( args.length < 3 ) {
+ System.out.println("usage: java -jar DocumentLoader.jar " +
+ "\"<Favoured printer>\" \"<URL|path>\" \"<Pages>\"");
+ System.out.println( "\ne.g.:" );
+ System.out.println("java -jar DocumentLoader.jar \"amadeus\" " +
+ "\"file:///f:/TestPrint.odt\" \"1-3;7;9\"");
+ System.exit(1);
+ }
+
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ try {
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+
+ // get the remote office service manager
+ com.sun.star.lang.XMultiComponentFactory xMCF =
+ xContext.getServiceManager();
+
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext);
+
+ com.sun.star.frame.XComponentLoader xCompLoader =
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class, oDesktop);
+
+ java.io.File sourceFile = new java.io.File(args[1]);
+ StringBuffer sUrl = new StringBuffer("file:///");
+ sUrl.append(sourceFile.getCanonicalPath().replace('\\', '/'));
+
+ // Load a Writer document, which will be automatically displayed
+ com.sun.star.lang.XComponent xComp = xCompLoader.loadComponentFromURL(
+ sUrl.toString(), "_blank", 0,
+ new com.sun.star.beans.PropertyValue[0] );
+
+ // Querying for the interface XPrintable on the loaded document
+ com.sun.star.view.XPrintable xPrintable =
+ UnoRuntime.queryInterface(
+ com.sun.star.view.XPrintable.class, xComp);
+
+ // Setting the property "Name" for the favoured printer (name of
+ // IP address)
+ com.sun.star.beans.PropertyValue propertyValue[] =
+ new com.sun.star.beans.PropertyValue[1];
+ propertyValue[0] = new com.sun.star.beans.PropertyValue();
+ propertyValue[0].Name = "Name";
+ propertyValue[0].Value = args[ 0 ];
+
+ // Setting the name of the printer
+ xPrintable.setPrinter( propertyValue );
+
+ // Setting the property "Pages" so that only the desired pages
+ // will be printed.
+ propertyValue[0] = new com.sun.star.beans.PropertyValue();
+ propertyValue[0].Name = "Pages";
+ propertyValue[0].Value = args[ 2 ];
+
+ // Printing the loaded document
+ xPrintable.print( propertyValue );
+
+ System.exit(0);
+ }
+ catch( Exception e ) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/DocumentHandling/DocumentSaver.java b/odk/examples/java/DocumentHandling/DocumentSaver.java
new file mode 100644
index 000000000..ec1ce9242
--- /dev/null
+++ b/odk/examples/java/DocumentHandling/DocumentSaver.java
@@ -0,0 +1,131 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.uno.UnoRuntime;
+
+
+/** The purpose of this class is to open a specified text document and save this
+ * file to a specified URL. The type of the saved file is
+ * "swriter: StarOffice XML (Writer)".
+ */
+public class DocumentSaver {
+ /** The main method of the application.
+ * @param args The program needs two arguments:
+ * - full file name to open,
+ * - full file name to save.
+ */
+ public static void main(String args[]) {
+ if ( args.length < 2 ) {
+ System.out.println("usage: java -jar DocumentSaver.jar" +
+ "\"<URL|path to load>\" \"<URL|path to save>\"");
+ System.out.println("\ne.g.:");
+ System.out.println("java -jar DocumentSaver " +
+ "\"file:///f:/TestPrint.doc\"" +
+ "\"file:///f:/TestPrint.odt\"");
+ System.exit(1);
+ }
+
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ try {
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+
+ // get the remote office service manager
+ com.sun.star.lang.XMultiComponentFactory xMCF =
+ xContext.getServiceManager();
+
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext);
+
+ com.sun.star.frame.XComponentLoader xCompLoader =
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class, oDesktop);
+
+ java.io.File sourceFile = new java.io.File(args[0]);
+ StringBuffer sLoadUrl = new StringBuffer("file:///");
+ sLoadUrl.append(sourceFile.getCanonicalPath().replace('\\', '/'));
+
+ sourceFile = new java.io.File(args[1]);
+ StringBuffer sSaveUrl = new StringBuffer("file:///");
+ sSaveUrl.append(sourceFile.getCanonicalPath().replace('\\', '/'));
+
+ com.sun.star.beans.PropertyValue[] propertyValue =
+ new com.sun.star.beans.PropertyValue[1];
+ propertyValue[0] = new com.sun.star.beans.PropertyValue();
+ propertyValue[0].Name = "Hidden";
+ propertyValue[0].Value = Boolean.TRUE;
+
+ Object oDocToStore = xCompLoader.loadComponentFromURL(
+ sLoadUrl.toString(), "_blank", 0, propertyValue );
+ com.sun.star.frame.XStorable xStorable =
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XStorable.class, oDocToStore );
+
+ propertyValue = new com.sun.star.beans.PropertyValue[ 2 ];
+ propertyValue[0] = new com.sun.star.beans.PropertyValue();
+ propertyValue[0].Name = "Overwrite";
+ propertyValue[0].Value = Boolean.TRUE;
+ propertyValue[1] = new com.sun.star.beans.PropertyValue();
+ propertyValue[1].Name = "FilterName";
+ propertyValue[1].Value = "StarOffice XML (Writer)";
+ xStorable.storeAsURL( sSaveUrl.toString(), propertyValue );
+
+ System.out.println("\nDocument \"" + sLoadUrl + "\" saved under \"" +
+ sSaveUrl + "\"\n");
+
+ com.sun.star.util.XCloseable xCloseable = UnoRuntime.queryInterface(com.sun.star.util.XCloseable.class,
+ oDocToStore );
+
+ if (xCloseable != null ) {
+ xCloseable.close(false);
+ } else
+ {
+ com.sun.star.lang.XComponent xComp = UnoRuntime.queryInterface(
+ com.sun.star.lang.XComponent.class, oDocToStore );
+ xComp.dispose();
+ }
+ System.out.println("document closed!");
+ System.exit(0);
+ }
+ catch( Exception e ) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/DocumentHandling/Makefile b/odk/examples/java/DocumentHandling/Makefile
new file mode 100644
index 000000000..d8eff760d
--- /dev/null
+++ b/odk/examples/java/DocumentHandling/Makefile
@@ -0,0 +1,144 @@
+#*************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# the BSD license.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#**************************************************************************
+
+# Builds the Java DocumentHandling examples of the SDK.
+
+PRJ=../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+
+# Define non-platform/compiler specific settings
+SAMPLE_NAME=JavaDocumentHandlingExamples
+SAMPLE_CLASS_OUT = $(OUT_CLASS)/$(SAMPLE_NAME)
+SAMPLE_GEN_OUT = $(OUT_MISC)/$(SAMPLE_NAME)
+
+DIRFLAG=$(OUT_MISC)/$(SAMPLE_NAME)_directory.flag
+
+APP1_NAME=DocumentConverter
+APP1_JAR=$(SAMPLE_CLASS_OUT)/$(APP1_NAME).jar
+APP2_NAME=DocumentLoader
+APP2_JAR=$(SAMPLE_CLASS_OUT)/$(APP2_NAME).jar
+APP3_NAME=DocumentPrinter
+APP3_JAR=$(SAMPLE_CLASS_OUT)/$(APP3_NAME).jar
+APP4_NAME=DocumentSaver
+APP4_JAR=$(SAMPLE_CLASS_OUT)/$(APP4_NAME).jar
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(SAMPLE_CLASS_OUT))
+
+
+# Targets
+.PHONY: ALL
+ALL : \
+ $(SAMPLE_NAME)
+
+include $(SETTINGS)/stdtarget.mk
+
+$(SAMPLE_CLASS_OUT)/%.class : %.java
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(SAMPLE_CLASS_OUT) $<
+
+$(SAMPLE_CLASS_OUT)/%.mf :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo Main-Class: com.sun.star.lib.loader.Loader> $@
+ $(ECHOLINE)>> $@
+ @echo Name: com/sun/star/lib/loader/Loader.class>> $@
+ @echo Application-Class: $*>> $@
+
+$(SAMPLE_CLASS_OUT)/%.jar : $(SAMPLE_CLASS_OUT)/%.mf $(SAMPLE_CLASS_OUT)/%.class
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ +cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_JAR) cvfm $(@F) $*.mf $*.class
+ +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
+
+$(APP1_JAR) : $(SAMPLE_CLASS_OUT)/$(APP1_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP1_NAME).class
+$(APP2_JAR) : $(SAMPLE_CLASS_OUT)/$(APP2_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP2_NAME).class
+$(APP3_JAR) : $(SAMPLE_CLASS_OUT)/$(APP3_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP3_NAME).class
+$(APP4_JAR) : $(SAMPLE_CLASS_OUT)/$(APP4_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP4_NAME).class
+
+$(SAMPLE_NAME) : $(APP1_JAR) $(APP2_JAR) $(APP3_JAR) $(APP4_JAR)
+ @echo --------------------------------------------------------------------------------
+ @echo The $(APP1_NAME) search the "$(QM)./test$(QM)" directory for documents, convert
+ @echo them using the "$(QM)MS Word 97$(QM)" filter and the extension "$(QM).doc$(QM)".
+ @echo The converted files are store in "$(QM)$(SAMPLE_GEN_OUT)/converted_files$(QM)".
+ @echo The list of possible filter names can change. Normally an updated list can be found
+ @echo on "$(QM)http://www.openoffice.org/files/documents/25/111/filter_description.html$(QM)".
+ @echo -
+ @echo The $(APP2_NAME) loads the document "$(QM)./test/test1.odt$(QM)".
+ @echo -
+ @echo The $(APP3_NAME) prints the document "$(QM)./test/test1.odt$(QM)" using the
+ @echo the specified printer. If the printer is unknown, the default printer is used.
+ @echo -
+ @echo The $(APP5_NAME) loads the document "$(QM)./test/test1.odt$(QM)" and saves it
+ @echo under "$(QM)$(SAMPLE_GEN_OUT)/savetest/testsave.odt$(QM)".
+ @echo -
+ @echo Please use one of the following commands to execute the examples!
+ @echo -
+ @echo $(MAKE) $(APP1_NAME).run
+ @echo $(MAKE) $(APP2_NAME).run
+ @echo $(MAKE) $(APP3_NAME).run
+ @echo $(MAKE) $(APP4_NAME).run
+ @echo --------
+ @echo The examples need parameters. Please use one the following commands to
+ @echo start the demo if you do not want the default parameters specified in the
+ @echo this makefile. Starting without parameters print a command line help:
+ @echo --- $(APP1_NAME) ---
+ @echo java -jar $(APP1_NAME).jar "$(QM)directory$(QM)" "$(QM)filter name$(QM)" "$(QM)extension$(QM)" "$(QM)output_directory$(QM)"
+ @echo --- $(APP2_NAME) ---
+ @echo java -jar $(APP2_NAME).jar "$(QM)Url|path$(QM)"
+ @echo --- $(APP3_NAME) ---
+ @echo java -jar $(APP3_NAME).jar "$(QM)printername$(QM)" "$(QM)filename$(QM)" "$(QM)pages$(QM)"
+ @echo --- $(APP4_NAME) ---
+ @echo java -jar $(APP4_NAME).jar "$(QM)load Url|path$(QM)" "$(QM)save Url|path$(QM)"
+ @echo --------------------------------------------------------------------------------
+
+$(APP1_NAME).run: $(APP1_JAR)
+ -$(MKDIR) $(subst /,$(PS),$(SAMPLE_GEN_OUT)/converted_files)
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $< "./test" "MS Word 97" "doc" "$(SAMPLE_GEN_OUT)/converted_files"
+
+$(APP2_NAME).run: $(APP2_JAR)
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $< "./test/test1.odt"
+
+$(APP3_NAME).run: $(APP3_JAR)
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $< "my_printer" "./test/test1.odt" 1
+
+$(APP4_NAME).run: $(APP4_JAR)
+ -$(MKDIR) $(subst /,$(PS),$(SAMPLE_GEN_OUT)/savetest)
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $< "./test/test1.odt" "$(SAMPLE_GEN_OUT)/savetest/testsave.odt"
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_CLASS_OUT))
+ -$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_GEN_OUT))
diff --git a/odk/examples/java/DocumentHandling/test/test1.odt b/odk/examples/java/DocumentHandling/test/test1.odt
new file mode 100644
index 000000000..6a3c769ee
--- /dev/null
+++ b/odk/examples/java/DocumentHandling/test/test1.odt
Binary files differ
diff --git a/odk/examples/java/Drawing/Makefile b/odk/examples/java/Drawing/Makefile
new file mode 100644
index 000000000..861ab96ff
--- /dev/null
+++ b/odk/examples/java/Drawing/Makefile
@@ -0,0 +1,91 @@
+#*************************************************************************
+#
+# 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
+
+# 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 000000000..5d2f9a52e
--- /dev/null
+++ b/odk/examples/java/Drawing/SDraw.java
@@ -0,0 +1,266 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+
+// 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 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 =
+ UnoRuntime.queryInterface(
+ com.sun.star.drawing.XDrawPagesSupplier.class, xDrawDoc);
+ com.sun.star.drawing.XDrawPages xDPn = xDPS.getDrawPages();
+ com.sun.star.container.XIndexAccess xDPi =
+ UnoRuntime.queryInterface(
+ com.sun.star.container.XIndexAccess.class, xDPn);
+ 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 = 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.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 = 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 =
+ UnoRuntime.queryInterface(
+ com.sun.star.lang.XMultiServiceFactory.class, xDocComp );
+
+ try {
+ Object oInt = xDocMSF.createInstance("com.sun.star.drawing."
+ +kind + "Shape");
+ 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 = UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xShape);
+
+ try {
+ xSPS.setPropertyValue("FillColor", Integer.valueOf(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 = 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 =
+ 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 = 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 occurs.FAILED
+ System.err.println( "Couldn't get Shape "+ e );
+ e.printStackTrace(System.err);
+ }
+
+ b=b+8;
+
+ com.sun.star.beans.XPropertySet xSPS = UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,
+ xShape);
+
+ try {
+ xSPS.setPropertyValue("FillColor", Integer.valueOf(getCol(r,g,b)));
+ xSPS.setPropertyValue("Shadow", 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 =
+ 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;
+ }
+}
+
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/EmbedDocument/Container1/EmbedContApp.java b/odk/examples/java/EmbedDocument/Container1/EmbedContApp.java
new file mode 100644
index 000000000..a275c27ea
--- /dev/null
+++ b/odk/examples/java/EmbedDocument/Container1/EmbedContApp.java
@@ -0,0 +1,1044 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+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.util.XCloseable;
+
+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( 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.LOADED )
+ {
+ m_xEmbedObj.changeState( EmbedStates.RUNNING );
+ nState = EmbedStates.RUNNING;
+ }
+
+ if ( nState == EmbedStates.ACTIVE || nState == EmbedStates.RUNNING )
+ {
+ XComponentSupplier xCompProv = (XComponentSupplier)UnoRuntime.queryInterface(
+ XComponentSupplier.class,
+ m_xEmbedObj );
+ if ( xCompProv != null )
+ {
+ XCloseable 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.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
+ }
+
+ 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 persistence 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 owned 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.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) 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] = Integer.valueOf( ElementModes.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] = Integer.valueOf( ElementModes.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.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.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 );
+
+ }
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/EmbedDocument/Container1/EmbedContFrame.java b/odk/examples/java/EmbedDocument/Container1/EmbedContFrame.java
new file mode 100644
index 000000000..afc3496e2
--- /dev/null
+++ b/odk/examples/java/EmbedDocument/Container1/EmbedContFrame.java
@@ -0,0 +1,128 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+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;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/EmbedDocument/Container1/Makefile b/odk/examples/java/EmbedDocument/Container1/Makefile
new file mode 100644
index 000000000..88279bbe5
--- /dev/null
+++ b/odk/examples/java/EmbedDocument/Container1/Makefile
@@ -0,0 +1,65 @@
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you under the Apache
+# License, Version 2.0 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+
+# Builds the Java Storage test example of the SDK.
+
+PRJ=../../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.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 100644
index 000000000..fb15106b7
--- /dev/null
+++ b/odk/examples/java/EmbedDocument/EmbeddedObject/EditorFrame.java
@@ -0,0 +1,134 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+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;
+
+public class EditorFrame extends JFrame
+{
+ private final OwnEmbeddedObject m_aEmbObj;
+ private final JTextArea m_aTextArea;
+ private BufferedImage m_aBufImage;
+
+ private final WindowListener m_aCloser = new WindowAdapter()
+ {
+ @Override
+ public void windowClosing( WindowEvent e )
+ {
+ 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();
+ }
+
+ 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();
+ }
+
+ 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];
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/EmbedDocument/EmbeddedObject/EmbeddedObject.odt b/odk/examples/java/EmbedDocument/EmbeddedObject/EmbeddedObject.odt
new file mode 100644
index 000000000..dde408bd3
--- /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 100644
index 000000000..ce7f3785b
--- /dev/null
+++ b/odk/examples/java/EmbedDocument/EmbeddedObject/EmbeddedObject.xcu
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+-->
+<!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 000000000..b568c39c2
--- /dev/null
+++ b/odk/examples/java/EmbedDocument/EmbeddedObject/Makefile
@@ -0,0 +1,148 @@
+#*************************************************************************
+#
+# 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
+
+# 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
+COMP_COMPONENTS=$(COMP_NAME).components
+
+PACKAGE =
+
+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.configuration-data$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(SAMPLE_NAME).xcu$(QM)"/$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-components$(QM)">> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(COMP_NAME).components$(QM)"/$(CSEP)>> $@
+ @echo $(OSEP)/manifest:manifest$(CSEP) >> $@
+
+# rule for component package file
+$(COMP_PACKAGE) : $(COMP_JAR) $(COMP_UNOPKG_MANIFEST) $(COMP_NAME).components
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_ZIP) $@ $(SAMPLE_NAME).xcu
+ $(SDK_ZIP) $@ -u $(COMP_NAME).components
+ cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_ZIP) -u $@ $(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.components b/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObject.components
new file mode 100644
index 000000000..a77b099e0
--- /dev/null
+++ b/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObject.components
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<components xmlns="http://openoffice.org/2010/uno-components">
+ <component loader="com.sun.star.loader.Java2" uri="OwnEmbeddedObject.uno.jar">
+ <implementation name="OwnEmbeddedObjectFactory">
+ <service name="org.openoffice.examples.embedding.Factory69474366FD6F480683748EDD1B6E771D"/>
+ </implementation>
+ </component>
+</components>
diff --git a/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObject.java b/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObject.java
new file mode 100644
index 000000000..f2377dcbc
--- /dev/null
+++ b/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObject.java
@@ -0,0 +1,1123 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+import java.awt.Dimension;
+import java.util.ArrayList;
+
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.configuration.theDefaultProvider;
+import com.sun.star.container.XNameAccess;
+import com.sun.star.embed.VisualRepresentation;
+import com.sun.star.embed.XStorage;
+import com.sun.star.embed.XTransactedObject;
+import com.sun.star.io.XInputStream;
+import com.sun.star.io.XOutputStream;
+import com.sun.star.io.XStream;
+import com.sun.star.io.XTruncate;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lib.uno.helper.WeakBase;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+
+public final class OwnEmbeddedObject extends WeakBase
+ implements com.sun.star.embed.XEmbedPersist,
+ com.sun.star.embed.XEmbeddedObject
+{
+ private final XComponentContext m_xContext;
+ private final byte[] m_aClassID;
+
+ private boolean m_bDisposed = false;
+ private int m_nObjectState = -1;
+
+ private com.sun.star.embed.XStorage m_xParentStorage;
+ private com.sun.star.embed.XStorage m_xOwnStorage;
+ private String m_aEntryName;
+
+ private com.sun.star.embed.XStorage m_xNewParentStorage;
+ private com.sun.star.embed.XStorage m_xNewOwnStorage;
+ private String m_aNewEntryName;
+ private boolean m_bWaitSaveCompleted = false;
+
+ private EditorFrame m_aEditorFrame;
+
+ private ArrayList<Object> m_aListeners;
+
+ private com.sun.star.embed.VerbDescriptor[] m_pOwnVerbs;
+
+ private com.sun.star.embed.XEmbeddedClient m_xClient;
+
+ private Dimension m_aObjSize;
+
+
+ private ArrayList<Object> GetListeners()
+ {
+ if ( m_aListeners == null )
+ m_aListeners = new ArrayList<Object>(10);
+
+ return m_aListeners;
+ }
+
+
+ private 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();
+ }
+
+
+ private 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;
+ }
+ }
+
+
+ private 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.io.IOException e )
+ {
+ throw e;
+ }
+ catch( com.sun.star.uno.Exception e )
+ {
+ com.sun.star.io.IOException e2 = new com.sun.star.io.IOException( "Error while switching object storage!" );
+ e2.initCause(e);
+ throw e2;
+ }
+ }
+ }
+
+
+ private 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 = UnoRuntime.queryInterface( XComponent.class, xStream );
+ if ( xStreamComp == null )
+ throw new com.sun.star.uno.RuntimeException();
+
+ XOutputStream xOutStream = xStream.getOutputStream();
+ 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 = UnoRuntime.queryInterface( XComponent.class, xStream );
+ if ( xStreamComp == null )
+ throw new com.sun.star.uno.RuntimeException();
+
+ xOutStream = xStream.getOutputStream();
+ 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 = 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 = UnoRuntime.queryInterface( XTransactedObject.class, xStorage );
+ if ( xTransact != null )
+ xTransact.commit();
+
+ xStreamComp.dispose();
+ }
+ catch( com.sun.star.io.IOException e )
+ {
+ throw e;
+ }
+ catch( com.sun.star.uno.Exception e )
+ {
+ com.sun.star.io.IOException e2 = new com.sun.star.io.IOException( "Error while switching object storage!" );
+ e2.initCause(e);
+ throw e2;
+ }
+ }
+
+
+ private 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 = 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 );
+ }
+ }
+ }
+ }
+
+
+ private 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 = 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 );
+ }
+ }
+ }
+ }
+
+
+ private 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 = 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 = "";
+
+ 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.io.IOException e )
+ {
+ throw e;
+ }
+ catch( com.sun.star.uno.Exception e )
+ {
+ com.sun.star.io.IOException e2 = new com.sun.star.io.IOException( "Error while reading one of object streams!" );
+ e2.initCause(e);
+ throw e2;
+ }
+ }
+
+
+ private 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
+ }
+
+ // 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 persistent representation without initialization
+
+ // if the object is loaded
+ // it can switch persistent 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 = 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 );
+
+ 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 "";
+ }
+
+
+ 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
+ {
+ XMultiServiceFactory xConfProvider = theDefaultProvider.get(m_xContext);
+ 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 = 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 = 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 = 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 = 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
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObjectFactory.java b/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObjectFactory.java
new file mode 100644
index 000000000..a4333a8fd
--- /dev/null
+++ b/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObjectFactory.java
@@ -0,0 +1,106 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+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;
+
+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;
+ }
+
+ // 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;
+ }
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/Addons.xcu b/odk/examples/java/Inspector/Addons.xcu
new file mode 100644
index 000000000..2ea6abdef
--- /dev/null
+++ b/odk/examples/java/Inspector/Addons.xcu
@@ -0,0 +1,40 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+-->
+<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 000000000..c601d075e
--- /dev/null
+++ b/odk/examples/java/Inspector/HideableMutableTreeNode.java
@@ -0,0 +1,106 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+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.
+ */
+ private 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 _bIsVisible 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;
+ }
+
+}
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/HideableTreeModel.java b/odk/examples/java/Inspector/HideableTreeModel.java
new file mode 100644
index 000000000..b70d63046
--- /dev/null
+++ b/odk/examples/java/Inspector/HideableTreeModel.java
@@ -0,0 +1,258 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+import java.util.ArrayList;
+import javax.swing.event.TreeModelEvent;
+import javax.swing.event.TreeModelListener;
+import javax.swing.tree.TreeModel;
+import javax.swing.tree.TreeNode;
+import javax.swing.tree.TreePath;
+
+
+public class HideableTreeModel implements TreeModel {
+
+ private ArrayList<TreeModelListener> modelListeners = new ArrayList<TreeModelListener>();
+ private Object root = null;
+
+
+ public HideableTreeModel(TreeNode _root) {
+ super();
+ setRoot(_root);
+ }
+
+
+ public Object getRoot() {
+ return this.root;
+ }
+
+
+ private void setRoot(Object r) {
+ this.root = r;
+ }
+
+
+ private 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.add(l);
+ }
+
+
+ public void removeTreeModelListener(TreeModelListener l) {
+ modelListeners.remove(l);
+ }
+
+
+
+
+
+ public void valueForPathChanged(TreePath path, Object newValue) {
+ nodeChanged(path.getLastPathComponent());
+ }
+
+
+
+
+ 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));
+ }
+ }
+
+
+ private 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));
+ }
+ }
+
+
+ private void fireTreeNodesChanged(TreeModelEvent event) {
+ for(TreeModelListener l : modelListeners) {
+ l.treeNodesChanged(event);
+ }
+ }
+
+
+ private void fireTreeNodesInserted(TreeModelEvent event) {
+ for(TreeModelListener l : modelListeners) {
+ l.treeNodesInserted(event);
+ }
+ }
+
+
+ private void fireTreeNodesRemoved(TreeModelEvent event) {
+ for(TreeModelListener l : modelListeners) {
+ l.treeNodesRemoved(event);
+ }
+ }
+
+ public boolean isLeaf(Object _oNode) {
+ if(_oNode instanceof TreeNode) {
+ return ((TreeNode) _oNode).isLeaf();
+ }
+ return true;
+ }
+
+
+
+ private Object getParent(Object node) {
+ if(node != getRoot() && (node instanceof TreeNode)) {
+ return ((TreeNode)node).getParent();
+ }
+ return null;
+ }
+
+
+ private 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 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 = 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 = 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 = p.getChildAt(i);
+ if(pc.equals(c)) {
+ return index;
+ }
+ if(isNodeVisible(pc)) {
+ index++;
+ }
+ }
+ }
+ }
+ return index;
+ }
+}
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/Inspector.java b/odk/examples/java/Inspector/Inspector.java
new file mode 100644
index 000000000..18d8d909a
--- /dev/null
+++ b/odk/examples/java/Inspector/Inspector.java
@@ -0,0 +1,459 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.openoffice.XInstanceInspector;
+
+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.configuration.theDefaultProvider;
+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.XFolderPicker2;
+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;
+
+
+/** 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/idl/ref/";
+
+
+ /** This class implements the method of the interface XInstanceInspector.
+ * Also the class implements the interfaces XServiceInfo, and XTypeProvider.
+ */
+ public static class _Inspector extends WeakBase implements XInstanceInspector, XServiceInfo{
+
+ private static final String __serviceName = "org.openoffice.InstanceInspector";
+ private HashMap<String, String> aApplicationHashMap = new HashMap<String, String>();
+ private String sTitle = "Object Inspector";
+ private ArrayList<XComponent> aHiddenDocuments = new ArrayList<XComponent>();
+ private XComponentContext m_xComponentContext;
+ private HashMap<String, InspectorPane> aInspectorPanes = new HashMap<String, InspectorPane>();
+ 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);
+ }
+
+
+ public XComponentContext getXComponentContext(){
+ return m_xComponentContext;
+ }
+
+
+ public HashMap<String, InspectorPane> getInspectorPages(){
+ return aInspectorPanes;
+ }
+
+
+ private String getSDKPath(){
+ String sRetPath = "";
+ try{
+ XNameAccess xNameAccess = getConfigurationAccess("org.openoffice.inspector.ObjectInspector", true);
+ XPropertySet xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, xNameAccess);
+ sRetPath = (String) xPropertySet.getPropertyValue("SDKPath");
+ }catch( Exception exception ) {
+ exception.printStackTrace(System.err);
+ }
+ return sRetPath;
+ }
+
+
+ public String getIDLPath(){
+ String sRetPath = getSDKPath();
+ if (m_oIntrospector.isValidSDKInstallationPath(sRetPath)){
+ sRetPath = Introspector.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);
+ XFolderPicker2 xFolderPicker = UnoRuntime.queryInterface(XFolderPicker2.class, oFolderPicker);
+ XExecutableDialog xExecutable = UnoRuntime.queryInterface(XExecutableDialog.class, oFolderPicker);
+ 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 = UnoRuntime.queryInterface(XPropertySet.class, xNameAccess);
+ xPropertySet.setPropertyValue("SDKPath", sInstallationFolder);
+ XChangesBatch xBatch = UnoRuntime.queryInterface(XChangesBatch.class, xNameAccess);
+ xBatch.commitChanges();
+ }
+ else{
+ XPropertySet xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, xFolderPicker);
+ Object oWindow = xPropertySet.getPropertyValue("Window");
+ XWindowPeer xWindowPeer = UnoRuntime.queryInterface(XWindowPeer.class, oWindow);
+ showErrorMessageBox(xWindowPeer, sTitle, sWRONGINSTALLATIONPATH);
+ assignSDKPath();
+ }
+ }
+ xComponent.dispose();
+ }catch( Exception exception ) {
+ exception.printStackTrace(System.err);
+ }}
+
+
+ private void showErrorMessageBox(XWindowPeer _xWindowPeer, String _sTitle, String _sMessage){
+ try {
+ Object oToolkit = m_xComponentContext.getServiceManager().createInstanceWithContext("com.sun.star.awt.Toolkit", m_xComponentContext);
+ XMessageBoxFactory xMessageBoxFactory = UnoRuntime.queryInterface(XMessageBoxFactory.class, oToolkit);
+ XMessageBox xMessageBox = xMessageBoxFactory.createMessageBox(_xWindowPeer, com.sun.star.awt.MessageBoxType.ERRORBOX, com.sun.star.awt.MessageBoxButtons.BUTTONS_OK, _sTitle, _sMessage);
+ XComponent xComponent = UnoRuntime.queryInterface(XComponent.class, xMessageBox);
+ if (xMessageBox != null){
+ xMessageBox.execute();
+ xComponent.dispose();
+ }
+ } catch (com.sun.star.uno.Exception ex) {
+ ex.printStackTrace(System.err);
+ }}
+
+
+ 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.err);
+ }}
+
+
+ public void inspectOpenEmptyDocument(String _sApplicationDocUrl){
+ XComponent xComponent = getTDocSupplier().openEmptyDocument(_sApplicationDocUrl);
+ String sRootTitle = 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 = 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 = 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.err);
+ }}
+
+
+ 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<String> aSet = aApplicationHashMap.keySet();
+ String[][] sReturnList = new String[aSet.size()][];
+ int n= 0;
+ for ( Iterator<String> i = aSet.iterator(); i.hasNext(); ){
+ String[] sSingleApplication = new String[2];
+ sSingleApplication[0] = i.next();
+ // assign the title in the second index
+ sSingleApplication[1] = 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 = aHiddenDocuments.get(i);
+ if (xComponent != null){
+ try {
+ XCloseable xCloseable = UnoRuntime.queryInterface(XCloseable.class, xComponent);
+ xCloseable.close(true);
+ aHiddenDocuments.remove(i);
+ } catch (CloseVetoException ex) {
+ ex.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
+
+ private 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.
+ * @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.err);
+ }
+ return nLanguage;
+ }
+
+
+ private XNameAccess getConfigurationAccess(boolean _bUpdate){
+ return getConfigurationAccess("org.openoffice.inspector.ObjectInspector", _bUpdate);
+ }
+
+
+ private 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();
+ XMultiServiceFactory xMSFCfg = theDefaultProvider.get(this.getXComponentContext());
+ Object oAccess = xMSFCfg.createInstanceWithArguments(sAccess, new Object[]{new NamedValue("nodepath", _sNodePath)});
+ 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));
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/InspectorAddon.java b/odk/examples/java/Inspector/InspectorAddon.java
new file mode 100644
index 000000000..b001d17b5
--- /dev/null
+++ b/odk/examples/java/Inspector/InspectorAddon.java
@@ -0,0 +1,224 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.frame.DispatchDescriptor;
+import com.sun.star.frame.XController;
+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 org.openoffice.XInstanceInspector xInstInspector = null;
+// Dispatcher oDispatcher = null;
+ private 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.equals("org.openoffice.Office.addon.Inspector:") ) {
+ if ( aURL.Path.equals( "inspect" ) ){
+ // 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 = UnoRuntime.queryInterface(XFrame.class, object[ 0 ] );
+ }
+ }
+
+ private class Dispatcher implements XDispatch{
+ private XFrame m_xFrame = null;
+ private XModel xModel = null;
+
+ private 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.equals("org.openoffice.Office.addon.Inspector:") ){
+ 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 = 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 = UnoRuntime.queryInterface(XFrame.class, oDesktop);
+ oUnoInspectObject = m_xFrame;
+ }
+ XPropertySet xFramePropertySet = 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.err);
+ }}
+
+ 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 ) {
+ }
+
+
+ }
+
+
+ private 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.
+ * @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);
+ }
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/InspectorPane.java b/odk/examples/java/Inspector/InspectorPane.java
new file mode 100644
index 000000000..6483958b7
--- /dev/null
+++ b/odk/examples/java/Inspector/InspectorPane.java
@@ -0,0 +1,577 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+
+import org.openoffice.XInstanceInspector;
+
+import com.sun.star.beans.Property;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.beans.XIntrospectionAccess;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.lib.uno.helper.WeakBase;
+import com.sun.star.reflection.XIdlMethod;
+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 com.sun.star.uno.XComponentContext;
+
+ public class InspectorPane extends WeakBase implements XInstanceInspector{ //, XServiceInfo
+ 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.
+ */
+ 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);
+ }
+
+ /** Inspect the given object for methods, properties, interfaces, and
+ * services.
+ * @param _oUserDefinedObject 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.err);
+ }}
+
+
+ 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 (AnyConverter.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 = Introspector.getShortClassName(aReturnObject.getType().getTypeName());
+ sNodeDescription += m_oSourceCodeGenerator.getVariableNameforUnoObject(sShortClassName);
+ }
+ if (Introspector.isArray(oUnoReturnObject)){
+ if (Introspector.isUnoTypeObject(oUnoReturnObject)){
+ oUnoNode = addUnoFacetteNode(_oUnoMethodNode, XUnoFacetteNode.SINTERFACEDESCRIPTION, _oUnoMethodNode.getUnoObject());
+ }
+ else if(Introspector.isUnoPropertyTypeObject(oUnoReturnObject)){
+ oUnoNode = addUnoFacetteNode(_oUnoMethodNode, XUnoFacetteNode.SPROPERTYINFODESCRIPTION, oUnoReturnObject);
+ }
+ else if(Introspector.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);
+ 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);
+ }
+
+
+
+ private void addMethodsToTreeNode(XUnoNode _oGrandParentNode, Object _oUnoParentObject, XIdlMethod[] _xIdlMethods){
+ if (Introspector.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)){
+ addUnoFacetteNode(_oParentNode, XUnoFacetteNode.SMETHODDESCRIPTION, _oUnoObject);
+ }
+ if (m_oIntrospector.hasProperties(_oUnoObject)){
+ addUnoFacetteNode(_oParentNode, XUnoFacetteNode.SPROPERTYDESCRIPTION, _oUnoObject);
+ }
+ if (m_oIntrospector.hasInterfaces(_oUnoObject)){
+ addUnoFacetteNode(_oParentNode, XUnoFacetteNode.SINTERFACEDESCRIPTION, _oUnoObject);
+ }
+ if (m_oIntrospector.isContainer(_oUnoObject)){
+ addUnoFacetteNode(_oParentNode, XUnoFacetteNode.SCONTAINERDESCRIPTION, _oUnoObject);
+ }
+ if (m_oIntrospector.hasSupportedServices(_oUnoObject)){
+ 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.err);
+ }}
+
+
+ // add all services for the given object to the tree under the node parent
+ private void addServicesToTreeNode(XUnoNode _oGrandParentNode, Object _oUnoObject) {
+ try{
+ 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.err);
+ }}
+
+
+ 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 = 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.err);
+ }}
+
+
+ private void addContainerElementsToTreeNode(XUnoNode _oParentNode, Object _oUnoParentObject){
+ Object[] oUnoContainerElements = m_oIntrospector.getUnoObjectsOfContainer(_oUnoParentObject);
+ if (Introspector.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 (!Introspector.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 (Introspector.isObjectPrimitive(object[i])){
+ addUnoNode(_oUnoNode, null, UnoNode.getNodeDescription(object[i]));
+ }
+ }
+ }
+ else{
+ String[] sDisplayValues = UnoNode.getDisplayValuesofPrimitiveArray(_oUnoObject);
+ for ( int i = 0; i < sDisplayValues.length; i++ ) {
+ 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 (Introspector.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 (! Introspector.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){
+ 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{
+ //TODO: this code is redundant!!!
+ if ( oUnoObject.getClass().isArray()){
+ // TODO: probably we should provide 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 distinguish the different UnoFacetteNodes only by the node description
+ 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()){
+ // TODO: probably we should provide 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);
+ }
+
+
+ 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;
+ }
+
+
+ public void showPopUpMenu(Object _invoker, int x, int y) throws ClassCastException{
+ XUnoNode oUnoNode = getSelectedNode();
+ boolean bdoEnableInvoke = oUnoNode instanceof XUnoMethodNode;
+ if (bdoEnableInvoke){
+ XUnoMethodNode oUnoMethodNode = (XUnoMethodNode) oUnoNode;
+ bdoEnableInvoke = oUnoMethodNode.isInvokable();
+ }
+ m_xDialogProvider.enablePopupMenuItem(XDialogProvider.SINVOKE, bdoEnableInvoke);
+ m_xDialogProvider.showPopUpMenu(_invoker, x, y);
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/InstanceInspectorTest.odt b/odk/examples/java/Inspector/InstanceInspectorTest.odt
new file mode 100644
index 000000000..74cde4e68
--- /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 000000000..b8d3be3c0
--- /dev/null
+++ b/odk/examples/java/Inspector/Introspector.java
@@ -0,0 +1,643 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.sun.star.beans.IllegalTypeException;
+import com.sun.star.beans.MethodConcept;
+import com.sun.star.beans.Property;
+import com.sun.star.beans.XIntrospection;
+import com.sun.star.beans.XIntrospectionAccess;
+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.lang.XMultiComponentFactory;
+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.TypeDescriptionSearchDepth;
+import com.sun.star.reflection.XConstantTypeDescription;
+import com.sun.star.reflection.XConstantsTypeDescription;
+import com.sun.star.reflection.XIdlClass;
+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.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.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;
+
+public class Introspector extends WeakBase{
+
+ private XIntrospection m_xIntrospection;
+ private XMultiComponentFactory m_xMultiComponentFactory;
+ private XComponentContext m_xComponentContext;
+ private XTypeDescriptionEnumerationAccess m_xTDEnumerationAccess;
+ private XIdlReflection mxIdlReflection;
+ 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 = UnoRuntime.queryInterface(XIntrospection.class, o );
+ Object oCoreReflection = getXMultiComponentFactory().createInstanceWithContext("com.sun.star.reflection.CoreReflection", getXComponentContext());
+ mxIdlReflection = UnoRuntime.queryInterface(XIdlReflection.class, oCoreReflection);
+ initTypeDescriptionManager();
+ }
+ catch( Exception exception ) {
+ System.err.println( exception );
+ }}
+
+
+ protected XComponentContext getXComponentContext(){
+ return m_xComponentContext;
+ }
+
+
+ private 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 = UnoRuntime.queryInterface(XEnumerationAccess.class, xIntrospectionAccessObject.queryAdapter( new Type( XEnumerationAccess.class ) ) );
+ if (xEnumerationAccess != null){
+ XEnumeration xEnumeration = xEnumerationAccess.createEnumeration();
+ bIsContainer = xEnumeration.hasMoreElements();
+ }
+ if (!bIsContainer){
+ 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.err);
+ }
+ 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 {
+ ArrayList<Object> oRetComponentsVector = new ArrayList<Object>();
+ XIntrospectionAccess xIntrospectionAccessObject = getXIntrospectionAccess(_oUnoParentObject);
+ if ( xIntrospectionAccessObject != null ) {
+ 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 = 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[] { Integer.valueOf(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;
+ }}
+
+
+
+
+
+ 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<Property> aListOfProperties = java.util.Arrays.asList(aProperties);
+ ArrayList<Property> aPropertiesVector = new ArrayList<Property>(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<Type> aListOfTypes = java.util.Arrays.asList(aTypes);
+ ArrayList<Type> aTypesVector = new ArrayList<Type>(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 = 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<? extends Object> _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 ));
+ }
+
+
+ private void initTypeDescriptionManager() {
+ try {
+ Object oTypeDescriptionManager = getXComponentContext().getValueByName("/singletons/com.sun.star.reflection.theTypeDescriptionManager");
+ m_xTDEnumerationAccess = UnoRuntime.queryInterface(XTypeDescriptionEnumerationAccess.class, oTypeDescriptionManager);
+ } catch ( java.lang.Exception e) {
+ System.out.println(System.out);
+ }}
+
+
+ private 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 = 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 = UnoRuntime.queryInterface(XServiceTypeDescription.class, xTD);
+ return xServiceTypeDescription;
+ }
+ }
+ }
+ return null;
+ } catch (Exception ex) {
+ ex.printStackTrace(System.err);
+ 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 = UnoRuntime.queryInterface(XHierarchicalNameAccess.class, m_xTDEnumerationAccess);
+ if (xHierarchicalNameAccess != null){
+ if (xHierarchicalNameAccess.hasByHierarchicalName(_sTypeName)){
+ XIndirectTypeDescription xIndirectTypeDescription = UnoRuntime.queryInterface(XIndirectTypeDescription.class, xHierarchicalNameAccess.getByHierarchicalName(_sTypeName));
+ if (xIndirectTypeDescription != null){
+ xTypeDescription = xIndirectTypeDescription.getReferencedType();
+ }
+ }
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace(System.err);
+ }
+ return xTypeDescription;
+ }
+
+
+ private 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[]{};
+ }
+
+
+ private 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");
+ }
+
+
+ private 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 isArray(Object _oObject){
+ return _oObject.getClass().isArray();
+ }
+
+
+ public boolean hasSupportedServices(Object _oUnoObject){
+ boolean bHasSupportedServices = false;
+ 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 = com.sun.star.uno.UnoRuntime.queryInterface(XSimpleFileAccess.class, oSimpleFileAccess);
+ }
+ return xSimpleFileAccess;
+ } catch (com.sun.star.uno.Exception ex) {
+ ex.printStackTrace(System.err);
+ 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.err);
+ }
+ return bIsValid;
+ }
+
+
+ public static String addToPath(String _sPath, String _sSubPath){
+ if (!_sPath.endsWith("/")){
+ _sPath += "/";
+ }
+ return _sPath + _sSubPath;
+ }
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/Makefile b/odk/examples/java/Inspector/Makefile
new file mode 100644
index 000000000..b7c611be0
--- /dev/null
+++ b/odk/examples/java/Inspector/Makefile
@@ -0,0 +1,186 @@
+#*************************************************************************
+#
+# 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
+
+# Define non-platform/compiler specific settings
+
+# we use the sample directory name for 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
+
+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)))
+
+# 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 creating the component rdb file
+$(COMP_GEN_OUT)/%.rdb : $(patsubst %,$(PACKAGE)/%,$(IDLFILES))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(UNOIDLWRITE) $(URE_TYPES) $(OFFICE_TYPES) . $@
+
+# rule for creating IDL dependent class files
+$(GEN_CLASSFILES) : $(COMP_RDB)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(JAVAMAKER) -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 description.xml $(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 description.xml
+ 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 000000000..216ef87f3
--- /dev/null
+++ b/odk/examples/java/Inspector/MethodParametersDialog.java
@@ -0,0 +1,351 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import 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.util.ArrayList;
+
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+
+import com.sun.star.reflection.ParamInfo;
+import com.sun.star.reflection.XIdlMethod;
+import com.sun.star.uno.TypeClass;
+
+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_oUnoObject = null;
+ private Object m_oUnoReturnObject = null;
+ private JLabel jLblResult;
+ private JPanel jResultPanel = null;
+ private boolean bisdisposed = 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();
+ }
+
+
+ public ArrayList<Object> 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 (!bisdisposed){
+ ArrayList<Object> aMethodObjects = new ArrayList<Object>();
+ 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{
+ @Override
+ 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) {
+ bisdisposed = true;
+ dispose();
+ }
+ });
+
+ jPnlBottomCenter.add(jCancelButton);
+ add(jPnlBottomCenter);
+ }
+ }
+
+
+ public void addActionListener(ActionListener _oActionListener){
+ oActionListener = _oActionListener;
+ jHelpButton.setEnabled(oActionListener != null);
+ }
+
+
+ private void invokeParameterMethod(){
+ try{
+ Object[] oParameters = getParameterValues();
+ m_oUnoReturnObject = m_xUnoMethodNode.invoke(m_oUnoObject, oParameters);
+ insertResultPanel(null);
+ } catch (Exception ex) {
+ insertResultPanel(ex);
+ m_oUnoReturnObject = null;
+ }}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/ObjectInspector.xcs b/odk/examples/java/Inspector/ObjectInspector.xcs
new file mode 100644
index 000000000..552e72ef8
--- /dev/null
+++ b/odk/examples/java/Inspector/ObjectInspector.xcs
@@ -0,0 +1,34 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+-->
+<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 100644
index 000000000..d6fb08a0f
--- /dev/null
+++ b/odk/examples/java/Inspector/ObjectInspector.xcu
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+-->
+<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 100644
index 000000000..30f3b6b44
--- /dev/null
+++ b/odk/examples/java/Inspector/ProtocolHandler.xcu
@@ -0,0 +1,28 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+-->
+<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 000000000..51158c392
--- /dev/null
+++ b/odk/examples/java/Inspector/ProtocolHandlerAddon.java
@@ -0,0 +1,273 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.uno.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.XServiceInfo;
+import com.sun.star.frame.XStatusListener;
+import com.sun.star.frame.XDispatchProvider;
+import com.sun.star.frame.XDispatch;
+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.
+ */
+ private static 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;
+
+
+ /** The constructor of the inner class has a XMultiServiceFactory parameter.
+ * @param xComponentContext 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 com.sun.star.uno.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 = UnoRuntime.queryInterface(
+ XFrame.class, object[ 0 ] );
+ }
+
+ // Create the toolkit to have access to it later
+ m_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();
+ }
+
+ private static String[] getServiceNames() {
+ return m_serviceNames;
+ }
+
+ /** 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 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.equals("org.openoffice.Office.addon.example:") ) {
+ if ( aURL.Path.equals( "Function1" ) )
+ xRet = this;
+ if ( aURL.Path.equals( "Function2" ) )
+ xRet = this;
+ if ( aURL.Path.equals( "Help" ) )
+ 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.equals("org.openoffice.Office.addon.example:") )
+ {
+ if ( aURL.Path.equals( "Function1" ) )
+ {
+ showMessageBox("SDK DevGuide Add-On example", "Function 1 activated");
+ }
+ if ( aURL.Path.equals( "Function2" ) )
+ {
+ showMessageBox("SDK DevGuide Add-On example", "Function 2 activated");
+ }
+ if ( aURL.Path.equals( "Help" ) )
+ {
+ 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 ) {
+ }
+
+ private void showMessageBox(String sTitle, String sMessage) {
+ if ( null != m_xFrame && null != m_xToolkit ) {
+
+ // describe window properties.
+ WindowDescriptor aDescriptor = new WindowDescriptor();
+ aDescriptor.Type = WindowClass.MODALTOP;
+ aDescriptor.WindowServiceName = "infobox";
+ aDescriptor.ParentIndex = -1;
+ aDescriptor.Parent = 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 = UnoRuntime.queryInterface(
+ XMessageBox.class, xPeer);
+ if ( null != xMsgBox )
+ {
+ xMsgBox.setCaptionText( sTitle );
+ xMsgBox.setMessageText( sMessage );
+ xMsgBox.execute();
+ }
+ }
+ }
+ }
+ }
+
+
+ /** 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 sImplementationName The implementation name of the component.
+ */
+ 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 );
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/SourceCodeGenerator.java b/odk/examples/java/Inspector/SourceCodeGenerator.java
new file mode 100644
index 000000000..9ff6ad793
--- /dev/null
+++ b/odk/examples/java/Inspector/SourceCodeGenerator.java
@@ -0,0 +1,1635 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+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.uno.Any;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.uno.TypeClass;
+
+
+
+public class SourceCodeGenerator {
+ private ArrayList<String> sExceptions = new ArrayList<String>();
+ private ArrayList<String> sHeaderStatements = new HeaderStatements();
+ private XLanguageSourceCodeGenerator m_xLanguageSourceCodeGenerator;
+ private String sStatementCode = "";
+ private String sMainMethodSignature = "";
+
+ private HashMap<String, UnoObjectDefinition> aVariables = new HashMap<String, UnoObjectDefinition>();
+ private final String SSUFFIXSEPARATOR = "_";
+ private final String SVARIABLENAME = "VariableName";
+ private Introspector m_oIntrospector;
+ private ArrayList<XTreePathProvider> aTreepathProviders = new ArrayList<XTreePathProvider>();
+ 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 _baddHeader){
+ 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" + 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" + getPropertyStatementSourceCode(oUnoPropertyNode, sVariableName, oUnoReturnObjectDefinition);
+ }
+ sVariableName = oUnoReturnObjectDefinition.getVariableName();
+ }
+ }
+ }
+ }
+ String sCompleteCode = combineCompleteSourceCode(_baddHeader);
+ 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);
+ 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(aTreepathProviders.get(i), false, (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(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;
+ }
+
+
+ private 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;
+ }
+
+
+ private 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 getHeaderSourceCode(){
+ for(UnoObjectDefinition oUnoObjectDefinition : aVariables.values()){
+ 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 ArrayList<String> {
+
+ public boolean contains(String _oElement){
+ String sCompName = _oElement;
+ for (int i = 0; i < this.size(); i++){
+ String sElement = this.get(i);
+ if (sElement.equals(sCompName)){
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ @Override
+ public boolean add(String _oElement){
+ 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 (Introspector.isObjectPrimitive(oUnoObject)){
+ bisDeclared = false;
+ }
+ else if (Introspector.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 = 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 = Introspector.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;
+ }
+
+
+ private 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;
+ }
+ }
+
+
+private class UnoObjectDefinition{
+ private Object m_oUnoObject = null;
+
+ private String sVariableStemName = "";
+ private String m_sCentralVariableStemName = "";
+ private String sVariableName = "";
+ private String m_sTypeName = "";
+ private TypeClass m_aTypeClass = null;
+ private Object[] m_oParameterObjects = null;
+
+
+ private UnoObjectDefinition(Any _oUnoObject){
+ m_sTypeName = _oUnoObject.getType().getTypeName();
+ m_aTypeClass = _oUnoObject.getType().getTypeClass();
+ m_oUnoObject = _oUnoObject;
+ m_sCentralVariableStemName = getCentralVariableStemName(m_aTypeClass);
+ }
+
+
+ private UnoObjectDefinition(Object _oUnoObject, String _sTypeName, TypeClass _aTypeClass){
+ m_oUnoObject = _oUnoObject;
+ m_sTypeName = _sTypeName;
+ m_aTypeClass = _aTypeClass;
+ m_sCentralVariableStemName = getCentralVariableStemName(m_aTypeClass);
+ }
+
+
+ private 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 = Introspector.getShortClassName(getTypeName());
+ sCentralVariableStemName = getVariableNameforUnoObject(sShortClassName);
+ default:
+ sCentralVariableStemName = SVARIABLENAME;
+ }
+ return sCentralVariableStemName;
+ }
+
+ /** may return null
+ */
+ public Object getUnoObject(){
+ return m_oUnoObject;
+ }
+
+
+ public TypeClass getTypeClass(){
+ return m_aTypeClass;
+ }
+
+
+ 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;
+ }
+
+
+ private void addParameterObjects(Object[] _oParameterObjects){
+ m_oParameterObjects = _oParameterObjects;
+ }
+
+
+ public Object[] getParameterObjects(){
+ return m_oParameterObjects;
+ }
+
+
+
+
+
+ private 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 = Introspector.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 = aVariables.get(sVariableName).getUnoObject().toString();
+ if (m_oUnoObject != null){
+ if ((sUnoObjectIdentity.equals(m_oUnoObject.toString()) && (!Introspector.isPrimitive(this.getTypeClass())) &&
+ (! Introspector.isObjectSequence(m_oUnoObject)))){
+ bleaveloop = true;
+ }
+ else{
+ sVariableName = getVariableStemName() + SSUFFIXSEPARATOR + a++;
+ }
+ }
+ else{
+ bleaveloop = true;
+ }
+ }
+ else{
+ bleaveloop = true;
+ }
+ }
+ }
+ 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;
+ }
+
+
+ private class JavaCodeGenerator implements XLanguageSourceCodeGenerator{
+
+ private boolean bAddAnyConverter = false;
+ private 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 (!Introspector.isObjectPrimitive(_oUnoObject)){
+ if (Introspector.isObjectSequence(_oUnoObject)){
+ XTypeDescription xTypeDescription = m_oIntrospector.getReferencedType(sClassName);
+ if (xTypeDescription != null){
+ if (!Introspector.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);";
+ 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 = Introspector.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;
+ }
+
+
+ public String getObjectTypeDescription(String _sClassName, boolean _bAsHeader){
+ String sReturn = "";
+ if (_bAsHeader){
+ sReturn = _sClassName;
+ }
+ else{
+ sReturn = Introspector.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 = 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.err);\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 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 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 getCommentSign(){
+ return "//";
+ }
+ }
+
+
+ private class BasicCodeGenerator implements XLanguageSourceCodeGenerator{
+
+
+ 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 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 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 getCommentSign(){
+ return "'";
+ }
+
+ }
+
+ private class CPlusPlusCodeGenerator implements XLanguageSourceCodeGenerator{
+
+ private boolean bIncludeStringHeader = false;
+ private boolean bIncludeAny = false;
+ private 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 (!Introspector.isObjectPrimitive(_oUnoObject)){
+ if (Introspector.isObjectSequence(_oUnoObject)){
+ XTypeDescription xTypeDescription = m_oIntrospector.getReferencedType(sClassName);
+ if (xTypeDescription != null){
+ if (!Introspector.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 ::rtl::OUString;\n";
+ return sReturn;
+ }
+
+
+ private String getHeaderOfClass(String _sClassName){
+ return "#include \"" + _sClassName.replace('.', '/') + ".hpp\"\n";
+ }
+
+
+
+ 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 = 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( "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){
+ return _sObjectDescription + " >>= " + _sReturnVariableName;
+ }
+
+
+ public String getStringValue(String _sValue){
+ bIncludeStringHeader = true;
+ return "OUString(\"" + _sValue + "\")";
+ }
+
+
+ public String getObjectTypeDescription(String _sClassName, boolean _bAsHeader){
+ String sReturn = "";
+ if (_bAsHeader){
+ sReturn = _sClassName.replace('.', '/');
+ }
+ else{
+ String sModuleName = Introspector.getModuleName(_sClassName);
+ sModuleName = Introspector.getShortClassName(sModuleName);
+ sReturn = getCSSNameSpaceString() + "::" + sModuleName + "::" + Introspector.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 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 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 = Introspector.isPrimitive(_aTypeClass);
+
+ 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 getCommentSign(){
+ return "//";
+ }
+
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/SwingDialogProvider.java b/odk/examples/java/Inspector/SwingDialogProvider.java
new file mode 100644
index 000000000..e66bedce8
--- /dev/null
+++ b/odk/examples/java/Inspector/SwingDialogProvider.java
@@ -0,0 +1,444 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.uno.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.JDialog;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+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;
+ }
+
+
+ private void addMenuBar(JMenuBar _jMenuBar){
+ getDialog().setJMenuBar(_jMenuBar);
+ }
+
+
+ private 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){
+ String sInspectorPanelTitle = m_jTabbedPane1.getTitleAt(_nIndex);
+ oInspectorPane = m_oInspector.getInspectorPages().get(sInspectorPanelTitle);
+ }
+ return oInspectorPane;
+ }
+
+
+ private void removeTabPanes(){
+ int nCount = m_jTabbedPane1.getTabCount();
+ if (nCount > 0){
+ for (int i = nCount-1; i >= 0; i--){
+ removeTabPaneByIndex(i);
+ }
+ }
+ }
+
+ private void removeSelectedTabPane(){
+ int nIndex = getTabbedPane().getSelectedIndex();
+ removeTabPaneByIndex(nIndex);
+ }
+
+
+ private class InspectorComponentAdapter extends ComponentAdapter{
+ @Override
+ public void componentHidden(ComponentEvent e){
+ m_jInspectorDialog.pack();
+ m_jInspectorDialog.invalidate();
+
+ }
+
+ @Override
+ public void componentShown(ComponentEvent e){
+ m_jInspectorDialog.pack();
+ m_jInspectorDialog.invalidate();
+ }
+ }
+
+ private class InspectorWindowAdapter extends WindowAdapter{
+ @Override
+ public void windowClosed(WindowEvent e){
+ removeTabPanes();
+ m_oInspector.disposeHiddenDocuments();
+ }
+
+ @Override
+ 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.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);
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/SwingTreeControlProvider.java b/odk/examples/java/Inspector/SwingTreeControlProvider.java
new file mode 100644
index 000000000..c8cbb4dcb
--- /dev/null
+++ b/odk/examples/java/Inspector/SwingTreeControlProvider.java
@@ -0,0 +1,423 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.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.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.JPanel;
+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 JTree jTree = new javax.swing.JTree();
+ private XDialogProvider m_xDialogProvider;
+ private HideableTreeModel treeModel;
+ 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) {
+ 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{
+ @Override
+ 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 _oUserDefinedObject 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() {
+ @Override
+ 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() {
+ @Override
+ 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.err);
+ }
+ 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)){
+ 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(_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;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/SwingTreePathProvider.java b/odk/examples/java/Inspector/SwingTreePathProvider.java
new file mode 100644
index 000000000..c0f6703ca
--- /dev/null
+++ b/odk/examples/java/Inspector/SwingTreePathProvider.java
@@ -0,0 +1,60 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+import javax.swing.tree.TreePath;
+
+public class SwingTreePathProvider implements XTreePathProvider {
+ private 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;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/SwingUnoFacetteNode.java b/odk/examples/java/Inspector/SwingUnoFacetteNode.java
new file mode 100644
index 000000000..31a80ffd9
--- /dev/null
+++ b/odk/examples/java/Inspector/SwingUnoFacetteNode.java
@@ -0,0 +1,84 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+
+
+public class SwingUnoFacetteNode extends SwingUnoNode implements XUnoFacetteNode{
+ private 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;
+ }
+
+ @Override
+ 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);
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/SwingUnoMethodNode.java b/odk/examples/java/Inspector/SwingUnoMethodNode.java
new file mode 100644
index 000000000..f06f2161c
--- /dev/null
+++ b/odk/examples/java/Inspector/SwingUnoMethodNode.java
@@ -0,0 +1,144 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+
+import com.sun.star.reflection.XIdlMethod;
+import com.sun.star.uno.TypeClass;
+
+
+
+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();
+ }
+
+ @Override
+ public String getName(){
+ return m_oUnoMethodNode.getName();
+ }
+
+ @Override
+ public String getClassName(){
+ String sClassName = "";
+ sClassName = getXIdlMethod().getDeclaringClass().getName();
+ if (sClassName.equals("")){
+ sClassName = super.getClassName();
+ }
+ return sClassName;
+ }
+
+ @Override
+ 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 ArrayList<Object> 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();
+ }
+}
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/SwingUnoNode.java b/odk/examples/java/Inspector/SwingUnoNode.java
new file mode 100644
index 000000000..c1d84d85e
--- /dev/null
+++ b/odk/examples/java/Inspector/SwingUnoNode.java
@@ -0,0 +1,160 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+import com.sun.star.uno.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());
+ }
+
+ 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();
+ }
+
+
+ @Override
+ 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();
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/SwingUnoPropertyNode.java b/odk/examples/java/Inspector/SwingUnoPropertyNode.java
new file mode 100644
index 000000000..0e65a0361
--- /dev/null
+++ b/odk/examples/java/Inspector/SwingUnoPropertyNode.java
@@ -0,0 +1,102 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+import com.sun.star.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);
+ }
+
+ @Override
+ public String getName(){
+ return m_oUnoPropertyNode.getName();
+ }
+
+
+ public Object getUnoReturnObject(){
+ return m_oUnoPropertyNode.getUnoReturnObject();
+ }
+
+
+ @Override
+ public String getClassName(){
+ String sClassName = m_oUnoPropertyNode.getClassName();
+ if (sClassName.equals("")){
+ sClassName = super.getClassName();
+ }
+ return sClassName;
+ }
+
+ @Override
+ 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();
+ }
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/TDocSupplier.java b/odk/examples/java/Inspector/TDocSupplier.java
new file mode 100644
index 000000000..593c8a852
--- /dev/null
+++ b/odk/examples/java/Inspector/TDocSupplier.java
@@ -0,0 +1,166 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.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.UniversalContentBroker;
+import com.sun.star.ucb.XCommandProcessor;
+import com.sun.star.ucb.XContent;
+import com.sun.star.ucb.XContentIdentifier;
+import com.sun.star.ucb.XSimpleFileAccess;
+import com.sun.star.ucb.XUniversalContentBroker;
+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();
+ }
+
+
+ private XComponentContext getXComponentContext(){
+ return m_xComponentContext;
+ }
+
+
+ private 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 = UnoRuntime.queryInterface(XModel.class, oModel);
+ return xModel;
+ }
+ }catch(Exception exception){
+ exception.printStackTrace(System.err);
+ }
+ 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.err);
+ }
+ 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{
+ XUniversalContentBroker xUCB = UniversalContentBroker.create( getXComponentContext() );
+ XContentIdentifier xId = xUCB.createContentIdentifier(_sTDocUrl);
+ XContent xContent = xUCB.queryContent(xId);
+ XCommandProcessor xCmdProcessor = 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 = UnoRuntime.queryInterface(XRow.class, oAny);
+ return xRow;
+ }catch(Exception exception){
+ exception.printStackTrace(System.err);
+ 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 = 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 = UnoRuntime.queryInterface(XComponentLoader.class, oDesktop);
+ return xCL.loadComponentFromURL(_sUrl, "_default", 0, aPropertyValues);
+ }
+ catch( Exception exception ) {
+ System.err.println( exception );
+ return null;
+ }}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/TestInspector.java b/odk/examples/java/Inspector/TestInspector.java
new file mode 100644
index 000000000..208acf25b
--- /dev/null
+++ b/odk/examples/java/Inspector/TestInspector.java
@@ -0,0 +1,88 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.lang.XSingleComponentFactory;
+import com.sun.star.uno.UnoRuntime;
+
+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.err);
+ 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 = 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 instantiate within
+ frames. */
+ com.sun.star.frame.XComponentLoader xCmpLoader = UnoRuntime.queryInterface( com.sun.star.frame.XComponentLoader.class,
+ xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext));
+
+ // Load a new spreadsheet document, which will be automatically
+ // 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();
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/UnoMethodNode.java b/odk/examples/java/Inspector/UnoMethodNode.java
new file mode 100644
index 000000000..a620fc81a
--- /dev/null
+++ b/odk/examples/java/Inspector/UnoMethodNode.java
@@ -0,0 +1,228 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.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;
+
+public class UnoMethodNode extends UnoNode{
+ private XIdlMethod m_xIdlMethod = null;
+ private Object[] m_oParamObjects = null;
+ private Object m_oUnoReturnObject = null;
+ private boolean m_bisInvoked = false;
+ private 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;
+ }
+
+
+ @Override
+ 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{
+ java.util.List<Object> 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 = "";
+ 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.err);
+ 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);
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/UnoNode.java b/odk/examples/java/Inspector/UnoNode.java
new file mode 100644
index 000000000..0e72d1efd
--- /dev/null
+++ b/odk/examples/java/Inspector/UnoNode.java
@@ -0,0 +1,351 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.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.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;
+
+public class UnoNode{
+
+
+ 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;
+ }
+
+
+ private XComponentContext getXComponentContext(){
+ return m_xComponentContext;
+ }
+
+
+ private XMultiComponentFactory getXMultiComponentFactory(){
+ return m_xMultiComponentFactory;
+ }
+
+
+ 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){
+ 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 = "https://api.libreoffice.org/" + Inspector.sIDLDOCUMENTSUBFOLDER;
+ }
+ if (!sIDLUrl.endsWith("/")){
+ sIDLUrl += "/";
+ }
+ if (_sClassName.equals("")){
+ sIDLUrl += "index";
+ sAnchor = "";
+ }
+ else{
+ sIDLUrl += _sClassName.replace(".", "_1_1");
+ }
+ sIDLUrl += ".html";
+ if (sAnchor != null){
+ if (!sAnchor.equals("")){
+ sIDLUrl += "#" + sAnchor;
+ }
+ }
+ 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.err);
+ }}
+
+
+ private com.sun.star.util.URL getDispatchURL(String _sURL){
+ try {
+ Object oTransformer = getXMultiComponentFactory().createInstanceWithContext("com.sun.star.util.URLTransformer", getXComponentContext());
+ XURLTransformer xTransformer = 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.err);
+ }
+ return null;
+ }
+
+
+ private XFrame getCurrentFrame(){
+ try{
+ Object oDesktop = getXMultiComponentFactory().createInstanceWithContext("com.sun.star.frame.Desktop", getXComponentContext());
+ XDesktop xDesktop = UnoRuntime.queryInterface(XDesktop.class, oDesktop);
+ return xDesktop.getCurrentFrame();
+ } catch (Exception e) {
+ e.printStackTrace(System.err);
+ 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 = UnoRuntime.queryInterface(XDispatchProvider.class, getCurrentFrame());
+ XDispatch xDispatch = xDispatchProvider.queryDispatch(oURLArray[0], "_top", FrameSearchFlag.ALL); // "_self"
+ return xDispatch;
+ } catch (Exception e) {
+ e.printStackTrace(System.err);
+ return null;
+ }}
+
+
+ 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 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) {
+ String n = sequenceType.getTypeName();
+ final String PREFIX = "[]";
+ return new Type(n.substring(PREFIX.length()));
+ }
+
+
+
+
+
+ public static String getNodeDescription(Object _oUnoObject){
+ XServiceInfo xServiceInfo = UnoRuntime.queryInterface( XServiceInfo.class, _oUnoObject );
+ if ( xServiceInfo != null ) {
+ return xServiceInfo.getImplementationName();
+ }
+ if (Introspector.isObjectPrimitive(_oUnoObject)){ //super.isO{sObjectClassName.equals("String"))issClassName.equals("String"))
+ return _oUnoObject.toString();
+ }
+ else{
+ return _oUnoObject.getClass().getName();
+ }
+ }
+
+ public void setParameterObjects(Object[] _oParamObjects){
+ m_oParamObjects = _oParamObjects;
+ }
+
+ public Object[] getParameterObjects(){
+ return m_oParamObjects;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/UnoPropertyNode.java b/odk/examples/java/Inspector/UnoPropertyNode.java
new file mode 100644
index 000000000..51b6569b2
--- /dev/null
+++ b/odk/examples/java/Inspector/UnoPropertyNode.java
@@ -0,0 +1,218 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.beans.Property;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.reflection.XPropertyTypeDescription;
+import com.sun.star.uno.UnoRuntime;
+
+public class UnoPropertyNode extends UnoNode{
+
+ private Property aProperty;
+ private PropertyValue aPropertyValue;
+ private String m_sPropertyName;
+ private Object m_oUnoReturnObject;
+ private int m_nPropertyType = XUnoPropertyNode.nDEFAULT;
+ private String sLabel = "";
+
+
+ /** 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;
+ }
+
+
+ @Override
+ public String getClassName(){
+ String sClassName = "";
+ if (m_oUnoObject != null){
+ 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;
+ }
+
+
+ @Override
+ public String getAnchor(){
+ return m_sPropertyName;
+ }
+
+
+
+ private 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;
+ }
+
+ private 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);
+ }
+ }
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/UnoTreeRenderer.java b/odk/examples/java/Inspector/UnoTreeRenderer.java
new file mode 100644
index 000000000..81e62a6d1
--- /dev/null
+++ b/odk/examples/java/Inspector/UnoTreeRenderer.java
@@ -0,0 +1,122 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+import java.awt.Component;
+import java.awt.Graphics;
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+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 resources, treecell icons will not be displayed.");
+ }
+ }
+
+
+ @Override
+ 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)){
+ } else if (sLabelText.equals(XUnoFacetteNode.SCONTENTDESCRIPTION)){
+ } else if (sLabelText.equals(XUnoFacetteNode.SINTERFACEDESCRIPTION)){
+ } else if (sLabelText.equals(XUnoFacetteNode.SMETHODDESCRIPTION)){
+ } else if (sLabelText.equals(XUnoFacetteNode.SPROPERTYDESCRIPTION)){
+ } else if (sLabelText.startsWith(XUnoFacetteNode.SPROPERTYINFODESCRIPTION)){
+ } else if (sLabelText.equals(XUnoFacetteNode.SPROPERTYVALUEDESCRIPTION)){
+ } else if (sLabelText.equals(XUnoFacetteNode.SSERVICEDESCRIPTION)){
+ } else{
+ setText(sLabelText);
+ rc.validate();
+ }
+ setSize(getPreferredSize());
+ rc.validate();
+ doLayout();
+ }
+ } catch (RuntimeException e) {
+ System.out.println("Sorry, icon for treecell could not be displayed.");
+ }
+ return this;
+ }
+
+
+
+ @Override
+ public void paintComponent(Graphics g) {
+ int x;
+ if(getIcon() == null) {
+ x = 0;
+ } else {
+ x = getIcon().getIconWidth() + getIconTextGap();
+ }
+ g.setColor(getForeground());
+ super.paintComponent(g);
+ }
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/XDialogProvider.java b/odk/examples/java/Inspector/XDialogProvider.java
new file mode 100644
index 000000000..78b0c792e
--- /dev/null
+++ b/odk/examples/java/Inspector/XDialogProvider.java
@@ -0,0 +1,68 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+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);
+
+
+
+ // returns one of the constants defined in XLanguageSourceCodeGenerator
+ public int getLanguage();
+
+ public String getIDLPath();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/XLanguageSourceCodeGenerator.java b/odk/examples/java/Inspector/XLanguageSourceCodeGenerator.java
new file mode 100644
index 000000000..8729471e2
--- /dev/null
+++ b/odk/examples/java/Inspector/XLanguageSourceCodeGenerator.java
@@ -0,0 +1,108 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+import com.sun.star.uno.TypeClass;
+
+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 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 getanyTypeDescription(boolean _bAsHeaderSourceCode);
+
+
+
+ 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();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/XTreeControlProvider.java b/odk/examples/java/Inspector/XTreeControlProvider.java
new file mode 100644
index 000000000..1cb69c972
--- /dev/null
+++ b/odk/examples/java/Inspector/XTreeControlProvider.java
@@ -0,0 +1,96 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.beans.Property;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.reflection.XIdlMethod;
+import com.sun.star.uno.Type;
+
+public interface XTreeControlProvider {
+
+
+
+ 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);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/XTreePathProvider.java b/odk/examples/java/Inspector/XTreePathProvider.java
new file mode 100644
index 000000000..ecbf52dd4
--- /dev/null
+++ b/odk/examples/java/Inspector/XTreePathProvider.java
@@ -0,0 +1,33 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+public interface XTreePathProvider {
+
+ public XUnoNode getLastPathComponent();
+
+ public XUnoNode getPathComponent(int i);
+
+ public int getPathCount();
+
+ public XTreePathProvider getParentPath();
+
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/XUnoFacetteNode.java b/odk/examples/java/Inspector/XUnoFacetteNode.java
new file mode 100644
index 000000000..ad1e114c1
--- /dev/null
+++ b/odk/examples/java/Inspector/XUnoFacetteNode.java
@@ -0,0 +1,66 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+
+
+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);
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/XUnoMethodNode.java b/odk/examples/java/Inspector/XUnoMethodNode.java
new file mode 100644
index 000000000..4749c92a0
--- /dev/null
+++ b/odk/examples/java/Inspector/XUnoMethodNode.java
@@ -0,0 +1,70 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.reflection.XIdlMethod;
+import com.sun.star.uno.TypeClass;
+
+
+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 java.util.List<Object> getMethodObjects();
+
+ public boolean isFoldable();
+
+ public String getStandardMethodDescription();
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/XUnoNode.java b/odk/examples/java/Inspector/XUnoNode.java
new file mode 100644
index 000000000..11eba35da
--- /dev/null
+++ b/odk/examples/java/Inspector/XUnoNode.java
@@ -0,0 +1,87 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+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();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/XUnoPropertyNode.java b/odk/examples/java/Inspector/XUnoPropertyNode.java
new file mode 100644
index 000000000..1902a5db2
--- /dev/null
+++ b/odk/examples/java/Inspector/XUnoPropertyNode.java
@@ -0,0 +1,54 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+import com.sun.star.beans.Property;
+
+
+public interface XUnoPropertyNode extends XUnoNode {
+
+ public static int nDEFAULT = 0;
+ public static int nPROPERTYSETINFOTYPE = 1;
+
+
+ public Object getUnoReturnObject();
+
+ public int getPropertyNodeType();
+
+ public void setPropertyNodeType(int _nPropertyType);
+
+ public Property getProperty();
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/description.xml b/odk/examples/java/Inspector/description.xml
new file mode 100644
index 000000000..6c4e2396b
--- /dev/null
+++ b/odk/examples/java/Inspector/description.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+-->
+<d:description xmlns:d="http://openoffice.org/extensions/description/2006">
+ <d:dependencies>
+ <l:LibreOffice-minimal-version value="4.1" d:name="LibreOffice 4.1"
+ xmlns:l="http://libreoffice.org/extensions/description/2011"/>
+ </d:dependencies>
+</d:description>
diff --git a/odk/examples/java/Inspector/images/containers_16.png b/odk/examples/java/Inspector/images/containers_16.png
new file mode 100644
index 000000000..0b4c62f11
--- /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 100644
index 000000000..758169260
--- /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 100644
index 000000000..cf633ac9c
--- /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 100644
index 000000000..25cd8b45c
--- /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 100644
index 000000000..4e22dd1d5
--- /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 100644
index 000000000..024a16ed6
--- /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 100644
index 000000000..328e8e5bc
--- /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/Inspector/org/openoffice/InstanceInspector.idl b/odk/examples/java/Inspector/org/openoffice/InstanceInspector.idl
new file mode 100644
index 000000000..81b396170
--- /dev/null
+++ b/odk/examples/java/Inspector/org/openoffice/InstanceInspector.idl
@@ -0,0 +1,55 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+#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 object.
+ */
+ service InstanceInspector: XInstanceInspector;
+
+}; };
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/org/openoffice/XInstanceInspector.idl b/odk/examples/java/Inspector/org/openoffice/XInstanceInspector.idl
new file mode 100644
index 000000000..ca96a27e1
--- /dev/null
+++ b/odk/examples/java/Inspector/org/openoffice/XInstanceInspector.idl
@@ -0,0 +1,59 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+#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 dependent
+ * 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
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/MinimalComponent/Makefile b/odk/examples/java/MinimalComponent/Makefile
new file mode 100644
index 000000000..5b303ddb6
--- /dev/null
+++ b/odk/examples/java/MinimalComponent/Makefile
@@ -0,0 +1,199 @@
+#*************************************************************************
+#
+# 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
+
+# Define non-platform/compiler specific settings
+
+# we use the sample directory name for 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
+COMP_COMPONENTS=$(COMP_NAME).components
+
+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)))
+
+# 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 $*)>> $@
+
+$(COMP_GEN_OUT)/%.rdb : $(IDLFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(UNOIDLWRITE) $(URE_TYPES) $(OFFICE_TYPES) $< $@
+
+$(GEN_CLASSFILES) : $(COMP_RDB)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(JAVAMAKER) -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-components$(QM)">> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(COMP_NAME).components$(QM)"/$(CSEP)>> $@
+ @echo $(OSEP)/manifest:manifest$(CSEP) >> $@
+
+# rule for component package file
+$(COMP_PACKAGE) : $(COMP_RDB) $(COMP_JAR) $(COMP_UNOPKG_MANIFEST) $(COMP_NAME).components description.xml
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_ZIP) $@ $(COMP_NAME).components description.xml
+ cd $(subst /,$(PS),$(COMP_GEN_OUT)) && $(SDK_ZIP) -u ../../../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.components b/odk/examples/java/MinimalComponent/MinimalComponent.components
new file mode 100644
index 000000000..9e413f2b6
--- /dev/null
+++ b/odk/examples/java/MinimalComponent/MinimalComponent.components
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<components xmlns="http://openoffice.org/2010/uno-components">
+ <component loader="com.sun.star.loader.Java2" uri="MinimalComponent.uno.jar">
+ <implementation name="MinimalComponent$_MinimalComponent">
+ <service name="org.openoffice.MinimalComponent"/>
+ </implementation>
+ </component>
+</components>
diff --git a/odk/examples/java/MinimalComponent/MinimalComponent.idl b/odk/examples/java/MinimalComponent/MinimalComponent.idl
new file mode 100644
index 000000000..1b63b7705
--- /dev/null
+++ b/odk/examples/java/MinimalComponent/MinimalComponent.idl
@@ -0,0 +1,55 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+#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
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/MinimalComponent/MinimalComponent.java b/odk/examples/java/MinimalComponent/MinimalComponent.java
new file mode 100644
index 000000000..b8efbafcc
--- /dev/null
+++ b/odk/examples/java/MinimalComponent/MinimalComponent.java
@@ -0,0 +1,156 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.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.XComponentContext;
+import com.sun.star.lang.XInitialization;
+import com.sun.star.lang.XServiceInfo;
+
+/** 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.
+ */
+ private static 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 xCompContext 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 com.sun.star.uno.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 are expected and in which
+ * order! At this point you can read the objects and initialize
+ * 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.
+ */
+ private 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;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/MinimalComponent/TestMinimalComponent.java b/odk/examples/java/MinimalComponent/TestMinimalComponent.java
new file mode 100644
index 000000000..604e16163
--- /dev/null
+++ b/odk/examples/java/MinimalComponent/TestMinimalComponent.java
@@ -0,0 +1,67 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.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);
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/MinimalComponent/description.xml b/odk/examples/java/MinimalComponent/description.xml
new file mode 100644
index 000000000..6c4e2396b
--- /dev/null
+++ b/odk/examples/java/MinimalComponent/description.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+-->
+<d:description xmlns:d="http://openoffice.org/extensions/description/2006">
+ <d:dependencies>
+ <l:LibreOffice-minimal-version value="4.1" d:name="LibreOffice 4.1"
+ xmlns:l="http://libreoffice.org/extensions/description/2011"/>
+ </d:dependencies>
+</d:description>
diff --git a/odk/examples/java/NotesAccess/Makefile b/odk/examples/java/NotesAccess/Makefile
new file mode 100644
index 000000000..47d024db8
--- /dev/null
+++ b/odk/examples/java/NotesAccess/Makefile
@@ -0,0 +1,112 @@
+#*************************************************************************
+#
+# 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
+
+# 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 external "$(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 000000000..0d0a0bb5e
--- /dev/null
+++ b/odk/examples/java/NotesAccess/NotesAccess.java
@@ -0,0 +1,282 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// 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;
+
+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.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 args 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( notesaccess );
+ }
+ else {
+ // Extracting the host, user, and password.
+ NotesAccess notesaccess = new NotesAccess();
+
+ // Allowing remote calls to the Domino classes.
+ thread = new Thread( notesaccess );
+ }
+
+ // Starting the thread.
+ thread.start();
+ }
+
+ /** 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 instantiate within
+ frames. */
+ XComponentLoader xLoader = UnoRuntime.queryInterface(XComponentLoader.class,
+ xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext));
+
+ // Load a Writer document, which will be automatically displayed
+ XComponent xComponent = xLoader.loadComponentFromURL(
+ "private:factory/scalc", "_blank", 0,
+ new PropertyValue[0] );
+
+ // Querying for the interface XSpreadsheetDocument
+ XSpreadsheetDocument xSpreadsheetDoc =
+ UnoRuntime.queryInterface(
+ XSpreadsheetDocument.class, xComponent);
+
+ // Getting all sheets from the spreadsheet document.
+ XSpreadsheets xSpreadsheets = xSpreadsheetDoc.getSheets() ;
+
+ // Querying for the interface XIndexAccess.
+ XIndexAccess xIndexAccess = UnoRuntime.queryInterface(
+ XIndexAccess.class, xSpreadsheets);
+
+ // Getting the first spreadsheet.
+ 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"
+ + ( intRow + 1 )
+ + "*C" + (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"
+ + ( intRowToStart + 1 ) + ":D"
+ + 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);
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/NotesAccess/Stocks.nsf b/odk/examples/java/NotesAccess/Stocks.nsf
new file mode 100644
index 000000000..10ed138ed
--- /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 000000000..2ab04e13e
--- /dev/null
+++ b/odk/examples/java/PropertySet/Makefile
@@ -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.
+#
+#**************************************************************************
+
+# Builds the Java PropertySet component example of the SDK.
+
+PRJ=../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.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_COMPONENTS=$(COMP_NAME).components
+
+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-components$(QM)">> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(COMP_NAME).components$(QM)"/$(CSEP)>> $@
+ @echo $(OSEP)/manifest:manifest$(CSEP) >> $@
+
+# rule for component package file
+$(COMP_PACKAGE) : $(COMP_JAR) $(COMP_UNOPKG_MANIFEST) $(COMP_NAME).components
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_ZIP) $@ $(COMP_NAME).components
+ cd $(subst /,$(PS),$(COMP_CLASS_OUT)) && $(SDK_ZIP) -u ../../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.components b/odk/examples/java/PropertySet/PropTest.components
new file mode 100644
index 000000000..320e3511c
--- /dev/null
+++ b/odk/examples/java/PropertySet/PropTest.components
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<components xmlns="http://openoffice.org/2010/uno-components">
+ <component loader="com.sun.star.loader.Java2" uri="PropTest.uno.jar">
+ <implementation name="PropTest">
+ <service name="PropTest"/>
+ </implementation>
+ </component>
+</components>
diff --git a/odk/examples/java/PropertySet/PropTest.java b/odk/examples/java/PropertySet/PropTest.java
new file mode 100644
index 000000000..c77a905e8
--- /dev/null
+++ b/odk/examples/java/PropertySet/PropTest.java
@@ -0,0 +1,262 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+/*
+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 following 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= Integer.valueOf(100);
+ public Object roObjectA= Integer.valueOf(101);
+ public Any roAnyA= new Any( new Type(int.class), Integer.valueOf(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;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/PropertySet/PropertySet.odt b/odk/examples/java/PropertySet/PropertySet.odt
new file mode 100644
index 000000000..31d326e41
--- /dev/null
+++ b/odk/examples/java/PropertySet/PropertySet.odt
Binary files differ
diff --git a/odk/examples/java/Spreadsheet/CalcAddins.components b/odk/examples/java/Spreadsheet/CalcAddins.components
new file mode 100644
index 000000000..c16c4a3a9
--- /dev/null
+++ b/odk/examples/java/Spreadsheet/CalcAddins.components
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<components xmlns="http://openoffice.org/2010/uno-components">
+ <component loader="com.sun.star.loader.Java2" uri="CalcAddins.uno.jar">
+ <implementation name="CalcAddins$_CalcAddins">
+ <service name="org.openoffice.sheet.addin.CalcAddins"/>
+ <service name="com.sun.star.sheet.AddIn"/>
+ </implementation>
+ </component>
+</components>
diff --git a/odk/examples/java/Spreadsheet/CalcAddins.java b/odk/examples/java/Spreadsheet/CalcAddins.java
new file mode 100644
index 000000000..37785056e
--- /dev/null
+++ b/odk/examples/java/Spreadsheet/CalcAddins.java
@@ -0,0 +1,283 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// Template for an Office Calc add-in Java implementation file.
+
+/** You can find more
+ * information on the following web page:
+ * https://api.libreoffice.org/
+ */
+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.lib.uno.helper.WeakBase;
+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 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
+ */
+ public static class _CalcAddins extends WeakBase implements
+ XCalcAddins,
+ XAddIn,
+ XServiceName,
+ XServiceInfo
+ {
+
+/** The component will be registered under this name.
+ */
+ private static final String __serviceName = "org.openoffice.sheet.addin.CalcAddins";
+
+ private static 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"
+ };
+
+/** 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 1;
+ }
+
+ public int getMySecondValue(
+ com.sun.star.beans.XPropertySet xOptions,
+ int intDummy
+ ) {
+ return 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;
+ }
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Spreadsheet/CalcAddins.ods b/odk/examples/java/Spreadsheet/CalcAddins.ods
new file mode 100644
index 000000000..133539d5a
--- /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 000000000..d436b3889
--- /dev/null
+++ b/odk/examples/java/Spreadsheet/ChartTypeChange.java
@@ -0,0 +1,347 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+import com.sun.star.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.
+ */
+public class ChartTypeChange {
+
+ /** Table chart, which type will be changed.
+ */
+ private XTableChart xtablechart = null;
+
+ /** Service factory
+ */
+ private final XMultiComponentFactory xMCF;
+
+ /** Component context
+ */
+ private final XComponentContext xCompContext;
+
+ /** 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.
+ * @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 an 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 = UnoRuntime.queryInterface(XEmbeddedObjectSupplier.class, xtablechart);
+ XInterface xInterface = xEmbeddedObjSupplier.getEmbeddedObject();
+
+ XChartDocument xChartDoc = UnoRuntime.queryInterface(
+ XChartDocument.class, xInterface);
+ XDiagram xDiagram = xChartDoc.getDiagram();
+ XMultiServiceFactory xMSF = UnoRuntime.queryInterface( XMultiServiceFactory.class, xChartDoc );
+ Object object = xMSF.createInstance( stringType );
+ xDiagram = UnoRuntime.queryInterface(XDiagram.class, object);
+
+ XPropertySet xPropSet = UnoRuntime.queryInterface(
+ XPropertySet.class, xDiagram );
+ xPropSet.setPropertyValue( "Dim3D", Boolean.valueOf( 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 instantiate within
+ frames. */
+ XComponentLoader xComponentloader = UnoRuntime.queryInterface( XComponentLoader.class,
+ xMCF.createInstanceWithContext("com.sun.star.frame.Desktop",
+ xCompContext ) );
+
+ // Load a Writer document, which will be automatically displayed
+ XComponent xComponent = xComponentloader.loadComponentFromURL(
+ "file:///" + stringFileName, "_blank", 0,
+ new PropertyValue[0] );
+
+ // Query for the interface XSpreadsheetDocument
+ XSpreadsheetDocument xSpreadSheetDocument = UnoRuntime.queryInterface( XSpreadsheetDocument.class, xComponent );
+
+ XSpreadsheets xSpreadsheets = xSpreadSheetDocument.getSheets() ;
+
+ XIndexAccess xIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets );
+
+ XSpreadsheet xSpreadsheet = UnoRuntime.queryInterface(
+ XSpreadsheet.class, xIndexAccess.getByIndex(0));
+
+ XTableChartsSupplier xTableChartsSupplier = UnoRuntime.queryInterface( XTableChartsSupplier.class, xSpreadsheet );
+
+ xIndexAccess = UnoRuntime.queryInterface(
+ XIndexAccess.class, xTableChartsSupplier.getCharts() );
+
+ this.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 instantiate within
+ frames. */
+ XComponentLoader xcomponentloader = UnoRuntime.queryInterface( XComponentLoader.class,
+ xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop",
+ xCompContext ) );
+
+ // Create an empty calc document, which will be automatically displayed
+ XComponent xComponent = xcomponentloader.loadComponentFromURL(
+ "private:factory/scalc", "_blank", 0,
+ new PropertyValue[0] );
+
+ // Query for the interface 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 = UnoRuntime.queryInterface(
+ XIndexAccess.class, xspreadsheets );
+
+ // Get the first spreadsheet.
+ 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.
+ ChartTypeChange.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 = 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 =
+ 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 = 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 = UnoRuntime.queryInterface(
+ XTableChart.class, 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 );
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Spreadsheet/EuroAdaption.java b/odk/examples/java/Spreadsheet/EuroAdaption.java
new file mode 100644
index 000000000..c6906f45b
--- /dev/null
+++ b/odk/examples/java/Spreadsheet/EuroAdaption.java
@@ -0,0 +1,383 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+
+// comment: Step 1: get the Desktop object from the office
+// Step 2: open an empty Calc document
+// Step 3: enter an 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.XSpreadsheetDocument;
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.uno.XComponentContext;
+
+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 service manager and the desktop object.
+ com.sun.star.frame.XDesktop xDesktop = null;
+ xDesktop = getDesktop();
+
+ // create a sheet document
+ XSpreadsheetDocument xSheetdocument = null;
+ xSheetdocument = createSheetdocument( xDesktop );
+ System.out.println( "Create a new Spreadsheet" );
+
+ // get the collection of all sheets from the document
+ XSpreadsheets xSheets = null;
+ xSheets = xSheetdocument.getSheets();
+
+ // the Action Interface provides methods to hide actions,
+ // like inserting data, on a sheet, that increase the performance
+ XActionLockable xActionInterface = null;
+ xActionInterface = 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 = UnoRuntime.queryInterface(
+ XIndexAccess.class, xSheets );
+
+ // specify the first sheet from the spreadsheet
+ xSheet = 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 = 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 =
+ UnoRuntime.queryInterface(
+ XCellFormatRangesSupplier.class, xSheet );
+
+ // getCellFormatRanges() has the interfaces for the enumeration
+ XEnumerationAccess xEnumerationAccess =
+ UnoRuntime.queryInterface(
+ XEnumerationAccess.class,
+ xCellFormatSupplier.getCellFormatRanges() );
+
+ XEnumeration xRanges = xEnumerationAccess.createEnumeration();
+
+ while( xRanges.hasMoreElements() ) {
+ // the enumeration returns a cellrange
+ XCellRange xCellRange = UnoRuntime.queryInterface(
+ XCellRange.class, xRanges.nextElement());
+
+ // the PropertySet the get and set the properties from the cellrange
+ XPropertySet xCellProp = 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 = AnyConverter.toInt(oNumberObject);
+
+ // get the properties from the cellrange numberformat
+ XPropertySet xFormat = xNumberFormats.getByKey(iNumberFormat );
+
+ short fType = AnyConverter.toShort(xFormat.getPropertyValue("Type"));
+ String sCurrencySymbol = AnyConverter.toString(
+ xFormat.getPropertyValue("CurrencySymbol"));
+
+ // change the numberformat only on cellranges with a
+ // currency numberformat
+ if( ( (fType & com.sun.star.util.NumberFormat.CURRENCY) > 0) &&
+ ( sCurrencySymbol.equals( sOldSymbol ) ) ) {
+ boolean bThousandSep = AnyConverter.toBoolean(
+ xFormat.getPropertyValue("ThousandsSeparator"));
+ boolean bNegativeRed = AnyConverter.toBoolean(
+ xFormat.getPropertyValue("NegativeRed"));
+ short fDecimals = AnyConverter.toShort(
+ xFormat.getPropertyValue("Decimals"));
+ short fLeadingZeros = AnyConverter.toShort(
+ xFormat.getPropertyValue("LeadingZeros"));
+ Locale oLocale = (Locale) AnyConverter.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",
+ Integer.valueOf( iNewNumberFormat ) );
+
+ // iterate over all cells from the cellrange with an
+ // content and use the DM/EUR factor
+ 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 = UnoRuntime.queryInterface(
+ XCell.class, xCellEnumeration.nextElement());
+ xCell.setValue( 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 PropertySet from the cell, to change the numberformat
+ XPropertySet xCellProp = UnoRuntime.queryInterface(
+ XPropertySet.class, xCellRange );
+ xCellProp.setPropertyValue( "NumberFormat",
+ Integer.valueOf(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 = 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 = 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 xEmptyArgs[] = new PropertyValue[0];
+
+ try {
+ xComponentLoader = UnoRuntime.queryInterface(
+ XComponentLoader.class, xDesktop );
+
+ xComponent = xComponentLoader.loadComponentFromURL(
+ sURL, "_blank", 0, xEmptyArgs);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return xComponent ;
+ }
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Spreadsheet/Makefile b/odk/examples/java/Spreadsheet/Makefile
new file mode 100644
index 000000000..f4d845be9
--- /dev/null
+++ b/odk/examples/java/Spreadsheet/Makefile
@@ -0,0 +1,209 @@
+#*************************************************************************
+#
+# 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
+
+# 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
+
+COMP_NAME=CalcAddins
+COMP_RDB_NAME=$(COMP_NAME).uno.rdb
+COMP_RDB=$(OUT_COMP_GEN)/$(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=$(OUT_COMP_CLASS)/$(COMP_JAR_NAME)
+COMP_MANIFESTFILE=$(OUT_COMP_CLASS)/$(COMP_NAME).uno.Manifest
+COMP_UNOPKG_MANIFEST = $(OUT_COMP_CLASS)/$(COMP_NAME)/META-INF/manifest.xml
+COMP_REGISTERFLAG=$(OUT_MISC)$(PS)java_$(COMP_NAME)_register_component.flag
+COMP_COMPONENTS=$(COMP_NAME).components
+
+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)))
+
+COMPCLASSFILES = $(patsubst %.java,$(OUT_COMP_CLASS)/%.class,$(COMPJAVAFILES))
+#COMPCLASSFILES += $(subst $(OUT_COMP_GEN),$(OUT_COMP_CLASS),$(GENJAVAFILES:.java=.class))
+
+$(COMP_NAME)_CLASSFILES = $(COMP_NAME).class \
+ $(COMP_NAME)$(QUOTE)$$_$(COMP_NAME).class
+
+#$(COMP_NAME)_CLASSFILES += $(subst $(OUT_COMP_GEN)/,,$(GENJAVAFILES:.java=.class))
+$(COMP_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)/%.rdb : $(IDLFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(UNOIDLWRITE) $(URE_TYPES) $(OFFICE_TYPES) $< $@
+
+#$(OUT_COMP_GEN)/%.java : $(COMP_RDB)
+$(GENCLASSFILES) : $(COMP_RDB)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(JAVAMAKER) -nD $(GENTYPELIST) -O$(OUT_COMP_CLASS) $(COMP_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
+$(COMP_JAR) : $(COMP_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-components$(QM)">> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(COMP_NAME).components$(QM)"/$(CSEP)>> $@
+ @echo $(OSEP)/manifest:manifest$(CSEP) >> $@
+
+# rule for component package file
+$(COMP_PACKAGE) : $(COMP_RDB) $(COMP_JAR) $(COMP_UNOPKG_MANIFEST) $(COMP_NAME).components description.xml
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(COPY) $(subst /,$(PS),$<) $(subst /,$(PS),$(OUT_COMP_CLASS))
+ $(SDK_ZIP) $@ -u $(COMP_NAME).components description.xml
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_ZIP) -u ../../bin/$(@F) $(COMP_RDB_NAME) $(COMP_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)))
+
+$(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
+
+$(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) : $(COMP_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 : $(COMP_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),$(COMP_PACKAGE_URL)))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_REGISTERFLAG)))
diff --git a/odk/examples/java/Spreadsheet/SCalc.java b/odk/examples/java/Spreadsheet/SCalc.java
new file mode 100644
index 000000000..90c5ce00f
--- /dev/null
+++ b/odk/examples/java/Spreadsheet/SCalc.java
@@ -0,0 +1,408 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+
+// 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 styles
+// 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.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 family
+ // CellStyle. Create an instance of com.sun.star.style.CellStyle and
+ // add it to the family. Now change some properties
+
+
+ try {
+ XStyleFamiliesSupplier xSFS = UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, myDoc);
+ XNameAccess xSF = xSFS.getStyleFamilies();
+ XNameAccess xCS = UnoRuntime.queryInterface(
+ XNameAccess.class, xSF.getByName("CellStyles"));
+ XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, myDoc );
+ XNameContainer oStyleFamilyNameContainer = UnoRuntime.queryInterface(
+ XNameContainer.class, xCS);
+ XInterface oInt1 = (XInterface) oDocMSF.createInstance(
+ "com.sun.star.style.CellStyle");
+ oStyleFamilyNameContainer.insertByName("My Style", oInt1);
+ XPropertySet oCPS1 = UnoRuntime.queryInterface(
+ XPropertySet.class, oInt1 );
+ oCPS1.setPropertyValue("IsCellBackgroundTransparent", Boolean.FALSE);
+ oCPS1.setPropertyValue("CellBackColor",Integer.valueOf(6710932));
+ oCPS1.setPropertyValue("CharColor",Integer.valueOf(16777215));
+ XInterface oInt2 = (XInterface) oDocMSF.createInstance(
+ "com.sun.star.style.CellStyle");
+ oStyleFamilyNameContainer.insertByName("My Style2", oInt2);
+ XPropertySet oCPS2 = UnoRuntime.queryInterface(
+ XPropertySet.class, oInt2 );
+ oCPS2.setPropertyValue("IsCellBackgroundTransparent", Boolean.FALSE);
+ oCPS2.setPropertyValue("CellBackColor",Integer.valueOf(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 = UnoRuntime.queryInterface(
+ XIndexAccess.class, xSheets);
+ xSheet = 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 Diagram. Change the properties
+ // Dim3D (3 dimension) and String (the title) of the diagram.
+
+
+ // insert a chart
+
+ Rectangle oRect = new Rectangle();
+ oRect.X = 500;
+ oRect.Y = 3000;
+ oRect.Width = 25000;
+ oRect.Height = 11000;
+
+ XCellRange oRange = UnoRuntime.queryInterface(
+ XCellRange.class, xSheet);
+ XCellRange myRange = oRange.getCellRangeByName("A1:N4");
+ XCellRangeAddressable oRangeAddr = UnoRuntime.queryInterface(XCellRangeAddressable.class, myRange);
+ CellRangeAddress myAddr = oRangeAddr.getRangeAddress();
+
+ CellRangeAddress[] oAddr = new CellRangeAddress[1];
+ oAddr[0] = myAddr;
+ XTableChartsSupplier oSupp = 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 diagram and change some of the properties
+
+ try {
+ oChart = (UnoRuntime.queryInterface(
+ XTableChart.class, UnoRuntime.queryInterface(
+ XNameAccess.class, oCharts).getByName("Example")));
+ XEmbeddedObjectSupplier oEOS = UnoRuntime.queryInterface(XEmbeddedObjectSupplier.class, oChart);
+ XInterface oInt = oEOS.getEmbeddedObject();
+ XChartDocument xChart = UnoRuntime.queryInterface(
+ XChartDocument.class,oInt);
+ XDiagram oDiag = xChart.getDiagram();
+ System.out.println("Change Diagram to 3D");
+ XPropertySet oCPS = UnoRuntime.queryInterface(
+ XPropertySet.class, oDiag );
+ oCPS.setPropertyValue("Dim3D", Boolean.TRUE);
+ System.out.println("Change the title");
+ Thread.sleep(200);
+ XPropertySet oTPS = UnoRuntime.queryInterface(
+ XPropertySet.class, xChart.getTitle() );
+ oTPS.setPropertyValue("String","The new title");
+ } catch (Exception e){
+ System.err.println("Changing 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 service manager from the office
+ xMCF = xContext.getServiceManager();
+
+ // create a new instance of the desktop
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext );
+
+ // query the desktop object for the XComponentLoader
+ xCLoader = UnoRuntime.queryInterface(
+ XComponentLoader.class, oDesktop );
+
+ PropertyValue [] szEmptyArgs = new PropertyValue [0];
+ String strDoc = "private:factory/scalc";
+
+ xComp = xCLoader.loadComponentFromURL(strDoc, "_blank", 0, szEmptyArgs );
+ xSpreadSheetDoc = 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 = 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);
+ }
+ }
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Spreadsheet/XCalcAddins.idl b/odk/examples/java/Spreadsheet/XCalcAddins.idl
new file mode 100644
index 000000000..79767b12c
--- /dev/null
+++ b/odk/examples/java/Spreadsheet/XCalcAddins.idl
@@ -0,0 +1,103 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+#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 the necessary 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
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Spreadsheet/description.xml b/odk/examples/java/Spreadsheet/description.xml
new file mode 100644
index 000000000..6c4e2396b
--- /dev/null
+++ b/odk/examples/java/Spreadsheet/description.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+-->
+<d:description xmlns:d="http://openoffice.org/extensions/description/2006">
+ <d:dependencies>
+ <l:LibreOffice-minimal-version value="4.1" d:name="LibreOffice 4.1"
+ xmlns:l="http://libreoffice.org/extensions/description/2011"/>
+ </d:dependencies>
+</d:description>
diff --git a/odk/examples/java/Storage/Makefile b/odk/examples/java/Storage/Makefile
new file mode 100644
index 000000000..3bf990b5d
--- /dev/null
+++ b/odk/examples/java/Storage/Makefile
@@ -0,0 +1,75 @@
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you under the Apache
+# License, Version 2.0 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+
+# Builds the Java Storage test example of the SDK.
+
+PRJ=../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.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 000000000..5b848019b
--- /dev/null
+++ b/odk/examples/java/Storage/StorageFunctionality.java
@@ -0,0 +1,156 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.bridge.XUnoUrlResolver;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XNamingService;
+import com.sun.star.uno.XComponentContext;
+
+import com.sun.star.lang.*;
+
+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 = 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] = new Test01( xMSF, xStorageFactory );
+ pTests[1] = new Test02( xMSF, xStorageFactory );
+ pTests[2] = new Test03( xMSF, xStorageFactory );
+ pTests[3] = new Test04( xMSF, xStorageFactory );
+ pTests[4] = new Test05( xMSF, xStorageFactory );
+ pTests[5] = new Test06( xMSF, xStorageFactory );
+ pTests[6] = new Test07( xMSF, xStorageFactory );
+ pTests[7] = new Test08( xMSF, xStorageFactory );
+ pTests[8] = 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 = UnoRuntime.queryInterface(
+ XUnoUrlResolver.class, oUrlResolver );
+
+ Object oInitialObject = xUrlResolver.resolve( sConnectStr );
+ XNamingService xName = 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 = UnoRuntime.queryInterface( XMultiServiceFactory.class, oMSF );
+ }
+ else
+ System.out.println( "Error: Can't get XNamingService interface from url resolver!" );
+
+ return xMSF;
+ }
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Storage/StorageTest.java b/odk/examples/java/Storage/StorageTest.java
new file mode 100644
index 000000000..b146d2229
--- /dev/null
+++ b/odk/examples/java/Storage/StorageTest.java
@@ -0,0 +1,25 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+public interface StorageTest
+{
+ boolean test();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Storage/Test01.java b/odk/examples/java/Storage/Test01.java
new file mode 100644
index 000000000..649f28440
--- /dev/null
+++ b/odk/examples/java/Storage/Test01.java
@@ -0,0 +1,169 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.embed.*;
+
+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.equals("") )
+ {
+ 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 = 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.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.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.WRITE ) )
+ return false;
+
+ // create temporary storage based on a previously created temporary file
+ Object pArgs[] = new Object[2];
+ pArgs[0] = sTempFileURL;
+ pArgs[1] = Integer.valueOf( ElementModes.WRITE );
+
+ Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xTempFileStorage = 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 committed
+ 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] = Integer.valueOf( ElementModes.READWRITE );
+ Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xResultStorage = 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.READWRITE ) )
+ return false;
+
+ // open existing substorage
+ XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage,
+ "SubStorage1",
+ ElementModes.READ );
+ if ( xResultSubStorage == null )
+ {
+ m_aTestHelper.Error( "Can't open existing substorage!" );
+ return false;
+ }
+
+ if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, "MediaType4", false, ElementModes.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;
+ }
+ }
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Storage/Test02.java b/odk/examples/java/Storage/Test02.java
new file mode 100644
index 000000000..92f5a8c81
--- /dev/null
+++ b/odk/examples/java/Storage/Test02.java
@@ -0,0 +1,165 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.io.XStream;
+import com.sun.star.io.XInputStream;
+
+import com.sun.star.embed.*;
+
+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] = xTempFileStream;
+ pArgs[1] = Integer.valueOf( ElementModes.WRITE );
+
+ Object oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xTempStorage = 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.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.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.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] = xTempInStream;
+
+ Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pOneArg );
+ XStorage xResultStorage = 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.READ ) )
+ return false;
+
+ // open existing substorage
+ XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage,
+ "SubStorage1",
+ ElementModes.READ );
+ if ( xResultSubStorage == null )
+ {
+ m_aTestHelper.Error( "Can't open existing substorage!" );
+ return false;
+ }
+
+ if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, "MediaType3", false, ElementModes.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;
+ }
+ }
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Storage/Test03.java b/odk/examples/java/Storage/Test03.java
new file mode 100644
index 000000000..500d46b92
--- /dev/null
+++ b/odk/examples/java/Storage/Test03.java
@@ -0,0 +1,220 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.embed.*;
+import com.sun.star.container.XNameAccess;
+
+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 = 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.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.WRITE ) )
+ return false;
+
+ if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
+ return false;
+
+ if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
+ return false;
+
+
+ // check storage hierarchy tree
+
+
+ // check that isStorageElement() and isStreamElement reacts to nonexistent object correctly
+ try {
+ xTempStorage.isStorageElement( "does not exist" );
+ m_aTestHelper.Error( "Nonexistent 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( "Nonexistent 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 = 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.READ ) )
+ return false;
+
+ XNameAccess xChildAccess = 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 = 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;
+ }
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Storage/Test04.java b/odk/examples/java/Storage/Test04.java
new file mode 100644
index 000000000..535253b19
--- /dev/null
+++ b/odk/examples/java/Storage/Test04.java
@@ -0,0 +1,282 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.container.XNameAccess;
+
+import com.sun.star.embed.*;
+
+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.equals("") )
+ {
+ 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 = 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.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.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.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.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.WRITE ) )
+ return false;
+
+ // create temporary storage based on a previously created temporary file
+ Object pArgs[] = new Object[2];
+ pArgs[0] = sTempFileURL;
+ pArgs[1] = Integer.valueOf( ElementModes.WRITE );
+
+ Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xTempFileStorage = 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 committed 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] = Integer.valueOf( ElementModes.READWRITE );
+ Object oResStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xResStorage = 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.READ );
+ if ( xResSubStorage1 == null )
+ {
+ m_aTestHelper.Error( "Can't open existing substorage!" );
+ return false;
+ }
+
+ if ( !m_aTestHelper.checkStorageProperties( xResSubStorage1, "MediaType4", false, ElementModes.READ ) )
+ return false;
+
+
+ // open and check SubStorage2
+ XStorage xResSubStorage2 = m_aTestHelper.openSubStorage( xResStorage,
+ "SubStorage2",
+ ElementModes.READ );
+ if ( xResSubStorage2 == null )
+ {
+ m_aTestHelper.Error( "Can't open existing substorage!" );
+ return false;
+ }
+
+ if ( !m_aTestHelper.checkStorageProperties( xResSubStorage2, "MediaType5", false, ElementModes.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 completely
+ if ( !m_aTestHelper.removeElement( xResStorage, "SubStorage2" ) )
+ return false;
+
+ try
+ {
+ XNameAccess xResAccess = 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;
+ }
+ }
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Storage/Test05.java b/odk/examples/java/Storage/Test05.java
new file mode 100644
index 000000000..29cf99d52
--- /dev/null
+++ b/odk/examples/java/Storage/Test05.java
@@ -0,0 +1,278 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.io.XStream;
+
+import com.sun.star.embed.*;
+
+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.equals("") )
+ {
+ 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] = sTempFileURL;
+ pArgs[1] = Integer.valueOf( ElementModes.WRITE );
+
+ Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xTempFileStorage = 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.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.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.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.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.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.READWRITE | ElementModes.NOCREATE );
+ XStream xSubStream2 = m_aTestHelper.OpenStream( xSubSubStorage,
+ "SubStream2",
+ ElementModes.READ | ElementModes.NOCREATE );
+ if ( xSubStream1 == null || xSubStream2 == null )
+ return false;
+
+ // it should be possible to have more than one copy of stream for reading
+ XStream xSubStream2clone = m_aTestHelper.OpenStream( xSubSubStorage,
+ "SubStream2",
+ ElementModes.READ | ElementModes.NOCREATE );
+
+
+ // so now the first stream can not be open neither for reading nor for writing
+ if ( !m_aTestHelper.cantOpenStream( xSubSubStorage, "SubStream1", ElementModes.WRITE )
+ || !m_aTestHelper.cantOpenStream( xSubSubStorage, "SubStream1", ElementModes.READ ) )
+ return false;
+
+ // the second stream can not be open for writing
+ if ( !m_aTestHelper.cantOpenStream( xSubSubStorage, "SubStream2", ElementModes.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] = Integer.valueOf( ElementModes.READ );
+ Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xResultStorage = 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.READ ) )
+ return false;
+
+ // open existing substorage
+ XStorage xResSubStorage = m_aTestHelper.openSubStorage( xResultStorage,
+ "SubStorage1",
+ ElementModes.READ );
+ if ( xResSubStorage == null )
+ {
+ m_aTestHelper.Error( "Can't open existing substorage 'SubSubStorage'!" );
+ return false;
+ }
+
+ if ( !m_aTestHelper.checkStorageProperties( xResSubStorage, "MediaType4", false, ElementModes.READ ) )
+ return false;
+
+ // open existing substorage
+ XStorage xResSubSubStorage = m_aTestHelper.openSubStorage( xResSubStorage,
+ "SubSubStorage1",
+ ElementModes.READ );
+ if ( xResSubSubStorage == null )
+ {
+ m_aTestHelper.Error( "Can't open existing substorage 'SubSubStorage'!" );
+ return false;
+ }
+
+ if ( !m_aTestHelper.checkStorageProperties( xResSubSubStorage, "MediaType5", false, ElementModes.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;
+ }
+ }
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Storage/Test06.java b/odk/examples/java/Storage/Test06.java
new file mode 100644
index 000000000..027a4a2c1
--- /dev/null
+++ b/odk/examples/java/Storage/Test06.java
@@ -0,0 +1,285 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.embed.*;
+
+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 = 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 exception because of illegal parameter : " + e );
+ return false;
+ }
+
+ // open new substorages
+ XStorage xTempSubStorage1 = m_aTestHelper.openSubStorage( xTempStorage,
+ "SubStorage1",
+ ElementModes.WRITE );
+ XStorage xTempSubStorage2 = m_aTestHelper.openSubStorage( xTempStorage,
+ "SubStorage2",
+ ElementModes.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.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 exception 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.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 exception 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 exception 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 exception 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 exception 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 exception in case empty reference is provided 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 exception in case empty reference is provided 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 = 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.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 nonexistent element!" );
+ return false;
+ }
+ catch( com.sun.star.container.NoSuchElementException ne )
+ {}
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Unexpected exception 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 nonexistent element!" );
+ return false;
+ }
+ catch( com.sun.star.container.NoSuchElementException ne )
+ {}
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Unexpected exception 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 exception 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 exception in case target for moving already exists: " + e );
+ return false;
+ }
+
+
+ return true;
+ }
+ catch( Exception e )
+ {
+ m_aTestHelper.Error( "Exception: " + e );
+ return false;
+ }
+ }
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Storage/Test07.java b/odk/examples/java/Storage/Test07.java
new file mode 100644
index 000000000..d96b0e1eb
--- /dev/null
+++ b/odk/examples/java/Storage/Test07.java
@@ -0,0 +1,148 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.embed.*;
+
+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.equals("") )
+ {
+ 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 = 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] = sTempFileURL;
+ pArgs[1] = Integer.valueOf( ElementModes.WRITE );
+
+ Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xTempFileStorage = 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 committed
+ 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] = Integer.valueOf( ElementModes.READWRITE );
+ Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xResultStorage = 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 = 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;
+ }
+ }
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Storage/Test08.java b/odk/examples/java/Storage/Test08.java
new file mode 100644
index 000000000..323e2d78c
--- /dev/null
+++ b/odk/examples/java/Storage/Test08.java
@@ -0,0 +1,224 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.embed.*;
+
+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 = 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 =
+ 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.setEncryptionPassword( new String(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.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.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.WRITE ) )
+ return false;
+
+ // create temporary file
+ String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF );
+ if ( sTempFileURL == null || sTempFileURL.equals("") )
+ {
+ 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] = sTempFileURL;
+ pArgs[1] = Integer.valueOf( ElementModes.WRITE );
+
+ Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xTempFileStorage = 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 committed
+ 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] = Integer.valueOf( ElementModes.READ );
+ Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xResultStorage = 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.READ ) )
+ return false;
+
+ // open existing substorage
+ XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage,
+ "SubStorage1",
+ ElementModes.READ );
+ if ( xResultSubStorage == null )
+ {
+ m_aTestHelper.Error( "Can't open existing substorage!" );
+ return false;
+ }
+
+ if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, "MediaType5", false, ElementModes.READ ) )
+ return false;
+
+ // set the global password for the root storage
+ XEncryptionProtectedSource xResultStorageEncryption =
+ 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.setEncryptionPassword( new String(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;
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Storage/Test09.java b/odk/examples/java/Storage/Test09.java
new file mode 100644
index 000000000..131ff06d8
--- /dev/null
+++ b/odk/examples/java/Storage/Test09.java
@@ -0,0 +1,134 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.embed.*;
+
+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 = 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.equals( "" ) )
+ {
+ 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] = sTempFileURL;
+ pArgs[1] = Integer.valueOf( ElementModes.WRITE );
+
+ Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xTempFileStorage = 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 committed
+ 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] = Integer.valueOf( ElementModes.READ );
+ Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
+ XStorage xResultStorage = 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;
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Storage/TestHelper.java b/odk/examples/java/Storage/TestHelper.java
new file mode 100644
index 000000000..a486f1d53
--- /dev/null
+++ b/odk/examples/java/Storage/TestHelper.java
@@ -0,0 +1,881 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+import com.sun.star.uno.UnoRuntime;
+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 XTruncate implementation from output stream
+ 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 = 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", Boolean.valueOf( 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 = 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.WRITE );
+ xSubStream = 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.WRITE, new String(pPass) );
+ xSubStream = 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.WRITE );
+ xSubStream = 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 = 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", Boolean.valueOf( 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.WRITE, new String(pOldPass) );
+ xSubStream = 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 =
+ UnoRuntime.queryInterface( XEncryptionProtectedSource.class, xSubStream );
+
+ if ( xStreamEncryption == null )
+ {
+ Message( "Optional interface XEncryptionProtectedSource is not implemented, feature can not be tested!" );
+ return -1;
+ }
+
+ try {
+ xStreamEncryption.setEncryptionPassword( new String(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 = 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 = 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.READ ) != ( nMode | ElementModes.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 = 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.READ ) != ( nMode | ElementModes.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 = 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" ) );
+ long nPropSize = AnyConverter.toLong( 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.READ );
+ xSubStream = 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
+ {
+ xParentStorage.openStreamElement( sName, ElementModes.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
+ {
+ xParentStorage.openEncryptedStreamElement( sName, ElementModes.READ, new String(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.READ, new String(pPass) );
+ xSubStream = 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 = 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 = 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 = 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 = 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 = UnoRuntime.queryInterface( XPropertySet.class, oTempFile );
+ }
+ catch( Exception e )
+ {}
+
+ if ( xTempFileProps != null )
+ {
+ try
+ {
+ xTempFileProps.setPropertyValue( "RemoveFile", 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 = 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 = 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.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 );
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Text/BookmarkInsertion.java b/odk/examples/java/Text/BookmarkInsertion.java
new file mode 100644
index 000000000..0b9dd3fa9
--- /dev/null
+++ b/odk/examples/java/Text/BookmarkInsertion.java
@@ -0,0 +1,275 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+
+// comment: Step 1: get the Desktop object from the office
+// Step 2: open an empty text document
+// Step 3: enter an 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 service 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 = FindFirst(
+ xTextDocument, mList[ iCounter ] );
+
+ if( xSearchInterface != null ) {
+ // get the TextRange from the XInterface
+ xSearchTextRange = 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 = UnoRuntime.queryInterface(
+ com.sun.star.lang.XMultiServiceFactory.class, xTextDocument);
+
+ // the bookmark service is a context dependent 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 = 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 = 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 = UnoRuntime.queryInterface(
+ com.sun.star.util.XSearchable.class, xTextDocument);
+ xSearchDescriptor = xSearchable.createSearchDescriptor();
+
+ xSearchDescriptor.setSearchString(sSearchString);
+
+ com.sun.star.beans.XPropertySet xPropertySet = null;
+ xPropertySet = UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xSearchDescriptor);
+
+ xPropertySet.setPropertyValue("SearchRegularExpression",
+ 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 = 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 lightning 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 = 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 = 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 xEmptyArgs[] =
+ new com.sun.star.beans.PropertyValue[0];
+
+ try {
+ 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 ;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Text/GraphicsInserter.java b/odk/examples/java/Text/GraphicsInserter.java
new file mode 100644
index 000000000..b4b5b49ea
--- /dev/null
+++ b/odk/examples/java/Text/GraphicsInserter.java
@@ -0,0 +1,195 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.uno.UnoRuntime;
+
+import java.io.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 instantiate within
+ frames. */
+ com.sun.star.frame.XDesktop xDesktop = UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class,
+ xMCF.createInstanceWithContext("com.sun.star.frame.Desktop",
+ xContext ) );
+
+ com.sun.star.frame.XComponentLoader xCompLoader =
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class, xDesktop);
+
+ // Load a Writer document, which will be automatically 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 =
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XTextDocument.class, xComp);
+
+ // Querying for the interface XMultiServiceFactory on the xtextdocument
+ com.sun.star.lang.XMultiServiceFactory xMSFDoc =
+ 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 =
+ 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 =
+ 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 + "\"");
+
+ com.sun.star.graphic.XGraphicProvider xGraphicProvider =
+ UnoRuntime.queryInterface(com.sun.star.graphic.XGraphicProvider.class,
+ xMCF.createInstanceWithContext("com.sun.star.graphic.GraphicProvider",
+ xContext));
+
+
+ com.sun.star.beans.PropertyValue[] aMediaProps = new com.sun.star.beans.PropertyValue[] { new com.sun.star.beans.PropertyValue() };
+ aMediaProps[0].Name = "URL";
+ aMediaProps[0].Value = sUrl;
+
+ com.sun.star.graphic.XGraphic xGraphic =
+ UnoRuntime.queryInterface(com.sun.star.graphic.XGraphic.class,
+ xGraphicProvider.queryGraphic(aMediaProps));
+
+ // Setting the anchor type
+ xPropSet.setPropertyValue("AnchorType",
+ com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH );
+
+ // Setting the graphic url
+ xPropSet.setPropertyValue( "Graphic", xGraphic );
+
+ // Setting the horizontal position
+ xPropSet.setPropertyValue( "HoriOrientPosition",
+ Integer.valueOf( 5500 ) );
+
+ // Setting the vertical position
+ xPropSet.setPropertyValue( "VertOrientPosition",
+ Integer.valueOf( 4200 ) );
+
+ // Setting the width
+ xPropSet.setPropertyValue( "Width", Integer.valueOf( 4400 ) );
+
+ // Setting the height
+ xPropSet.setPropertyValue( "Height", Integer.valueOf( 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);
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Text/HardFormatting.java b/odk/examples/java/Text/HardFormatting.java
new file mode 100644
index 000000000..81a294c86
--- /dev/null
+++ b/odk/examples/java/Text/HardFormatting.java
@@ -0,0 +1,279 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+
+// comment: Step 1: get the Desktop object from the office
+// Step 2: open an empty text document
+// Step 3: enter an 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 service 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 through 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 = 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 formatting'
+ // the text range not the cursor contains the 'parastyle' property
+ xTextRange = xText.getEnd();
+ xPropertySet = UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xTextRange);
+
+ // create a paragraph cursor to travel through the paragraphs
+ com.sun.star.text.XParagraphCursor xParagraphCursor = null;
+ 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 = UnoRuntime.queryInterface(
+ com.sun.star.text.XWordCursor.class, xTextRange);
+
+ // the PropertySet from the cursor contains the text attributes
+ 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 = UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xWordCursor);
+ xPropertySet.setPropertyValue("CharWeight",
+ new Float(com.sun.star.awt.FontWeight.BOLD));
+ xPropertySet.setPropertyValue("CharColor", Integer.valueOf( 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 formatted or not.
+ com.sun.star.beans.XPropertyState xPropertyState = null;
+ 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 formatting' 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()
+ + "' completely hard formatted" );
+ break;
+ }
+
+ case com.sun.star.beans.PropertyState.DEFAULT_VALUE_value: {
+ System.out.println( "-> The selection '"
+ + xWordCursor.getString()
+ + "' isn't hard formatted" );
+ break;
+ }
+
+ case com.sun.star.beans.PropertyState.AMBIGUOUS_VALUE_value: {
+ System.out.println( "-> The selection '"
+ + xWordCursor.getString()
+ + "' isn't completely hard formatted" );
+ 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 = 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 = 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 xEmptyArgs[] =
+ new com.sun.star.beans.PropertyValue[0];
+
+ try {
+ 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 ;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Text/Makefile b/odk/examples/java/Text/Makefile
new file mode 100644
index 000000000..cdfdcb29f
--- /dev/null
+++ b/odk/examples/java/Text/Makefile
@@ -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.
+#
+#**************************************************************************
+
+# Builds the Java Text examples of the SDK.
+
+PRJ=../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.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 000000000..fc960c1f2
--- /dev/null
+++ b/odk/examples/java/Text/SWriter.java
@@ -0,0 +1,390 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+
+// 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 and 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 =
+ 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 = 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 = 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 = UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, xTT);
+
+ // Change the BackColor
+ try {
+ xTTPS.setPropertyValue("BackTransparent", Boolean.FALSE);
+ xTTPS.setPropertyValue("BackColor",Integer.valueOf(13421823));
+ xTTRowPS.setPropertyValue("BackTransparent", Boolean.FALSE);
+ xTTRowPS.setPropertyValue("BackColor",Integer.valueOf(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 = UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,
+ xTCursor);
+
+ // Change the CharColor and add a Shadow
+ try {
+ xTCPS.setPropertyValue("CharColor",Integer.valueOf(255));
+ xTCPS.setPropertyValue("CharShadowed", 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 and 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 = UnoRuntime.queryInterface(
+ com.sun.star.text.XTextFrame.class,oInt);
+ xTFS = 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 = 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",Integer.valueOf(65536));
+ xTCPS.setPropertyValue("CharShadowed", 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 = 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 = 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 = 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 = UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, xTC);
+
+ try {
+ xTPS.setPropertyValue("CharColor",Integer.valueOf(16777215));
+ } catch (Exception e) {
+ System.err.println(" Exception " + e);
+ e.printStackTrace(System.err);
+ }
+
+ //inserting some Text
+ xTableText.setString( theText );
+
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Text/StyleCreation.java b/odk/examples/java/Text/StyleCreation.java
new file mode 100644
index 000000000..d5151eca7
--- /dev/null
+++ b/odk/examples/java/Text/StyleCreation.java
@@ -0,0 +1,224 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+
+// 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 service 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 dependent, you need
+ // the multi service factory from the document to use the service
+ com.sun.star.lang.XMultiServiceFactory xDocMSF =
+ 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 =
+ 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 =
+ 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 =
+ 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", "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", Boolean.TRUE );
+ System.out.println( "set the paragraph attribute 'AutoKerning'" );
+ xPropertySet.setPropertyValue("ParaAdjust",
+ Integer.valueOf( com.sun.star.style.ParagraphAdjust.CENTER_value ) );
+ System.out.println( "set the paragraph adjust to LEFT" );
+
+ xPropertySet.setPropertyValue("ParaFirstLineIndent", Integer.valueOf( 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 =
+ 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",
+ "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 = 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 = 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 xEmptyArgs[] =
+ new com.sun.star.beans.PropertyValue[0];
+
+ try {
+ 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 ;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Text/StyleInitialization.java b/odk/examples/java/Text/StyleInitialization.java
new file mode 100644
index 000000000..63ea29b24
--- /dev/null
+++ b/odk/examples/java/Text/StyleInitialization.java
@@ -0,0 +1,311 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+
+// comment: Step 1: get the Desktop object from the office
+// Step 2: open an empty text document
+// Step 3: enter an 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 service 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 through 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 = xTextDocument.getText().createTextCursor();
+
+ com.sun.star.beans.XPropertySet oCPS = 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 = 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 through the paragraphs, with a
+ // paragraph cursor, or an enumeration.
+ // You find both ways in this example
+
+ // The first way, with the paragraph cursor
+ com.sun.star.text.XParagraphCursor xParagraphCursor = null;
+ 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 = UnoRuntime.queryInterface(
+ com.sun.star.container.XEnumerationAccess.class, xText );
+
+ // the enumeration contains all paragraph from 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 = 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 = 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 = 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
+
+ // create a supplier to get the styles-collection
+ com.sun.star.style.XStyleFamiliesSupplier xSupplier = null;
+ xSupplier = 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 = UnoRuntime.queryInterface(
+ com.sun.star.container.XNameContainer.class, xNameAccess.getByName( "ParagraphStyles" ));
+
+ // create an 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 = UnoRuntime.queryInterface(
+ com.sun.star.style.XStyle.class,
+ xParaStyleCollection.getByName( sElementNames[iCounter] ));
+
+ // create a property set of all properties from the style
+ xPropertySet = UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xStyle );
+
+ String sFontname = AnyConverter.toString(xPropertySet.getPropertyValue("CharFontName"));
+ sFontname = sFontname.toLowerCase();
+
+ // if the style use the font 'Albany', apply it to the current paragraph
+ if( sFontname.equals("albany") ) {
+ // create a property set from the current paragraph, to change the paragraph style
+ 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", 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 = 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 = 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 xEmptyArgs[] =
+ new com.sun.star.beans.PropertyValue[0];
+
+ try {
+ 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 ;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Text/TextDocumentStructure.java b/odk/examples/java/Text/TextDocumentStructure.java
new file mode 100644
index 000000000..7f284556d
--- /dev/null
+++ b/odk/examples/java/Text/TextDocumentStructure.java
@@ -0,0 +1,201 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+
+// 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 remote service manager
+ 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 =
+ 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 =
+ 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 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 =
+ UnoRuntime.queryInterface(
+ com.sun.star.container.XEnumerationAccess.class, xText);
+ xParagraphEnumeration = xEnumerationAccess.createEnumeration();
+
+ // Loop through all paragraphs of the document
+ while ( xParagraphEnumeration.hasMoreElements() ) {
+ xTextElement = UnoRuntime.queryInterface(
+ com.sun.star.text.XTextContent.class,
+ xParagraphEnumeration.nextElement());
+ com.sun.star.lang.XServiceInfo 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 =
+ UnoRuntime.queryInterface(
+ com.sun.star.container.XEnumerationAccess.class,
+ xTextElement);
+ xTextPortionEnum = xParaEnumerationAccess.createEnumeration();
+
+ while ( xTextPortionEnum.hasMoreElements() ) {
+ com.sun.star.text.XTextRange xTextPortion =
+ 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 =
+ 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 =
+ 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 =
+ 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 =
+ 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);
+ }
+
+
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Text/TextReplace.java b/odk/examples/java/Text/TextReplace.java
new file mode 100644
index 000000000..588d88ae6
--- /dev/null
+++ b/odk/examples/java/Text/TextReplace.java
@@ -0,0 +1,224 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+
+// comment: Step 1: get the Desktop object from the office
+// Step 2: open an empty text document
+// Step 3: enter an 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 service 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.XReplaceable xReplaceable = null;
+
+ xReplaceable = UnoRuntime.queryInterface(
+ com.sun.star.util.XReplaceable.class, xTextDocument);
+
+ // You need a descriptor to set properties for Replace
+ xReplaceDescr = 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 = xTextDocument.getText().createTextCursor();
+ com.sun.star.text.XText 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 = UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xTextCursor);
+ // Set the word blue
+ xCPS.setPropertyValue( "CharColor", Integer.valueOf( 255 ) );
+ // Go to last character
+ xTextCursor.gotoEnd(false);
+ xCPS.setPropertyValue( "CharColor", Integer.valueOf( 0 ) );
+
+ xText.insertString( xTextCursor, "in the alley. Like lightning 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 = UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xTextCursor);
+ // Set the word blue
+ xCPS.setPropertyValue( "CharColor", Integer.valueOf( 255 ) );
+ // Go to last character
+ xTextCursor.gotoEnd(false);
+ xCPS.setPropertyValue( "CharColor", Integer.valueOf( 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 = 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 = 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 xEmptyArgs[] =
+ new com.sun.star.beans.PropertyValue[0];
+
+ try {
+ 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 ;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Text/WriterSelector.java b/odk/examples/java/Text/WriterSelector.java
new file mode 100644
index 000000000..31d873733
--- /dev/null
+++ b/odk/examples/java/Text/WriterSelector.java
@@ -0,0 +1,161 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.uno.UnoRuntime;
+
+/** This class 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 = UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class,
+ xMCF.createInstanceWithContext("com.sun.star.frame.Desktop",
+ xContext ) );
+
+ com.sun.star.frame.XComponentLoader xCompLoader =
+ 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 =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 =
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XModel.class, xDoc);
+
+ com.sun.star.view.XViewSettingsSupplier xViewSettings =
+ UnoRuntime.queryInterface(
+ com.sun.star.view.XViewSettingsSupplier.class, xModel.getCurrentController());
+ xViewSettings.getViewSettings().setPropertyValue(
+ "ZoomType", Short.valueOf((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 =
+ UnoRuntime.queryInterface(
+ com.sun.star.view.XSelectionSupplier.class, xController );
+
+ Object oSelection = xSelSupplier.getSelection();
+
+ com.sun.star.lang.XServiceInfo xServInfo =
+ UnoRuntime.queryInterface(
+ com.sun.star.lang.XServiceInfo.class, oSelection );
+
+ if ( xServInfo.supportsService("com.sun.star.text.TextRanges") )
+ {
+ com.sun.star.container.XIndexAccess 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 = 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 = 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);
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Text/oo_smiley.gif b/odk/examples/java/Text/oo_smiley.gif
new file mode 100644
index 000000000..f9fc08d50
--- /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 000000000..4fdc8a31f
--- /dev/null
+++ b/odk/examples/java/ToDo/Makefile
@@ -0,0 +1,160 @@
+#*************************************************************************
+#
+# 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
+
+# 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
+COMP_COMPONENTS=$(COMP_NAME).components
+
+IDLFILES = XToDo.idl \
+ ToDo.idl
+
+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)))
+
+
+$(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)/%.rdb : $(patsubst %,$(PACKAGE)/%,$(IDLFILES))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(UNOIDLWRITE) $(URE_TYPES) $(OFFICE_TYPES) . $@
+
+$(GEN_CLASSFILES) : $(COMP_RDB)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(JAVAMAKER) -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-components$(QM)">> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(COMP_NAME).components$(QM)"/$(CSEP)>> $@
+ @echo $(OSEP)/manifest:manifest$(CSEP) >> $@
+
+# rule for component package file
+$(COMP_PACKAGE) : $(COMP_RDB) $(COMP_JAR) $(COMP_UNOPKG_MANIFEST) $(COMP_NAME).components description.xml
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_ZIP) $@ $(COMP_NAME).components description.xml
+ cd $(subst /,$(PS),$(COMP_GEN_OUT)) && $(SDK_ZIP) -u ../../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.components b/odk/examples/java/ToDo/ToDo.components
new file mode 100644
index 000000000..0b667b96a
--- /dev/null
+++ b/odk/examples/java/ToDo/ToDo.components
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<components xmlns="http://openoffice.org/2010/uno-components">
+ <component loader="com.sun.star.loader.Java2" uri="ToDo.uno.jar">
+ <implementation name="ToDo$ToDoImpl">
+ <service name="org.openoffice.ToDo"/>
+ </implementation>
+ </component>
+</components>
diff --git a/odk/examples/java/ToDo/ToDo.java b/odk/examples/java/ToDo/ToDo.java
new file mode 100644
index 000000000..312ab42d3
--- /dev/null
+++ b/odk/examples/java/ToDo/ToDo.java
@@ -0,0 +1,932 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.container.XIndexAccess;
+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.sheet.XCellRangeMovement;
+import com.sun.star.sheet.XFunctionAccess;
+import com.sun.star.sheet.XSpreadsheet;
+import com.sun.star.sheet.XSpreadsheetDocument;
+import com.sun.star.table.CellAddress;
+import com.sun.star.table.CellRangeAddress;
+import com.sun.star.table.XCell;
+import com.sun.star.table.XCellRange;
+import com.sun.star.table.XColumnRowRange;
+import com.sun.star.table.XTableRows;
+import com.sun.star.text.XSimpleText;
+import com.sun.star.text.XText;
+import com.sun.star.text.XTextCursor;
+import com.sun.star.text.XTextField;
+import com.sun.star.text.XTextRange;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+import org.openoffice.XToDo;
+
+/** 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
+ private static final int INT_COLUMN_FEATURE = 0;
+ private static final int INT_COLUMN_NEEDEDDAYS = 2;
+ private static final int INT_COLUMN_STARTDATE = 3;
+ private static final int INT_COLUMN_START_DAY_OF_WEEK = 4;
+ private static final int INT_COLUMN_ENDDATE = 5;
+ private static final int INT_COLUMN_END_DAY_OF_WEEK = 6;
+ private static final int INT_COLUMN_DUEDATE = 7;
+ private static final int INT_COLUMN_STATUS = 8;
+
+ private static final int INT_ROW_FROM = 14; // 8
+
+ private static final int INT_ROW_HOLIDAYS_START = 4;
+ private static final int INT_COLUMN_HOLIDAYS_START = 7; // 10
+
+ private static 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();
+ }
+
+ private static String[] getServiceNames() {
+ String[] sSupportedServiceNames = { __serviceName };
+ return sSupportedServiceNames;
+ }
+
+ /** This method returns true, if the given service will be
+ * supported by the component.
+ * @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 =
+ UnoRuntime.queryInterface(
+ XSpreadsheetDocument.class, aInstance );
+
+ // Querying for the interface XIndexAccess
+ XIndexAccess xindexaccess = UnoRuntime.queryInterface( XIndexAccess.class,
+ xspreadsheetdocument.getSheets() );
+
+ // Getting the first XSpreadsheet
+ XSpreadsheet xspreadsheet = UnoRuntime.queryInterface(
+ XSpreadsheet.class, xindexaccess.getByIndex( 0 ));
+
+ // Querying for the interface XCellRange on the XSpreadsheet
+ 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 = UnoRuntime.queryInterface(XFunctionAccess.class,
+ objectFunctionAccess );
+
+ // Creating vector for holidays
+ ArrayList<Object> vectorHolidays = new ArrayList<Object>();
+
+ // 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 = ToDoImpl.INT_ROW_FROM - 1;
+
+ // Getting the feature of the first cell
+ String sFeature = this.getStringFromCell(xcellrange,
+ intRowTo + 1,
+ ToDoImpl.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, ToDoImpl.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 = ToDoImpl.INT_ROW_FROM; intRow < INT_ROW_TO + 5;
+ intRow++ ) {
+ for ( int intColumn = ToDoImpl.INT_COLUMN_STARTDATE;
+ intColumn <= ToDoImpl.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 = ToDoImpl.INT_ROW_FROM; intRow < INT_ROW_TO; intRow++)
+ {
+ // Querying for the interface XPropertySet for the cell
+ // providing the due date
+ XPropertySet xpropertyset = UnoRuntime.queryInterface(XPropertySet.class,
+ xcellrange.getCellByPosition(
+ ToDoImpl.INT_COLUMN_DUEDATE,
+ intRow ));
+
+ // Changing the background color of the cell to white
+ xpropertyset.setPropertyValue( "CellBackColor",
+ Integer.valueOf( 16777215 ) );
+
+ // Getting the cell of the bug id
+ XCell xcell = xcellrange.getCellByPosition(
+ ToDoImpl.INT_COLUMN_FEATURE, intRow );
+
+ // Querying for the interface XSimpleText
+ XSimpleText xsimpletext = UnoRuntime.queryInterface( XSimpleText.class, xcell );
+
+ // Getting the text cursor
+ XTextCursor xtextcursor = xsimpletext.createTextCursor();
+
+ // Querying for the interface 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 =
+ 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 = UnoRuntime.queryInterface( XTextField.class,
+ objectTextField );
+
+ // Querying for the interface XPropertySet
+ XPropertySet xpropertysetTextField = 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 = 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 = ToDoImpl.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, ToDoImpl.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,
+ ToDoImpl.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,
+ ToDoImpl.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,
+ ToDoImpl.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, ToDoImpl.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, ToDoImpl.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,
+ ToDoImpl.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,
+ ToDoImpl.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,
+ ToDoImpl.INT_COLUMN_STARTDATE );
+ }
+
+ // Get the GregorianCalendar 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,
+ ToDoImpl.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 = UnoRuntime.queryInterface(
+ XPropertySet.class,
+ xcellrange.getCellByPosition(
+ ToDoImpl.INT_COLUMN_DUEDATE,
+ intRow ) );
+
+ // Changing the background color of the cell
+ // to red
+ xpropertyset.setPropertyValue(
+ "CellBackColor", Integer.valueOf( 16711680 ) );
+ } else {
+ // Querying for the interface XColumnRowRange
+ // on the XCellRange
+ 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 =
+ 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 >= ToDoImpl.INT_ROW_FROM ) {
+ // Get the start date
+ gregCalStartDate =
+ this.getGregorianCalendarFromString(
+ this.getStringFromCell( xcellrange,
+ intRow,ToDoImpl.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).
+ */
+ private String getStringFromGregorianCalendar( GregorianCalendar gregCal ) {
+ String sDate = ( gregCal.get( Calendar.MONTH ) + 1 )
+ + STRING_SEPARATOR + gregCal.get( Calendar.DATE )
+ + 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.
+ */
+ private 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.
+ */
+ private 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.
+ */
+ private 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 = 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.
+ */
+ private 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 = 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.
+ */
+ private 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.
+ */
+ private void getOfficialHolidays(
+ ArrayList<Object> 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[] { Integer.valueOf(intYear) });
+
+ int intEasterSunday = (int)Math.round(
+ dEasterSunday.doubleValue());
+
+ // New-year
+ vectorHolidays.add( xfunctionaccess.callFunction(
+ "DATE",
+ new Object[] {
+ Integer.valueOf( intYear ),
+ Integer.valueOf( 1 ),
+ Integer.valueOf( 1 ) } ));
+
+ // Good Friday
+ vectorHolidays.add(
+ new Double( intEasterSunday - 2 ) );
+
+ // Easter monday
+ vectorHolidays.add(
+ new Double( intEasterSunday + 1 ) );
+
+ // Labour Day
+ vectorHolidays.add( xfunctionaccess.callFunction(
+ "DATE",
+ new Object[] {
+ Integer.valueOf( intYear ),
+ Integer.valueOf( 5 ),
+ Integer.valueOf( 1 ) } ));
+
+ // Ascension Day
+ vectorHolidays.add(new Double(intEasterSunday + 39 ));
+
+ // Pentecost monday
+ vectorHolidays.add(new Double(intEasterSunday + 50 ));
+
+ // German Unification
+ vectorHolidays.add( xfunctionaccess.callFunction(
+ "DATE",
+ new Object[] {
+ Integer.valueOf( intYear ),
+ Integer.valueOf( 10 ),
+ Integer.valueOf( 3 ) } ));
+
+ // Christmas Day First
+ vectorHolidays.add( xfunctionaccess.callFunction(
+ "DATE",
+ new Object[] {
+ Integer.valueOf( intYear ),
+ Integer.valueOf( 12 ),
+ Integer.valueOf( 25 ) } ));
+
+ // Christmas Day Second
+ vectorHolidays.add( xfunctionaccess.callFunction(
+ "DATE",
+ new Object[] {
+ Integer.valueOf( intYear ),
+ Integer.valueOf( 12 ),
+ Integer.valueOf( 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.
+ */
+ private 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[] {
+ Integer.valueOf( gregCalStartDate.get( Calendar.YEAR ) ),
+ Integer.valueOf( gregCalStartDate.get( Calendar.MONTH ) + 1 ),
+ Integer.valueOf( gregCalStartDate.get( Calendar.DATE ) )
+ } );
+
+ Double dWorkday = ( Double ) xfunctionaccess.callFunction(
+ "com.sun.star.sheet.addin.Analysis.getWorkday",
+ new Object[] { dDate, Integer.valueOf( 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.
+ */
+ private void getPrivateHolidays( ArrayList<Object> vectorHolidays,
+ XCellRange xcellrange,
+ XFunctionAccess xfunctionaccess ) {
+ try {
+ int intRow = ToDoImpl.INT_ROW_HOLIDAYS_START;
+ int intColumn = ToDoImpl.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.add(
+ Integer.valueOf( (int) Math.round(
+ dHolidayStart ) ) );
+ }
+ else {
+ for ( int intHoliday = (int) Math.round(
+ dHolidayStart );
+ intHoliday <= (int) Math.round( dHolidayEnd );
+ intHoliday++ ) {
+ vectorHolidays.add( 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.
+ */
+ private 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 occurred exception.
+ * @see #showMessage(String)
+ */
+ private 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;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/ToDo/ToDo.ods b/odk/examples/java/ToDo/ToDo.ods
new file mode 100644
index 000000000..344a5c2e9
--- /dev/null
+++ b/odk/examples/java/ToDo/ToDo.ods
Binary files differ
diff --git a/odk/examples/java/ToDo/description.xml b/odk/examples/java/ToDo/description.xml
new file mode 100644
index 000000000..6c4e2396b
--- /dev/null
+++ b/odk/examples/java/ToDo/description.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+-->
+<d:description xmlns:d="http://openoffice.org/extensions/description/2006">
+ <d:dependencies>
+ <l:LibreOffice-minimal-version value="4.1" d:name="LibreOffice 4.1"
+ xmlns:l="http://libreoffice.org/extensions/description/2011"/>
+ </d:dependencies>
+</d:description>
diff --git a/odk/examples/java/ToDo/org/openoffice/ToDo.idl b/odk/examples/java/ToDo/org/openoffice/ToDo.idl
new file mode 100644
index 000000000..d632831c4
--- /dev/null
+++ b/odk/examples/java/ToDo/org/openoffice/ToDo.idl
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+#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
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/ToDo/org/openoffice/XToDo.idl b/odk/examples/java/ToDo/org/openoffice/XToDo.idl
new file mode 100644
index 000000000..11a107c08
--- /dev/null
+++ b/odk/examples/java/ToDo/org/openoffice/XToDo.idl
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+#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
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */