de.vc.jfo.rtf.listeners

## Class SimpleDataSource

- java.lang.Object
- - de.vc.jfo.rtf.listeners.AbstractDataSource
  - - de.vc.jfo.rtf.listeners.SimpleDataSource

- All Implemented Interfaces:
    FieldListener
  Direct Known Subclasses:
    DataMergeFieldListener, StylesheetDataSource

      public class SimpleDataSource
      extends AbstractDataSource

  This listener pushs business data (text, tables and other FO-objects) into a RTF field and executes actions. A field is identificated by a keyword (i.e. a token of a field). Following types of fields are used as placeholders for data in general:
  - {FILLIN keyword}
  - {MERGEFIELD keyword} [supported switches are \b and \f]
  It's also possible to use this data provider to process other fields like {DATE} to override JFO's field processing for these fields. Simply use DATE as the keyword. Furthermore it is possible to add one or more actions to a keyword. Therefore use addAction...() methodes.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `SimpleDataSource.ActionDescriptor` Field actions are used to execute context related actions.
    `protected class` | `SimpleDataSource.ValueDescriptor` Value assigned to a keyword.

  - ### Field Summary

    - ### Fields inherited from interface de.vc.jfo.rtf.FieldListener

      `FIELD_FILLIN, FIELD_MERGEFIELD`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SimpleDataSource()` Creates a new field listener.
    `SimpleDataSource(boolean caseSensitiveKeywords)` Creates a new field listener.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addActionWrapListItem(java.lang.String keyword, Node wrapper)` Adds an action that wraps the list-item of current list into another node.
    `void` | `addActionWrapTableRow(java.lang.String keyword, Node wrapper)` Adds an action that wraps the table row of current cell into another node.
    `SimpleDataSource.ValueDescriptor` | `getValue(java.lang.String keyword)`
    `boolean` | `hasValue(java.lang.String keyword)` Checks whether a value is assigned to a keyword.
    `protected boolean` | `insertResult(FieldContext ctx, java.lang.String keyword)` Inserts the result for a field depending of type of data.
    `boolean` | `isCloneIfNeccessary()` Checks if special objects in field result should be cloned or not if they are inserted multiple times.
    `boolean` | `isEmptyValue(java.lang.String keyword)` Checks whether an empty value is assigned to a keyword.
    `java.util.List` | `listActions(java.lang.String keyword)` Lists all actions assigned to a keyword.
    `void` | `removeActions(java.lang.String keyword)` Removes all actions that are assigned to `keyword`.
    `void` | `removeValue(java.lang.String keyword)` Removes a value.
    `void` | `setCloneIfNeccessary(boolean cloneIfNeccessary)` If a value (result) of a field is inserted multiple times and it contains some `NodeElement` Objects (e.g. fo:inline, fo:block) then these node elements should be cloned.
    `void` | `setDocument(java.lang.String keyword, Document document, boolean restartPageNumbering)` Sets a whole document as a value for a field.
    `void` | `setDocumentContent(java.lang.String keyword, Document document)` Sets a the content of a document as fields value.
    `void` | `setEmptyValue(java.lang.String keyword)` Sets an empty value for a field.
    `void` | `setListItems(java.lang.String keyword, java.lang.Object[] items)` Sets items for a list or numbering.
    `void` | `setTableColumn(java.lang.String keyword, java.lang.Object[] cells)` Sets cells for a table column.
    `void` | `setValue(java.lang.String keyword, java.lang.Object value)` Sets the value for a field.

    - ### Methods inherited from class de.vc.jfo.rtf.listeners.AbstractDataSource

      `fieldEncountered, handleUnpopulatedField, isCaseSensitiveKeywords, isEnableDateFormatting, isEnableNumberFormatting, isHighlightUnpopulatedFields, normalizeKey, setCaseSensitiveKeywords, setEnableDateFormatting, setEnableNumberFormatting, setHighlightUnpopulatedFields`

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

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

- - ### Constructor Detail

    - #### SimpleDataSource

          public SimpleDataSource()

      Creates a new field listener. Keywords are not handled case sensitive.

    - #### SimpleDataSource

          public SimpleDataSource(boolean caseSensitiveKeywords)

      Creates a new field listener.
      Parameters:
        `caseSensitiveKeywords` - `true` to handle keywords of fields (prompt of fill-in or field name of mergefield) casesensitive.

  - ### Method Detail

    - #### setValue

          public void setValue(java.lang.String keyword,
                      java.lang.Object value)

      Sets the value for a field. A value can be a single NodeElement (FormattingObject), an array of elements or a java.util.Collection of elements.
      Parameters:
        `keyword` - Keyword of field.
        `value` - Value of field.

    - #### setEmptyValue

          public void setEmptyValue(java.lang.String keyword)

      Sets an empty value for a field.
      Parameters:
        `keyword` - Keyword of field.

    - #### setTableColumn

          public void setTableColumn(java.lang.String keyword,
                            java.lang.Object[] cells)

      Sets cells for a table column. Note, inserting a table column outside of a table will produce an error.
      Parameters:
        `keyword` - Keyword of field
        `cells` - Cells of table column.

    - #### setListItems

          public void setListItems(java.lang.String keyword,
                          java.lang.Object[] items)

      Sets items for a list or numbering.
      Parameters:
        `keyword` - Keyword of field.
        `items` - Items for numbering.

    - #### hasValue

          public boolean hasValue(java.lang.String keyword)

      Checks whether a value is assigned to a keyword.
      Specified by:
        `hasValue` in class `AbstractDataSource`
      Parameters:
        `keyword` - Keyword.
      Returns:
        boolean `true` if there is a registered value for keyword.

    - #### isEmptyValue

          public boolean isEmptyValue(java.lang.String keyword)

      Description copied from class: `AbstractDataSource`
      Checks whether an empty value is assigned to a keyword.
      Specified by:
        `isEmptyValue` in class `AbstractDataSource`
      Parameters:
        `keyword` - Keyword
      Returns:
        `true` if value of `keyword` is empty.

    - #### setCloneIfNeccessary

          public void setCloneIfNeccessary(boolean cloneIfNeccessary)

      If a value (result) of a field is inserted multiple times and it contains some `NodeElement` Objects (e.g. fo:inline, fo:block) then these node elements should be cloned. By default cloning is enabled (set to true).
      Parameters:
        `cloneIfNeccessary` - Clone objects if neccessary.

    - #### isCloneIfNeccessary

          public boolean isCloneIfNeccessary()

      Checks if special objects in field result should be cloned or not if they are inserted multiple times.
      Returns:
        boolean If cloning is enabled.

    - #### setDocument

          public void setDocument(java.lang.String keyword,
                         Document document,
                         boolean restartPageNumbering)

      Sets a whole document as a value for a field. The document starts at a new page (page-sequence).
      Parameters:
        `keyword` - Keyword of field.
        `document` - The document you want to insert.
        `restartPageNumbering` - `true` if you want to restart page numbering.

    - #### setDocumentContent

          public void setDocumentContent(java.lang.String keyword,
                                Document document)

      Sets a the content of a document as fields value.
      Parameters:
        `keyword` - Keyword of field.
        `document` - Document.

    - #### addActionWrapTableRow

          public void addActionWrapTableRow(java.lang.String keyword,
                                   Node wrapper)

      Adds an action that wraps the table row of current cell into another node. First the table row is replaced by the root(!) of the wrapper and then that table row is added to `wrapper`
      Parameters:
        `keyword` - Keyword of field.
        `wrapper` - Wrapper.

    - #### addActionWrapListItem

          public void addActionWrapListItem(java.lang.String keyword,
                                   Node wrapper)

      Adds an action that wraps the list-item of current list into another node. First the list-item is replaced by the root(!) of the wrapper and then that list-item is added to `wrapper`
      Parameters:
        `keyword` - Keyword of field.
        `wrapper` - Wrapper.

    - #### removeActions

          public void removeActions(java.lang.String keyword)

      Removes all actions that are assigned to `keyword`.
      Parameters:
        `keyword` - Keyword of a field.

    - #### listActions

          public java.util.List listActions(java.lang.String keyword)

      Lists all actions assigned to a keyword.
      Parameters:
        `keyword` - Keyword of a field.
      Returns:
        List of DataMergeFieldListener.FieldAction.

    - #### getValue

          public SimpleDataSource.ValueDescriptor getValue(java.lang.String keyword)

    - #### removeValue

          public void removeValue(java.lang.String keyword)

      Removes a value.
      Parameters:
        `keyword` - Keywords.

    - #### insertResult

          protected boolean insertResult(FieldContext ctx,
                             java.lang.String keyword)

      Inserts the result for a field depending of type of data.
      Specified by:
        `insertResult` in class `AbstractDataSource`
      Parameters:
        `ctx` - FieldContext.
        `keyword` - Keyword of field
      Returns:
        boolean false if keyword not registered.

© 2003-2011 by Sascha Schmidt (vision-cloud.de). All Rights Reserved.