summaryrefslogtreecommitdiffstats
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.java338
-rw-r--r--odk/examples/DevelopersGuide/UCB/DataStreamComposer.java246
-rw-r--r--odk/examples/DevelopersGuide/UCB/DataStreamRetriever.java227
-rw-r--r--odk/examples/DevelopersGuide/UCB/Helper.java242
-rw-r--r--odk/examples/DevelopersGuide/UCB/Makefile155
-rw-r--r--odk/examples/DevelopersGuide/UCB/MyActiveDataSink.java74
-rw-r--r--odk/examples/DevelopersGuide/UCB/MyInputStream.java180
-rw-r--r--odk/examples/DevelopersGuide/UCB/PropertiesComposer.java289
-rw-r--r--odk/examples/DevelopersGuide/UCB/PropertiesRetriever.java245
-rw-r--r--odk/examples/DevelopersGuide/UCB/ResourceCreator.java304
-rw-r--r--odk/examples/DevelopersGuide/UCB/ResourceManager.java280
-rw-r--r--odk/examples/DevelopersGuide/UCB/ResourceRemover.java175
-rw-r--r--odk/examples/DevelopersGuide/UCB/data/data.txt1
13 files changed, 2756 insertions, 0 deletions
diff --git a/odk/examples/DevelopersGuide/UCB/ChildrenRetriever.java b/odk/examples/DevelopersGuide/UCB/ChildrenRetriever.java
new file mode 100644
index 000000000..102119dfc
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/ChildrenRetriever.java
@@ -0,0 +1,338 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+import com.sun.star.beans.Property;
+import com.sun.star.sdbc.XResultSet;
+import com.sun.star.sdbc.XRow;
+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.uno.UnoRuntime;
+
+/**
+ * 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 ArrayList<String> m_propnames = new ArrayList<String>();
+
+ /**
+ * Constructor. Create a new connection with the specific args to a running office
+ *
+ *@param args This constructor requires the arguments:
+ * -url=... (optional)
+ * -propNames=... (optional)
+ * See Help (method printCmdLineUsage()).
+ * Without the arguments a new connection to a
+ * running office cannot created.
+ */
+ 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 Returns children properties values if values successfully retrieved,
+ * null otherwise
+ */
+ public ArrayList<ArrayList<Object>> getChildren()
+ throws com.sun.star.ucb.CommandAbortedException, com.sun.star.uno.Exception {
+ ArrayList<String> properties = getProperties();
+ return getChildren ( properties );
+ }
+
+ /**
+ * Open a folder content, get properties values for the properties.
+ *
+ *@return Returns children properties values if values successfully retrieved,
+ * null otherwise
+ */
+ public ArrayList<ArrayList<Object>> getChildren( ArrayList<String> properties )
+ throws com.sun.star.ucb.CommandAbortedException, com.sun.star.uno.Exception {
+
+ ArrayList<ArrayList<Object>> 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 = 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; // static final for 32768
+ arg.Properties = props;
+
+ XDynamicResultSet set;
+
+ // Execute command "open".
+ set = UnoRuntime.queryInterface(
+ XDynamicResultSet.class, m_helper.executeCommand( m_content, "open", arg ));
+ XResultSet resultSet = set.getStaticResultSet();
+
+ result = new ArrayList<ArrayList<Object>>();
+
+
+ // Iterate over children, access children and property values...
+
+
+ // Move to begin.
+ if ( resultSet.first() ) {
+ XContentAccess contentAccess = UnoRuntime.queryInterface(
+ XContentAccess.class, resultSet );
+ XRow row = UnoRuntime.queryInterface( XRow.class, resultSet );
+
+ do {
+ ArrayList<Object> propsValues = new ArrayList<Object>();
+
+ // 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 ArrayList<String> getProperties() {
+ return m_propnames;
+ }
+
+ /**
+ * Parse arguments
+ *
+ *@param args Arguments
+ */
+ 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 .
+ */
+ public void printLine( ArrayList<Object> 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.
+ */
+ 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.
+ ArrayList<ArrayList<Object>> 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() ) {
+
+ ArrayList<Object> cont = new ArrayList<Object>();
+ cont.add("URL:");
+ ArrayList<String> 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 ( ArrayList<Object> propsV : result ) {
+ 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 );
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/DevelopersGuide/UCB/DataStreamComposer.java b/odk/examples/DevelopersGuide/UCB/DataStreamComposer.java
new file mode 100644
index 000000000..ce6edae31
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/DataStreamComposer.java
@@ -0,0 +1,246 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.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 args This constructor 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.
+ */
+ 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
+ */
+ 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 sourceURL Source URL
+ *@return true if data stream successfully seted, false otherwise
+ */
+ 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...
+ *
+ *@return boolean Returns true if data stream successfully seted, false otherwise
+ */
+ 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
+ */
+ 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.
+ */
+ 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 );
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/DevelopersGuide/UCB/DataStreamRetriever.java b/odk/examples/DevelopersGuide/UCB/DataStreamRetriever.java
new file mode 100644
index 000000000..5644af0c2
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/DataStreamRetriever.java
@@ -0,0 +1,227 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.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 args This constructor requires the arguments:
+ * -url=... (optional)
+ * See Help (method printCmdLineUsage()).
+ * Without the arguments a new connection to a
+ * running office cannot created.
+ */
+ 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
+ */
+ 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; // static final 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 args Arguments
+ */
+ private 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
+ */
+ private 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.
+ */
+ private 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.
+ */
+ 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 );
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/DevelopersGuide/UCB/Helper.java b/odk/examples/DevelopersGuide/UCB/Helper.java
new file mode 100644
index 000000000..846f942dd
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/Helper.java
@@ -0,0 +1,242 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import java.io.File;
+import java.io.FileOutputStream;
+
+import com.sun.star.ucb.Command;
+import com.sun.star.ucb.UniversalContentBroker;
+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 manager is used to create the ucb. If necessary
+ * a new office process is started.
+ */
+ 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 ...");
+ }
+
+ m_ucb = UnoRuntime.queryInterface(
+ XInterface.class, UniversalContentBroker.create(m_xContext));
+ }
+
+ /**
+ * Returns created identifier object for given URL...
+ *
+ *@return XContent Created identifier object for given URL
+ */
+ public XContent createUCBContent() throws java.lang.Exception {
+ return createUCBContent( getContentURL() );
+ }
+
+ /**
+ * Returned created identifier object for given URL.
+ *
+ *@param connectURL Connect URL. Example : -url=file:///
+ *@return Created identifier object for given URL
+ */
+ private XContent createUCBContent( String connectURL ) throws java.lang.Exception {
+ XContent content = null;
+ if ( connectURL != null && !connectURL.equals( "" )) {
+
+ // Obtain required UCB interfaces...
+ XContentIdentifierFactory idFactory
+ = UnoRuntime.queryInterface(
+ XContentIdentifierFactory.class, m_ucb );
+ XContentProvider provider
+ = 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
+ = 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.toURI().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 "";
+ }
+
+ 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.toURI().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 = "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 "";
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/DevelopersGuide/UCB/Makefile b/odk/examples/DevelopersGuide/UCB/Makefile
new file mode 100644
index 000000000..22dd94bad
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/Makefile
@@ -0,0 +1,155 @@
+#*************************************************************************
+#
+# 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
+
+# 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 000000000..fcfadc7e4
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/MyActiveDataSink.java
@@ -0,0 +1,74 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.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
+ */
+ private XInputStream m_aStream = null;
+
+ /**
+ * Constructor
+ */
+ public MyActiveDataSink() {
+ super();
+ }
+
+ /**
+ * Plugs the input stream.
+ */
+ public void setInputStream( XInputStream aStream ) {
+ m_aStream = aStream;
+ }
+
+ /**
+ * Get the plugged stream.
+ *
+ *@return XInputStream The plugged stream
+ */
+ public XInputStream getInputStream() {
+ return m_aStream;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/DevelopersGuide/UCB/MyInputStream.java b/odk/examples/DevelopersGuide/UCB/MyInputStream.java
new file mode 100644
index 000000000..048f2950c
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/MyInputStream.java
@@ -0,0 +1,180 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.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.
+ */
+ 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.
+ */
+ 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.
+ */
+ 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.
+ */
+ 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;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/DevelopersGuide/UCB/PropertiesComposer.java b/odk/examples/DevelopersGuide/UCB/PropertiesComposer.java
new file mode 100644
index 000000000..1ebc9cbaa
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/PropertiesComposer.java
@@ -0,0 +1,289 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.ucb.XContent;
+
+/**
+ * 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 ArrayList<String> m_propNames = new ArrayList<String>();
+ private ArrayList<String> m_propValues = new ArrayList<String>();
+
+ /**
+ * Constructor.
+ *
+ *@param args This constructor 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.
+ */
+ 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
+ */
+ public Object[] setProperties()
+ throws com.sun.star.ucb.CommandAbortedException, com.sun.star.uno.Exception {
+ ArrayList<String> properties = getProperties();
+ ArrayList<String> propertyValues = getPropertyValues();
+ return setProperties( properties, propertyValues );
+ }
+
+ /**
+ * Set values of the properties.
+ *
+ *@return Object[] Returns null or instance object of com.sun.star.uno.Any
+ * if values successfully seted, properties otherwise
+ */
+ public Object[] setProperties( ArrayList<String> properties, ArrayList<String> 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 = 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 ArrayList<String> getProperties() {
+ return m_propNames;
+ }
+
+ /**
+ * Get properties values.
+ *
+ *@return Vector That contains the properties values
+ */
+ public ArrayList<String> getPropertyValues() {
+ return m_propValues;
+ }
+
+ /**
+ * Get connect URL.
+ *
+ *@return String That contains the connect URL
+ */
+ public String getContentURL() {
+ return m_contenturl;
+ }
+
+ /**
+ * Parse arguments
+ */
+ 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.
+ */
+ 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 );
+ ArrayList<String> properties = setProp.getProperties();
+ ArrayList<String> 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 );
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/DevelopersGuide/UCB/PropertiesRetriever.java b/odk/examples/DevelopersGuide/UCB/PropertiesRetriever.java
new file mode 100644
index 000000000..641b1de86
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/PropertiesRetriever.java
@@ -0,0 +1,245 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+import com.sun.star.beans.Property;
+import com.sun.star.sdbc.XRow;
+import com.sun.star.ucb.XContent;
+import com.sun.star.uno.UnoRuntime;
+
+
+/**
+ * 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 ArrayList<String> m_propNames = new ArrayList<String>();
+
+ /**
+ * Constructor.
+ *
+ *@param args This constructor requires the arguments:
+ * -url=... (optional)
+ * -propNames=... (optional)
+ * See Help (method printCmdLineUsage()).
+ * Without the arguments a new connection to a
+ * running office cannot created.
+ */
+ 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.
+ *
+ *@return Properties values if values successfully retrieved, null otherwise
+ */
+ public ArrayList<Object> getPropertyValues()
+ throws com.sun.star.ucb.CommandAbortedException, com.sun.star.uno.Exception {
+ ArrayList<String> properties = getProperties();
+ return getPropertyValues ( properties );
+ }
+
+ /**
+ * Get values of the properties.
+ *
+ *@return Properties values if values successfully retrieved, null otherwise
+ */
+ public ArrayList<Object> getPropertyValues( ArrayList<String> properties )
+ throws com.sun.star.ucb.CommandAbortedException, com.sun.star.uno.Exception {
+ ArrayList<Object> 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 = properties.get( index );
+ prop.Handle = -1; // n/a
+ props[ index ] = prop;
+ }
+
+ // Execute command "getPropertyValues".
+ XRow values =
+ UnoRuntime.queryInterface(
+ XRow.class, m_helper.executeCommand( m_content,"getPropertyValues", props ));
+
+ m_propValues = new ArrayList<Object>();
+
+ /*
+ 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 ArrayList<String> getProperties() {
+ return m_propNames;
+ }
+
+ /**
+ * Parse arguments
+ */
+ 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.
+ */
+ 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 );
+ ArrayList<String> properties = obtProperty.getProperties();
+ ArrayList<Object> 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 = 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 );
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/DevelopersGuide/UCB/ResourceCreator.java b/odk/examples/DevelopersGuide/UCB/ResourceCreator.java
new file mode 100644
index 000000000..0f7e2f200
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/ResourceCreator.java
@@ -0,0 +1,304 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.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 args This constructor 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.
+ */
+ 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
+ */
+ 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 sourceURL Source resource URL
+ *@param name New resource name
+ *@return true if resource successfully created, false otherwise
+ */
+ 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 stream Source resource stream
+ *@param name New resource name
+ *@return true if resource successfully created, false otherwise
+ */
+ 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 = 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
+ */
+ 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.
+ */
+ 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 );
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/DevelopersGuide/UCB/ResourceManager.java b/odk/examples/DevelopersGuide/UCB/ResourceManager.java
new file mode 100644
index 000000000..61d64c8c0
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/ResourceManager.java
@@ -0,0 +1,280 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.ucb.NameClash;
+import com.sun.star.ucb.TransferCommandOperation;
+import com.sun.star.ucb.GlobalTransferCommandArgument;
+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_targetFolderURL = "";
+ private String m_newTitle = "";
+ private String m_transOperation = "";
+
+ /**
+ * Constructor.
+ *
+ *@param args This constructor 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.
+ */
+ 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 true if resource successfully transferred, false otherwise
+ */
+ 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 sourceURL Source URL
+ *@param targetFolderURL Target folder URL
+ *@param transOperation Transferring operation (copy, move, link)
+ *@return true if resource successfully transferred, false otherwise
+ */
+ 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 transferring Operation.
+ *
+ *@return String That contains the transferring 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 transferred.
+ *
+ *@return String That contains a new title for the transferred
+ * 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
+ */
+ 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 = "transferred-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=transferred-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.
+ */
+ 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( "\nTransferring resource succeeded." );
+ else
+ System.out.println( "Transferring 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 );
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/DevelopersGuide/UCB/ResourceRemover.java b/odk/examples/DevelopersGuide/UCB/ResourceRemover.java
new file mode 100644
index 000000000..e6ac8fc1c
--- /dev/null
+++ b/odk/examples/DevelopersGuide/UCB/ResourceRemover.java
@@ -0,0 +1,175 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+/**
+ * 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 args This constructor requires the arguments:
+ * -url=... (optional)
+ * -workdir=... (optional)
+ * See Help (method printCmdLineUsage()).
+ * Without the arguments a new connection to a
+ * running office cannot created.
+ */
+ 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 true if resource successfully deleted, false otherwise
+ */
+ 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 = 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
+ */
+ 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.
+ */
+ 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 );
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/DevelopersGuide/UCB/data/data.txt b/odk/examples/DevelopersGuide/UCB/data/data.txt
new file mode 100644
index 000000000..dd47db97d
--- /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