summaryrefslogtreecommitdiffstats
path: root/odk/examples/java/EmbedDocument
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
commit940b4d1848e8c70ab7642901a68594e8016caffc (patch)
treeeb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /odk/examples/java/EmbedDocument
parentInitial commit. (diff)
downloadlibreoffice-upstream.tar.xz
libreoffice-upstream.zip
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'odk/examples/java/EmbedDocument')
-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
10 files changed, 2801 insertions, 0 deletions
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: */