summaryrefslogtreecommitdiff
path: root/odk/examples/DevelopersGuide/UCB
diff options
context:
space:
mode:
Diffstat (limited to 'odk/examples/DevelopersGuide/UCB')
-rw-r--r--odk/examples/DevelopersGuide/UCB/ChildrenRetriever.java348
-rw-r--r--odk/examples/DevelopersGuide/UCB/DataStreamComposer.java258
-rw-r--r--odk/examples/DevelopersGuide/UCB/DataStreamRetriever.java233
-rw-r--r--odk/examples/DevelopersGuide/UCB/Helper.java250
-rw-r--r--odk/examples/DevelopersGuide/UCB/Makefile156
-rw-r--r--odk/examples/DevelopersGuide/UCB/MyActiveDataSink.java73
-rw-r--r--odk/examples/DevelopersGuide/UCB/MyInputStream.java190
-rw-r--r--odk/examples/DevelopersGuide/UCB/PropertiesComposer.java299
-rw-r--r--odk/examples/DevelopersGuide/UCB/PropertiesRetriever.java254
-rw-r--r--odk/examples/DevelopersGuide/UCB/ResourceCreator.java313
-rw-r--r--odk/examples/DevelopersGuide/UCB/ResourceManager.java289
-rw-r--r--odk/examples/DevelopersGuide/UCB/ResourceRemover.java180
-rw-r--r--odk/examples/DevelopersGuide/UCB/data/data.txt1
-rw-r--r--odk/examples/DevelopersGuide/UCB/makefile.mk75
14 files changed, 2919 insertions, 0 deletions
diff --git a/odk/examples/DevelopersGuide/UCB/ChildrenRetriever.java b/odk/examples/DevelopersGuide/UCB/ChildrenRetriever.java
new file mode 100644
index 000000000000..daa3d821eebf
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/ChildrenRetriever.java
@@ -0,0 +1,348 @@
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.ucb.OpenCommandArgument2;
+import com.sun.star.ucb.OpenMode;
+import com.sun.star.ucb.XContent;
+import com.sun.star.ucb.XContentAccess;
+import com.sun.star.ucb.XDynamicResultSet;
+import com.sun.star.beans.Property;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.sdbc.XRow;
+import com.sun.star.sdbc.XResultSet;
+
+import java.util.Vector;
+import java.util.Enumeration;
+import java.util.StringTokenizer;
+
+/**
+ * Retrieve the Children of a UCB Folder Content
+ */
+public class ChildrenRetriever {
+
+ /**
+ * Member properties
+ */
+ private Helper m_helper;
+ private XContent m_content;
+ private String m_contenturl = "";
+ private Vector m_propnames = new Vector();
+
+ /**
+ * Constructor. Create a new connection with the specific args to a running office
+ *
+ *@param String[] This construtor requires the arguments:
+ * -url=... (optional)
+ * -propNames=... (optional)
+ * See Help (method printCmdLineUsage()).
+ * Without the arguments a new connection to a
+ * running office cannot created.
+ *@exception java.lang.Exception
+ */
+ public ChildrenRetriever( String args[] ) throws java.lang.Exception {
+
+ // Parse arguments
+ parseArguments( args );
+
+ // Init
+ m_helper = new Helper( getContentURL() );
+
+ // Create UCB content
+ m_content = m_helper.createUCBContent();
+ }
+
+ /**
+ * Open a folder content, get properties values.
+ * This method requires the main and the optional arguments to be set in order to work.
+ * See Constructor.
+ *
+ *@return Vector Returns children properties values if values successfully retrieved,
+ * null otherwise
+ *@exception com.sun.star.ucb.CommandAbortedException
+ *@exception com.sun.star.uno.Exception
+ */
+ public Vector getChildren()
+ throws com.sun.star.ucb.CommandAbortedException, com.sun.star.uno.Exception {
+ Vector properties = getProperties();
+ return getChildren ( properties );
+ }
+
+ /**
+ * Open a folder content, get properties values for the properties.
+ *
+ *@param Vector Properties
+ *@return Vector Returns children properties values if values successfully retrieved,
+ * null otherwise
+ *@exception com.sun.star.ucb.CommandAbortedException
+ *@exception com.sun.star.uno.Exception
+ */
+ public Vector getChildren( Vector properties )
+ throws com.sun.star.ucb.CommandAbortedException, com.sun.star.uno.Exception {
+
+ Vector result = null;
+ if ( m_content != null ) {
+ int size = 0;
+ if ( properties != null && !properties.isEmpty()) {
+ size = properties.size();
+ }
+ // Fill info for the properties wanted.
+ Property[] props = new Property[ size ];
+ for ( int index = 0 ; index < size; index++ ) {
+
+ // Define property sequence.
+ Property prop = new Property();
+ prop.Name = ( String )properties.get( index );
+ prop.Handle = -1; // n/a
+ props[ index ] = prop;
+ }
+
+ // Fill argument structure...
+ OpenCommandArgument2 arg = new OpenCommandArgument2();
+ arg.Mode = OpenMode.ALL; // FOLDER, DOCUMENTS -> simple filter
+ arg.Priority = 32768; // Final static for 32768
+ arg.Properties = props;
+
+ XDynamicResultSet set;
+
+ // Execute command "open".
+ set = ( XDynamicResultSet )UnoRuntime.queryInterface(
+ XDynamicResultSet.class, m_helper.executeCommand( m_content, "open", arg ));
+ XResultSet resultSet = ( XResultSet )set.getStaticResultSet();
+
+ result = new Vector();
+
+ /////////////////////////////////////////////////////////////////////
+ // Iterate over children, access children and property values...
+ /////////////////////////////////////////////////////////////////////
+
+ // Move to begin.
+ if ( resultSet.first() ) {
+ XContentAccess contentAccess = ( XContentAccess )UnoRuntime.queryInterface(
+ XContentAccess.class, resultSet );
+ XRow row = ( XRow )UnoRuntime.queryInterface( XRow.class, resultSet );
+
+ do {
+ Vector propsValues = new Vector();
+
+ // Obtain URL of child.
+ String id = contentAccess.queryContentIdentifierString();
+ propsValues.add( id );
+ for ( int i = 1; i <= size ; i++) {
+ Object propValue = row.getObject( i, null );
+ if ( !row.wasNull() && !(propValue instanceof com.sun.star.uno.Any )) {
+ propsValues.add( propValue );
+ } else {
+ propsValues.add( "[ Property not found ]" );
+ }
+ }
+ result.add( propsValues );
+ } while ( resultSet.next() ); // next child
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Get connect URL.
+ *
+ *@return String That contains the connect URL
+ */
+ public String getContentURL() {
+ return m_contenturl;
+ }
+
+ /**
+ * Get the properties.
+ *
+ *@return String That contains the properties
+ */
+ public Vector getProperties() {
+ return m_propnames;
+ }
+
+ /**
+ * Parse arguments
+ *
+ *@param String[] Arguments
+ *@exception java.lang.Exception
+ */
+ public void parseArguments( String[] args ) throws java.lang.Exception {
+
+ for ( int i = 0; i < args.length; i++ ) {
+ if ( args[i].startsWith( "-url=" )) {
+ m_contenturl = args[i].substring( 5 );
+ } else if ( args[i].startsWith( "-propNames=" )) {
+ StringTokenizer tok
+ = new StringTokenizer( args[i].substring( 11 ), ";" );
+
+ while ( tok.hasMoreTokens() )
+ m_propnames.add( tok.nextToken() );
+
+ } else if ( args[i].startsWith( "-help" ) ||
+ args[i].startsWith( "-?" )) {
+ printCmdLineUsage();
+ System.exit( 0 );
+ }
+ }
+
+ if ( m_contenturl == null || m_contenturl.equals( "" )) {
+ m_contenturl = "file:///";
+ }
+
+ if ( m_propnames.size() == 0 ) {
+ m_propnames.add( "Title" );
+ m_propnames.add( "IsDocument" );
+ }
+ }
+
+ /**
+ * Print the commands options
+ */
+ public void printCmdLineUsage() {
+ System.out.println(
+ "Usage : ChildrenRetriever -url=... -propNames=..." );
+ System.out.println(
+ "Defaults: -url=file:/// -propNames=Title,IsDocument" );
+ System.out.println(
+ "\nExample : -url=file:///temp/ -propNames=Title;IsFolder;IsDocument" );
+ }
+
+ /**
+ * Print all properties out contained in vector .
+ *
+ *@param Vector
+ */
+ public void printLine( Vector props ) {
+ int limit;
+ while ( !props.isEmpty() ) {
+ String print = "";
+ int size = props.size();
+ for ( int i = 0; i < size; i++ ) {
+ limit = 15;
+ Object obj = props.get( i );
+ if ( obj != null) {
+ String prop = obj.toString();
+ int leng = prop.length();
+ if ( leng < limit ) {
+ for ( int l = leng; l < limit; l++) {
+ prop += " ";
+ }
+ print+= prop + " ";
+ props.set( i, null );
+ } else {
+ String temp1 = prop.substring( 0, limit );
+ String temp2 = prop.substring( limit );
+ print+= temp1 + " ";
+ props.set( i, temp2 );
+ }
+ } else {
+ for ( int l = 0; l < limit; l++) {
+ print += " ";
+ }
+ print+= " ";
+ }
+ }
+ System.out.println( print );
+ boolean isEmpty = true;
+ for ( int i = 0; i < size; i++ ) {
+ Object obj = props.get( i );
+ if( obj != null )
+ isEmpty = false;
+ }
+ if( isEmpty )
+ props.clear();
+ }
+ }
+
+ /**
+ * Create a new connection with the specific args to a running office and
+ * access the children from a folder.
+ *
+ *@param String[] Arguments
+ */
+ public static void main ( String args[] ) {
+
+ System.out.println( "\n" );
+ System.out.println(
+ "-----------------------------------------------------------------" );
+ System.out.println(
+ "ChildrenRetriever - obtains the children of a folder resource." );
+ System.out.println(
+ "-----------------------------------------------------------------" );
+
+ try {
+ ChildrenRetriever access = new ChildrenRetriever( args );
+
+ // Get the properties Title and IsFolder for the children.
+ Vector result = access.getChildren();
+
+ String tempPrint = "\nChildren of resource " + access.getContentURL();
+ int size = tempPrint.length();
+ System.out.println( tempPrint );
+ tempPrint = "";
+ for( int i = 0; i < size; i++ ) {
+ tempPrint += "-";
+ }
+ System.out.println( tempPrint );
+
+ if ( result != null && !result.isEmpty() ) {
+
+ Vector cont = new Vector();
+ cont.add("URL:");
+ Vector props = access.getProperties();
+ size = props.size();
+ for ( int i = 0; i < size; i++ ) {
+ Object obj = props.get( i );
+ String prop = obj.toString();
+ cont.add( prop + ":" );
+ }
+ access.printLine(cont);
+ System.out.println( "\n" );
+ for ( Enumeration e = result.elements(); e.hasMoreElements(); ) {
+ Vector propsV = ( Vector )e.nextElement();
+ access.printLine( propsV );
+ }
+ }
+ } catch ( com.sun.star.ucb.ResultSetException e ) {
+ System.out.println( "Error: " + e );
+ } catch ( com.sun.star.ucb.CommandAbortedException e ) {
+ System.out.println( "Error: " + e );
+ } catch ( com.sun.star.uno.Exception e ) {
+ System.out.println( "Error: " + e );
+ } catch ( java.lang.Exception e ) {
+ System.out.println( "Error: " + e );
+ }
+ System.exit( 0 );
+ }
+}
diff --git a/odk/examples/DevelopersGuide/UCB/DataStreamComposer.java b/odk/examples/DevelopersGuide/UCB/DataStreamComposer.java
new file mode 100644
index 000000000000..899861a0451f
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/DataStreamComposer.java
@@ -0,0 +1,258 @@
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.ucb.InsertCommandArgument;
+import com.sun.star.ucb.XContent;
+import com.sun.star.io.XInputStream;
+
+/**
+ * Setting (Storing) the Content Data Stream of a UCB Document Content.
+ */
+public class DataStreamComposer {
+
+ /**
+ * Member properties
+ */
+ private Helper m_helper;
+ private XContent m_content;
+ private String m_contenturl = "";
+ private String m_srcURL = "";
+
+
+ /**
+ * Constructor.
+ *
+ *@param String[] This construtor requires the arguments:
+ * -url=... (optional)
+ * -srcURL=... (optional)
+ * -workdir=... (optional)
+ * See Help (method printCmdLineUsage()).
+ * Without the arguments a new connection to a
+ * running office cannot created.
+ *@exception java.lang.Exception
+ */
+ public DataStreamComposer( String args[] ) throws java.lang.Exception {
+
+ // Parse arguments
+ parseArguments( args );
+
+ // Init
+ m_helper = new Helper( getContentURL() );
+
+ // Create UCB content
+ m_content = m_helper.createUCBContent();
+ }
+
+ /**
+ * Write the document data stream of a document content.
+ * This method requires the main and the optional arguments to be set in order to work.
+ * See Constructor.
+ *
+ *@return boolean Result
+ *@exception com.sun.star.ucb.CommandAbortedException
+ *@exception com.sun.star.uno.Exception
+ *@exception java.lang.Exception
+ */
+ public boolean setDataStream()
+ throws com.sun.star.ucb.CommandAbortedException,
+ com.sun.star.uno.Exception,
+ java.lang.Exception {
+
+ String sourceURL = getSourceURL();
+ return ( setDataStream( sourceURL ));
+ }
+
+ /**
+ * Write the document data stream of a document content.
+ *
+ *@param String Source URL
+ *@return boolean Returns true if data stream successfully seted, false otherwise
+ *@exception com.sun.star.ucb.CommandAbortedException
+ *@exception com.sun.star.uno.Exception
+ *@exception java.lang.Exception
+ */
+ public boolean setDataStream( String sourceURL )
+ throws com.sun.star.ucb.CommandAbortedException,
+ com.sun.star.uno.Exception,
+ java.lang.Exception {
+
+ XInputStream stream;
+ if ( sourceURL == null || sourceURL.equals("") ) {
+ stream = new MyInputStream();
+ } else {
+ String[] args = new String[ 1 ];
+ args[ 0 ] = "-url=" + sourceURL;
+ DataStreamRetriever access = new DataStreamRetriever( args );
+ stream = access.getDataStream();
+ }
+ return ( setDataStream( stream ));
+ }
+
+ /**
+ * Write the document data stream of a document content...
+ *
+ *@param XInputStream Stream
+ *@return boolean Returns true if data stream successfully seted, false otherwise
+ *@exception com.sun.star.ucb.CommandAbortedException
+ *@exception com.sun.star.uno.Exception
+ */
+ public boolean setDataStream( XInputStream stream )
+ throws com.sun.star.ucb.CommandAbortedException, com.sun.star.uno.Exception {
+
+ boolean result = false;
+ XInputStream data = stream;
+ if ( data != null && m_content != null ) {
+
+ // Fill argument structure...
+ InsertCommandArgument arg = new InsertCommandArgument();
+ arg.Data = data;
+ arg.ReplaceExisting = true;
+
+ // Execute command "insert".
+ m_helper.executeCommand( m_content, "insert", arg );
+ result = true;
+ }
+ return result;
+ }
+
+ /**
+ * Get source URL.
+ *
+ *@return String That contains the source URL
+ */
+ public String getSourceURL() {
+ return m_srcURL;
+ }
+
+ /**
+ * Get connect URL.
+ *
+ *@return String That contains the connect URL
+ */
+ public String getContentURL() {
+ return m_contenturl;
+ }
+
+ /**
+ * Parse arguments
+ *
+ *@param String[] Arguments
+ *@exception java.lang.Exception
+ */
+ public void parseArguments( String[] args ) throws java.lang.Exception {
+
+ String workdir = "";
+
+ for ( int i = 0; i < args.length; i++ ) {
+ if ( args[i].startsWith( "-url=" )) {
+ m_contenturl = args[i].substring( 5 );
+ } else if ( args[i].startsWith( "-srcURL=" )) {
+ m_srcURL = args[i].substring( 9 );
+ } else if ( args[i].startsWith( "-workdir=" )) {
+ workdir = args[i].substring( 9 );
+ } else if ( args[i].startsWith( "-help" ) ||
+ args[i].startsWith( "-?" )) {
+ printCmdLineUsage();
+ System.exit( 0 );
+ }
+ }
+
+ if ( m_contenturl == null || m_contenturl.equals( "" )) {
+ m_contenturl = Helper.createTargetDataFile( workdir );
+ }
+
+ if ( m_srcURL == null || m_srcURL.equals( "" )) {
+ m_srcURL = Helper.prependCurrentDirAsAbsoluteFileURL( "data/data.txt" );
+ }
+ }
+
+ /**
+ * Print the commands options
+ */
+ public void printCmdLineUsage() {
+ System.out.println(
+ "Usage : DataStreamComposer -url=... -srcURL=... -workdir=..." );
+ System.out.println(
+ "Defaults: -url=<workdir>/resource-<uniquepostfix> -srcURL=<currentdir>/data/data.txt -workdir=<currentdir>" );
+ System.out.println(
+ "\nExample : -url=file:///temp/my.txt -srcURL=file:///temp/src.txt " );
+ }
+
+
+ /**
+ * Create a new connection with the specific args to a running office and
+ * set the Content Data Stream of a UCB Document Content.
+ *
+ *@param String[] Arguments
+ */
+ public static void main ( String args[] ) {
+ System.out.println( "\n" );
+ System.out.println(
+ "-----------------------------------------------------------------" );
+ System.out.println(
+ "DataStreamComposer - sets the data stream of a document resource." );
+ System.out.println(
+ " The data stream is obtained from another (the source) document " );
+ System.out.println(
+ " resource before." );
+ System.out.println(
+ "-----------------------------------------------------------------" );
+ try {
+
+ DataStreamComposer dataStream = new DataStreamComposer( args );
+ String sourceURL = dataStream.getSourceURL();
+ boolean result = dataStream.setDataStream( sourceURL );
+ if ( result ) {
+ System.out.println(
+ "\nSetting data stream succeeded.\n Source URL: " +
+ dataStream.getSourceURL() +
+ "\n Target URL: " +
+ dataStream.getContentURL() );
+ } else {
+ System.out.println(
+ "\nSetting data stream failed. \n Source URL: " +
+ dataStream.getSourceURL() +
+ "\n Target URL: " +
+ dataStream.getContentURL() );
+ }
+ } catch ( com.sun.star.ucb.CommandAbortedException e ) {
+ System.out.println( "Error: " + e );
+ } catch ( com.sun.star.uno.Exception e ) {
+ System.out.println( "Error: " + e );
+ } catch ( java.lang.Exception e ) {
+ System.out.println( "Error: " + e );
+ }
+ System.exit( 0 );
+ }
+}
diff --git a/odk/examples/DevelopersGuide/UCB/DataStreamRetriever.java b/odk/examples/DevelopersGuide/UCB/DataStreamRetriever.java
new file mode 100644
index 000000000000..5bf66124fdd3
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/DataStreamRetriever.java
@@ -0,0 +1,233 @@
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.ucb.OpenCommandArgument2;
+import com.sun.star.ucb.OpenMode;
+import com.sun.star.ucb.XContent;
+import com.sun.star.io.XActiveDataSink;
+import com.sun.star.io.XInputStream;
+
+/**
+ * Accessing (Loading) the Content Data Stream of a UCB Document Content
+ */
+public class DataStreamRetriever {
+
+ /**
+ * Member properties
+ */
+ private Helper m_helper;
+ private XContent m_content;
+ private String m_contenturl = "";
+
+ /**
+ * Constructor.
+ *
+ *@param String[] This construtor requires the arguments:
+ * -url=... (optional)
+ * See Help (method printCmdLineUsage()).
+ * Without the arguments a new connection to a
+ * running office cannot created.
+ *@exception java.lang.Exception
+ */
+ public DataStreamRetriever( String args[] ) throws java.lang.Exception {
+
+ // Parse arguments
+ parseArguments( args );
+
+ // Init
+ m_helper = new Helper( getContentURL() );
+
+ // Create UCB content
+ m_content = m_helper.createUCBContent();
+ }
+
+ /**
+ * Read the document data stream of a document content using a
+ * XActiveDataSink implementation as data sink....
+ *
+ *@return XInputStream Returns input stream if stream successfully retrieved,
+ * null otherwise
+ *@exception com.sun.star.ucb.CommandAbortedException
+ *@exception com.sun.star.uno.Exception
+ */
+ public XInputStream getDataStream()
+ throws com.sun.star.ucb.CommandAbortedException, com.sun.star.uno.Exception {
+
+ XInputStream data = null;
+ if ( m_content != null ) {
+
+ // Fill argument structure...
+ OpenCommandArgument2 arg = new OpenCommandArgument2();
+ arg.Mode = OpenMode.DOCUMENT;
+ arg.Priority = 32768; // Final static for 32768
+
+ // Create data sink implementation object.
+ XActiveDataSink dataSink = new MyActiveDataSink();
+ arg.Sink = dataSink;
+
+ // Execute command "open". The implementation of the command will
+ // supply an XInputStream implementation to the data sink.
+ m_helper.executeCommand( m_content, "open", arg );
+
+ // Get input stream supplied by the open command implementation.
+ data = dataSink.getInputStream();
+ }
+ return data;
+ }
+
+ /**
+ * Get connect URL.
+ *
+ *@return String That contains the connect URL
+ */
+ public String getContentURL() {
+ return m_contenturl;
+ }
+
+ /**
+ * Parse arguments
+ *
+ *@param String[] Arguments
+ *@exception java.lang.Exception
+ */
+ public void parseArguments( String[] args ) throws java.lang.Exception {
+
+ for ( int i = 0; i < args.length; i++ ) {
+ if ( args[i].startsWith( "-url=" )) {
+ m_contenturl = args[i].substring( 5 );
+ } else if ( args[i].startsWith( "-help" ) ||
+ args[i].startsWith( "-?" )) {
+ printCmdLineUsage();
+ System.exit( 0 );
+ }
+ }
+
+ if ( m_contenturl == null || m_contenturl.equals( "" )) {
+ m_contenturl = Helper.prependCurrentDirAsAbsoluteFileURL( "data/data.txt" );
+ }
+ }
+
+ /**
+ * Print the commands options
+ */
+ public void printCmdLineUsage() {
+ System.out.println(
+ "Usage : DataStreamRetriever -url=..." );
+ System.out.println(
+ "Defaults: -url=<currentdir>/data/data.txt" );
+ System.out.println(
+ "\nExample : -url=file:///temp/my.txt" );
+ }
+
+ /**
+ * Print Stream content.
+ *
+ *@param XInputStream
+ *@exception com.sun.star.uno.Exception
+ */
+ public void printStream( XInputStream data )
+ throws com.sun.star.uno.Exception {
+
+ /////////////////////////////////////////////////////////////////////
+ // Read data from input stream...65536
+ /////////////////////////////////////////////////////////////////////
+
+ // Data buffer. Will be allocated by input stream implementation!
+ byte[][] buffer = new byte[ 1 ][ 65536 ];
+ int read = data.readSomeBytes( buffer, 65536 );
+ System.out.println( "Read bytes : " + read );
+ System.out.println( "Read data (only first 64K displayed): ");
+ while ( read > 0 ) {
+ byte[] bytes = new byte[ read ];
+ for( int i = 0; i < read; i++ ) {
+ bytes[ i ] = buffer[ 0 ][ i ];
+ }
+ System.out.println( new String(bytes) );
+
+ // Process data contained in buffer.
+ read = data.readSomeBytes( buffer, 65536 );
+ }
+ }
+
+ /**
+ * Create a new connection with the specific args to a running office and
+ * access (Load) the content data stream of a UCB document content.
+ *
+ *@param String[] Arguments
+ */
+ public static void main ( String args[] ) {
+ System.out.println( "\n" );
+ System.out.println(
+ "-----------------------------------------------------------------------" );
+ System.out.println(
+ "DataStreamRetriever - obtains the data stream from a document resource." );
+ System.out.println(
+ "-----------------------------------------------------------------------" );
+
+ try {
+
+ DataStreamRetriever access = new DataStreamRetriever( args );
+ XInputStream data = access.getDataStream();
+ String url = access.getContentURL();
+ if ( data != null ) {
+ String tempPrint = "\nGetting data stream for resource " + url +
+ " succeeded.";
+ int size = tempPrint.length();
+ System.out.println( tempPrint );
+ tempPrint = "";
+ for( int i = 0; i < size; i++ ) {
+ tempPrint += "-";
+ }
+ System.out.println( tempPrint );
+ access.printStream( data );
+ } else {
+ System.out.println(
+ "Getting data stream for resource " + url + " failed." );
+ }
+ } catch ( com.sun.star.io.NotConnectedException e ) {
+ System.out.println( "Error: " + e );
+ } catch ( com.sun.star.io.BufferSizeExceededException e ) {
+ System.out.println( "Error: " + e );
+ } catch ( com.sun.star.io.IOException e ) {
+ System.out.println( "Error: " + e );
+ } catch ( com.sun.star.ucb.CommandAbortedException e ) {
+ System.out.println( "Error: " + e );
+ } catch ( com.sun.star.uno.Exception e ) {
+ System.out.println( "Error: " + e );
+ } catch ( java.lang.Exception e ) {
+ System.out.println( "Error: " + e );
+ }
+ System.exit( 0 );
+ }
+}
diff --git a/odk/examples/DevelopersGuide/UCB/Helper.java b/odk/examples/DevelopersGuide/UCB/Helper.java
new file mode 100644
index 000000000000..dbba9156f4eb
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/Helper.java
@@ -0,0 +1,250 @@
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import java.util.Vector;
+
+import java.io.File;
+import java.io.FileOutputStream;
+
+import com.sun.star.lang.XMultiComponentFactory;
+
+import com.sun.star.ucb.Command;
+import com.sun.star.ucb.XContent;
+import com.sun.star.ucb.XContentProvider;
+import com.sun.star.ucb.XContentIdentifier;
+import com.sun.star.ucb.XContentIdentifierFactory;
+import com.sun.star.ucb.XCommandProcessor;
+
+import com.sun.star.uno.XInterface;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+
+
+/**
+ * Helper for creating a new connection with the specific args to a running office.
+ */
+public class Helper {
+
+ /**
+ * Member properties
+ */
+ private XInterface m_ucb = null;
+ private String m_contenturl = null;
+ private static XComponentContext m_xContext = null;
+
+ /**
+ * Constructor, create a new instance of the ucb. UNO is bootstrapped and
+ * the remote office service manger is used to create the ucb. If necessary
+ * a new office process is started.
+ *
+ * @exception java.lang.Exception
+ */
+ public Helper(String url) throws java.lang.Exception {
+ m_contenturl = url;
+
+ if (null == m_xContext ) {
+ // get the remote office component context
+ m_xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+ }
+
+ XMultiComponentFactory xMCF = m_xContext.getServiceManager();
+
+ m_ucb = (XInterface)UnoRuntime.queryInterface(XInterface.class,
+ xMCF.createInstanceWithContext(
+ "com.sun.star.ucb.UniversalContentBroker", m_xContext));
+ }
+
+ /**
+ * Returns created identifier object for given URL..
+ *
+ *@return XContent Created identifier object for given URL
+ *@exception java.lang.Exception
+ */
+ public XContent createUCBContent() throws java.lang.Exception {
+ return createUCBContent( getContentURL() );
+ }
+
+ /**
+ * Returned created identifier object for given URL.
+ *
+ *@param String Connect URL. Example : -url=file:///
+ *@return XContent Created identifier object for given URL
+ *@exception java.lang.Exception
+ */
+ public XContent createUCBContent( String connectURL ) throws java.lang.Exception {
+ XContent content = null;
+ if ( connectURL != null && !connectURL.equals( "" )) {
+
+ // Obtain required UCB interfaces...
+ XContentIdentifierFactory idFactory
+ = ( XContentIdentifierFactory )UnoRuntime.queryInterface(
+ XContentIdentifierFactory.class, m_ucb );
+ XContentProvider provider
+ = ( XContentProvider )UnoRuntime.queryInterface(
+ XContentProvider.class, m_ucb );
+
+ // Create identifier object for given URL.
+ XContentIdentifier id = idFactory.createContentIdentifier( connectURL );
+ content = provider.queryContent( id );
+ }
+ return content;
+ }
+
+ /**
+ * Get ucb instance.
+ *
+ *@return XInterface That contains the ucb instance
+ */
+ public XInterface getUCB() {
+ return m_ucb;
+ }
+
+ /**
+ * Get connect URL.
+ *
+ *@return String That contains the connect URL
+ */
+ public String getContentURL() {
+ return m_contenturl;
+ }
+
+ /**
+ * Executes a command.
+ *
+ *param XInterface
+ *param String
+ *param Object
+ *@return Object The result according to the specification of the command.
+ *@exception com.sun.star.ucb.CommandAbortedException
+ *@exception com.sun.star.uno.Exception
+ */
+ Object executeCommand( XInterface ifc, String commandName, Object argument )
+ throws com.sun.star.ucb.CommandAbortedException, com.sun.star.uno.Exception {
+
+ /////////////////////////////////////////////////////////////////////
+ // Obtain command processor interface from given content.
+ /////////////////////////////////////////////////////////////////////
+
+ XCommandProcessor cmdProcessor
+ = (XCommandProcessor)UnoRuntime.queryInterface(
+ XCommandProcessor.class, ifc );
+
+ /////////////////////////////////////////////////////////////////////
+ // Assemble command to execute.
+ /////////////////////////////////////////////////////////////////////
+
+ Command command = new Command();
+ command.Name = commandName;
+ command.Handle = -1; // not available
+ command.Argument = argument;
+
+ // Note: throws CommandAbortedException, Exception
+ return cmdProcessor.execute( command, 0, null );
+ }
+
+ public static String getAbsoluteFileURLFromSystemPath( String systemPath )
+ {
+ try
+ {
+ File file = new File( systemPath );
+ String url = file.toURL().toString();
+ if ( url.charAt( 6 ) != '/' ) { // file:/xxx vs. file:///xxxx
+ StringBuffer buf1 = new StringBuffer( "file:///" );
+ buf1.append( url.substring( 6 ) );
+ url = buf1.toString();
+ }
+ return url;
+ }
+ catch ( java.net.MalformedURLException e )
+ {
+ e.printStackTrace();
+ }
+ return new String();
+ }
+
+ public static String prependCurrentDirAsAbsoluteFileURL( String relativeURL )
+ {
+ // get url of current dir.
+ String url = getAbsoluteFileURLFromSystemPath( "" );
+ StringBuffer buf = new StringBuffer( url );
+ if ( !url.endsWith( File.separator ) )
+ buf.append( File.separator );
+ buf.append( relativeURL );
+ return buf.toString();
+ }
+
+ public static String createTargetDataFile( String workDir )
+ {
+ try
+ {
+ StringBuffer buf = new StringBuffer();
+ if ( workDir != null && workDir.length() > 0 ) {
+ buf.append( workDir );
+ buf.append( File.separator );
+ }
+ buf.append( "resource-" );
+ buf.append( System.currentTimeMillis() );
+ File file = new File( buf.toString() );
+ String url = file.toURL().toString();
+ if ( url.charAt( 6 ) != '/' ) { // file:/xxx vs. file:///xxxx
+ StringBuffer buf1 = new StringBuffer( "file:///" );
+ buf1.append( url.substring( 6 ) );
+ url = buf1.toString();
+ }
+
+ try
+ {
+ file.createNewFile();
+ String content = new String(
+ "This is the content of a sample data file." );
+ FileOutputStream stream = new FileOutputStream( file );
+ stream.write( content.getBytes() );
+ stream.close();
+ }
+ catch ( java.io.IOException e )
+ {
+ e.printStackTrace();
+ }
+
+ return url;
+ }
+ catch ( java.net.MalformedURLException e )
+ {
+ e.printStackTrace();
+ }
+
+ return new String();
+ }
+}
diff --git a/odk/examples/DevelopersGuide/UCB/Makefile b/odk/examples/DevelopersGuide/UCB/Makefile
new file mode 100644
index 000000000000..a6b172bfa602
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/Makefile
@@ -0,0 +1,156 @@
+#*************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# the BSD license.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#**************************************************************************
+# Builds the UCB examples of the Developers Guide.
+
+PRJ=../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+EXAMPLE_NAME=UCBExamples
+OUT_APP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME)
+OUT_APP_MISC = $(OUT_MISC)/$(EXAMPLE_NAME)
+
+APP1_NAME=ChildrenRetriever
+APP1_JAR=$(OUT_APP_CLASS)/$(APP1_NAME).jar
+APP2_NAME=DataStreamComposer
+APP2_JAR=$(OUT_APP_CLASS)/$(APP2_NAME).jar
+APP3_NAME=DataStreamRetriever
+APP3_JAR=$(OUT_APP_CLASS)/$(APP3_NAME).jar
+APP4_NAME=PropertiesComposer
+APP4_JAR=$(OUT_APP_CLASS)/$(APP4_NAME).jar
+APP5_NAME=PropertiesRetriever
+APP5_JAR=$(OUT_APP_CLASS)/$(APP5_NAME).jar
+APP6_NAME=ResourceCreator
+APP6_JAR=$(OUT_APP_CLASS)/$(APP6_NAME).jar
+APP7_NAME=ResourceManager
+APP7_JAR=$(OUT_APP_CLASS)/$(APP7_NAME).jar
+APP8_NAME=ResourceRemover
+APP8_JAR=$(OUT_APP_CLASS)/$(APP8_NAME).jar
+
+APP_JAVAFILES = \
+ Helper.java \
+ MyActiveDataSink.java \
+ MyInputStream.java
+
+APP_CLASSFILES = $(patsubst %.java,$(OUT_APP_CLASS)/%.class,$(APP_JAVAFILES))
+APP_CLASSNAMES = $(patsubst %.java,%.class,$(APP_JAVAFILES))
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(OUT_APP_CLASS))
+
+OUT_APP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME)
+
+# Targets
+.PHONY: ALL
+ALL : \
+ UCBExamples
+
+include $(SETTINGS)/stdtarget.mk
+
+$(APP_CLASSFILES) : $(APP_JAVAFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_APP_CLASS) $(APP_JAVAFILES)
+
+$(OUT_APP_CLASS)/%.class : %.java $(APP_CLASSFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_APP_CLASS) $<
+
+$(OUT_APP_CLASS)/$(APP2_NAME).class : $(APP2_NAME).java $(OUT_APP_CLASS)/DataStreamRetriever.class $(APP_CLASSFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_APP_CLASS) $<
+
+$(OUT_APP_CLASS)/$(APP6_NAME).class : $(APP6_NAME).java $(OUT_APP_CLASS)/DataStreamRetriever.class $(APP_CLASSFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_APP_CLASS) $<
+
+$(OUT_APP_CLASS)/%.mf :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo Main-Class: com.sun.star.lib.loader.Loader> $@
+ $(ECHOLINE)>> $@
+ @echo Name: com/sun/star/lib/loader/Loader.class>> $@
+ @echo Application-Class: $*>> $@
+
+$(OUT_APP_CLASS)/%.jar : $(OUT_APP_CLASS)/%.mf $(OUT_APP_CLASS)/%.class $(APP_CLASSFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ +cd $(subst /,$(PS),$(OUT_APP_CLASS)) && $(SDK_JAR) cvfm $(@F) $*.mf $*.class $(APP_CLASSNAMES)
+ +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
+
+$(APP2_JAR) : $(OUT_APP_CLASS)/$(APP2_NAME).mf $(OUT_APP_CLASS)/$(APP2_NAME).class $(OUT_APP_CLASS)/DataStreamRetriever.class $(APP_CLASSFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ +cd $(subst /,$(PS),$(OUT_APP_CLASS)) && $(SDK_JAR) cvfm $(@F) $(basename $(@F)).mf $(basename $(@F)).class DataStreamRetriever.class $(APP_CLASSNAMES)
+ +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
+
+$(APP6_JAR) : $(OUT_APP_CLASS)/$(APP6_NAME).mf $(OUT_APP_CLASS)/$(APP6_NAME).class $(OUT_APP_CLASS)/DataStreamRetriever.class $(APP_CLASSFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ +cd $(subst /,$(PS),$(OUT_APP_CLASS)) && $(SDK_JAR) cvfm $(@F) $(basename $(@F)).mf $(basename $(@F)).class DataStreamRetriever.class $(APP_CLASSNAMES)
+ +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
+
+
+$(APP1_JAR) : $(OUT_APP_CLASS)/$(APP1_NAME).mf $(OUT_APP_CLASS)/$(APP1_NAME).class
+$(APP2_JAR) : $(OUT_APP_CLASS)/$(APP2_NAME).mf $(OUT_APP_CLASS)/$(APP2_NAME).class
+$(APP3_JAR) : $(OUT_APP_CLASS)/$(APP3_NAME).mf $(OUT_APP_CLASS)/$(APP3_NAME).class
+$(APP4_JAR) : $(OUT_APP_CLASS)/$(APP4_NAME).mf $(OUT_APP_CLASS)/$(APP4_NAME).class
+$(APP5_JAR) : $(OUT_APP_CLASS)/$(APP5_NAME).mf $(OUT_APP_CLASS)/$(APP5_NAME).class
+$(APP6_JAR) : $(OUT_APP_CLASS)/$(APP6_NAME).mf $(OUT_APP_CLASS)/$(APP6_NAME).class
+$(APP7_JAR) : $(OUT_APP_CLASS)/$(APP7_NAME).mf $(OUT_APP_CLASS)/$(APP7_NAME).class
+$(APP8_JAR) : $(OUT_APP_CLASS)/$(APP8_NAME).mf $(OUT_APP_CLASS)/$(APP8_NAME).class
+
+UCBExamples : $(APP1_JAR) $(APP2_JAR) $(APP3_JAR) $(APP4_JAR) $(APP5_JAR) $(APP6_JAR) $(APP7_JAR) $(APP8_JAR)
+ @echo --------------------------------------------------------------------------------
+ @echo Please use one of the following commands to execute the examples!
+ @echo -
+ @echo $(MAKE) $(APP1_NAME).run
+ @echo $(MAKE) $(APP2_NAME).run
+ @echo $(MAKE) $(APP3_NAME).run
+ @echo $(MAKE) $(APP4_NAME).run
+ @echo $(MAKE) $(APP5_NAME).run
+ @echo $(MAKE) $(APP6_NAME).run
+ @echo $(MAKE) $(APP7_NAME).run
+ @echo $(MAKE) $(APP8_NAME).run
+ @echo --------------------------------------------------------------------------------
+
+%.run: $(OUT_APP_CLASS)/%.jar
+ -$(MKDIR) $(subst /,$(PS),$(OUT_APP_MISC))
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $< -workdir=$(OUT_APP_MISC)
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_CLASS))
diff --git a/odk/examples/DevelopersGuide/UCB/MyActiveDataSink.java b/odk/examples/DevelopersGuide/UCB/MyActiveDataSink.java
new file mode 100644
index 000000000000..3eb0dc8fd7d0
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/MyActiveDataSink.java
@@ -0,0 +1,73 @@
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.io.XActiveDataSink;
+import com.sun.star.io.XInputStream;
+
+/**
+ * XActiveDataSink interface implementation. Makes it possible to read
+ * the corresponding object from an input stream.
+ */
+public class MyActiveDataSink implements XActiveDataSink {
+
+ /**
+ * Member properties
+ */
+ XInputStream m_aStream = null;
+
+ /**
+ * Constructor
+ */
+ public MyActiveDataSink() {
+ super();
+ }
+
+ /**
+ * Plugs the input stream.
+ *
+ *@param XInputStream
+ */
+ public void setInputStream( XInputStream aStream ) {
+ m_aStream = aStream;
+ }
+
+ /**
+ * Get the plugged stream.
+ *
+ *@return XInputStream The plugged stream
+ */
+ public XInputStream getInputStream() {
+ return m_aStream;
+ }
+}
diff --git a/odk/examples/DevelopersGuide/UCB/MyInputStream.java b/odk/examples/DevelopersGuide/UCB/MyInputStream.java
new file mode 100644
index 000000000000..187ff97e861b
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/MyInputStream.java
@@ -0,0 +1,190 @@
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+
+// imports
+import com.sun.star.io.BufferSizeExceededException;
+import com.sun.star.io.NotConnectedException;
+import com.sun.star.io.XInputStream;
+import com.sun.star.io.XSeekable;
+
+/**
+ * XInputStream interface implementation.
+ */
+public class MyInputStream implements XSeekable, XInputStream {
+
+ /**
+ * Member properties
+ */
+ private int offset = 0;
+ private int read = offset;
+ private byte[] bigbuffer;
+
+ /**
+ * Constructor
+ */
+ public MyInputStream() {
+ }
+
+ // XSeekable. Makes it possible to seek to a certain position within a stream.
+
+ /**
+ * Returns the length of the stream.
+ *
+ *@return long The length of the storage medium on which the stream works.
+ */
+ public synchronized long getLength()
+ throws com.sun.star.io.IOException,com.sun.star.uno.RuntimeException {
+ if ( bigbuffer != null ) {
+ return bigbuffer.length - offset;
+ } else {
+ return 0;
+ }
+ }
+
+ /**
+ * Returns the current offset of the stream.
+ *
+ *@return long The current offset in this stream.
+ */
+ public synchronized long getPosition()
+ throws com.sun.star.io.IOException,com.sun.star.uno.RuntimeException {
+ return read - offset ;
+ }
+
+ /**
+ * Changes the seek pointer to a new location relative to the beginning of the stream.
+ *
+ *@param long
+ */
+ public synchronized void seek(long p0)
+ throws IllegalArgumentException, com.sun.star.io.IOException,
+ com.sun.star.uno.RuntimeException {
+ if( bigbuffer != null ) {
+ p0 +=offset;
+ read = ( int ) p0;
+ if( read < offset || read > bigbuffer.length )
+ throw new IllegalArgumentException();
+ }
+ }
+
+ // XInputStream. This is the basic interface to read data from a stream.
+
+ /**
+ * States how many bytes can be read or skipped without blocking.
+ *
+ *@return int If not available, then returned 0
+ */
+ public synchronized int available()
+ throws NotConnectedException, com.sun.star.io.IOException,
+ com.sun.star.uno.RuntimeException {
+ if( bigbuffer != null )
+ return ( bigbuffer.length - read );
+ else
+ return 0;
+ }
+
+ /**
+ * Closes the stream. .
+ */
+ public void closeInput()
+ throws NotConnectedException,com.sun.star.io.IOException,
+ com.sun.star.uno.RuntimeException {
+ read = -1;
+ }
+
+ /**
+ * Reads the specified number of bytes in the given sequence.
+ *
+ *@param byte[][]
+ *@param int
+ *@return int
+ */
+ public synchronized int readBytes(byte[][] p0, int p1)
+ throws NotConnectedException, BufferSizeExceededException,
+ com.sun.star.io.IOException, com.sun.star.uno.RuntimeException {
+ if( bigbuffer != null ) {
+ if( read == -1 )
+ return 0;
+ int i = 0;
+ int available;
+ if ( p1 > bigbuffer.length - read )
+ available = bigbuffer.length - read;
+ else
+ available = p1;
+
+ p0[0] = new byte[p1];
+ while( available != 0 ) {
+ p0[0][i++] = bigbuffer[read++];
+ --available;
+ }
+ return i;
+ } else {
+ p0[0] = new byte[0];
+ return 0;
+ }
+ }
+
+ /**
+ * Reads the available number of bytes at maximum nMaxBytesToRead .
+ * This method blocks the thread until at least one byte is available.
+ *
+ *@param byte[][]
+ *@param int
+ *@return int
+ */
+ public synchronized int readSomeBytes(byte[][] p0, int p1)
+ throws NotConnectedException,
+ BufferSizeExceededException,
+ com.sun.star.io.IOException,
+ com.sun.star.uno.RuntimeException {
+ return readBytes( p0,p1 );
+ }
+
+ /**
+ * Skips the next nBytesToSkip bytes (must be positive).
+ * It is up to the implementation whether this method is blocking the thread or not.
+ *
+ *@param int
+ */
+ public synchronized void skipBytes(int p0)
+ throws NotConnectedException, BufferSizeExceededException,
+ com.sun.star.io.IOException, com.sun.star.uno.RuntimeException {
+ read += p0;
+ if( read > bigbuffer.length )
+ read = bigbuffer.length;
+
+ if( read < offset )
+ read = offset;
+ }
+}
diff --git a/odk/examples/DevelopersGuide/UCB/PropertiesComposer.java b/odk/examples/DevelopersGuide/UCB/PropertiesComposer.java
new file mode 100644
index 000000000000..3807447a0dfa
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/PropertiesComposer.java
@@ -0,0 +1,299 @@
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import java.util.Vector;
+import java.util.StringTokenizer;
+
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.ucb.XContent;
+import com.sun.star.uno.UnoRuntime;
+
+/**
+ * Setting Property Values of a UCB Content
+ */
+public class PropertiesComposer {
+
+ /**
+ * Member properties
+ */
+ private Helper m_helper;
+ private XContent m_content;
+ private String m_contenturl = "";
+ private Vector m_propNames = new Vector();
+ private Vector m_propValues = new Vector();
+
+ /**
+ * Constructor.
+ *
+ *@param String[] This construtor requires the arguments:
+ * -url=... (optional)
+ * -propNames=... (optional)
+ * -propValues=... (optional)
+ * -workdir=... (optional)
+ * See Help (method printCmdLineUsage()).
+ * Without the arguments a new connection to a
+ * running office cannot created.
+ *@exception java.lang.Exception
+ */
+ public PropertiesComposer( String args[] ) throws java.lang.Exception {
+
+ // Parse arguments
+ parseArguments( args );
+
+ // Init
+ m_helper = new Helper( getContentURL() );
+
+ // Create UCB content
+ m_content = m_helper.createUCBContent();
+ }
+
+ /**
+ * Set values of the properties.
+ * This method requires the main and the optional arguments to be set in order to work.
+ * See Constructor.
+ *
+ *@return Object[] Returns null or instance object of com.sun.star.uno.Any
+ * if values successfully seted, properties otherwise
+ *@exception com.sun.star.ucb.CommandAbortedException
+ *@exception com.sun.star.uno.Exception
+ */
+ public Object[] setProperties()
+ throws com.sun.star.ucb.CommandAbortedException, com.sun.star.uno.Exception {
+ Vector properties = getProperties();
+ Vector propertyValues = getPropertyValues();
+ return setProperties( properties, propertyValues );
+ }
+
+ /**
+ * Set values of the properties.
+ *
+ *@param Vector Properties
+ *@param Vector Properties value
+ *@return Object[] Returns null or instance object of com.sun.star.uno.Any
+ * if values successfully seted, properties otherwise
+ *@exception com.sun.star.ucb.CommandAbortedException
+ *@exception com.sun.star.uno.Exception
+ */
+ public Object[] setProperties( Vector properties, Vector propertiesValues )
+ throws com.sun.star.ucb.CommandAbortedException, com.sun.star.uno.Exception {
+
+ Object[] result = null;
+ if ( m_content != null && !properties.isEmpty() &&
+ !propertiesValues.isEmpty() &&
+ properties.size() == propertiesValues.size() ) {
+
+ /*
+ **** This code is for unregistered properties. ****
+
+ XPropertyContainer xPropContainer
+ = (XPropertyContainer)UnoRuntime.queryInterface(
+ XPropertyContainer.class, m_content );
+
+ XPropertySetInfo xPropSetInfo = ( XPropertySetInfo )UnoRuntime.queryInterface(
+ XPropertySetInfo.class,
+ m_helper.executeCommand( m_content, "getPropertySetInfo", null ));
+ */
+
+ int size = properties.size();
+ PropertyValue[] props = new PropertyValue[ size ];
+ for ( int index = 0 ; index < size; index++ ) {
+ String propName = ( String )properties.get( index );
+ Object propValue = propertiesValues.get( index );
+
+ /*
+ **** This code is for unregistered properties. ****
+
+ if ( !xPropSetInfo.hasPropertyByName( propName )) {
+ xPropContainer.addProperty(
+ propName, PropertyAttribute.MAYBEVOID, propValue );
+ }
+ */
+
+ // Define property sequence.
+ PropertyValue prop = new PropertyValue();
+ prop.Name = propName;
+ prop.Handle = -1; // n/a
+ prop.Value = propValue;
+ props[ index ] = prop;
+ }
+
+ // Execute command "setPropertiesValues".
+ Object[] obj =
+ ( Object[] )m_helper.executeCommand( m_content, "setPropertyValues", props );
+ if ( obj.length == size )
+ result = obj;
+ }
+ return result;
+ }
+
+ /**
+ * Get properties names.
+ *
+ *@return Vector That contains the properties names
+ */
+ public Vector getProperties() {
+ return m_propNames;
+ }
+
+ /**
+ * Get properties values.
+ *
+ *@return Vector That contains the properties values
+ */
+ public Vector getPropertyValues() {
+ return m_propValues;
+ }
+
+ /**
+ * Get connect URL.
+ *
+ *@return String That contains the connect URL
+ */
+ public String getContentURL() {
+ return m_contenturl;
+ }
+
+ /**
+ * Parse arguments
+ *
+ *@param String[] Arguments
+ *@exception java.lang.Exception
+ */
+ public void parseArguments( String[] args ) throws java.lang.Exception {
+
+ String workdir = "";
+
+ for ( int i = 0; i < args.length; i++ ) {
+ if ( args[i].startsWith( "-url=" )) {
+ m_contenturl = args[i].substring( 5 );
+ } else if ( args[i].startsWith( "-propNames=" )) {
+ StringTokenizer tok
+ = new StringTokenizer( args[i].substring( 11 ), ";" );
+
+ while ( tok.hasMoreTokens() )
+ m_propNames.add( tok.nextToken() );
+
+ } else if ( args[i].startsWith( "-propValues=" )) {
+ StringTokenizer tok
+ = new StringTokenizer( args[i].substring( 12 ), ";" );
+
+ while ( tok.hasMoreTokens() )
+ m_propValues.add( tok.nextToken() );
+ } else if ( args[i].startsWith( "-workdir=" )) {
+ workdir = args[i].substring( 9 );
+ } else if ( args[i].startsWith( "-help" ) ||
+ args[i].startsWith( "-?" )) {
+ printCmdLineUsage();
+ System.exit( 0 );
+ }
+ }
+
+ if ( m_contenturl == null || m_contenturl.equals( "" )) {
+ m_contenturl = Helper.createTargetDataFile( workdir );
+ }
+
+ if ( m_propNames.size() == 0 ) {
+ m_propNames.add( "Title" );
+ }
+
+ if ( m_propValues.size() == 0 ) {
+ m_propValues.add(
+ "changed-" + m_contenturl.substring(
+ m_contenturl.lastIndexOf( "/" ) + 1 ) );
+ }
+ }
+
+ /**
+ * Print the commands options
+ */
+ public void printCmdLineUsage() {
+ System.out.println(
+ "Usage : PropertiesComposer -url=... -propNames=... -propValues=... -workdir=..." );
+ System.out.println(
+ "Defaults: -url=<workdir>/resource-<uniquepostfix> -propNames=Title -propValues=changed-<uniquepostfix> -workdir=<currentdir>" );
+ System.out.println(
+ "\nExample : -propNames=Title;Foo -propValues=MyRenamedFile.txt;bar" );
+ }
+
+ /**
+ * Create a new connection with the specific args to a running office and
+ * set properties of a resource.
+ *
+ *@param String[] Arguments
+ */
+ public static void main ( String args[] ) {
+ System.out.println( "\n" );
+ System.out.println(
+ "--------------------------------------------------------" );
+ System.out.println(
+ "PropertiesComposer - sets property values of a resource." );
+ System.out.println(
+ "--------------------------------------------------------" );
+
+ try {
+
+ PropertiesComposer setProp = new PropertiesComposer( args );
+ Vector properties = setProp.getProperties();
+ Vector propertiesValues = setProp.getPropertyValues();
+ Object[] result = setProp.setProperties( properties, propertiesValues );
+
+ String tempPrint = "\nSetting properties of resource " + setProp.getContentURL();
+ int size = tempPrint.length();
+ System.out.println( tempPrint );
+ tempPrint = "";
+ for( int i = 0; i < size; i++ ) {
+ tempPrint += "-";
+ }
+ System.out.println( tempPrint );
+ if ( result != null ) {
+ for ( int index = 0; index < result.length; index++ ) {
+ Object obj = result[ index ];
+ if( obj == null || obj instanceof com.sun.star.uno.Any )
+ System.out.println(
+ "Setting property " + properties.get( index ) + " succeeded." );
+ else
+ System.out.println(
+ "Setting property " + properties.get( index ) + " failed." );
+ }
+ }
+ } catch ( com.sun.star.ucb.CommandAbortedException e ) {
+ System.out.println( "Error: " + e );
+ } catch ( com.sun.star.uno.Exception e ) {
+ System.out.println( "Error: " + e );
+ } catch ( java.lang.Exception e ) {
+ System.out.println( "Error: " + e );
+ }
+ System.exit( 0 );
+ }
+}
diff --git a/odk/examples/DevelopersGuide/UCB/PropertiesRetriever.java b/odk/examples/DevelopersGuide/UCB/PropertiesRetriever.java
new file mode 100644
index 000000000000..ea7bb3c588de
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/PropertiesRetriever.java
@@ -0,0 +1,254 @@
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import java.util.Vector;
+import java.util.StringTokenizer;
+
+import com.sun.star.beans.Property;
+import com.sun.star.ucb.XContent;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.sdbc.XRow;
+
+
+/**
+ * Obtaining Property Values from a UCB Content
+ */
+public class PropertiesRetriever {
+
+ /**
+ * Member properties
+ */
+ private Helper m_helper;
+ private XContent m_content;
+ private String m_contenturl = "";
+ private Vector m_propNames = new Vector();
+
+ /**
+ * Constructor.
+ *
+ *@param String[] This construtor requires the arguments:
+ * -url=... (optional)
+ * -propNames=... (optional)
+ * See Help (method printCmdLineUsage()).
+ * Without the arguments a new connection to a
+ * running office cannot created.
+ *@exception java.lang.Exception
+ */
+ public PropertiesRetriever( String args[] ) throws java.lang.Exception {
+
+ // Parse arguments
+ parseArguments( args );
+
+ // Init
+ m_helper = new Helper( getContentURL() );
+
+ // Create UCB content
+ m_content = m_helper.createUCBContent();
+ }
+
+ /**
+ * Get values of the properties.
+ * This method requires the main and the optional arguments to be set in order to work.
+ * See Constructor.
+ *
+ *@param Vector Properties
+ *@return Vector Returns Properties values if values successfully retrieved, null otherwise
+ *@exception com.sun.star.ucb.CommandAbortedException
+ *@exception com.sun.star.uno.Exception
+ */
+ public Vector getPropertyValues()
+ throws com.sun.star.ucb.CommandAbortedException, com.sun.star.uno.Exception {
+ Vector properties = getProperties();
+ return getPropertyValues ( properties );
+ }
+
+ /**
+ * Get values of the properties.
+ *
+ *@param Vector Properties
+ *@return Vector Returns Properties values if values successfully retrieved, null otherwise
+ *@exception com.sun.star.ucb.CommandAbortedException
+ *@exception com.sun.star.uno.Exception
+ */
+ public Vector getPropertyValues( Vector properties )
+ throws com.sun.star.ucb.CommandAbortedException, com.sun.star.uno.Exception {
+ Vector m_propValues = null;
+ if ( m_content != null && properties != null && !properties.isEmpty() ) {
+
+ int size = properties.size();
+
+ // Fill info for the properties wanted.
+ Property[] props = new Property[ size ];
+ for ( int index = 0 ; index < size; index++ ) {
+
+ // Define property sequence.
+ Property prop = new Property();
+ prop.Name = ( String )properties.get( index );
+ prop.Handle = -1; // n/a
+ props[ index ] = prop;
+ }
+
+ // Execute command "getPropertyValues".
+ XRow values =
+ ( XRow )UnoRuntime.queryInterface(
+ XRow.class, m_helper.executeCommand( m_content,"getPropertyValues", props ));
+
+ m_propValues = new Vector();
+
+ /*
+ Extract values from row object. Note that the
+ first column is 1, not 0.
+ Title: Obtain value of column 1 as string.*/
+ for ( int index = 1 ; index <= size; index++ ) {
+ Object propertyValue = values.getObject( index, null );
+ if ( !values.wasNull() && !(propertyValue instanceof com.sun.star.uno.Any ))
+ m_propValues.add( propertyValue );
+ else
+ m_propValues.add( "[ Property not found ]" );
+ }
+ }
+ return m_propValues;
+ }
+
+ /**
+ * Get connect URL.
+ *
+ *@return String That contains the connect URL
+ */
+ public String getContentURL() {
+ return m_contenturl;
+ }
+
+ /**
+ * Get the properties.
+ *
+ *@return Vector That contains the properties
+ */
+ public Vector getProperties() {
+ return m_propNames;
+ }
+
+ /**
+ * Parse arguments
+ *
+ *@param String[] Arguments
+ *@exception java.lang.Exception
+ */
+ public void parseArguments( String[] args ) throws java.lang.Exception {
+
+ for ( int i = 0; i < args.length; i++ ) {
+ if ( args[i].startsWith( "-url=" )) {
+ m_contenturl = args[i].substring( 5 );
+ } else if ( args[i].startsWith( "-propNames=" )) {
+ StringTokenizer tok
+ = new StringTokenizer( args[i].substring( 11 ), ";" );
+
+ while ( tok.hasMoreTokens() )
+ m_propNames.add( tok.nextToken() );
+
+ } else if ( args[i].startsWith( "-help" ) ||
+ args[i].startsWith( "-?" )) {
+ printCmdLineUsage();
+ System.exit( 0 );
+ }
+ }
+
+ if ( m_contenturl == null || m_contenturl.equals( "" )) {
+ m_contenturl = Helper.prependCurrentDirAsAbsoluteFileURL( "data/data.txt" );
+ }
+
+ if ( m_propNames.size() == 0 ) {
+ m_propNames.add( "Title" );
+ m_propNames.add( "IsDocument" );
+ }
+ }
+
+ /**
+ * Print the commands options
+ */
+ public void printCmdLineUsage() {
+ System.out.println(
+ "Usage : PropertiesRetriever -url=... -propNames=..." );
+ System.out.println(
+ "Defaults: -url=<currentdir>/data/data.txt -propNames=Title;IsDocument" );
+ System.out.println(
+ "\nExample : -propNames=Title;IsFolder" );
+ }
+
+ /**
+ * Create a new connection with the specific args to a running office and
+ * get the properties values from a resource.
+ *
+ *@param String[] Arguments
+ */
+ public static void main ( String args[] ) {
+ System.out.println( "\n" );
+ System.out.println(
+ "--------------------------------------------------------------" );
+ System.out.println(
+ "PropertiesRetriever - obtains property values from a resource." );
+ System.out.println(
+ "--------------------------------------------------------------" );
+ try {
+ PropertiesRetriever obtProperty = new PropertiesRetriever( args );
+ Vector properties = obtProperty.getProperties();
+ Vector propertiesValues = obtProperty.getPropertyValues( properties );
+
+ String tempPrint = "\nProperties of resource " + obtProperty.getContentURL();
+ int size = tempPrint.length();
+ System.out.println( tempPrint );
+ tempPrint = "";
+ for( int i = 0; i < size; i++ ) {
+ tempPrint += "-";
+ }
+ System.out.println( tempPrint );
+
+ if ( properties != null && propertiesValues != null ) {
+ size = properties.size();
+ for (int index = 0; index < size ; index++ ) {
+ String property = ( String )properties.get( index );
+ Object propValue = propertiesValues.get( index );
+ System.out.println( property + " : " + propValue );
+ }
+ }
+ } catch ( com.sun.star.ucb.CommandAbortedException e ) {
+ System.out.println( "Error: " + e );
+ } catch ( com.sun.star.uno.Exception e ) {
+ System.out.println( "Error: " + e );
+ } catch ( java.lang.Exception e ) {
+ System.out.println( "Error: " + e );
+ }
+ System.exit( 0 );
+ }
+}
diff --git a/odk/examples/DevelopersGuide/UCB/ResourceCreator.java b/odk/examples/DevelopersGuide/UCB/ResourceCreator.java
new file mode 100644
index 000000000000..4dc1946c752e
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/ResourceCreator.java
@@ -0,0 +1,313 @@
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.ucb.ContentInfo;
+import com.sun.star.ucb.InsertCommandArgument;
+import com.sun.star.ucb.XContent;
+import com.sun.star.io.XInputStream;
+
+
+/**
+ * Creating a New Resource
+ */
+public class ResourceCreator {
+
+ /**
+ * Member properties
+ */
+ private Helper m_helper;
+ private XContent m_content;
+ private String m_contenturl = "";
+ private String m_name = "";
+ private String m_srcURL = "";
+
+ /**
+ * Constructor.
+ *
+ *@param String[] This construtor requires the arguments:
+ * -url=... (optional)
+ * -name=... (optional)
+ * -srcURL=... (optional)
+ * -workdir=... (optional)
+ * See Help (method printCmdLineUsage()).
+ * Without the arguments a new connection to a
+ * running office cannot created.
+ *@exception java.lang.Exception
+ */
+ public ResourceCreator( String args[] ) throws java.lang.Exception {
+
+ // Parse arguments
+ parseArguments( args );
+ String url = getContentURL();
+
+ // Init
+ m_helper = new Helper( url );
+ if ( url.startsWith( "file:///" )) {
+
+ // Create UCB content
+ m_content = m_helper.createUCBContent();
+ } else {
+ throw new Exception(
+ "Create new resource : parameter 'url' must contain a File URL " +
+ "pointing to the file system folder in which the new resource " +
+ "shall be created. (Example: file:///tmp/)" );
+ }
+ }
+
+ /**
+ * Create a new resource.
+ * This method requires the main and the optional arguments to be set in order to work.
+ * See Constructor.
+ *
+ *@return boolean Returns true if resource successfully created, false otherwise
+ *@exception com.sun.star.ucb.CommandAbortedException
+ *@exception com.sun.star.uno.Exception
+ */
+ public boolean createNewResource()
+ throws com.sun.star.ucb.CommandAbortedException,
+ com.sun.star.uno.Exception,
+ java.lang.Exception {
+
+ String sourceURL = getSourceURL();
+ String name = getName();
+ return createNewResource( sourceURL, name );
+ }
+
+ /**
+ * Create a new resource.
+ *
+ *@param String Source resource URL
+ *@param String New resource name
+ *@return boolean Returns true if resource successfully created, false otherwise
+ *@exception com.sun.star.ucb.CommandAbortedException
+ *@exception com.sun.star.uno.Exception
+ */
+ public boolean createNewResource( String sourceURL, String name )
+ throws com.sun.star.ucb.CommandAbortedException,
+ com.sun.star.uno.Exception,
+ java.lang.Exception {
+
+ XInputStream stream = null;
+ if ( sourceURL == null || sourceURL.equals( "" )) {
+ stream = new MyInputStream();
+ } else {
+ String[] args = new String[ 1 ];
+ args[ 0 ] = "-url=" + sourceURL;
+ DataStreamRetriever access = new DataStreamRetriever( args );
+ stream = access.getDataStream();
+ }
+ return createNewResource( stream, name );
+ }
+
+ /**
+ * Create a new resource.
+ *
+ *@param XInputStream Source resource stream
+ *@param String New resource name
+ *@return boolean Returns true if resource successfully created, false otherwise
+ *@exception com.sun.star.ucb.CommandAbortedException
+ *@exception com.sun.star.uno.Exception
+ */
+ public boolean createNewResource( XInputStream stream, String name )
+ throws com.sun.star.ucb.CommandAbortedException, com.sun.star.uno.Exception {
+
+ boolean result = false;
+ if ( stream != null && name != null && !name.equals( "" )) {
+
+ // Note: The data for info may have been obtained from
+ // property CreatableContentsInfo.
+ ContentInfo info = new ContentInfo();
+ info.Type = "application/vnd.sun.staroffice.fsys-file";
+ info.Attributes = 0;
+
+ // Create new, empty content (execute command "createNewContent").
+ XContent newContent = ( XContent )UnoRuntime.queryInterface(
+ XContent.class,
+ m_helper.executeCommand( m_content, "createNewContent", info ) );
+
+ if ( newContent != null ) {
+
+ /////////////////////////////////////////////////////////////////////
+ // Set mandatory properties...
+ /////////////////////////////////////////////////////////////////////
+
+ // Define property value sequence.
+ PropertyValue[] props = new PropertyValue[ 1 ];
+ PropertyValue prop = new PropertyValue();
+ prop.Name = "Title";
+ prop.Handle = -1; // n/a
+ prop.Value = name;
+ props[ 0 ] = prop;
+
+ // Execute command "setPropertyValues".
+ m_helper.executeCommand( newContent, "setPropertyValues", props );
+
+ /////////////////////////////////////////////////////////////////////
+ // Write the new file to disk...
+ /////////////////////////////////////////////////////////////////////
+
+ // Obtain document data for the new file.
+ XInputStream data = stream;
+
+ // Fill argument structure...
+ InsertCommandArgument arg = new InsertCommandArgument();
+ arg.Data = data;
+ arg.ReplaceExisting = false;
+
+ // Execute command "insert".
+ m_helper.executeCommand( newContent, "insert", arg );
+ result = true;
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Get new resource name.
+ *
+ *@return String That contains the name
+ */
+ public String getName() {
+ return m_name;
+ }
+
+ /**
+ * Get source URL.
+ *
+ *@return String That contains the source URL
+ */
+ public String getSourceURL() {
+ return m_srcURL;
+ }
+
+ /**
+ * Get connect URL.
+ *
+ *@return String That contains the connect URL
+ */
+ public String getContentURL() {
+ return m_contenturl;
+ }
+
+ /**
+ * Parse arguments
+ *
+ *@param String[] Arguments
+ *@exception java.lang.Exception
+ */
+ public void parseArguments( String[] args ) throws java.lang.Exception {
+
+ String workdir = "";
+
+ for ( int i = 0; i < args.length; i++ ) {
+ if ( args[i].startsWith( "-url=" )) {
+ m_contenturl = args[i].substring( 5 );
+ } else if ( args[i].startsWith( "-name=" )) {
+ m_name = args[i].substring( 6 );
+ } else if ( args[i].startsWith( "-srcURL=" )) {
+ m_srcURL = args[i].substring( 8 );
+ } else if ( args[i].startsWith( "-workdir=" )) {
+ workdir = args[i].substring( 9 );
+ } else if ( args[i].startsWith( "-help" ) ||
+ args[i].startsWith( "-?" )) {
+ printCmdLineUsage();
+ System.exit( 0 );
+ }
+ }
+
+ if ( m_contenturl == null || m_contenturl.equals( "" )) {
+ m_contenturl = Helper.getAbsoluteFileURLFromSystemPath( workdir );
+ }
+
+ if ( m_name == null || m_name.equals( "" )) {
+ m_name = "created-resource-" + System.currentTimeMillis();
+ }
+
+ if ( m_srcURL == null || m_srcURL.equals( "" )) {
+ m_srcURL = Helper.prependCurrentDirAsAbsoluteFileURL( "data/data.txt" );
+ }
+ }
+
+ /**
+ * Print the commands options
+ */
+ public void printCmdLineUsage() {
+ System.out.println(
+ "Usage : ResourceCreator -url=... -name=... -srcURL=... -workdir=..." );
+ System.out.println(
+ "Defaults: -url=<workdir> -name=created-resource-<uniquepostfix> -srcURL=<currentdir>/data/data.txt> -workdir=<currentdir>" );
+ System.out.println(
+ "\nExample : -url=file:///home/kai/ -name=newfile.txt -srcURL=file:///home/kai/sourcefile.txt" );
+ }
+
+ /**
+ * Create a new connection with the specific args to a running office and
+ * create a new resource.
+ *
+ *@param String[] Arguments
+ */
+ public static void main ( String args[] ) {
+ System.out.println( "\n" );
+ System.out.println(
+ "-----------------------------------------------------------------------" );
+ System.out.println(
+ "ResourceCreator - creates a new file in an existing file system folder." );
+ System.out.println(
+ " (Content for the new file can be retrieved from another file)." );
+ System.out.println(
+ "-----------------------------------------------------------------------" );
+ try {
+ ResourceCreator create = new ResourceCreator( args );
+ boolean result = create.createNewResource();
+ if ( result ) {
+ System.out.println(
+ "Creation of new resource " + create.getName() + " in folder: " +
+ create.getContentURL() + " succeeded." );
+ } else {
+ System.out.println(
+ "Creation of new resource " + create.getName() + " in folder: " +
+ create.getContentURL() + " failed." );
+ }
+ } catch ( com.sun.star.ucb.CommandAbortedException e ) {
+ System.out.println( "Error: " + e );
+ } catch ( com.sun.star.uno.Exception e ) {
+ System.out.println( "Error: " + e );
+ } catch ( java.lang.Exception e ) {
+ System.out.println( "Error: " + e );
+ }
+ System.exit( 0 );
+ }
+}
diff --git a/odk/examples/DevelopersGuide/UCB/ResourceManager.java b/odk/examples/DevelopersGuide/UCB/ResourceManager.java
new file mode 100644
index 000000000000..bfe94ed59667
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/ResourceManager.java
@@ -0,0 +1,289 @@
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.ucb.NameClash;
+import com.sun.star.ucb.TransferCommandOperation;
+import com.sun.star.ucb.GlobalTransferCommandArgument;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XInterface;
+
+/**
+ * Copying, Moving and Creating Links to a Resource
+ */
+public class ResourceManager {
+
+ /**
+ * Member properties
+ */
+ private Helper m_helper;
+ private XInterface m_ucb;
+ private String m_contenturl = "";
+ private String m_srcURL = "";
+ private String m_targetFolderURL = "";
+ private String m_newTitle = "";
+ private String m_transOperation = "";
+
+ /**
+ * Constructor.
+ *
+ *@param String[] This construtor requires the arguments:
+ * -url=... (optional)
+ * -targetFolderURL=... (optional)
+ * -newTitle=... (optional)
+ * -transOper=... (optional)
+ * -workdir=... (optional)
+ * See Help (method printCmdLineUsage()).
+ * Without the arguments a new connection to a
+ * running office cannot created.
+ *@exception java.lang.Exception
+ */
+ public ResourceManager( String args[] ) throws java.lang.Exception {
+
+ // Parse arguments
+ parseArguments( args );
+
+ // Init
+ m_helper = new Helper( getContentURL() );
+
+ // Get xUCB
+ m_ucb = m_helper.getUCB();
+ }
+
+ /**
+ * Copy, move or create a link for a resource.
+ * This method requires the main and the optional arguments to be set in order to work.
+ * See Constructor.
+ *
+ *@return boolean Returns true if resource successfully transfered, false otherwise
+ *@exception com.sun.star.ucb.CommandAbortedException
+ *@exception com.sun.star.uno.Exception
+ */
+ public boolean transferResource()
+ throws com.sun.star.ucb.CommandAbortedException, com.sun.star.uno.Exception {
+ String sourceURL = getContentURL(); // URL of the source object
+ String targetFolderURL = getTargetFolderURL(); // URL of the target folder
+ String newTitle = getNewTitle(); // New name for the resource
+ String transOperation = getTransOperation();
+ return transferResource( sourceURL, targetFolderURL, newTitle, transOperation );
+ }
+
+ /**
+ * Copy, move or create a link for a resource.
+ *
+ *@param String Source URL
+ *@param String Target folder URL
+ *@param String Transfering operation (copy, move, link)
+ *@return boolean Returns true if resource successfully transfered, false otherwise
+ *@exception com.sun.star.ucb.CommandAbortedException
+ *@exception com.sun.star.uno.Exception
+ */
+ public boolean transferResource(
+ String sourceURL, String targetFolderURL,
+ String newTitle, String transOperation )
+ throws com.sun.star.ucb.CommandAbortedException, com.sun.star.uno.Exception {
+
+ boolean result = false;
+ if ( m_ucb != null && sourceURL != null && !sourceURL.equals( "" ) &&
+ targetFolderURL != null && !targetFolderURL.equals( "" ) &&
+ newTitle != null && transOperation != null && !transOperation.equals( "" ) &&
+ ( transOperation.equals( "copy" ) || transOperation.equals( "move" ) ||
+ transOperation.equals( "link" ))) {
+
+ /////////////////////////////////////////////////////////////////////
+ // Copy, move or create a link for a resource to another location...
+ /////////////////////////////////////////////////////////////////////
+ GlobalTransferCommandArgument arg = new GlobalTransferCommandArgument();
+ if ( transOperation.equals( "copy" )) {
+ arg.Operation = TransferCommandOperation.COPY;
+ } else if ( transOperation.equals( "move" )) {
+ arg.Operation = TransferCommandOperation.MOVE;
+ } else if ( transOperation.equals( "link" )) {
+ arg.Operation = TransferCommandOperation.LINK;
+ }
+ arg.SourceURL = sourceURL;
+ arg.TargetURL = targetFolderURL;
+
+ // object get a new unique name
+ arg.NewTitle = newTitle;
+
+ // fail, if object with same name exists in target folder
+ arg.NameClash = NameClash.ERROR;
+
+ // Let UCB execute the command "globalTransfer".
+ m_helper.executeCommand( m_ucb, "globalTransfer", arg );
+ result = true;
+ }
+ return result;
+ }
+
+ /**
+ * Get connect URL.
+ *
+ *@return String That contains the connect URL
+ */
+ public String getContentURL() {
+ return m_contenturl;
+ }
+
+ /**
+ * Get trasfering Operation.
+ *
+ *@return String That contains the trasfering Operation
+ */
+ public String getTransOperation() {
+ return m_transOperation;
+ }
+
+ /**
+ * Get target folder URL.
+ *
+ *@return String That contains the target folder URL
+ */
+ public String getTargetFolderURL() {
+ return m_targetFolderURL;
+ }
+
+ /**
+ * Get new title for the resource to be transfered.
+ *
+ *@return String That contains a new title for the transfered
+ * resource. Can be empty. In this case resource
+ * will keep the title it has in the source folder.
+ */
+ public String getNewTitle() {
+ return m_newTitle;
+ }
+
+ /**
+ * Parse arguments
+ *
+ *@param String[] Arguments
+ *@exception java.lang.Exception
+ */
+ public void parseArguments( String[] args ) throws java.lang.Exception {
+
+ String workdir = "";
+
+ for ( int i = 0; i < args.length; i++ ) {
+ if ( args[i].startsWith( "-url=" )) {
+ m_contenturl = args[i].substring( 5 );
+ } else if ( args[i].startsWith( "-targetFolderURL=" )) {
+ m_targetFolderURL = args[i].substring( 17 );
+ } else if ( args[i].startsWith( "-newTitle=" )) {
+ m_newTitle = args[i].substring( 10 );
+ } else if ( args[i].startsWith( "-transOper=" )) {
+ m_transOperation = args[i].substring( 11 );
+ } else if ( args[i].startsWith( "-workdir=" )) {
+ workdir = args[i].substring( 9 );
+ } else if ( args[i].startsWith( "-help" ) ||
+ args[i].startsWith( "-?" )) {
+ printCmdLineUsage();
+ System.exit( 0 );
+ }
+ }
+
+ if ( m_contenturl == null || m_contenturl.equals( "" )) {
+ m_contenturl = Helper.prependCurrentDirAsAbsoluteFileURL( "data/data.txt" );;
+ }
+
+ if ( m_targetFolderURL == null || m_targetFolderURL.equals( "" )) {
+ m_targetFolderURL = Helper.getAbsoluteFileURLFromSystemPath( workdir );
+ }
+
+ if ( m_newTitle == null || m_newTitle.equals( "" )) {
+ m_newTitle = "transfered-resource-" + System.currentTimeMillis();
+ }
+
+ if ( m_transOperation == null || m_transOperation.equals( "" )) {
+ m_transOperation = "copy";
+ }
+ }
+
+ /**
+ * Print the commands options
+ */
+ public void printCmdLineUsage() {
+ System.out.println(
+ "Usage: ResourceManager -url=... -targetFolderURL=... -newTitle=... -transOper=... -workdir=..." );
+ System.out.println(
+ "Defaults: -url=<currentdir>/data/data.txt> -targetFolderURL=<workdir> -newTitle=transfered-resource-<uniquepostfix> -transOper=copy -workdir=<currentdir>");
+ System.out.println(
+ "\nExample : -url=file:///temp/MyFile.txt -targetFolderURL=file:///test/ -newTitle=RenamedFile.txt -transOper=copy " );
+ }
+
+ /**
+ * Create a new connection with the specific args to a running office and
+ * copy, move or create links a resource.
+ *
+ *@param String[] Arguments
+ */
+ public static void main ( String args[] ) {
+
+ System.out.println( "\n" );
+ System.out.println(
+ "-----------------------------------------------------------------" );
+ System.out.println(
+ "ResourceManager - copies/moves a resource." );
+ System.out.println(
+ "-----------------------------------------------------------------" );
+
+ try {
+ ResourceManager transResource = new ResourceManager( args );
+ String sourceURL = transResource.getContentURL();
+ String targetFolderURL = transResource.getTargetFolderURL();
+ String newTitle = transResource.getNewTitle();
+ String transOperation = transResource.getTransOperation();
+ boolean result = transResource.transferResource(
+ sourceURL, targetFolderURL, newTitle, transOperation );
+ if ( result )
+ System.out.println( "\nTransfering resource succeeded." );
+ else
+ System.out.println( "Transfering resource failed." );
+
+ System.out.println( " Source URL : " + sourceURL );
+ System.out.println( " Target Folder URL : " + targetFolderURL );
+ System.out.println( " New name : " + newTitle );
+ System.out.println( " Transfer Operation: " + transOperation );
+
+
+ } catch ( com.sun.star.ucb.CommandAbortedException e ) {
+ System.out.println( "Error: " + e );
+ } catch ( com.sun.star.uno.Exception e ) {
+ System.out.println( "Error: " + e );
+ } catch ( java.lang.Exception e ) {
+ System.out.println( "Error: " + e );
+ }
+ System.exit( 0 );
+ }
+}
diff --git a/odk/examples/DevelopersGuide/UCB/ResourceRemover.java b/odk/examples/DevelopersGuide/UCB/ResourceRemover.java
new file mode 100644
index 000000000000..09a6bcb7c21c
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/ResourceRemover.java
@@ -0,0 +1,180 @@
+/*************************************************************************
+ *
+ * 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.
+ *
+ *************************************************************************/
+
+/**
+ * Deleting a resource
+ */
+public class ResourceRemover {
+
+ /**
+ * Member properties
+ */
+ private Helper m_helper;
+ private String m_contenturl = "";
+ private com.sun.star.ucb.XContent m_content;
+
+ /**
+ * Constructor.
+ *
+ *@param String[] This construtor requires the arguments:
+ * -url=... (optional)
+ * -workdir=... (optional)
+ * See Help (method printCmdLineUsage()).
+ * Without the arguments a new connection to a
+ * running office cannot created.
+ *@exception java.lang.Exception
+ */
+ public ResourceRemover( String args[] ) throws java.lang.Exception {
+
+ // Parse arguments
+ parseArguments( args );
+
+ // Init
+ m_helper = new Helper( getContentURL() );
+
+ // Create UCB content
+ m_content = m_helper.createUCBContent();
+ }
+
+ /**
+ * Delete resource.
+ *
+ *@return boolean Returns true if resource successfully deleted, false otherwise
+ *@exception com.sun.star.ucb.CommandAbortedException
+ *@exception com.sun.star.uno.Exception
+ */
+ public boolean deleteResource()
+ throws com.sun.star.ucb.CommandAbortedException, com.sun.star.uno.Exception {
+
+ boolean result = false;
+ if ( m_content != null ) {
+
+ /////////////////////////////////////////////////////////////////////
+ // Destroy a resource physically...
+ /////////////////////////////////////////////////////////////////////
+
+ Boolean deletePhysically = new Boolean( true );
+
+ // Execute command "delete".
+ m_helper.executeCommand( m_content, "delete", deletePhysically );
+ result = true;
+ }
+ return result;
+ }
+
+ /**
+ * Get connect URL.
+ *
+ *@return String That contains the connect URL
+ */
+ public String getContentURL() {
+ return m_contenturl;
+ }
+
+ /**
+ * Parse arguments
+ *
+ *@param String[] Arguments
+ *@exception java.lang.Exception
+ */
+ public void parseArguments( String[] args ) throws java.lang.Exception {
+
+ String workdir = "";
+
+ for ( int i = 0; i < args.length; i++ ) {
+ if ( args[i].startsWith( "-url=" )) {
+ m_contenturl = args[i].substring( 5 );
+ } else if ( args[i].startsWith( "-workdir=" )) {
+ workdir = args[i].substring( 9 );
+ } else if ( args[i].startsWith( "-help" ) ||
+ args[i].startsWith( "-?" )) {
+ printCmdLineUsage();
+ System.exit( 0 );
+ }
+ }
+
+ if ( m_contenturl == null || m_contenturl.equals( "" )) {
+ m_contenturl = Helper.createTargetDataFile( workdir );
+ }
+ }
+
+ /**
+ * Print the commands options
+ */
+ public void printCmdLineUsage() {
+ System.out.println(
+ "Usage : ResourceRemover -url=... -workdir=..." );
+ System.out.println(
+ "Defaults: -url=<workdir>/resource-<uniquepostfix> -workdir=<currentdir>" );
+ System.out.println(
+ "\nExample : -url=file:///temp/MyFile.txt \n" );
+ }
+
+ /**
+ * Create a new connection with the specific args to a running office and
+ * delete a resource.
+ *
+ *@param String[] Arguments
+ */
+ public static void main ( String args[] ) {
+
+ System.out.println( "\n" );
+ System.out.println(
+ "-----------------------------------------------------------------" );
+ System.out.println(
+ "ResourceRemover - destroys a resource." );
+ System.out.println(
+ "-----------------------------------------------------------------" );
+
+ try {
+ ResourceRemover delete = new ResourceRemover( args );
+ boolean result = delete.deleteResource();
+ String url = delete.getContentURL();
+ if ( result ) {
+ System.out.println(
+ "Delete of resource " + url + " succeeded." );
+ } else {
+ System.out.println(
+ "Delete of resource " + url + " failed." );
+ }
+ } catch ( com.sun.star.ucb.CommandAbortedException e ) {
+ System.out.println( "Error: " + e );
+ } catch ( com.sun.star.uno.Exception e ) {
+ System.out.println( "Error: " + e );
+ } catch ( java.lang.Exception e ) {
+ System.out.println( "Error: " + e );
+ }
+ System.exit( 0 );
+ }
+}
diff --git a/odk/examples/DevelopersGuide/UCB/data/data.txt b/odk/examples/DevelopersGuide/UCB/data/data.txt
new file mode 100644
index 000000000000..dd47db97da34
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/data/data.txt
@@ -0,0 +1 @@
+sample sample sample sample sample sample sample sample EOF \ No newline at end of file
diff --git a/odk/examples/DevelopersGuide/UCB/makefile.mk b/odk/examples/DevelopersGuide/UCB/makefile.mk
new file mode 100644
index 000000000000..c95d3769e49a
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/makefile.mk
@@ -0,0 +1,75 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+PRJ=..$/..$/..
+PRJNAME=odk
+TARGET=copying
+
+#----------------------------------------------------------------
+.INCLUDE: settings.mk
+.INCLUDE: $(PRJ)$/util$/makefile.pmk
+#----------------------------------------------------------------
+
+#----------------------------------------------------
+# this makefile is only used for copying the example
+# files into the SDK
+#----------------------------------------------------
+
+UCB_FILES=\
+ $(DESTDIRDEVGUIDEEXAMPLES)$/UCB$/data$/data.txt \
+ $(DESTDIRDEVGUIDEEXAMPLES)$/UCB$/ChildrenRetriever.java \
+ $(DESTDIRDEVGUIDEEXAMPLES)$/UCB$/DataStreamComposer.java \
+ $(DESTDIRDEVGUIDEEXAMPLES)$/UCB$/DataStreamRetriever.java \
+ $(DESTDIRDEVGUIDEEXAMPLES)$/UCB$/Helper.java \
+ $(DESTDIRDEVGUIDEEXAMPLES)$/UCB$/Makefile \
+ $(DESTDIRDEVGUIDEEXAMPLES)$/UCB$/MyActiveDataSink.java \
+ $(DESTDIRDEVGUIDEEXAMPLES)$/UCB$/MyInputStream.java \
+ $(DESTDIRDEVGUIDEEXAMPLES)$/UCB$/PropertiesComposer.java \
+ $(DESTDIRDEVGUIDEEXAMPLES)$/UCB$/PropertiesRetriever.java \
+ $(DESTDIRDEVGUIDEEXAMPLES)$/UCB$/ResourceCreator.java \
+ $(DESTDIRDEVGUIDEEXAMPLES)$/UCB$/ResourceManager.java \
+ $(DESTDIRDEVGUIDEEXAMPLES)$/UCB$/ResourceRemover.java
+
+DIR_FILE_LIST= \
+ $(UCB_FILES) \
+
+DIR_DIRECTORY_LIST=$(uniq $(DIR_FILE_LIST:d))
+DIR_CREATE_FLAG=$(MISC)$/devguide_ucb_dirs_created.txt
+DIR_FILE_FLAG=$(MISC)$/devguide_ucb.txt
+
+#--------------------------------------------------
+# TARGETS
+#--------------------------------------------------
+all : \
+ $(DIR_FILE_LIST) \
+ $(DIR_FILE_FLAG)
+
+#--------------------------------------------------
+# use global rules
+#--------------------------------------------------
+.INCLUDE: $(PRJ)$/util$/odk_rules.pmk
+