## org.eclipse.jet
Interface JET2Writer

All Known Implementing Classes:
  BodyContentWriter

    public interface JET2Writer

Define a JET2 output writer

Method Summary
`void` `addEventListener(java.lang.String category, IWriterListener listener)` Add a listener to the writer life cycle events.
`void` `addPosition(java.lang.String category, org.eclipse.jface.text.Position position)` Convenience method wrapping getDocument().addPosition(String, Position).
`void` `addPositionCategory(java.lang.String category)` Convenience method wrapping getDocument().addPositionCategory(String).
`void` `contentCommitted(java.lang.Object committedObject)` Inform listeners that the content has been committed to some permanent store.
`void` `finalizeContent(java.lang.Object file)` Finalize the writers contents.
`org.eclipse.jface.text.IDocument` `getDocument()` Return the backing IDocument for this writer.
`int` `getLength()` Return the current length (in characters) of the output
`JET2Writer` `getParentWriter()` Return the parent of this writer, if it was created via `newNestedContentWriter()`.
`org.eclipse.jface.text.Position[]` `getPositions(java.lang.String category)` Convenience method wrapping getDocument().getPositions(String).
`JET2Writer` `newNestedContentWriter()` Create a writer for handling nested content.
`void` `replace(int offset, int length, java.lang.String text)` Convenience method wrapping getDocument().replace(int,int,String).
`void` `write(boolean b)` Write the passed boolean by calling `String.valueOf(boolean)`.
`void` `write(char c)` Write the passed character by calling `String.valueOf(char)`.
`void` `write(char[] data)` Write the passed character array by calling `String.valueOf(char[])`.
`void` `write(double d)` Write the passed double value by calling `String.valueOf(double)`.
`void` `write(float f)` Write the passed float value by calling `String.valueOf(float)`.
`void` `write(int i)` Write the passed integer by calling `String.valueOf(int)`.
`void` `write(JET2Writer bodyContent)` Write the contents of the passed writer to this writer.
`void` `write(long l)` Write the passed long value calling `String.valueOf(long)`.
`void` `write(java.lang.Object obj)` Write the pass object by calling `Object.toString()`.
`void` `write(java.lang.String string)` Write the passed string.

Method Detail

### write

    void write(java.lang.String string)

  Write the passed string.

  Parameters:
    `string` - a string value.

### write

    void write(JET2Writer bodyContent)

  Write the contents of the passed writer to this writer.

  Parameters:
    `bodyContent` - a writer

### write

    void write(boolean b)

  Write the passed boolean by calling `String.valueOf(boolean)`.

  Parameters:
    `b` - a boolean value

### write

    void write(char c)

  Write the passed character by calling `String.valueOf(char)`.

  Parameters:
    `c` - a char value

### write

    void write(char[] data)

  Write the passed character array by calling `String.valueOf(char[])`.

  Parameters:
    `data` - an array of characters

### write

    void write(double d)

  Write the passed double value by calling `String.valueOf(double)`.

  Parameters:
    `d` - a double value

### write

    void write(float f)

  Write the passed float value by calling `String.valueOf(float)`.

  Parameters:
    `f` - a float value

### write

    void write(int i)

  Write the passed integer by calling `String.valueOf(int)`.

  Parameters:
    `i` - an integer value

### write

    void write(long l)

  Write the passed long value calling `String.valueOf(long)`.

  Parameters:
    `l` - a long value.

### write

    void write(java.lang.Object obj)

  Write the pass object by calling `Object.toString()`.

  Parameters:
    `obj` - an object.

### newNestedContentWriter

    JET2Writer newNestedContentWriter()

  Create a writer for handling nested content. The new writer will have access to all position handlers defined on the parent writer (and its parents)

  Returns:
    the nested content writer

### getParentWriter

    JET2Writer getParentWriter()

  Return the parent of this writer, if it was created via `newNestedContentWriter()`.

  Returns:
    the parent writer, or `null`.

### getLength

    int getLength()

  Return the current length (in characters) of the output

  Returns:
    the current length

### getDocument

    org.eclipse.jface.text.IDocument getDocument()

  Return the backing IDocument for this writer. Use this method to do advanced writer processing, such as adding Positions for later re-writing of the document contents.

  Returns:
    the backing document

### finalizeContent

    void finalizeContent(java.lang.Object file)
                         throws JET2TagException

  Finalize the writers contents. Once finalized, no more content may be written to the writer. Calls `IWriterListener.finalizeContent(JET2Writer, Object)` on all registered listeners. Listeners are called in the order in which the listeners were registered via `addEventListener(String, IWriterListener)`.

  The type of `file` varies depending on the context in which the content is finalized. The standard JET2 Workspace tags pass an org.eclipse.core.resources.IFile.

  Parameters:
    `file` - the file object to which the finalized contents will be written.
  Throws:
    `JET2TagException` - if an error occurs
  See Also:
    `addEventListener(String, IWriterListener)`

### contentCommitted

    void contentCommitted(java.lang.Object committedObject)
                          throws JET2TagException

  Inform listeners that the content has been committed to some permanent store. Calls `IWriterListener.postCommitContent(JET2Writer, Object)` on all registered listeners. Listeners are called in the order in which the listeners were registered via `addEventListener(String, IWriterListener)`.

  The type of `committedObject` varies, depending on the context in which the content is committed. The standard JET2 Workspace tags pass an org.eclipse.core.resources.IFile.

  Parameters:
    `committedObject` - the committed object.
  Throws:
    `JET2TagException` - if event handle cannot terminate correctly.

### addEventListener

    void addEventListener(java.lang.String category,
                          IWriterListener listener)

  Add a listener to the writer life cycle events. The writer records one listener per category. Subsequent calls to this method with the same category value have no effect. If the listener was created view `newNestedContentWriter()`, then the listener is added to the root writer, rather than the listener itself.

  Parameters:
    `category` - the listener category
    `listener` - a listener
  Throws:
    `java.lang.NullPointerException` - if listener is `null`.

### addPositionCategory

    void addPositionCategory(java.lang.String category)

  Convenience method wrapping getDocument().addPositionCategory(String).

  Parameters:
    `category` - a Position Category
  Throws:
    `java.lang.IllegalArgumentException` - wrapping a `BadPositionCategoryException`
  See Also:
    `IDocument.addPositionCategory(java.lang.String)`

### addPosition

    void addPosition(java.lang.String category,
                     org.eclipse.jface.text.Position position)

  Convenience method wrapping getDocument().addPosition(String, Position). Any `BadPositionCategoryException` or `BadLocationException` is wrapped in a a runtime exception.

  Parameters:
    `category` - a position category
    `position` - a position
  Throws:
    `WriterPositionException` - wrapping a `BadPositionCategoryException` or `BadLocationException`
  See Also:
    `IDocument.addPosition(java.lang.String, org.eclipse.jface.text.Position)`

### getPositions

    org.eclipse.jface.text.Position[] getPositions(java.lang.String category)

  Convenience method wrapping getDocument().getPositions(String). Any `BadPositionCategoryException` is wrapped in a runtime exception.

  Parameters:
    `category` - a position category
  Returns:
    an array of positions
  Throws:
    `WriterPositionException` - wrapping a `BadPositionCategoryException`
  See Also:
    `IDocument.getPositions(java.lang.String)`

### replace

    void replace(int offset,
                 int length,
                 java.lang.String text)

  Convenience method wrapping getDocument().replace(int,int,String). Any `BadLocationException` is wrapped in a runtime exception.

  Parameters:
    `offset` - the offset of the text to replace
    `length` - the length of the text to replace
    `text` - the replacement text
  Throws:
    `WriterPositionException` - wrapping a `BadLocationException`
  See Also:
    `IDocument.replace(int, int, java.lang.String)`

Copyright 2006 IBM Corporation and others. All Rights Reserved.