summaryrefslogtreecommitdiff
path: root/bean/com/sun/star/comp/beans
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2014-09-16 14:23:21 +0200
committerStephan Bergmann <sbergman@redhat.com>2014-09-16 14:25:01 +0200
commitbe36698f60d459cc88b703a007e3bf4209842492 (patch)
tree3dd5da06a631870335cba2fc113a446cf9e98323 /bean/com/sun/star/comp/beans
parent3ff2e4dc1d0ba922e06f0d5c90c85fee33623784 (diff)
Revert bean part of "java: remove dead methods"
...34bcf9b498bccb5c924f4cec850ff15d88df6f07; bean is a client API, not dead code. Change-Id: Iea17b6306152b9a4f2968bed550a44917803d9ec
Diffstat (limited to 'bean/com/sun/star/comp/beans')
-rw-r--r--bean/com/sun/star/comp/beans/ContainerFactory.java9
-rw-r--r--bean/com/sun/star/comp/beans/Controller.java8
-rw-r--r--bean/com/sun/star/comp/beans/OOoBean.java252
-rw-r--r--bean/com/sun/star/comp/beans/OfficeConnection.java8
4 files changed, 274 insertions, 3 deletions
diff --git a/bean/com/sun/star/comp/beans/ContainerFactory.java b/bean/com/sun/star/comp/beans/ContainerFactory.java
index bd0e48a88a94..d06a082c7db6 100644
--- a/bean/com/sun/star/comp/beans/ContainerFactory.java
+++ b/bean/com/sun/star/comp/beans/ContainerFactory.java
@@ -18,6 +18,8 @@
package com.sun.star.comp.beans;
+import java.awt.Container;
+
/**
* This interface represents an AWT container factory.
*
@@ -27,5 +29,10 @@ package com.sun.star.comp.beans;
public interface ContainerFactory
{
-
+ /**
+ * Creates an AWT container.
+ *
+ * @return An AWT container.
+ */
+ Container createContainer();
}
diff --git a/bean/com/sun/star/comp/beans/Controller.java b/bean/com/sun/star/comp/beans/Controller.java
index 4a68980a8866..9e93c5878b2f 100644
--- a/bean/com/sun/star/comp/beans/Controller.java
+++ b/bean/com/sun/star/comp/beans/Controller.java
@@ -83,7 +83,13 @@ public class Controller
// com.sun.star.frame.XDispatchProvider
-
+ public com.sun.star.frame.XDispatch queryDispatch(
+ /*IN*/ com.sun.star.util.URL aURL,
+ /*IN*/ String aTargetFrameName,
+ /*IN*/ int nSearchFlags )
+ {
+ return xDispatchProvider.queryDispatch( aURL, aTargetFrameName, nSearchFlags );
+ }
public com.sun.star.frame.XDispatch[] queryDispatches(
/*IN*/ com.sun.star.frame.DispatchDescriptor[] aRequests )
diff --git a/bean/com/sun/star/comp/beans/OOoBean.java b/bean/com/sun/star/comp/beans/OOoBean.java
index 2ffe5ee9c0e7..0d1e34ee6ca5 100644
--- a/bean/com/sun/star/comp/beans/OOoBean.java
+++ b/bean/com/sun/star/comp/beans/OOoBean.java
@@ -181,7 +181,25 @@ public class OOoBean
xConnectionListener = this.new EventListener("setOOoConnection");
}
+ // @requirement FUNC.CON.STRT/0.4
+ /** Starts a connection to an OOo instance which is lauched if not running.
+ @throws HasConnectionException
+ if a connection was already established.
+
+ @throws NoConnectionException
+ if the specified connection cannot be established
+ */
+ public void startOOoConnection( String aConnectionURL )
+ throws java.net.MalformedURLException,
+ HasConnectionException,
+ NoConnectionException
+ {
+ // create a new connection from the given connection URL
+ LocalOfficeConnection aConnection = new LocalOfficeConnection();
+ aConnection.setUnoUrl( aConnectionURL );
+ setOOoConnection( aConnection );
+ }
// @requirement FUNC.CON.CHK/0.7
/** Returns true if this OOoBean is connected to an OOo instance,
@@ -313,7 +331,31 @@ public class OOoBean
return xDesktop;
}
+ /** Resets this bean to an empty document.
+
+ If a document is loaded and the content modified,
+ the changes are dismissed. Otherwise nothing happens.
+ This method is intended to be overridden in derived classes.
+ This implementation simply calls clear.
+
+ @param bClearStateToo
+ Not only the document content but also the state of the bean,
+ like visibility of child components is cleared.
+
+ @deprecated There is currently no way to dismiss changes, except for loading
+ of the unchanged initial document. Furthermore it is unclear how derived classes
+ handle this and what exactly their state is (e.g. what members make up their state).
+ Calling this method on a derived class requires knowledge about their implementation.
+ Therefore a deriving class should declare their own clearDocument if needed. Clients
+ should call the clearDocument of the deriving class or {@link #clear} which discards
+ the currently displayed document.
+ */
+ public synchronized void clearDocument( boolean bClearStateToo )
+ {
+ // TBD
+ clear();
+ }
/** Resets the OOoBean to an empty status.
@@ -654,9 +696,219 @@ public class OOoBean
}
}
+ /** Loads a document from a Java stream.
+
+ See loadFromURL() for further information.
+ */
+ public void loadFromStream(
+ final java.io.InputStream iInStream,
+ final com.sun.star.beans.PropertyValue aArguments[] )
+ throws
+ // @requirement FUNC.CON.LOST/0.2
+ NoConnectionException,
+ java.io.IOException,
+ com.sun.star.lang.IllegalArgumentException,
+ com.sun.star.util.CloseVetoException
+ {
+ // wrap Java stream into UNO stream
+
+ // copy stream....
+ int s = 4096;
+ int r=0 ,n = 0;
+ byte[] buffer = new byte[s];
+ byte[] newBuffer = null;
+ while ((r = iInStream.read(buffer, n, buffer.length-n))>0) {
+ n += r;
+ if (iInStream.available() > buffer.length - n) {
+ newBuffer = new byte[buffer.length*2];
+ System.arraycopy(buffer, 0, newBuffer, 0, n);
+ buffer = newBuffer;
+ }
+ }
+ if (buffer.length != n) {
+ newBuffer = new byte[n];
+ System.arraycopy(buffer, 0, newBuffer, 0, n);
+ buffer = newBuffer;
+ }
+ com.sun.star.io.XInputStream xStream =
+ new com.sun.star.lib.uno.adapter.ByteArrayToXInputStreamAdapter(buffer);
+
+ // add stream to arguments
+ com.sun.star.beans.PropertyValue[] aExtendedArguments =
+ addArgument( aArguments, new com.sun.star.beans.PropertyValue(
+ "InputStream", -1, xStream, com.sun.star.beans.PropertyState.DIRECT_VALUE ) );
+
+ // call normal load method
+ loadFromURL( "private:stream", aExtendedArguments );
+ }
+
+ /** Loads a document from a byte array.
+ See loadFromURL() for further information.
+ */
+ public void loadFromByteArray(
+ final byte aInBuffer[],
+ final com.sun.star.beans.PropertyValue aArguments[] )
+ throws
+ // @requirement FUNC.CON.LOST/0.2
+ NoConnectionException,
+ java.io.IOException,
+ com.sun.star.lang.IllegalArgumentException,
+ com.sun.star.util.CloseVetoException
+ {
+ // wrap byte arrray into UNO stream
+ com.sun.star.io.XInputStream xStream =
+ new com.sun.star.lib.uno.adapter.ByteArrayToXInputStreamAdapter(
+ aInBuffer );
+
+ // add stream to arguments
+ com.sun.star.beans.PropertyValue[] aExtendedArguments =
+ addArgument( aArguments, new com.sun.star.beans.PropertyValue(
+ "InputStream", -1, xStream, com.sun.star.beans.PropertyState.DIRECT_VALUE ) );
+
+ // call normal load method
+ loadFromURL( "private:stream", aExtendedArguments );
+ }
+ /** Stores a document to the given URL.
+ <p>
+ Due due a bug (50651) calling this method may cause the office to crash,
+ when at the same time the office writes a backup of the document. This bug
+ also affects {@link #storeToByteArray storeToByteArray} and
+ {@link #storeToStream storeToStream}. The workaround
+ is to start the office with the option --norestore, which disables the automatic
+ backup and recovery mechanism. OOoBean offers currently no supported way of providing
+ startup options for OOo. But it is possible to set a Java property when starting
+ Java, which is examined by OOoBean:
+ <pre>
+ java -Dcom.sun.star.officebean.Options=--norestore ...
+ </pre>
+ It is planned to offer a way of specifying startup options in a future version.
+ The property can be used until then. When using this property only one option
+ can be provided.
+
+ @throws IllegalArgumentException
+ if either of the arguments is out of the specified range.
+ @throws java.io.IOException
+ if an IO error occurs reading the resource specified by the URL.
+
+ @throws com.sun.star.lang.NoConnectionException
+ if no connection is established.
+
+ @throws NoDocumentException
+ if no document is loaded
+ */
+ private void storeToURL(
+ final String aURL,
+ final com.sun.star.beans.PropertyValue aArguments[] )
+ throws
+ // @requirement FUNC.CON.LOST/0.2
+ NoConnectionException,
+ java.io.IOException,
+ com.sun.star.lang.IllegalArgumentException,
+ NoDocumentException
+ {
+ // no document available?
+ if ( aDocument == null )
+ throw new NoDocumentException();
+
+ try
+ {
+ // start runtime timeout
+ CallWatchThread aCallWatchThread =
+ new CallWatchThread( nOOoCallTimeOut, "storeToURL" );
+
+ // store the document
+ try { aDocument.storeToURL( aURL, aArguments ); }
+ catch ( com.sun.star.io.IOException aExc )
+ { throw new java.io.IOException(); }
+
+ // end runtime timeout
+ aCallWatchThread.cancel();
+ }
+ catch ( java.lang.InterruptedException aExc )
+ { throw new NoConnectionException(); }
+ }
+
+ /** Stores a document to a stream.
+
+ See {@link #storeToURL storeToURL} for further information.
+ @see #storeToURL storeToURL
+ */
+ public java.io.OutputStream storeToStream(
+ java.io.OutputStream aOutStream,
+ final com.sun.star.beans.PropertyValue aArguments[] )
+ throws
+ // @requirement FUNC.CON.LOST/0.2
+ NoConnectionException,
+ NoDocumentException,
+ java.io.IOException,
+ com.sun.star.lang.IllegalArgumentException
+
+ {
+ // wrap Java stream into UNO stream
+ com.sun.star.lib.uno.adapter.OutputStreamToXOutputStreamAdapter aStream =
+ new com.sun.star.lib.uno.adapter.OutputStreamToXOutputStreamAdapter(
+ aOutStream );
+
+ // add stream to arguments
+ com.sun.star.beans.PropertyValue[] aExtendedArguments =
+ addArgument( aArguments, new com.sun.star.beans.PropertyValue(
+ "OutputStream", -1, aStream, com.sun.star.beans.PropertyState.DIRECT_VALUE ) );
+
+ // call normal store method
+ storeToURL( "private:stream", aExtendedArguments );
+
+ // get byte array from document stream
+ try { aStream.closeOutput(); }
+ catch ( com.sun.star.io.NotConnectedException aExc )
+ { /* TDB */ }
+ catch ( com.sun.star.io.BufferSizeExceededException aExc )
+ { /* TDB */ }
+ catch ( com.sun.star.io.IOException aExc )
+ { throw new java.io.IOException(); }
+ return aOutStream;
+ }
+
+ /** Stores a document to a byte array.
+
+ See {@link #storeToURL storeToURL} for further information.
+ @see #storeToURL storeToURL
+ */
+ public byte[] storeToByteArray(
+ byte aOutBuffer[],
+ final com.sun.star.beans.PropertyValue aArguments[] )
+ throws
+ // @requirement FUNC.CON.LOST/0.2
+ NoConnectionException,
+ NoDocumentException,
+ java.io.IOException,
+ com.sun.star.lang.IllegalArgumentException
+ {
+ // wrap byte arrray into UNO stream
+ com.sun.star.lib.uno.adapter.XOutputStreamToByteArrayAdapter aStream =
+ new com.sun.star.lib.uno.adapter.XOutputStreamToByteArrayAdapter(
+ aOutBuffer );
+
+ // add stream to arguments
+ com.sun.star.beans.PropertyValue[] aExtendedArguments =
+ addArgument( aArguments, new com.sun.star.beans.PropertyValue(
+ "OutputStream", -1, aStream, com.sun.star.beans.PropertyState.DIRECT_VALUE ) );
+
+ // call normal store method
+ storeToURL( "private:stream", aExtendedArguments );
+
+ // get byte array from document stream
+ try { aStream.closeOutput(); }
+ catch ( com.sun.star.io.NotConnectedException aExc )
+ { /* TDB */ }
+ catch ( com.sun.star.io.BufferSizeExceededException aExc )
+ { /* TDB */ }
+ catch ( com.sun.star.io.IOException aExc )
+ { throw new java.io.IOException(); }
+ return aStream.getBuffer();
+ }
// @requirement FUNC.BEAN.PROG/0.5
// @requirement API.SIM.SEAP/0.2
diff --git a/bean/com/sun/star/comp/beans/OfficeConnection.java b/bean/com/sun/star/comp/beans/OfficeConnection.java
index ec239d480c56..2786810654d8 100644
--- a/bean/com/sun/star/comp/beans/OfficeConnection.java
+++ b/bean/com/sun/star/comp/beans/OfficeConnection.java
@@ -40,7 +40,13 @@ public interface OfficeConnection
void setUnoUrl(String url)
throws java.net.MalformedURLException;
-
+ /**
+ * Sets an AWT container catory.
+ *
+ * @param containerFactory This is a application provided AWT container
+ * factory.
+ */
+ void setContainerFactory(ContainerFactory containerFactory);
/**
* Retrieves the UNO component context.