de.esprit.appsuite.xml

## Class TagWriter<C extends ApplicationContext>

- java.lang.Object
- - de.esprit.common.util.DumpableObject
  - - de.esprit.appsuite.launch.AbstractApplicationObject<C>
    - - de.esprit.appsuite.task.AbstractAsyncExecutable<C>
      - - de.esprit.appsuite.io.DataWriter<C>
        - - de.esprit.appsuite.xml.TagWriter<C>

- All Implemented Interfaces:
    ApplicationObject<C>, AsyncExecutable<C>, CancellableTask, TaskMonitorSupport, SimpleLogSupport, Dumpable, Executable, java.io.Closeable, java.lang.AutoCloseable
  Direct Known Subclasses:
    DBOHtmlWriter, StringTagWriter, XmlTagWriter

      public abstract class TagWriter<C extends ApplicationContext>
      extends DataWriter<C>

  This class is a writer for tag-oriented output such as XML or HTML. It keeps track of all opened tags and closes them all when the output stream is closed. It also manages the indentation in order to print a well indented document. Furthermore it supports name-spaces by automatically prefixing the tags with the current name-space.
  Author:
    Rainer Buesch

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected AttrList` | `attrs`
    `static java.lang.String` | `DEFAULT_ENCODING`

    - ### Fields inherited from class de.esprit.appsuite.task.AbstractAsyncExecutable

      `childTaskRef, isTestMode, monitorController, resultRef, stateFlag`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TagWriter(C ctx, java.io.File file)`
    `TagWriter(C ctx, java.io.File file, java.lang.String encoding)`
    `TagWriter(C ctx, java.io.OutputStream out)`
    `TagWriter(C ctx, java.io.OutputStream out, java.lang.String encoding)`
    `TagWriter(C ctx, java.lang.String fileName)`
    `TagWriter(C ctx, java.lang.String fileName, java.lang.String encoding)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `AttrList` | `attr(java.lang.String key, java.lang.String value)` Convenience method for single attribute
    `void` | `close()` Closes the output stream.
    `void` | `closeTag()` Closes the tag that was last opened.
    `protected java.lang.String` | `getSimpleTagCloseBracket()`
    `protected java.lang.String` | `getTag(java.lang.String tag)`
    `boolean` | `isWritingEmptyTags()` Tells whether tags that contain no content should be written at all.
    `void` | `openTag(java.lang.String tag)` Opens a tag with the given name.
    `void` | `openTag(java.lang.String tag, AttrList attrs)` Opens a tag with the given name and the given attribute list.
    `protected void` | `performWrite()` Needs to be overridden to actually write data.
    `protected abstract void` | `performWriteBody()`
    `protected void` | `performWriteFooter()`
    `protected void` | `performWriteHeader()`
    `protected void` | `printIndent()`
    `void` | `setIndentString(java.lang.String indentStr)` Sets the indentation String which is a String of two blanks by default.
    `void` | `setWriteEmptyTags(boolean state)` Tells whether tags that contain no content should be written at all.
    `void` | `writeComment(java.lang.String comment)` Writes a tagged comment.
    `void` | `writeTag(java.lang.String tag)` Writes a simple non argument tag.
    `void` | `writeTag(java.lang.String tag, AttrList attrs)` Writes a complete tag which has attributes only but no value.
    `void` | `writeTag(java.lang.String tag, AttrList attrs, java.lang.String value)` Opens, writes and closes a tag with the given name, attributes and value.
    `void` | `writeTag(java.lang.String tag, java.lang.String value)` Opens, writes and closes a tag with the given name and value.
    `void` | `writeValue(java.lang.String value)` Writes the value for the last opened tag.
    `protected void` | `writeXmlHeader()`

    - ### Methods inherited from class de.esprit.appsuite.io.DataWriter

      `createFileOutputStream, executeAsync, flush, format, format, getEncoding, getOutputFile, getWriteDuration, getWriter, openStream, print, print, print, print, print, print, print, print, print, printf, printf, printLine, println, println, println, println, println, println, println, println, println, println, setCloseStreamWhenFinished, setEncoding, setOutputFile, setOutputStream, write, write, write, write, write`

    - ### Methods inherited from class de.esprit.appsuite.task.AbstractAsyncExecutable

      `addMonitor, checkCancelled, checkForErrorAndRethrow, clearMonitors, createRunStateFlag, doOnCancel, doOnFailure, execute, executeSubTask, getError, getMaxProgressSteps, getMonitorCount, getMonitors, getName, getProgressStepCount, getResult, getRunStateFlag, getTaskId, getType, handleCancellation, handleFailure, handleFinish, handleStart, handleSuccess, hasError, hasMonitor, isCancellable, notifyProceeded, registerTaskStateChange, removeMonitor, resetProgress, setCancellable, setLogLevel, setMaxProgressSteps, setMonitor, setName, setName, setResult, setRunStateFlag, setTaskId, setType, shouldFireMonitor, sleepChecked, wasCancelled`

    - ### Methods inherited from class de.esprit.appsuite.launch.AbstractApplicationObject

      `getApplicationContext, getLogChannel, isLogDebug, isLogVerbose, logDebug, logDump, logError, logError, logFatal, logInfo, logVerbose, logWarning, setLogChannel`

    - ### Methods inherited from class de.esprit.common.util.DumpableObject

      `configureDumpHeadlineLength, configureDumpMaxElementsPrinted, copyDumpStringValues, copyToStringValues, createDumpHeader, toDumpString, toDumpString, toString, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface de.esprit.appsuite.launch.ApplicationObject

      `getApplicationContext`

    - ### Methods inherited from interface de.esprit.common.log.SimpleLogSupport

      `getLogChannel, isLogDebug, isLogVerbose, logDebug, logDump, logError, logError, logFatal, logInfo, logVerbose, logWarning, setLogChannel`

- - ### Field Detail

    - #### DEFAULT_ENCODING

          public static final java.lang.String DEFAULT_ENCODING

    - #### attrs

          protected final AttrList attrs

  - ### Constructor Detail

    - #### TagWriter

          public TagWriter(C ctx,
                   java.lang.String fileName)

    - #### TagWriter

          public TagWriter(C ctx,
                   java.lang.String fileName,
                   java.lang.String encoding)

    - #### TagWriter

          public TagWriter(C ctx,
                   java.io.File file)

    - #### TagWriter

          public TagWriter(C ctx,
                   java.io.File file,
                   java.lang.String encoding)

    - #### TagWriter

          public TagWriter(C ctx,
                   java.io.OutputStream out)

    - #### TagWriter

          public TagWriter(C ctx,
                   java.io.OutputStream out,
                   java.lang.String encoding)

  - ### Method Detail

    - #### writeXmlHeader

          protected void writeXmlHeader()

    - #### performWrite

          protected final void performWrite()
                                     throws java.lang.Exception

      Description copied from class: `DataWriter`
      Needs to be overridden to actually write data.
      Specified by:
        `performWrite` in class `DataWriter<C extends ApplicationContext>`
      Throws:
        `java.lang.Exception`

    - #### performWriteHeader

          protected void performWriteHeader()
                                     throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### performWriteBody

          protected abstract void performWriteBody()
                                            throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### performWriteFooter

          protected void performWriteFooter()
                                     throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### attr

          public AttrList attr(java.lang.String key,
                      java.lang.String value)

      Convenience method for single attribute

    - #### setIndentString

          public void setIndentString(java.lang.String indentStr)

      Sets the indentation String which is a String of two blanks by default. You may set it to a tab ("\t") if you prefer tab-indentation.

    - #### setWriteEmptyTags

          public void setWriteEmptyTags(boolean state)

      Tells whether tags that contain no content should be written at all.

    - #### isWritingEmptyTags

          public boolean isWritingEmptyTags()

      Tells whether tags that contain no content should be written at all.

    - #### openTag

          public void openTag(java.lang.String tag)

      Opens a tag with the given name. The tag must be closed again with the `closeTag()` method.

    - #### openTag

          public void openTag(java.lang.String tag,
                     AttrList attrs)

      Opens a tag with the given name and the given attribute list. The tag must be closed again with the `closeTag()` method.

    - #### writeTag

          public void writeTag(java.lang.String tag)

      Writes a simple non argument tag.

    - #### writeTag

          public void writeTag(java.lang.String tag,
                      java.lang.String value)

      Opens, writes and closes a tag with the given name and value.

    - #### writeTag

          public void writeTag(java.lang.String tag,
                      AttrList attrs)

      Writes a complete tag which has attributes only but no value.

    - #### getSimpleTagCloseBracket

          protected java.lang.String getSimpleTagCloseBracket()

    - #### writeTag

          public void writeTag(java.lang.String tag,
                      AttrList attrs,
                      java.lang.String value)

      Opens, writes and closes a tag with the given name, attributes and value.

    - #### closeTag

          public void closeTag()

      Closes the tag that was last opened.

    - #### getTag

          protected java.lang.String getTag(java.lang.String tag)

    - #### writeValue

          public void writeValue(java.lang.String value)

      Writes the value for the last opened tag.

    - #### writeComment

          public void writeComment(java.lang.String comment)

      Writes a tagged comment.

    - #### printIndent

          protected void printIndent()

    - #### close

          public void close()
                     throws java.io.IOException

      Closes the output stream. If there are still open tags when closing, those are closed automatically but a comment is written into the output telling which tags have been left open.
      Specified by:
        `close` in interface `java.io.Closeable`
      Specified by:
        `close` in interface `java.lang.AutoCloseable`
      Overrides:
        `close` in class `DataWriter<C extends ApplicationContext>`
      Throws:
        `java.io.IOException`

Copyright © 2014 EsprIT-Systems. All Rights Reserved.