Holger's
Java API

com.antelmann.ooffice
Class TextFrame

java.lang.Object
  extended by com.antelmann.ooffice.TextFrame
All Implemented Interfaces:
ThirdParty, Closeable

public class TextFrame
extends Object
implements ThirdParty, Closeable

simplifies the handling of OpenOffice Writer documents This class implements ThirdParty for its use of OpenOffice libraries; see www.openoffice.org

Author:
Holger Antelmann

Nested Class Summary
static class TextFrame.AnchorType
           
 
Constructor Summary
TextFrame()
          creates a blank new document
TextFrame(File template)
          creates a new document based on the given template file
TextFrame(File file, Map<Object,Object> props)
          loads a document (the given file) into a blank frame along with the given properties
TextFrame(String url, Map<Object,Object> props)
          loads a document from the given url into a blank frame along with the given properties.
 
Method Summary
 void close()
          closes and disposes the document
static TextFrame getActiveDocument()
          seeks the currently active document on the desktop (if any) and returns it
 com.sun.star.text.XTextCursor getBookmarkCursor(String bookmark)
           
 com.sun.star.text.XTextRange getBookmarkRange(String bookmark)
           
 String[] getBookmarks()
           
 String getBookmarkText(String bookmark)
           
static String getDefaultFileExtension()
           
 com.sun.star.text.XTextDocument getDocument()
           
 String[] getFieldNames()
           
 String getFieldText(String fieldName)
          the fully quantified field name is to be supplied
 String[] getUserFieldNames()
           
 String getUserFieldText(String userFieldName)
           
 com.sun.star.text.XTextViewCursor getViewCursor()
          returns the XTextCursor that is currently visible in the document
 com.sun.star.text.XTextViewCursor gotoBookmark(String bookmark)
          sets the view cursor to the given bookmark
 com.sun.star.text.XTextCursor gotoFirst(String searchText, boolean caseSensitive)
          sets the view cursor to the first occurrence of the given String and returns it as a cursor for further handling
 void insertFileAt(File file, com.sun.star.text.XTextCursor cursor)
          inserts one document into another
 void insertImage(File file, com.sun.star.text.XTextCursor cursor, TextFrame.AnchorType at, Map<Object,Object> props)
          props may be null
 void insertImage(String url, com.sun.star.text.XTextCursor cursor, TextFrame.AnchorType at, Map<Object,Object> props)
          props may be null
 void insertUrlAt(String url, com.sun.star.text.XTextCursor cursor)
          inserts one document into another
 void print()
           
 void print(String printerName)
           
 void replaceAll(String search, String replace)
          performs a simple search/replace on the entire document
 void setBookmarkText(String bookmark, String text)
          sets the text of for a defined bookmark within the given document
 void setFieldText(String fieldName, String text)
          the fully quantified field name is to be supplied
 void setUserFieldContent(Map<Object,Object> fields)
          sets the field content of the field variables contained in the map.
 void storeTo(File file, boolean representNewLocation)
          saves the embedded document to the given file (overwriting it, if it exists)
 void storeTo(File file, String filterName, boolean representNewLocation)
          saves the given document to the given file (overwriting it, if it exists) in the given format
 void storeTo(String url, boolean representNewLocation)
          saves the given document to the given url (overwriting the url if it exists)
 void storeTo(String url, String filterName, boolean representNewLocation)
          allows to specify a filterName that defines the output format (null is allowed).
 com.sun.star.text.XTextCursor writeText(String text, com.sun.star.text.XTextCursor cursor)
          writes text directly into the frame at the given cursor position; the cursor is returned for further handling
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextFrame

public TextFrame()
          throws OfficeException
creates a blank new document

Throws:
OfficeException

TextFrame

public TextFrame(File template)
          throws OfficeException,
                 IOException
creates a new document based on the given template file

Throws:
OfficeException
IOException

TextFrame

public TextFrame(File file,
                 Map<Object,Object> props)
          throws OfficeException,
                 IOException
loads a document (the given file) into a blank frame along with the given properties

Throws:
OfficeException
IOException

TextFrame

public TextFrame(String url,
                 Map<Object,Object> props)
          throws OfficeException,
                 IOException
loads a document from the given url into a blank frame along with the given properties. To load the document as a template, put the property AsTemplate into the properties mapped to true.

Throws:
OfficeException
IOException
Method Detail

getActiveDocument

public static TextFrame getActiveDocument()
                                   throws OfficeException
seeks the currently active document on the desktop (if any) and returns it

Throws:
OfficeException

getDocument

public com.sun.star.text.XTextDocument getDocument()

getDefaultFileExtension

public static String getDefaultFileExtension()

storeTo

public void storeTo(File file,
                    boolean representNewLocation)
             throws IOException
saves the embedded document to the given file (overwriting it, if it exists)

Throws:
IOException

storeTo

public void storeTo(File file,
                    String filterName,
                    boolean representNewLocation)
             throws IOException
saves the given document to the given file (overwriting it, if it exists) in the given format

Throws:
IOException

storeTo

public void storeTo(String url,
                    boolean representNewLocation)
             throws IOException
saves the given document to the given url (overwriting the url if it exists)

Throws:
IOException

storeTo

public void storeTo(String url,
                    String filterName,
                    boolean representNewLocation)
             throws IOException
allows to specify a filterName that defines the output format (null is allowed). Known filterNames (for representNewLocation = true) include: if representNewLocation is false (i.e. we are talking about an export w/o editing the document hereafter), the following entries are valid, too:

Throws:
IOException

close

public void close()
           throws IOException
closes and disposes the document

Specified by:
close in interface Closeable
Throws:
IOException

print

public void print()
           throws OfficeException
Throws:
OfficeException

print

public void print(String printerName)
           throws IllegalArgumentException
Throws:
IllegalArgumentException

getViewCursor

public com.sun.star.text.XTextViewCursor getViewCursor()
returns the XTextCursor that is currently visible in the document


gotoFirst

public com.sun.star.text.XTextCursor gotoFirst(String searchText,
                                               boolean caseSensitive)
                                        throws OfficeException
sets the view cursor to the first occurrence of the given String and returns it as a cursor for further handling

Throws:
OfficeException

gotoBookmark

public com.sun.star.text.XTextViewCursor gotoBookmark(String bookmark)
                                               throws OfficeException
sets the view cursor to the given bookmark

Throws:
OfficeException

writeText

public com.sun.star.text.XTextCursor writeText(String text,
                                               com.sun.star.text.XTextCursor cursor)
writes text directly into the frame at the given cursor position; the cursor is returned for further handling


replaceAll

public void replaceAll(String search,
                       String replace)
performs a simple search/replace on the entire document


getBookmarkRange

public com.sun.star.text.XTextRange getBookmarkRange(String bookmark)
                                              throws OfficeException
Throws:
OfficeException

getBookmarkCursor

public com.sun.star.text.XTextCursor getBookmarkCursor(String bookmark)
                                                throws OfficeException,
                                                       IllegalArgumentException
Throws:
OfficeException
IllegalArgumentException

getBookmarks

public String[] getBookmarks()

getBookmarkText

public String getBookmarkText(String bookmark)
                       throws OfficeException,
                              IllegalArgumentException
Throws:
OfficeException
IllegalArgumentException

setBookmarkText

public void setBookmarkText(String bookmark,
                            String text)
                     throws OfficeException,
                            IllegalArgumentException
sets the text of for a defined bookmark within the given document

Throws:
IllegalArgumentException - if the bookmark is unknown in this document
OfficeException

insertFileAt

public void insertFileAt(File file,
                         com.sun.star.text.XTextCursor cursor)
                  throws OfficeException,
                         IllegalArgumentException
inserts one document into another

Throws:
OfficeException
IllegalArgumentException

insertUrlAt

public void insertUrlAt(String url,
                        com.sun.star.text.XTextCursor cursor)
                 throws OfficeException,
                        IllegalArgumentException
inserts one document into another

Throws:
OfficeException
IllegalArgumentException

getFieldNames

public String[] getFieldNames()

insertImage

public void insertImage(File file,
                        com.sun.star.text.XTextCursor cursor,
                        TextFrame.AnchorType at,
                        Map<Object,Object> props)
                 throws OfficeException
props may be null

Throws:
OfficeException

insertImage

public void insertImage(String url,
                        com.sun.star.text.XTextCursor cursor,
                        TextFrame.AnchorType at,
                        Map<Object,Object> props)
                 throws OfficeException,
                        IllegalArgumentException
props may be null

Throws:
OfficeException
IllegalArgumentException

getUserFieldNames

public String[] getUserFieldNames()

getFieldText

public String getFieldText(String fieldName)
                    throws OfficeException,
                           IllegalArgumentException
the fully quantified field name is to be supplied

Throws:
OfficeException
IllegalArgumentException

getUserFieldText

public String getUserFieldText(String userFieldName)
                        throws OfficeException,
                               IllegalArgumentException
Throws:
OfficeException
IllegalArgumentException

setFieldText

public void setFieldText(String fieldName,
                         String text)
                  throws OfficeException,
                         IllegalArgumentException
the fully quantified field name is to be supplied

Throws:
OfficeException
IllegalArgumentException

setUserFieldContent

public void setUserFieldContent(Map<Object,Object> fields)
                         throws OfficeException
sets the field content of the field variables contained in the map. Non-existing fields will be ignored.

Parameters:
fields - maps field names to the content that is to be used for the key field name
Throws:
OfficeException


(c) 2001-2006 Holger Antelmann - all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads