summaryrefslogtreecommitdiff
path: root/odk/examples/java/Text
diff options
context:
space:
mode:
Diffstat (limited to 'odk/examples/java/Text')
-rw-r--r--odk/examples/java/Text/BookmarkInsertion.java284
-rw-r--r--odk/examples/java/Text/GraphicsInserter.java179
-rw-r--r--odk/examples/java/Text/HardFormatting.java286
-rw-r--r--odk/examples/java/Text/Makefile136
-rw-r--r--odk/examples/java/Text/SWriter.java397
-rw-r--r--odk/examples/java/Text/StyleCreation.java226
-rw-r--r--odk/examples/java/Text/StyleInitialization.java320
-rw-r--r--odk/examples/java/Text/TextDocumentStructure.java205
-rw-r--r--odk/examples/java/Text/TextReplace.java231
-rw-r--r--odk/examples/java/Text/WriterSelector.java162
-rw-r--r--odk/examples/java/Text/oo_smiley.gifbin0 -> 46109 bytes
11 files changed, 2426 insertions, 0 deletions
diff --git a/odk/examples/java/Text/BookmarkInsertion.java b/odk/examples/java/Text/BookmarkInsertion.java
new file mode 100644
index 000000000000..89fb0ec4e841
--- /dev/null
+++ b/odk/examples/java/Text/BookmarkInsertion.java
@@ -0,0 +1,284 @@
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+//***************************************************************************
+// comment: Step 1: get the Desktop object from the office
+// Step 2: open an empty text document
+// Step 3: enter a example text
+// Step 4: insert some bookmarks
+//
+// Chapter 5.1.1.4 Inserting bookmarks
+//***************************************************************************
+
+import com.sun.star.uno.UnoRuntime;
+
+public class BookmarkInsertion {
+
+ public static void main(String args[]) {
+ // You need the desktop to create a document
+ // The getDesktop method does the UNO bootstrapping, gets the
+ // remote servie manager and the desktop object.
+ com.sun.star.frame.XDesktop xDesktop = null;
+ xDesktop = getDesktop();
+
+ // create text document
+ com.sun.star.text.XTextDocument xTextDocument = null;
+ xTextDocument = createTextdocument(xDesktop);
+
+ // put example text in document
+ createExampleData(xTextDocument);
+
+
+ String mOffending[] = { "negro(e|es)?","bor(ed|ing)?",
+ "bloody?", "bleed(ing)?" };
+ String mBad[] = { "possib(le|ilit(y|ies))", "real(ly)+", "brilliant" };
+
+ String sOffendPrefix = "Offending";
+ String sBadPrefix = "BadStyle";
+
+ markList(xTextDocument, mOffending, sOffendPrefix);
+ markList(xTextDocument, mBad, sBadPrefix);
+
+ System.out.println("Done");
+
+ System.exit(0);
+ }
+
+ public static void markList(com.sun.star.text.XTextDocument xTextDocument,
+ String mList[], String sPrefix) {
+ int iCounter=0;
+ com.sun.star.uno.XInterface xSearchInterface = null;
+ com.sun.star.text.XTextRange xSearchTextRange = null;
+
+ try {
+ for( iCounter = 0; iCounter < mList.length; iCounter++ ) {
+ // the findfirst returns a XInterface
+ xSearchInterface = (com.sun.star.uno.XInterface)FindFirst(
+ xTextDocument, mList[ iCounter ] );
+
+ if( xSearchInterface != null ) {
+ // get the TextRange form the XInterface
+ xSearchTextRange = (com.sun.star.text.XTextRange)
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XTextRange.class, xSearchInterface);
+
+ InsertBookmark(xTextDocument, xSearchTextRange,
+ sPrefix + iCounter);
+ }
+ }
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+ }
+
+
+ public static void InsertBookmark(com.sun.star.text.XTextDocument xTextDocument,
+ com.sun.star.text.XTextRange xTextRange,
+ String sBookName) {
+ // create a bookmark on a TextRange
+ try {
+ // get the MultiServiceFactory from the text document
+ com.sun.star.lang.XMultiServiceFactory xDocMSF;
+ xDocMSF = (com.sun.star.lang.XMultiServiceFactory)
+ UnoRuntime.queryInterface(
+ com.sun.star.lang.XMultiServiceFactory.class, xTextDocument);
+
+ // the bookmark service is a context dependend service, you need
+ // the MultiServiceFactory from the document
+ Object xObject = xDocMSF.createInstance("com.sun.star.text.Bookmark");
+
+ // set the name from the bookmark
+ com.sun.star.container.XNamed xNameAccess = null;
+ xNameAccess = (com.sun.star.container.XNamed)
+ UnoRuntime.queryInterface(
+ com.sun.star.container.XNamed.class, xObject);
+
+ xNameAccess.setName(sBookName);
+
+ // create a XTextContent, for the method 'insertTextContent'
+ com.sun.star.text.XTextContent xTextContent = null;
+ xTextContent = (com.sun.star.text.XTextContent)
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XTextContent.class, xNameAccess);
+
+ // insertTextContent need a TextRange not a cursor to specify the
+ // position from the bookmark
+ xTextDocument.getText().insertTextContent(xTextRange, xTextContent, true);
+
+ System.out.println("Insert bookmark: " + sBookName);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+ }
+
+ protected static com.sun.star.uno.XInterface FindFirst(
+ com.sun.star.text.XTextDocument xTextDocument, String sSearchString)
+ {
+ com.sun.star.util.XSearchDescriptor xSearchDescriptor = null;
+ com.sun.star.util.XSearchable xSearchable = null;
+ com.sun.star.uno.XInterface xSearchInterface = null;
+
+ try {
+ xSearchable = (com.sun.star.util.XSearchable)
+ UnoRuntime.queryInterface(
+ com.sun.star.util.XSearchable.class, xTextDocument);
+ xSearchDescriptor = (com.sun.star.util.XSearchDescriptor)
+ xSearchable.createSearchDescriptor();
+
+ xSearchDescriptor.setSearchString(sSearchString);
+
+ com.sun.star.beans.XPropertySet xPropertySet = null;
+ xPropertySet = (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xSearchDescriptor);
+
+ xPropertySet.setPropertyValue("SearchRegularExpression",
+ new Boolean( true ) );
+
+ xSearchInterface = (com.sun.star.uno.XInterface)
+ xSearchable.findFirst(xSearchDescriptor);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return xSearchInterface;
+ }
+
+ protected static void createExampleData(
+ com.sun.star.text.XTextDocument xTextDocument )
+ {
+ com.sun.star.text.XTextCursor xTextCursor = null;
+
+ try {
+ xTextCursor = (com.sun.star.text.XTextCursor)
+ xTextDocument.getText().createTextCursor();
+
+ xTextCursor.setString( "He heard quiet steps behind him. That didn't bode well. Who could be following him this late at night and in this deadbeat part of town? And at this particular moment, just after he pulled off the big time and was making off with the greenbacks. Was there another crook who'd had the same idea, and was now watching him and waiting for a chance to grab the fruit of his labor?" );
+ xTextCursor.collapseToEnd();
+ xTextCursor.setString( "Or did the steps behind him mean that one of many bloody officers in town was on to him and just waiting to pounce and snap those cuffs on his wrists? He nervously looked all around. Suddenly he saw the alley. Like lightening he darted off to the left and disappeared between the two warehouses almost falling over the trash can lying in the middle of the sidewalk. He tried to nervously tap his way along in the inky darkness and suddenly stiffened: it was a dead-end, he would have to go back the way he had come" );
+ xTextCursor.collapseToEnd();
+ xTextCursor.setString( "The steps got louder and louder, he saw the black outline of a figure coming around the corner. Is this the end of the line? he thought pressing himself back against the wall trying to make himself invisible in the dark, was all that planning and energy wasted? He was dripping with sweat now, cold and wet, he could smell the brilliant fear coming off his clothes. Suddenly next to him, with a barely noticeable squeak, a door swung quietly to and fro in the night's breeze." );
+
+ xTextCursor.gotoStart(false);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ }
+
+ public static com.sun.star.frame.XDesktop getDesktop() {
+ com.sun.star.frame.XDesktop xDesktop = null;
+ com.sun.star.lang.XMultiComponentFactory xMCF = null;
+
+ try {
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+
+ // get the remote office service manager
+ xMCF = xContext.getServiceManager();
+ if( xMCF != null ) {
+ System.out.println("Connected to a running office ...");
+
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext);
+ xDesktop = (com.sun.star.frame.XDesktop) UnoRuntime.queryInterface(
+ com.sun.star.frame.XDesktop.class, oDesktop);
+ }
+ else
+ System.out.println( "Can't create a desktop. No connection, no remote office servicemanager available!" );
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+
+ return xDesktop;
+ }
+
+ public static com.sun.star.text.XTextDocument createTextdocument(
+ com.sun.star.frame.XDesktop xDesktop )
+ {
+ com.sun.star.text.XTextDocument aTextDocument = null;
+
+ try {
+ com.sun.star.lang.XComponent xComponent = CreateNewDocument(xDesktop,
+ "swriter");
+ aTextDocument = (com.sun.star.text.XTextDocument)
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XTextDocument.class, xComponent);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return aTextDocument;
+ }
+
+
+ protected static com.sun.star.lang.XComponent CreateNewDocument(
+ com.sun.star.frame.XDesktop xDesktop,
+ String sDocumentType )
+ {
+ String sURL = "private:factory/" + sDocumentType;
+
+ com.sun.star.lang.XComponent xComponent = null;
+ com.sun.star.frame.XComponentLoader xComponentLoader = null;
+ com.sun.star.beans.PropertyValue xValues[] =
+ new com.sun.star.beans.PropertyValue[1];
+ com.sun.star.beans.PropertyValue xEmptyArgs[] =
+ new com.sun.star.beans.PropertyValue[0];
+
+ try {
+ xComponentLoader = (com.sun.star.frame.XComponentLoader)
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class, xDesktop);
+
+ xComponent = xComponentLoader.loadComponentFromURL(
+ sURL, "_blank", 0, xEmptyArgs);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.out);
+ }
+
+ return xComponent ;
+ }
+}
diff --git a/odk/examples/java/Text/GraphicsInserter.java b/odk/examples/java/Text/GraphicsInserter.java
new file mode 100644
index 000000000000..866da1c0849f
--- /dev/null
+++ b/odk/examples/java/Text/GraphicsInserter.java
@@ -0,0 +1,179 @@
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.uno.UnoRuntime;
+
+import java.io.PrintWriter;
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+
+
+public class GraphicsInserter {
+ public static void main(String args[]) {
+ if ( args.length < 1 )
+ {
+ System.out.println(
+ "usage: java -jar GraphicsInserter.jar \"<Graphic URL|path>\"" );
+ System.out.println( "\ne.g.:" );
+ System.out.println(
+ "java -jar GraphicsInserter.jar \"file:///f:/TestGraphics.gif\"" );
+ System.exit( 1 );
+ }
+
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ try {
+
+ // bootstrap UNO and get the remote component context. The context can
+ // be used to get the service manager
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+
+ // get the remote office service manager
+ com.sun.star.lang.XMultiComponentFactory xMCF =
+ xContext.getServiceManager();
+
+ /* A desktop environment contains tasks with one or more
+ frames in which components can be loaded. Desktop is the
+ environment for components which can instanciate within
+ frames. */
+ com.sun.star.frame.XDesktop xDesktop = (com.sun.star.frame.XDesktop)
+ UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class,
+ xMCF.createInstanceWithContext("com.sun.star.frame.Desktop",
+ xContext ) );
+
+ com.sun.star.frame.XComponentLoader xCompLoader =
+ (com.sun.star.frame.XComponentLoader)UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class, xDesktop);
+
+ // Load a Writer document, which will be automaticly displayed
+ com.sun.star.lang.XComponent xComp = xCompLoader.loadComponentFromURL(
+ "private:factory/swriter", "_blank", 0,
+ new com.sun.star.beans.PropertyValue[0]);
+
+ // Querying for the interface XTextDocument on the xcomponent
+ com.sun.star.text.XTextDocument xTextDoc =
+ (com.sun.star.text.XTextDocument)UnoRuntime.queryInterface(
+ com.sun.star.text.XTextDocument.class, xComp);
+
+ // Querying for the interface XMultiServiceFactory on the xtextdocument
+ com.sun.star.lang.XMultiServiceFactory xMSFDoc =
+ (com.sun.star.lang.XMultiServiceFactory)UnoRuntime.queryInterface(
+ com.sun.star.lang.XMultiServiceFactory.class, xTextDoc);
+
+ // Providing a log file for output
+ PrintWriter printwriterLog = new PrintWriter(
+ new BufferedWriter( new FileWriter("log.txt") ) );
+
+ Object oGraphic = null;
+ try {
+ // Creating the service GraphicObject
+ oGraphic =
+ xMSFDoc.createInstance("com.sun.star.text.TextGraphicObject");
+ }
+ catch ( Exception exception ) {
+ System.out.println( "Could not create instance" );
+ exception.printStackTrace( printwriterLog );
+ }
+
+ // Getting the text
+ com.sun.star.text.XText xText = xTextDoc.getText();
+
+ // Getting the cursor on the document
+ com.sun.star.text.XTextCursor xTextCursor = xText.createTextCursor();
+
+ // Querying for the interface XTextContent on the GraphicObject
+ com.sun.star.text.XTextContent xTextContent =
+ (com.sun.star.text.XTextContent)UnoRuntime.queryInterface(
+ com.sun.star.text.XTextContent.class, oGraphic );
+
+ // Printing information to the log file
+ printwriterLog.println( "inserting graphic" );
+ try {
+ // Inserting the content
+ xText.insertTextContent(xTextCursor, xTextContent, true);
+ } catch ( Exception exception ) {
+ System.out.println( "Could not insert Content" );
+ exception.printStackTrace(System.err);
+ }
+
+ // Printing information to the log file
+ printwriterLog.println( "adding graphic" );
+
+ // Querying for the interface XPropertySet on GraphicObject
+ com.sun.star.beans.XPropertySet xPropSet =
+ (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, oGraphic);
+ try {
+ // Creating a string for the graphic url
+ java.io.File sourceFile = new java.io.File(args[0]);
+ StringBuffer sUrl = new StringBuffer("file:///");
+ sUrl.append(sourceFile.getCanonicalPath().replace('\\', '/'));
+ System.out.println( "insert graphic \"" + sUrl + "\"");
+
+ // Setting the anchor type
+ xPropSet.setPropertyValue("AnchorType",
+ com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH );
+
+ // Setting the graphic url
+ xPropSet.setPropertyValue( "GraphicURL", sUrl.toString() );
+
+ // Setting the horizontal position
+ xPropSet.setPropertyValue( "HoriOrientPosition",
+ new Integer( 5500 ) );
+
+ // Setting the vertical position
+ xPropSet.setPropertyValue( "VertOrientPosition",
+ new Integer( 4200 ) );
+
+ // Setting the width
+ xPropSet.setPropertyValue( "Width", new Integer( 4400 ) );
+
+ // Setting the height
+ xPropSet.setPropertyValue( "Height", new Integer( 4000 ) );
+ } catch ( Exception exception ) {
+ System.out.println( "Couldn't set property 'GraphicURL'" );
+ exception.printStackTrace( printwriterLog );
+ }
+
+ xContext = null;
+
+ System.exit(0);
+ }
+ catch( Exception e ) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+ }
+}
diff --git a/odk/examples/java/Text/HardFormatting.java b/odk/examples/java/Text/HardFormatting.java
new file mode 100644
index 000000000000..b1ec48da7cb7
--- /dev/null
+++ b/odk/examples/java/Text/HardFormatting.java
@@ -0,0 +1,286 @@
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+//***************************************************************************
+// comment: Step 1: get the Desktop object from the office
+// Step 2: open an empty text document
+// Step 3: enter a example text
+// Step 4: get some text attributes
+// Step 5: check the PropertyState from the selection
+//
+// Chapter 4.1.4 Hard formatting
+//***************************************************************************
+
+import com.sun.star.uno.UnoRuntime;
+
+public class HardFormatting {
+
+ public static void main(String args[]) {
+ // You need the desktop to create a document
+ // The getDesktop method does the UNO bootstrapping, gets the
+ // remote servie manager and the desktop object.
+ com.sun.star.frame.XDesktop xDesktop = null;
+ xDesktop = getDesktop();
+
+ try {
+ // create text document
+ com.sun.star.text.XTextDocument xTextDocument = null;
+ xTextDocument = createTextdocument(xDesktop);
+
+ // the text interface contains all methods and properties to
+ // manipulate the content from a text document
+ com.sun.star.text.XText xText = null;
+ xText = xTextDocument.getText();
+
+ String sMyText = "A very short paragraph for illustration only";
+
+ // you can travel with the cursor throught the text document.
+ // you travel only at the model, not at the view. The cursor that you can
+ // see on the document doesn't change the position
+ com.sun.star.text.XTextCursor xTextCursor = null;
+ xTextCursor = (com.sun.star.text.XTextCursor)
+ xTextDocument.getText().createTextCursor();
+
+ xText.insertString( xTextCursor, "Headline", false );
+ xText.insertControlCharacter(xTextCursor,
+ com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false);
+
+ xText.insertString(xTextCursor, sMyText, false);
+
+ com.sun.star.text.XTextRange xTextRange = null;
+ com.sun.star.beans.XPropertySet xPropertySet = null;
+
+ // BEGIN: 'Hard formating'
+ // the text range not the cursor contains the 'parastyle' property
+ xTextRange = xText.getEnd();
+ xPropertySet = (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xTextRange);
+
+ // create a paragraph cursor to travel throught the paragraphs
+ com.sun.star.text.XParagraphCursor xParagraphCursor = null;
+ xParagraphCursor = (com.sun.star.text.XParagraphCursor)
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XParagraphCursor.class, xTextRange);
+
+ xParagraphCursor.gotoStart( false );
+ xParagraphCursor.gotoEndOfParagraph( true );
+ xTextRange = xParagraphCursor.getText().getStart();
+
+ // create a WordCursor to travel into the paragraph
+ com.sun.star.text.XWordCursor xWordCursor = null;
+ xWordCursor = (com.sun.star.text.XWordCursor) UnoRuntime.queryInterface(
+ com.sun.star.text.XWordCursor.class, xTextRange);
+
+ // the PropertySet from the cursor contains the text attributes
+ xPropertySet = (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xWordCursor);
+ System.out.println(
+ "Parastyle : "
+ +xPropertySet.getPropertyValue("ParaStyleName").toString()
+ + "\nFontname : "
+ + xPropertySet.getPropertyValue("CharFontName").toString()
+ + "\nWeight : "
+ + xPropertySet.getPropertyValue("CharWeight").toString() );
+
+ xWordCursor.gotoNextWord(false);
+ xWordCursor.gotoNextWord(false);
+ xWordCursor.gotoEndOfWord(true);
+
+ xPropertySet = (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xWordCursor);
+ xPropertySet.setPropertyValue("CharWeight",
+ new Float(com.sun.star.awt.FontWeight.BOLD));
+ xPropertySet.setPropertyValue("CharColor", new Integer( 255 ) );
+
+ System.out.println(
+ "Parastyle : "
+ + xPropertySet.getPropertyValue("ParaStyleName").toString()
+ + "\nFontname : "
+ + xPropertySet.getPropertyValue("CharFontName").toString()
+ + "\nWeight : "
+ + xPropertySet.getPropertyValue("CharWeight").toString() );
+
+ // the PropertyState contains information where the attribute is set,
+ // is a text part hard formated or not.
+ com.sun.star.beans.XPropertyState xPropertyState = null;
+ xPropertyState = (com.sun.star.beans.XPropertyState)
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertyState.class, xWordCursor);
+
+ com.sun.star.beans.PropertyState xPropertyStateValue =
+ xPropertyState.getPropertyState("CharWeight");
+
+ checkPropertyState( xWordCursor, xPropertyStateValue );
+
+ xWordCursor.goRight( (short) 3 , true );
+ xPropertyStateValue = xPropertyState.getPropertyState("CharWeight");
+
+ System.out.println("Increase the selection with three characters");
+ checkPropertyState(xWordCursor, xPropertyStateValue);
+
+ xPropertyState.setPropertyToDefault("CharWeight");
+
+ System.out.println("Set the default value on the selection");
+ xPropertyStateValue = xPropertyState.getPropertyState("CharWeight");
+ checkPropertyState(xWordCursor, xPropertyStateValue);
+
+ // END: 'Hard formating' Section from the Cookbook
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+
+ System.out.println("Done");
+
+ System.exit(0);
+
+ }
+
+
+ public static void checkPropertyState(
+ com.sun.star.text.XWordCursor xWordCursor,
+ com.sun.star.beans.PropertyState xPropertyStateValue )
+ {
+ switch( xPropertyStateValue.getValue() ) {
+ case com.sun.star.beans.PropertyState.DIRECT_VALUE_value: {
+ System.out.println( "-> The selection '"
+ + xWordCursor.getString()
+ + "' completly hard formated" );
+ break;
+ }
+
+ case com.sun.star.beans.PropertyState.DEFAULT_VALUE_value: {
+ System.out.println( "-> The selection '"
+ + xWordCursor.getString()
+ + "' isn't hard formated" );
+ break;
+ }
+
+ case com.sun.star.beans.PropertyState.AMBIGUOUS_VALUE_value: {
+ System.out.println( "-> The selection '"
+ + xWordCursor.getString()
+ + "' isn't completly hard formated" );
+ break;
+ }
+
+ default:
+ System.out.println( "No PropertyState found" );
+ }
+ }
+
+ public static com.sun.star.frame.XDesktop getDesktop() {
+ com.sun.star.frame.XDesktop xDesktop = null;
+ com.sun.star.lang.XMultiComponentFactory xMCF = null;
+
+ try {
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+
+ // get the remote office service manager
+ xMCF = xContext.getServiceManager();
+ if( xMCF != null ) {
+ System.out.println("Connected to a running office ...");
+
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext);
+ xDesktop = (com.sun.star.frame.XDesktop) UnoRuntime.queryInterface(
+ com.sun.star.frame.XDesktop.class, oDesktop);
+ }
+ else
+ System.out.println( "Can't create a desktop. No connection, no remote office servicemanager available!" );
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+
+ return xDesktop;
+ }
+
+ public static com.sun.star.text.XTextDocument createTextdocument(
+ com.sun.star.frame.XDesktop xDesktop )
+ {
+ com.sun.star.text.XTextDocument aTextDocument = null;
+
+ try {
+ com.sun.star.lang.XComponent xComponent = CreateNewDocument(xDesktop,
+ "swriter");
+ aTextDocument = (com.sun.star.text.XTextDocument)
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XTextDocument.class, xComponent);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return aTextDocument;
+ }
+
+
+ protected static com.sun.star.lang.XComponent CreateNewDocument(
+ com.sun.star.frame.XDesktop xDesktop,
+ String sDocumentType )
+ {
+ String sURL = "private:factory/" + sDocumentType;
+
+ com.sun.star.lang.XComponent xComponent = null;
+ com.sun.star.frame.XComponentLoader xComponentLoader = null;
+ com.sun.star.beans.PropertyValue xValues[] =
+ new com.sun.star.beans.PropertyValue[1];
+ com.sun.star.beans.PropertyValue xEmptyArgs[] =
+ new com.sun.star.beans.PropertyValue[0];
+
+ try {
+ xComponentLoader = (com.sun.star.frame.XComponentLoader)
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class, xDesktop);
+
+ xComponent = xComponentLoader.loadComponentFromURL(
+ sURL, "_blank", 0, xEmptyArgs);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return xComponent ;
+ }
+}
diff --git a/odk/examples/java/Text/Makefile b/odk/examples/java/Text/Makefile
new file mode 100644
index 000000000000..9fb4b6226407
--- /dev/null
+++ b/odk/examples/java/Text/Makefile
@@ -0,0 +1,136 @@
+#*************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# the BSD license.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#**************************************************************************
+
+# Builds the Java Text examples of the SDK.
+
+PRJ=../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+EXAMPLE_NAME=JavaTextExamples
+OUT_APP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME)
+
+APP1_NAME=BookmarkInsertion
+APP1_JAR=$(OUT_APP_CLASS)/$(APP1_NAME).jar
+APP2_NAME=HardFormatting
+APP2_JAR=$(OUT_APP_CLASS)/$(APP2_NAME).jar
+APP3_NAME=StyleCreation
+APP3_JAR=$(OUT_APP_CLASS)/$(APP3_NAME).jar
+APP4_NAME=StyleInitialization
+APP4_JAR=$(OUT_APP_CLASS)/$(APP4_NAME).jar
+APP5_NAME=SWriter
+APP5_JAR=$(OUT_APP_CLASS)/$(APP5_NAME).jar
+APP6_NAME=TextDocumentStructure
+APP6_JAR=$(OUT_APP_CLASS)/$(APP6_NAME).jar
+APP7_NAME=TextReplace
+APP7_JAR=$(OUT_APP_CLASS)/$(APP7_NAME).jar
+APP8_NAME=WriterSelector
+APP8_JAR=$(OUT_APP_CLASS)/$(APP8_NAME).jar
+APP9_NAME=GraphicsInserter
+APP9_JAR=$(OUT_APP_CLASS)/$(APP9_NAME).jar
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(OUT_APP_CLASS))
+
+# Targets
+.PHONY: ALL
+ALL : \
+ $(EXAMPLE_NAME)
+
+include $(SETTINGS)/stdtarget.mk
+
+$(OUT_APP_CLASS)/%.class : %.java
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_APP_CLASS) $<
+
+$(OUT_APP_CLASS)/%.mf :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo Main-Class: com.sun.star.lib.loader.Loader> $@
+ $(ECHOLINE)>> $@
+ @echo Name: com/sun/star/lib/loader/Loader.class>> $@
+ @echo Application-Class: $*>> $@
+
+$(OUT_APP_CLASS)/%.jar : $(OUT_APP_CLASS)/%.mf $(OUT_APP_CLASS)/%.class
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ +cd $(subst /,$(PS),$(OUT_APP_CLASS)) && $(SDK_JAR) cvfm $(@F) $*.mf $*.class
+ +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
+
+
+$(APP1_JAR) : $(OUT_APP_CLASS)/$(APP1_NAME).mf $(OUT_APP_CLASS)/$(APP1_NAME).class
+$(APP2_JAR) : $(OUT_APP_CLASS)/$(APP2_NAME).mf $(OUT_APP_CLASS)/$(APP2_NAME).class
+$(APP3_JAR) : $(OUT_APP_CLASS)/$(APP3_NAME).mf $(OUT_APP_CLASS)/$(APP3_NAME).class
+$(APP4_JAR) : $(OUT_APP_CLASS)/$(APP4_NAME).mf $(OUT_APP_CLASS)/$(APP4_NAME).class
+$(APP5_JAR) : $(OUT_APP_CLASS)/$(APP5_NAME).mf $(OUT_APP_CLASS)/$(APP5_NAME).class
+$(APP6_JAR) : $(OUT_APP_CLASS)/$(APP6_NAME).mf $(OUT_APP_CLASS)/$(APP6_NAME).class
+$(APP7_JAR) : $(OUT_APP_CLASS)/$(APP7_NAME).mf $(OUT_APP_CLASS)/$(APP7_NAME).class
+$(APP8_JAR) : $(OUT_APP_CLASS)/$(APP8_NAME).mf $(OUT_APP_CLASS)/$(APP8_NAME).class
+$(APP9_JAR) : $(OUT_APP_CLASS)/$(APP9_NAME).mf $(OUT_APP_CLASS)/$(APP9_NAME).class
+
+$(EXAMPLE_NAME) : $(APP1_JAR) $(APP2_JAR) $(APP3_JAR) $(APP4_JAR) $(APP5_JAR) $(APP6_JAR) $(APP7_JAR) $(APP8_JAR) $(APP9_JAR)
+ @echo --------------------------------------------------------------------------------
+ @echo The GraphicsInserter example loads the graphic "$(QM)./oo_smiley.gif$(QM)" into a
+ @echo new document.
+ @echo -
+ @echo Please use one of the following commands to execute the examples!
+ @echo ------
+ @echo $(MAKE) BookmarkInsertion.run
+ @echo $(MAKE) HardFormatting.run
+ @echo $(MAKE) StyleCreation.run
+ @echo $(MAKE) StyleInitialization.run
+ @echo $(MAKE) SWriter.run
+ @echo $(MAKE) TextDocumentStructure.run
+ @echo $(MAKE) TextReplace.run
+ @echo $(MAKE) WriterSelector.run
+ @echo $(MAKE) GraphicsInserter.run
+ @echo --------
+ @echo The GraphicsInserter needs parameters. Please use the following command to
+ @echo start the demo if you do not want the default parameters specified in the
+ @echo this makefile. Starting without parameters print a command line help:
+ @echo --- GraphicsInserter ---
+ @echo java -jar GraphicsInserter.jar "$(QM)graphic Url|path$(QM)"
+ @echo --------------------------------------------------------------------------------
+
+%.run: $(OUT_APP_CLASS)/%.jar
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $<
+
+GraphicsInserter.run: $(OUT_APP_CLASS)/GraphicsInserter.jar
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $< oo_smiley.gif
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_CLASS))
diff --git a/odk/examples/java/Text/SWriter.java b/odk/examples/java/Text/SWriter.java
new file mode 100644
index 000000000000..18ae35481189
--- /dev/null
+++ b/odk/examples/java/Text/SWriter.java
@@ -0,0 +1,397 @@
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+//***************************************************************************
+// comment: Step 1: bootstrap UNO and get the remote component context
+// Step 2: open an empty text document
+// Step 3: enter some text
+// Step 4: insert a text table
+// Step 5: insert colored text
+// Step 6: insert a text frame
+//***************************************************************************
+
+import com.sun.star.uno.UnoRuntime;
+
+public class SWriter {
+
+ public static void main(String args[]) {
+
+
+ //oooooooooooooooooooooooooooStep 1oooooooooooooooooooooooooooooooooooooooo
+ // bootstrap UNO and get the remote component context. The context can
+ // be used to get the service manager
+ //*************************************************************************
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ try {
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ if( xContext != null )
+ System.out.println("Connected to a running office ...");
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+ //oooooooooooooooooooooooooooStep 2oooooooooooooooooooooooooooooooooooooooo
+ // open an empty document. In this case it's a writer document.
+ // For this purpose an instance of com.sun.star.frame.Desktop
+ // is created. It's interface XDesktop provides the XComponentLoader,
+ // which is used to open the document via loadComponentFromURL
+ //*************************************************************************
+
+ //Open Writer document
+
+ System.out.println("Opening an empty Writer document");
+ com.sun.star.text.XTextDocument myDoc = openWriter(xContext);
+
+ //*************************************************************************
+
+
+ //oooooooooooooooooooooooooooStep 3oooooooooooooooooooooooooooooooooooooooo
+ // insert some text.
+ // For this purpose get the Text-Object of the document an create the
+ // cursor. Now it is possible to insert a text at the cursor-position
+ // via insertString
+ //*************************************************************************
+
+
+ //getting the text object
+ com.sun.star.text.XText xText = myDoc.getText();
+
+ //create a cursor object
+ com.sun.star.text.XTextCursor xTCursor = xText.createTextCursor();
+
+ //inserting some Text
+ xText.insertString( xTCursor, "The first line in the newly created text document.\n", false );
+
+ //inserting a second line
+ xText.insertString( xTCursor, "Now we're in the second line\n", false );
+
+ //*************************************************************************
+
+
+ //oooooooooooooooooooooooooooStep 4oooooooooooooooooooooooooooooooooooooooo
+ // insert a text table.
+ // For this purpose get MultiServiceFactory of the document, create an
+ // instance of com.sun.star.text.TextTable and initialize it. Now it can
+ // be inserted at the cursor position via insertTextContent.
+ // After that some properties are changed and some data is inserted.
+ //*************************************************************************
+
+ //inserting a text table
+ System.out.println("Inserting a text table");
+
+ //getting MSF of the document
+ com.sun.star.lang.XMultiServiceFactory xDocMSF =
+ (com.sun.star.lang.XMultiServiceFactory) UnoRuntime.queryInterface(
+ com.sun.star.lang.XMultiServiceFactory.class, myDoc);
+
+ //create instance of a text table
+ com.sun.star.text.XTextTable xTT = null;
+
+ try {
+ Object oInt = xDocMSF.createInstance("com.sun.star.text.TextTable");
+ xTT = (com.sun.star.text.XTextTable)
+ UnoRuntime.queryInterface(com.sun.star.text.XTextTable.class,oInt);
+ } catch (Exception e) {
+ System.err.println("Couldn't create instance "+ e);
+ e.printStackTrace(System.err);
+ }
+
+ //initialize the text table with 4 columns an 4 rows
+ xTT.initialize(4,4);
+
+ com.sun.star.beans.XPropertySet xTTRowPS = null;
+
+ //insert the table
+ try {
+ xText.insertTextContent(xTCursor, xTT, false);
+ // get first Row
+ com.sun.star.container.XIndexAccess xTTRows = xTT.getRows();
+ xTTRowPS = (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xTTRows.getByIndex(0));
+
+ } catch (Exception e) {
+ System.err.println("Couldn't insert the table " + e);
+ e.printStackTrace(System.err);
+ }
+
+
+ // get the property set of the text table
+
+ com.sun.star.beans.XPropertySet xTTPS = (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, xTT);
+
+ // Change the BackColor
+ try {
+ xTTPS.setPropertyValue("BackTransparent", new Boolean(false));
+ xTTPS.setPropertyValue("BackColor",new Integer(13421823));
+ xTTRowPS.setPropertyValue("BackTransparent", new Boolean(false));
+ xTTRowPS.setPropertyValue("BackColor",new Integer(6710932));
+
+ } catch (Exception e) {
+ System.err.println("Couldn't change the color " + e);
+ e.printStackTrace(System.err);
+ }
+
+ // write Text in the Table headers
+ System.out.println("Write text in the table headers");
+
+ insertIntoCell("A1","FirstColumn", xTT);
+ insertIntoCell("B1","SecondColumn", xTT) ;
+ insertIntoCell("C1","ThirdColumn", xTT) ;
+ insertIntoCell("D1","SUM", xTT) ;
+
+
+ //Insert Something in the text table
+ System.out.println("Insert something in the text table");
+
+ (xTT.getCellByName("A2")).setValue(22.5);
+ (xTT.getCellByName("B2")).setValue(5615.3);
+ (xTT.getCellByName("C2")).setValue(-2315.7);
+ (xTT.getCellByName("D2")).setFormula("sum <A2:C2>");
+
+ (xTT.getCellByName("A3")).setValue(21.5);
+ (xTT.getCellByName("B3")).setValue(615.3);
+ (xTT.getCellByName("C3")).setValue(-315.7);
+ (xTT.getCellByName("D3")).setFormula("sum <A3:C3>");
+
+ (xTT.getCellByName("A4")).setValue(121.5);
+ (xTT.getCellByName("B4")).setValue(-615.3);
+ (xTT.getCellByName("C4")).setValue(415.7);
+ (xTT.getCellByName("D4")).setFormula("sum <A4:C4>");
+
+
+ //oooooooooooooooooooooooooooStep 5oooooooooooooooooooooooooooooooooooooooo
+ // insert a colored text.
+ // Get the propertySet of the cursor, change the CharColor and add a
+ // shadow. Then insert the Text via InsertString at the cursor position.
+ //*************************************************************************
+
+ // get the property set of the cursor
+ com.sun.star.beans.XPropertySet xTCPS = (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,
+ xTCursor);
+
+ Object oldValue = null;
+
+ // Change the CharColor and add a Shadow
+ try {
+ xTCPS.setPropertyValue("CharColor",new Integer(255));
+ xTCPS.setPropertyValue("CharShadowed", new Boolean(true));
+ } catch (Exception e) {
+ System.err.println("Couldn't change the color " + e);
+ e.printStackTrace(System.err);
+ }
+
+ //create a paragraph break
+ try {
+ xText.insertControlCharacter(xTCursor,
+ com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false);
+
+ } catch (Exception e) {
+ System.err.println("Couldn't insert break "+ e);
+ e.printStackTrace(System.err);
+ }
+
+ //inserting colored Text
+ System.out.println("Inserting colored Text");
+
+ xText.insertString(xTCursor, " This is a colored Text - blue with shadow\n",
+ false );
+
+ //create a paragraph break
+ try {
+ xText.insertControlCharacter(xTCursor,
+ com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false);
+
+ } catch (Exception e) {
+ System.err.println("Couldn't insert break "+ e);
+ e.printStackTrace(System.err);
+ }
+
+ //oooooooooooooooooooooooooooStep 6oooooooooooooooooooooooooooooooooooooooo
+ // insert a text frame.
+ // create an instance of com.sun.star.text.TextFrame using the MSF of the
+ // document. Change some properties an insert it.
+ // Now get the text-Object of the frame an the corresponding cursor.
+ // Insert some text via insertString.
+ //*************************************************************************
+
+ // Create a TextFrame
+ com.sun.star.text.XTextFrame xTF = null;
+ com.sun.star.drawing.XShape xTFS = null;
+
+ try {
+ Object oInt = xDocMSF.createInstance("com.sun.star.text.TextFrame");
+ xTF = (com.sun.star.text.XTextFrame) UnoRuntime.queryInterface(
+ com.sun.star.text.XTextFrame.class,oInt);
+ xTFS = (com.sun.star.drawing.XShape) UnoRuntime.queryInterface(
+ com.sun.star.drawing.XShape.class,oInt);
+
+ com.sun.star.awt.Size aSize = new com.sun.star.awt.Size();
+ aSize.Height = 400;
+ aSize.Width = 15000;
+
+ xTFS.setSize(aSize);
+ } catch (Exception e) {
+ System.err.println("Couldn't create instance "+ e);
+ e.printStackTrace(System.err);
+ }
+
+ // get the property set of the text frame
+ com.sun.star.beans.XPropertySet xTFPS = (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, xTF);
+
+ // Change the AnchorType
+ try {
+ xTFPS.setPropertyValue("AnchorType",
+ com.sun.star.text.TextContentAnchorType.AS_CHARACTER);
+ } catch (Exception e) {
+ System.err.println("Couldn't change the color " + e);
+ e.printStackTrace(System.err);
+ }
+
+ //insert the frame
+ System.out.println("Insert the text frame");
+
+ try {
+ xText.insertTextContent(xTCursor, xTF, false);
+ } catch (Exception e) {
+ System.err.println("Couldn't insert the frame " + e);
+ e.printStackTrace(System.err);
+ }
+
+ //getting the text object of Frame
+ com.sun.star.text.XText xTextF = xTF.getText();
+
+ //create a cursor object
+ com.sun.star.text.XTextCursor xTCF = xTextF.createTextCursor();
+
+ //inserting some Text
+ xTextF.insertString(xTCF,
+ "The first line in the newly created text frame.", false);
+
+
+ xTextF.insertString(xTCF,
+ "\nWith this second line the height of the frame raises.", false);
+
+ //insert a paragraph break
+ try {
+ xText.insertControlCharacter(xTCursor,
+ com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false );
+
+ } catch (Exception e) {
+ System.err.println("Couldn't insert break "+ e);
+ e.printStackTrace(System.err);
+ }
+
+ // Change the CharColor and add a Shadow
+ try {
+ xTCPS.setPropertyValue("CharColor",new Integer(65536));
+ xTCPS.setPropertyValue("CharShadowed", new Boolean(false));
+ } catch (Exception e) {
+ System.err.println("Couldn't change the color " + e);
+ e.printStackTrace(System.err);
+ }
+
+ xText.insertString(xTCursor, " That's all for now !!", false );
+
+ System.out.println("done");
+
+ System.exit(0);
+ }
+
+
+ public static com.sun.star.text.XTextDocument openWriter(
+ com.sun.star.uno.XComponentContext xContext)
+ {
+ //define variables
+ com.sun.star.frame.XComponentLoader xCLoader;
+ com.sun.star.text.XTextDocument xDoc = null;
+ com.sun.star.lang.XComponent xComp = null;
+
+ try {
+ // get the remote office service manager
+ com.sun.star.lang.XMultiComponentFactory xMCF =
+ xContext.getServiceManager();
+
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext);
+
+ xCLoader = (com.sun.star.frame.XComponentLoader)
+ UnoRuntime.queryInterface(com.sun.star.frame.XComponentLoader.class,
+ oDesktop);
+ com.sun.star.beans.PropertyValue [] szEmptyArgs =
+ new com.sun.star.beans.PropertyValue [0];
+ String strDoc = "private:factory/swriter";
+ xComp = xCLoader.loadComponentFromURL(strDoc, "_blank", 0, szEmptyArgs);
+ xDoc = (com.sun.star.text.XTextDocument)
+ UnoRuntime.queryInterface(com.sun.star.text.XTextDocument.class,
+ xComp);
+
+ } catch(Exception e){
+ System.err.println(" Exception " + e);
+ e.printStackTrace(System.err);
+ }
+ return xDoc;
+ }
+
+ public static void insertIntoCell(String CellName, String theText,
+ com.sun.star.text.XTextTable xTTbl) {
+
+ com.sun.star.text.XText xTableText = (com.sun.star.text.XText)
+ UnoRuntime.queryInterface(com.sun.star.text.XText.class,
+ xTTbl.getCellByName(CellName));
+
+ //create a cursor object
+ com.sun.star.text.XTextCursor xTC = xTableText.createTextCursor();
+
+ com.sun.star.beans.XPropertySet xTPS = (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, xTC);
+
+ try {
+ xTPS.setPropertyValue("CharColor",new Integer(16777215));
+ } catch (Exception e) {
+ System.err.println(" Exception " + e);
+ e.printStackTrace(System.err);
+ }
+
+ //inserting some Text
+ xTableText.setString( theText );
+
+ }
+}
diff --git a/odk/examples/java/Text/StyleCreation.java b/odk/examples/java/Text/StyleCreation.java
new file mode 100644
index 000000000000..91cfb3f7a8c6
--- /dev/null
+++ b/odk/examples/java/Text/StyleCreation.java
@@ -0,0 +1,226 @@
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+//***************************************************************************
+// comment: Step 1: get the Desktop object from the office
+// Step 2: open an empty text document
+// Step 3: create a new Paragraph style
+// Step 4: apply the Paragraph style
+//
+// Chapter 4.1.3 Defining Your Own Style
+//***************************************************************************
+
+import com.sun.star.uno.UnoRuntime;
+
+
+public class StyleCreation {
+ public static void main(String args[]) {
+ // You need the desktop to create a document
+ // The getDesktop method does the UNO bootstrapping, gets the
+ // remote servie manager and the desktop object.
+ com.sun.star.frame.XDesktop xDesktop = null;
+ xDesktop = getDesktop();
+
+ try {
+ // create text document
+ com.sun.star.text.XTextDocument xTextDocument = null;
+ xTextDocument = createTextdocument(xDesktop);
+
+ // the service '..ParagraphStyle' is context dependend, you need
+ // the multi service factory from the document to use the service
+ com.sun.star.lang.XMultiServiceFactory xDocMSF =
+ (com.sun.star.lang.XMultiServiceFactory)UnoRuntime.queryInterface(
+ com.sun.star.lang.XMultiServiceFactory.class, xTextDocument);
+
+ // use the service 'com.sun.star.style.ParagraphStyle'
+ com.sun.star.uno.XInterface xInterface = (com.sun.star.uno.XInterface)
+ xDocMSF.createInstance("com.sun.star.style.ParagraphStyle");
+
+ // create a supplier to get the Style family collection
+ com.sun.star.style.XStyleFamiliesSupplier xSupplier =
+ (com.sun.star.style.XStyleFamiliesSupplier)UnoRuntime.queryInterface(
+ com.sun.star.style.XStyleFamiliesSupplier.class, xTextDocument );
+
+ // get the NameAccess interface from the Style family collection
+ com.sun.star.container.XNameAccess xNameAccess =
+ xSupplier.getStyleFamilies();
+
+ // select the Paragraph styles, you get the Paragraph style collection
+ com.sun.star.container.XNameContainer xParaStyleCollection =
+ (com.sun.star.container.XNameContainer) UnoRuntime.queryInterface(
+ com.sun.star.container.XNameContainer.class,
+ xNameAccess.getByName("ParagraphStyles"));
+
+ // create a PropertySet to set the properties for the new Paragraphstyle
+ com.sun.star.beans.XPropertySet xPropertySet =
+ (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xInterface );
+ System.out.println( "create a PropertySet to set the properties for the new Paragraphstyle" );
+
+ // set some properties from the Paragraph style
+ xPropertySet.setPropertyValue("CharFontName", new String( "Helvetica" ) );
+ System.out.println( "set name of the font to 'Helvetica'" );
+
+ xPropertySet.setPropertyValue("CharHeight", new Float( 36 ) );
+ System.out.println( "Change the height of th font to 36" );
+
+ xPropertySet.setPropertyValue("CharWeight",
+ new Float( com.sun.star.awt.FontWeight.BOLD ) );
+ System.out.println( "set the font attribute 'Bold'" );
+
+ xPropertySet.setPropertyValue("CharAutoKerning", new Boolean( true ) );
+ System.out.println( "set the paragraph attribute 'AutoKerning'" );
+ xPropertySet.setPropertyValue("ParaAdjust",
+ new Integer( com.sun.star.style.ParagraphAdjust.CENTER_value ) );
+ System.out.println( "set the paragraph adjust to LEFT" );
+
+ xPropertySet.setPropertyValue("ParaFirstLineIndent", new Integer( 0 ) );
+ System.out.println( "set the first line indent to 0 cm" );
+
+ xPropertySet.setPropertyValue("BreakType",
+ com.sun.star.style.BreakType.PAGE_AFTER );
+ System.out.println( "set the paragraph attribute Breaktype to PageAfter" );
+
+ // insert the new Paragraph style in the Paragraph style collection
+ xParaStyleCollection.insertByName( "myheading", xPropertySet );
+ System.out.println( "create new paragraph style, with the values from the Propertyset");
+
+ // get the Textrange from the document
+ com.sun.star.text.XTextRange xTextRange =
+ xTextDocument.getText().getStart();
+
+ // get the PropertySet from the current paragraph
+ com.sun.star.beans.XPropertySet xParagraphPropertySet =
+ (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xTextRange );
+ // change the value from the property 'ParaStyle' to apply the
+ // Paragraph style
+ // To run the sample with StarOffice 5.2 you'll have to change
+ // 'ParaStyleName' to 'ParaStyle' in the next line
+ xParagraphPropertySet.setPropertyValue("ParaStyleName",
+ new String( "myheading" ) );
+ System.out.println( "apply the new paragraph style");
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+ System.out.println("done");
+
+ System.exit(0);
+ }
+
+
+ public static com.sun.star.frame.XDesktop getDesktop() {
+ com.sun.star.frame.XDesktop xDesktop = null;
+ com.sun.star.lang.XMultiComponentFactory xMCF = null;
+
+ try {
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+
+ // get the remote office service manager
+ xMCF = xContext.getServiceManager();
+ if( xMCF != null ) {
+ System.out.println("Connected to a running office ...");
+
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext);
+ xDesktop = (com.sun.star.frame.XDesktop) UnoRuntime.queryInterface(
+ com.sun.star.frame.XDesktop.class, oDesktop);
+ }
+ else
+ System.out.println( "Can't create a desktop. No connection, no remote office servicemanager available!" );
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+
+ return xDesktop;
+ }
+
+ public static com.sun.star.text.XTextDocument createTextdocument(
+ com.sun.star.frame.XDesktop xDesktop )
+ {
+ com.sun.star.text.XTextDocument aTextDocument = null;
+
+ try {
+ com.sun.star.lang.XComponent xComponent = CreateNewDocument(xDesktop,
+ "swriter");
+ aTextDocument = (com.sun.star.text.XTextDocument)
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XTextDocument.class, xComponent);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return aTextDocument;
+ }
+
+
+ protected static com.sun.star.lang.XComponent CreateNewDocument(
+ com.sun.star.frame.XDesktop xDesktop,
+ String sDocumentType )
+ {
+ String sURL = "private:factory/" + sDocumentType;
+
+ com.sun.star.lang.XComponent xComponent = null;
+ com.sun.star.frame.XComponentLoader xComponentLoader = null;
+ com.sun.star.beans.PropertyValue xValues[] =
+ new com.sun.star.beans.PropertyValue[1];
+ com.sun.star.beans.PropertyValue xEmptyArgs[] =
+ new com.sun.star.beans.PropertyValue[0];
+
+ try {
+ xComponentLoader = (com.sun.star.frame.XComponentLoader)
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class, xDesktop);
+
+ xComponent = xComponentLoader.loadComponentFromURL(
+ sURL, "_blank", 0, xEmptyArgs);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return xComponent ;
+ }
+}
+
diff --git a/odk/examples/java/Text/StyleInitialization.java b/odk/examples/java/Text/StyleInitialization.java
new file mode 100644
index 000000000000..c08243609499
--- /dev/null
+++ b/odk/examples/java/Text/StyleInitialization.java
@@ -0,0 +1,320 @@
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+//***************************************************************************
+// comment: Step 1: get the Desktop object from the office
+// Step 2: open an empty text document
+// Step 3: enter a example text
+// Step 4: use the paragraph collection
+// Step 5: apply a different paragraph style on the paragraphs
+//***************************************************************************
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.AnyConverter;
+
+public class StyleInitialization {
+
+ public static void main(String args[]) {
+ // You need the desktop to create a document
+ // The getDesktop method does the UNO bootstrapping, gets the
+ // remote servie manager and the desktop object.
+ com.sun.star.frame.XDesktop xDesktop = null;
+ xDesktop = getDesktop();
+
+ try {
+ // BEGIN: 'Style basics' Section from the Tutorial
+
+ // create text document
+ com.sun.star.text.XTextDocument xTextDocument = null;
+ xTextDocument = createTextdocument( xDesktop );
+
+ // the text interface contains all methods and properties to
+ // manipulate the content from a text document
+ com.sun.star.text.XText xText = null;
+ xText = xTextDocument.getText();
+
+ String sMyText = "A very short paragraph for illustration only";
+
+ // you can travel with the cursor throught the text document.
+ // you travel only at the model, not at the view. The cursor that you can
+ // see on the document doesn't change the position
+ com.sun.star.text.XTextCursor xTextCursor = null;
+ xTextCursor = (com.sun.star.text.XTextCursor)
+ xTextDocument.getText().createTextCursor();
+
+ com.sun.star.beans.XPropertySet oCPS = (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xTextCursor);
+ try {
+ oCPS.setPropertyValue("CharFontName","Helvetica");
+ }
+ catch (Exception ex) {
+
+ }
+
+ xText.insertString( xTextCursor, "Headline", false );
+
+ try {
+ oCPS.setPropertyValue("CharFontName","Times");
+ }
+ catch (Exception ex) {
+
+ }
+ xText.insertControlCharacter(xTextCursor,
+ com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false);
+
+ xText.insertString( xTextCursor, sMyText, false );
+
+ com.sun.star.text.XTextRange xTextRange = null;
+ com.sun.star.beans.XPropertySet xPropertySet = null;
+
+ // the text range not the cursor contains the 'parastyle' property
+ xTextRange = xText.getEnd();
+ xPropertySet = (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xTextRange );
+
+ // To run the sample with StarOffice 5.2 you'll have to change
+ // 'ParaStyleName' to 'ParaStyle' in the next line
+ System.out.println( "Current Parastyle : "
+ + xPropertySet.getPropertyValue("ParaStyleName") );
+
+ // END: 'Style basics' Section from the Tutorial
+
+ // There are two way to travel throught the paragraphs, with a
+ // paragraph cursor, or a enumeration.
+ // You find both ways in this example
+
+ // The first way, with the paragraph cursor
+ com.sun.star.text.XParagraphCursor xParagraphCursor = null;
+ xParagraphCursor = (com.sun.star.text.XParagraphCursor)
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XParagraphCursor.class, xTextRange );
+
+ xParagraphCursor.gotoStart( false );
+ xParagraphCursor.gotoEndOfParagraph( true );
+
+ // The second way, with the paragraph enumeration
+ com.sun.star.container.XEnumerationAccess xEnumerationAccess = null;
+ xEnumerationAccess = (com.sun.star.container.XEnumerationAccess)
+ UnoRuntime.queryInterface(
+ com.sun.star.container.XEnumerationAccess.class, xText );
+
+ // the enumeration contains all paragraph form the document
+ com.sun.star.container.XEnumeration xParagraphEnumeration = null;
+ xParagraphEnumeration = xEnumerationAccess.createEnumeration();
+
+ com.sun.star.text.XTextContent xParagraph = null;
+ com.sun.star.text.XTextRange xWord = null;
+
+ com.sun.star.container.XEnumerationAccess xParaEnumerationAccess = null;
+ com.sun.star.container.XEnumeration xPortionEnumeration = null;
+
+ // check if a paragraph is available
+ while ( xParagraphEnumeration.hasMoreElements() ) {
+ // get the next paragraph
+ xParagraph = (com.sun.star.text.XTextContent)
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XTextContent.class,
+ xParagraphEnumeration.nextElement());
+
+ // you need the method getAnchor to a TextRange -> to manipulate
+ // the paragraph
+ String sText = xParagraph.getAnchor().getString();
+
+ // create a cursor from this paragraph
+ com.sun.star.text.XTextCursor xParaCursor = null;
+ xParaCursor = xParagraph.getAnchor().getText().createTextCursor();
+
+ // goto the start and end of the paragraph
+ xParaCursor.gotoStart( false );
+ xParaCursor.gotoEnd( true );
+
+ // The enumeration from the paragraphs contain parts from the
+ // paragraph with a different attributes.
+ xParaEnumerationAccess = (com.sun.star.container.XEnumerationAccess)
+ UnoRuntime.queryInterface(
+ com.sun.star.container.XEnumerationAccess.class, xParagraph);
+ xPortionEnumeration = xParaEnumerationAccess.createEnumeration();
+
+ while ( xPortionEnumeration.hasMoreElements() ) {
+ // output of all parts from the paragraph with different attributes
+ xWord = (com.sun.star.text.XTextRange) UnoRuntime.queryInterface(
+ com.sun.star.text.XTextRange.class,
+ xPortionEnumeration.nextElement());
+ String sWordString = xWord.getString();
+ System.out.println( "Content of the paragraph : " + sWordString );
+ }
+ }
+
+ // BEGIN: 'Finding a suitable style' Section from the Tutorial
+
+ // craete a supplier to get the styles-collection
+ com.sun.star.style.XStyleFamiliesSupplier xSupplier = null;
+ xSupplier = ( com.sun.star.style.XStyleFamiliesSupplier ) UnoRuntime.queryInterface(
+ com.sun.star.style.XStyleFamiliesSupplier.class, xTextDocument );
+
+ // use the name access from the collection
+ com.sun.star.container.XNameAccess xNameAccess = null;
+ xNameAccess = xSupplier.getStyleFamilies();
+
+ com.sun.star.container.XNameContainer xParaStyleCollection = null;
+ xParaStyleCollection = (com.sun.star.container.XNameContainer) UnoRuntime.queryInterface(
+ com.sun.star.container.XNameContainer.class, xNameAccess.getByName( "ParagraphStyles" ));
+
+ // create a array from strings with the name of all paragraph styles from the text document
+ String[] sElementNames = xParaStyleCollection.getElementNames();
+ int iElementCount = sElementNames.length;
+
+ for( int iCounter = 0; iCounter < iElementCount; iCounter++ ) {
+ // specify one paragraph style
+ com.sun.star.style.XStyle xStyle = null;
+ xStyle = (com.sun.star.style.XStyle) UnoRuntime.queryInterface(
+ com.sun.star.style.XStyle.class,
+ xParaStyleCollection.getByName( sElementNames[iCounter] ));
+
+ // create a property set of all properties from the style
+ xPropertySet = (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xStyle );
+
+ AnyConverter aAnyConv = new AnyConverter();
+ String sFontname = aAnyConv.toString(xPropertySet.getPropertyValue("CharFontName"));
+ sFontname = sFontname.toLowerCase();
+
+ // if the style use the font 'Albany', apply it to the current paragraph
+ if( sFontname.compareTo("albany") == 0 ) {
+ // create a property set from the current paragraph, to change the paragraph style
+ xPropertySet = (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xTextRange );
+
+ // To run the sample with StarOffice 5.2 you'll have to change 'ParaStyleName'
+ // to 'ParaStyle' in the next line
+ xPropertySet.setPropertyValue("ParaStyleName", new String( sElementNames[iCounter] ) );
+ System.out.println( "Apply the paragraph style : " + sElementNames[iCounter] );
+ break;
+ }
+ }
+ // END: 'Finding a suitable style' Section from the Tutorial
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+
+ System.out.println("Done");
+
+ System.exit(0);
+
+ }
+
+ public static com.sun.star.frame.XDesktop getDesktop() {
+ com.sun.star.frame.XDesktop xDesktop = null;
+ com.sun.star.lang.XMultiComponentFactory xMCF = null;
+
+ try {
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+
+ // get the remote office service manager
+ xMCF = xContext.getServiceManager();
+ if( xMCF != null ) {
+ System.out.println("Connected to a running office ...");
+
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext);
+ xDesktop = (com.sun.star.frame.XDesktop) UnoRuntime.queryInterface(
+ com.sun.star.frame.XDesktop.class, oDesktop);
+ }
+ else
+ System.out.println( "Can't create a desktop. No connection, no remote office servicemanager available!" );
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+
+ return xDesktop;
+ }
+
+ public static com.sun.star.text.XTextDocument createTextdocument(
+ com.sun.star.frame.XDesktop xDesktop )
+ {
+ com.sun.star.text.XTextDocument aTextDocument = null;
+
+ try {
+ com.sun.star.lang.XComponent xComponent = CreateNewDocument(xDesktop,
+ "swriter");
+ aTextDocument = (com.sun.star.text.XTextDocument)
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XTextDocument.class, xComponent);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return aTextDocument;
+ }
+
+
+ protected static com.sun.star.lang.XComponent CreateNewDocument(
+ com.sun.star.frame.XDesktop xDesktop,
+ String sDocumentType )
+ {
+ String sURL = "private:factory/" + sDocumentType;
+
+ com.sun.star.lang.XComponent xComponent = null;
+ com.sun.star.frame.XComponentLoader xComponentLoader = null;
+ com.sun.star.beans.PropertyValue xValues[] =
+ new com.sun.star.beans.PropertyValue[1];
+ com.sun.star.beans.PropertyValue xEmptyArgs[] =
+ new com.sun.star.beans.PropertyValue[0];
+
+ try {
+ xComponentLoader = (com.sun.star.frame.XComponentLoader)
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class, xDesktop);
+
+ xComponent = xComponentLoader.loadComponentFromURL(
+ sURL, "_blank", 0, xEmptyArgs);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return xComponent ;
+ }
+}
diff --git a/odk/examples/java/Text/TextDocumentStructure.java b/odk/examples/java/Text/TextDocumentStructure.java
new file mode 100644
index 000000000000..f60ce98c937d
--- /dev/null
+++ b/odk/examples/java/Text/TextDocumentStructure.java
@@ -0,0 +1,205 @@
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+//***************************************************************************
+// comment: Step 1: bootstrap UNO and get the remote component context
+// Step 2: open an empty text document
+// Step 3: create an enumeration of all paragraphs
+// Step 4: create an enumeration of all text portions
+//***************************************************************************
+
+import com.sun.star.uno.UnoRuntime;
+
+public class TextDocumentStructure {
+
+ public static void main(String args[]) {
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ try {
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+
+ // get the rmeote service manger
+ com.sun.star.lang.XMultiComponentFactory xMCF =
+ xContext.getServiceManager();
+
+ // create a new instance of the desktop
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext);
+
+ // get the component laoder from the desktop to create a new
+ // text document
+ com.sun.star.frame.XComponentLoader xCLoader =
+ (com.sun.star.frame.XComponentLoader)
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class,oDesktop);
+ com.sun.star.beans.PropertyValue [] szEmptyArgs =
+ new com.sun.star.beans.PropertyValue [0];
+ String strDoc = "private:factory/swriter";
+
+ System.out.println("create new text document");
+
+ com.sun.star.lang.XComponent xComp = xCLoader.loadComponentFromURL(
+ strDoc, "_blank", 0, szEmptyArgs);
+
+ // query the new document for the XTextDocument interface
+ com.sun.star.text.XTextDocument xTextDocument =
+ (com.sun.star.text.XTextDocument)UnoRuntime.queryInterface(
+ com.sun.star.text.XTextDocument.class, xComp);
+
+ // create some example data
+ com.sun.star.text.XText xText = xTextDocument.getText();
+ createExampleData( xText );
+
+ // Begin section 'The structure of text documents' of the Tutorial
+
+ com.sun.star.container.XEnumeration xParagraphEnumeration = null;
+ com.sun.star.container.XEnumerationAccess xParaEnumerationAccess = null;
+ com.sun.star.container.XEnumeration xPortionEnumeration = null;
+ com.sun.star.container.XEnumeration xTextPortionEnum;
+ com.sun.star.text.XTextContent xTextElement = null;
+
+ System.out.println("create an enumeration of all paragraphs");
+ // create an enumeration access of all paragraphs of a document
+ com.sun.star.container.XEnumerationAccess xEnumerationAccess =
+ (com.sun.star.container.XEnumerationAccess)
+ UnoRuntime.queryInterface(
+ com.sun.star.container.XEnumerationAccess.class, xText);
+ xParagraphEnumeration = xEnumerationAccess.createEnumeration();
+
+ // Loop through all paragraphs of the document
+ while ( xParagraphEnumeration.hasMoreElements() ) {
+ xTextElement = (com.sun.star.text.XTextContent)
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XTextContent.class,
+ xParagraphEnumeration.nextElement());
+ com.sun.star.lang.XServiceInfo xServiceInfo =
+ (com.sun.star.lang.XServiceInfo)UnoRuntime.queryInterface(
+ com.sun.star.lang.XServiceInfo.class, xTextElement);
+
+ // check ifs the current paragraph really a paragraph or an
+ // anchor of a frame or picture
+ if( xServiceInfo.supportsService("com.sun.star.text.Paragraph") ) {
+ com.sun.star.text.XTextRange xTextRange =
+ xTextElement.getAnchor();
+ System.out.println( "This is a Paragraph" );
+
+ // create another enumeration to get all text portions of
+ // the paragraph
+ xParaEnumerationAccess =
+ (com.sun.star.container.XEnumerationAccess)
+ UnoRuntime.queryInterface(
+ com.sun.star.container.XEnumerationAccess.class,
+ xTextElement);
+ xTextPortionEnum = xParaEnumerationAccess.createEnumeration();
+
+ while ( xTextPortionEnum.hasMoreElements() ) {
+ com.sun.star.text.XTextRange xTextPortion =
+ (com.sun.star.text.XTextRange)UnoRuntime.queryInterface(
+ com.sun.star.text.XTextRange.class,
+ xTextPortionEnum.nextElement());
+ System.out.println( "Text from the portion : "
+ + xTextPortion.getString() );
+
+ com.sun.star.beans.XPropertySet xPropertySet =
+ (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class,
+ xTextPortion);
+ System.out.println( "Name of the font : "
+ + xPropertySet.getPropertyValue( "CharFontName" ) );
+
+ // PropertyState status of each text portion.
+ com.sun.star.beans.XPropertyState xPropertyState =
+ (com.sun.star.beans.XPropertyState)
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertyState.class,
+ xTextPortion);
+
+ if( xPropertyState.getPropertyState("CharWeight").equals(
+ com.sun.star.beans.PropertyState.AMBIGUOUS_VALUE) )
+ System.out.println( "- The text range contains more than one different attributes" );
+
+ if( xPropertyState.getPropertyState( "CharWeight" ).equals(
+ com.sun.star.beans.PropertyState.DIRECT_VALUE ) )
+ System.out.println( " - The text range contains hard formats" );
+
+ if( xPropertyState.getPropertyState( "CharWeight" ).equals(
+ com.sun.star.beans.PropertyState.DEFAULT_VALUE ) )
+ System.out.println( " - The text range doesn't contains hard formats" );
+ }
+ }
+ else
+ System.out.println( "The text portion isn't a text paragraph" );
+ // End section 'The structure of text documents' of the Tutorial
+ }
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+ System.out.println("done");
+ System.exit(0);
+ }
+
+ public static void createExampleData( com.sun.star.text.XText xText ) {
+
+ try {
+ xText.setString( "This is an example sentence" );
+
+ com.sun.star.text.XWordCursor xWordCursor =
+ (com.sun.star.text.XWordCursor)UnoRuntime.queryInterface(
+ com.sun.star.text.XWordCursor.class, xText.getStart());
+
+ xWordCursor.gotoNextWord(false);
+ xWordCursor.gotoNextWord(false);
+ xWordCursor.gotoEndOfWord(true);
+
+ com.sun.star.beans.XPropertySet xPropertySet =
+ (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xWordCursor );
+ xPropertySet.setPropertyValue("CharWeight",
+ new Float( com.sun.star.awt.FontWeight.BOLD ));
+
+ System.out.println("create example data");
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+
+ }
+}
diff --git a/odk/examples/java/Text/TextReplace.java b/odk/examples/java/Text/TextReplace.java
new file mode 100644
index 000000000000..980b955e990f
--- /dev/null
+++ b/odk/examples/java/Text/TextReplace.java
@@ -0,0 +1,231 @@
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+//***************************************************************************
+// comment: Step 1: get the Desktop object from the office
+// Step 2: open an empty text document
+// Step 3: enter a example text
+// Step 4: replace some english spelled words with US spelled
+//***************************************************************************
+
+
+import com.sun.star.uno.UnoRuntime;
+
+public class TextReplace {
+
+ public static void main(String args[]) {
+ // You need the desktop to create a document
+ // The getDesktop method does the UNO bootstrapping, gets the
+ // remote servie manager and the desktop object.
+ com.sun.star.frame.XDesktop xDesktop = null;
+ xDesktop = getDesktop();
+
+ com.sun.star.text.XTextDocument xTextDocument =
+ createTextdocument( xDesktop );
+
+ createExampleData( xTextDocument );
+
+ String mBritishWords[] = {"colour", "neighbour", "centre", "behaviour",
+ "metre", "through" };
+ String mUSWords[] = { "color", "neighbor", "center", "behavior",
+ "meter", "thru" };
+
+ try {
+ com.sun.star.util.XReplaceDescriptor xReplaceDescr = null;
+ com.sun.star.util.XSearchDescriptor xSearchDescriptor = null;
+ com.sun.star.util.XReplaceable xReplaceable = null;
+
+ xReplaceable = (com.sun.star.util.XReplaceable)
+ UnoRuntime.queryInterface(
+ com.sun.star.util.XReplaceable.class, xTextDocument);
+
+ // You need a descriptor to set properies for Replace
+ xReplaceDescr = (com.sun.star.util.XReplaceDescriptor)
+ xReplaceable.createReplaceDescriptor();
+
+ System.out.println("Change all occurrences of ...");
+ for( int iArrayCounter = 0; iArrayCounter < mBritishWords.length;
+ iArrayCounter++ )
+ {
+ System.out.println(mBritishWords[iArrayCounter] +
+ " -> " + mUSWords[iArrayCounter]);
+ // Set the properties the replace method need
+ xReplaceDescr.setSearchString(mBritishWords[iArrayCounter] );
+ xReplaceDescr.setReplaceString(mUSWords[iArrayCounter] );
+
+ // Replace all words
+ xReplaceable.replaceAll( xReplaceDescr );
+ }
+
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ System.out.println("Done");
+
+ System.exit(0);
+
+ }
+
+ protected static void createExampleData(
+ com.sun.star.text.XTextDocument xTextDocument )
+ {
+ // Create textdocument and insert example text
+ com.sun.star.text.XTextCursor xTextCursor = null;
+
+ try {
+ xTextCursor = (com.sun.star.text.XTextCursor)
+ xTextDocument.getText().createTextCursor();
+ com.sun.star.text.XText xText = (com.sun.star.text.XText)
+ xTextDocument.getText();
+
+ xText.insertString( xTextCursor,
+ "He nervously looked all around. Suddenly he saw his ", false );
+
+ xText.insertString( xTextCursor, "neighbour ", true );
+ com.sun.star.beans.XPropertySet xCPS = (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xTextCursor);
+ // Set the word blue
+ xCPS.setPropertyValue( "CharColor", new Integer( 255 ) );
+ // Go to last character
+ xTextCursor.gotoEnd(false);
+ xCPS.setPropertyValue( "CharColor", new Integer( 0 ) );
+
+ xText.insertString( xTextCursor, "in the alley. Like lightening he darted off to the left and disappeared between the two warehouses almost falling over the trash can lying in the ", false );
+
+ xText.insertString( xTextCursor, "centre ", true );
+ xCPS = (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xTextCursor);
+ // Set the word blue
+ xCPS.setPropertyValue( "CharColor", new Integer( 255 ) );
+ // Go to last character
+ xTextCursor.gotoEnd(false);
+ xCPS.setPropertyValue( "CharColor", new Integer( 0 ) );
+
+ xText.insertString( xTextCursor, "of the sidewalk.", false );
+
+ xText.insertControlCharacter( xTextCursor,
+ com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false );
+ xText.insertString( xTextCursor, "He tried to nervously tap his way along in the inky darkness and suddenly stiffened: it was a dead-end, he would have to go back the way he had come.", false );
+
+ xTextCursor.gotoStart(false);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ }
+
+ public static com.sun.star.frame.XDesktop getDesktop() {
+ com.sun.star.frame.XDesktop xDesktop = null;
+ com.sun.star.lang.XMultiComponentFactory xMCF = null;
+
+ try {
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+
+ // get the remote office service manager
+ xMCF = xContext.getServiceManager();
+ if( xMCF != null ) {
+ System.out.println("Connected to a running office ...");
+
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext);
+ xDesktop = (com.sun.star.frame.XDesktop) UnoRuntime.queryInterface(
+ com.sun.star.frame.XDesktop.class, oDesktop);
+ }
+ else
+ System.out.println( "Can't create a desktop. No connection, no remote office servicemanager available!" );
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+
+ return xDesktop;
+ }
+
+ public static com.sun.star.text.XTextDocument createTextdocument(
+ com.sun.star.frame.XDesktop xDesktop )
+ {
+ com.sun.star.text.XTextDocument aTextDocument = null;
+
+ try {
+ com.sun.star.lang.XComponent xComponent = CreateNewDocument(xDesktop,
+ "swriter");
+ aTextDocument = (com.sun.star.text.XTextDocument)
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XTextDocument.class, xComponent);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return aTextDocument;
+ }
+
+
+ protected static com.sun.star.lang.XComponent CreateNewDocument(
+ com.sun.star.frame.XDesktop xDesktop,
+ String sDocumentType )
+ {
+ String sURL = "private:factory/" + sDocumentType;
+
+ com.sun.star.lang.XComponent xComponent = null;
+ com.sun.star.frame.XComponentLoader xComponentLoader = null;
+ com.sun.star.beans.PropertyValue xValues[] =
+ new com.sun.star.beans.PropertyValue[1];
+ com.sun.star.beans.PropertyValue xEmptyArgs[] =
+ new com.sun.star.beans.PropertyValue[0];
+
+ try {
+ xComponentLoader = (com.sun.star.frame.XComponentLoader)
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class, xDesktop);
+
+ xComponent = xComponentLoader.loadComponentFromURL(
+ sURL, "_blank", 0, xEmptyArgs);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return xComponent ;
+ }
+}
diff --git a/odk/examples/java/Text/WriterSelector.java b/odk/examples/java/Text/WriterSelector.java
new file mode 100644
index 000000000000..6fd00189d657
--- /dev/null
+++ b/odk/examples/java/Text/WriterSelector.java
@@ -0,0 +1,162 @@
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.uno.UnoRuntime;
+
+/** This class gives you information on the selected objects (text range, text
+ * frame, or graphics) at an OpenOffice.org Server. The Office must be started in
+ * advance and you must have selected something (text, graphics, ...)
+ */
+public class WriterSelector {
+ /**
+ * @param args No arguments.
+ */
+ public static void main(String args[]) {
+ com.sun.star.uno.XComponentContext xContext = null;
+
+ try {
+
+ // bootstrap UNO and get the remote component context. The context can
+ // be used to get the service manager
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+
+ // get the remote office service manager
+ com.sun.star.lang.XMultiComponentFactory xMCF =
+ xContext.getServiceManager();
+
+ // get a new instance of the desktop
+ com.sun.star.frame.XDesktop xDesktop = (com.sun.star.frame.XDesktop)
+ UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class,
+ xMCF.createInstanceWithContext("com.sun.star.frame.Desktop",
+ xContext ) );
+
+ com.sun.star.frame.XComponentLoader xCompLoader =
+ (com.sun.star.frame.XComponentLoader)UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class, xDesktop);
+
+ com.sun.star.lang.XComponent xComponent =
+ xCompLoader.loadComponentFromURL("private:factory/swriter",
+ "_blank", 0, new com.sun.star.beans.PropertyValue[0]);
+ {
+ com.sun.star.text.XTextDocument xDoc =(com.sun.star.text.XTextDocument)
+ UnoRuntime.queryInterface(com.sun.star.text.XTextDocument.class,
+ xComponent);
+ xDoc.getText().setString("Please select something in this text and press then \"return\" in the shell where you have started the example.\n");
+
+ // ensure that the document content is optimal visible
+ com.sun.star.frame.XModel xModel =
+ (com.sun.star.frame.XModel)UnoRuntime.queryInterface(
+ com.sun.star.frame.XModel.class, xDoc);
+
+ com.sun.star.view.XViewSettingsSupplier xViewSettings =
+ (com.sun.star.view.XViewSettingsSupplier)UnoRuntime.queryInterface(
+ com.sun.star.view.XViewSettingsSupplier.class, xModel.getCurrentController());
+ xViewSettings.getViewSettings().setPropertyValue(
+ "ZoomType", new Short((short)0));
+ }
+ // test document will be closed later
+
+ System.out.println("\nPlease select something in the test document and press then \"return\" to continues the example ...");
+ char c = 'X';
+ do{
+ c = (char) System.in.read();
+ }while ((c != 13) && (c != 10));
+
+ // Getting the current frame from the OpenOffice.org Server.
+ com.sun.star.frame.XFrame xframe = xDesktop.getCurrentFrame();
+
+ // Getting the controller.
+ com.sun.star.frame.XController xController = xframe.getController();
+
+ com.sun.star.view.XSelectionSupplier xSelSupplier =
+ (com.sun.star.view.XSelectionSupplier)UnoRuntime.queryInterface(
+ com.sun.star.view.XSelectionSupplier.class, xController );
+
+ Object oSelection = xSelSupplier.getSelection();
+
+ com.sun.star.lang.XServiceInfo xServInfo =
+ (com.sun.star.lang.XServiceInfo)UnoRuntime.queryInterface(
+ com.sun.star.lang.XServiceInfo.class, oSelection );
+
+ if ( xServInfo.supportsService("com.sun.star.text.TextRanges") )
+ {
+ com.sun.star.container.XIndexAccess xIndexAccess =
+ (com.sun.star.container.XIndexAccess)UnoRuntime.queryInterface(
+ com.sun.star.container.XIndexAccess.class, oSelection);
+
+ int count = xIndexAccess.getCount();
+ com.sun.star.text.XTextRange xTextRange = null;
+ for ( int i = 0; i < count; i++ ) {
+ xTextRange = (com.sun.star.text.XTextRange)
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XTextRange.class,
+ xIndexAccess.getByIndex(i));
+
+ System.out.println( "You have selected a text range: \""
+ + xTextRange.getString() + "\"." );
+ }
+ }
+
+ if ( xServInfo.supportsService("com.sun.star.text.TextGraphicObject") )
+ {
+ System.out.println( "You have selected a graphics." );
+ }
+
+ if ( xServInfo.supportsService("com.sun.star.text.TextTableCursor") )
+ {
+ System.out.println( "You have selected a text table." );
+ }
+
+
+ // close test document
+ com.sun.star.util.XCloseable xCloseable = (com.sun.star.util.XCloseable)
+ UnoRuntime.queryInterface(com.sun.star.util.XCloseable.class,
+ xComponent );
+
+ if (xCloseable != null ) {
+ xCloseable.close(false);
+ } else
+ {
+ xComponent.dispose();
+ }
+
+ System.exit(0);
+ }
+ catch( Exception e ) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+ }
+}
diff --git a/odk/examples/java/Text/oo_smiley.gif b/odk/examples/java/Text/oo_smiley.gif
new file mode 100644
index 000000000000..f9fc08d5090c
--- /dev/null
+++ b/odk/examples/java/Text/oo_smiley.gif
Binary files differ