org.jfor.jfor.rtflib.rtfdoc
Class RtfElement

java.lang.Object
  extended by org.jfor.jfor.rtflib.rtfdoc.RtfElement
Direct Known Subclasses:
RtfBookmark, RtfContainer, RtfExternalGraphic, RtfFontTable, RtfLineBreak, RtfPageBreak, RtfText

public abstract class RtfElement
extends java.lang.Object

Base class for all elements of an RTF file.

Author:
Bertrand Delacretaz bdelacretaz@codeconsult.ch

Field Summary
protected  RtfAttributes m_attrib
           
protected  RtfContainer m_parent
           
protected  java.io.Writer m_writer
           
 
Constructor Summary
RtfElement(RtfContainer parent, java.io.Writer w)
          Create an RTF element as a child of given container
RtfElement(RtfContainer parent, java.io.Writer w, RtfAttributes attr)
          Create an RTF element as a child of given container with given attributes
 
Method Summary
 void close()
          Does nothing, meant to allow elements to write themselves without waiting for write(), but not implemented yet
(package private)  void dump(java.io.Writer w, int indent)
          debugging to given PrintWriter
(package private)  RtfElement getParentOfClass(java.lang.Class c)
          find the first parent where c.isAssignableFrom(parent.getClass()) is true
 RtfAttributes getRtfAttributes()
           
(package private)  RtfFile getRtfFile()
          access our RtfFile, which is always the topmost parent
(package private)  boolean isClosed()
          true if close() has been called
abstract  boolean isEmpty()
          true if this element would generate no "useful" RTF content
protected  boolean okToWriteRtf()
          can be overridden to suppress all RTF output
 java.lang.String toString()
          minimal debugging display
protected  void writeAttributes(RtfAttributes attr, java.lang.String[] nameList)
          write given attribute values to our Writer
protected  void writeControlWord(java.lang.String word)
          write an RTF control word to our Writer
protected  void writeControlWordNS(java.lang.String word)
          write rtf control word without the space behind it
protected  void writeExceptionInRtf(java.lang.Exception ie)
           
protected  void writeGroupMark(boolean isStart)
          Write a start or end group mark
protected  void writeOneAttribute(java.lang.String name, java.lang.Object value)
          write one attribute to our Writer
protected  void writeOneAttributeNS(java.lang.String name, java.lang.Object value)
          write one attribute to our Writer without a space
 void writeRtf()
          write the RTF code of this element to our Writer
protected abstract  void writeRtfContent()
          must be implemented to write RTF content to m_writer
protected  void writeRtfPrefix()
          called before writeRtfContent()
protected  void writeRtfSuffix()
          called after writeRtfContent()
protected  void writeStarControlWord(java.lang.String word)
          write an RTF control word to our Writer, preceeded by a star '*' meaning "ignore this if you don't know what it means"
protected  void writeStarControlWordNS(java.lang.String word)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_writer

protected final java.io.Writer m_writer

m_parent

protected final RtfContainer m_parent

m_attrib

protected final RtfAttributes m_attrib
Constructor Detail

RtfElement

RtfElement(RtfContainer parent,
           java.io.Writer w)
     throws java.io.IOException
Create an RTF element as a child of given container

Throws:
java.io.IOException

RtfElement

RtfElement(RtfContainer parent,
           java.io.Writer w,
           RtfAttributes attr)
     throws java.io.IOException
Create an RTF element as a child of given container with given attributes

Throws:
java.io.IOException
Method Detail

close

public final void close()
                 throws java.io.IOException
Does nothing, meant to allow elements to write themselves without waiting for write(), but not implemented yet

Throws:
java.io.IOException

writeRtf

public final void writeRtf()
                    throws java.io.IOException
write the RTF code of this element to our Writer

Throws:
java.io.IOException

writeControlWord

protected final void writeControlWord(java.lang.String word)
                               throws java.io.IOException
write an RTF control word to our Writer

Throws:
java.io.IOException

writeStarControlWord

protected final void writeStarControlWord(java.lang.String word)
                                   throws java.io.IOException
write an RTF control word to our Writer, preceeded by a star '*' meaning "ignore this if you don't know what it means"

Throws:
java.io.IOException

writeStarControlWordNS

protected final void writeStarControlWordNS(java.lang.String word)
                                     throws java.io.IOException
Throws:
java.io.IOException

writeControlWordNS

protected final void writeControlWordNS(java.lang.String word)
                                 throws java.io.IOException
write rtf control word without the space behind it

Throws:
java.io.IOException

writeRtfPrefix

protected void writeRtfPrefix()
                       throws java.io.IOException
called before writeRtfContent()

Throws:
java.io.IOException

writeRtfContent

protected abstract void writeRtfContent()
                                 throws java.io.IOException
must be implemented to write RTF content to m_writer

Throws:
java.io.IOException

writeRtfSuffix

protected void writeRtfSuffix()
                       throws java.io.IOException
called after writeRtfContent()

Throws:
java.io.IOException

writeGroupMark

protected final void writeGroupMark(boolean isStart)
                             throws java.io.IOException
Write a start or end group mark

Throws:
java.io.IOException

writeAttributes

protected void writeAttributes(RtfAttributes attr,
                               java.lang.String[] nameList)
                        throws java.io.IOException
write given attribute values to our Writer

Parameters:
nameList - if given, only attribute names from this list are considered
Throws:
java.io.IOException

writeOneAttribute

protected void writeOneAttribute(java.lang.String name,
                                 java.lang.Object value)
                          throws java.io.IOException
write one attribute to our Writer

Throws:
java.io.IOException

writeOneAttributeNS

protected void writeOneAttributeNS(java.lang.String name,
                                   java.lang.Object value)
                            throws java.io.IOException
write one attribute to our Writer without a space

Throws:
java.io.IOException

okToWriteRtf

protected boolean okToWriteRtf()
can be overridden to suppress all RTF output


dump

void dump(java.io.Writer w,
          int indent)
    throws java.io.IOException
debugging to given PrintWriter

Throws:
java.io.IOException

toString

public java.lang.String toString()
minimal debugging display

Overrides:
toString in class java.lang.Object

isClosed

boolean isClosed()
true if close() has been called


getRtfFile

RtfFile getRtfFile()
access our RtfFile, which is always the topmost parent


getParentOfClass

RtfElement getParentOfClass(java.lang.Class c)
find the first parent where c.isAssignableFrom(parent.getClass()) is true

Returns:
null if not found

isEmpty

public abstract boolean isEmpty()
true if this element would generate no "useful" RTF content


writeExceptionInRtf

protected void writeExceptionInRtf(java.lang.Exception ie)
                            throws java.io.IOException
Throws:
java.io.IOException

getRtfAttributes

public RtfAttributes getRtfAttributes()