com.raritantechnologies.searchApp.formatters
Class PatternResultFormatter

java.lang.Object
  extended bycom.raritantechnologies.searchApp.formatters.PatternResultFormatter
All Implemented Interfaces:
IConfigurable, IFieldFormatter

public class PatternResultFormatter
extends java.lang.Object
implements IFieldFormatter

Uses a String pattern template to format a field or set of fields in an IResult.

The template can be any string pattern. Field values are inserted into the template at positions indicated by {fieldname} sections where "fieldname" is the name of some result field.

XML Configuration Template:
   <Formatter formatterClass="com.raritantechnologies.searchApp.formatters.PatternResultFormatter"
                 outputID="[ fieldID that gets pattern result ]"
                 startBraceChar="[ character to start field name block - default is '{' ]"
                 endBraceChar="[ character to start field name block - default is '}' ]"
                 addValues="[ true|false(default) - if true, will add new value to output field ]" >

     <!-- =========================================================  -->
     <!-- String template that result field values will be inserted  -->
     <!-- into. If this is HTML or XML, the template block should be -->
     <!-- wrapped in a <!CDATA[  ]]> section.                        -->
     <!-- =========================================================  -->
     <Template>
        Display string with {fieldname} sections that will be replaced with result field values
        inserted by the PatternResultFormatter.

        Template can contain nested templates: e.g. {NESTED:nestedField:[ the sub template with inner {field}s ]}  

        Multiple field values can be handled by {MULTIPLE:multivalueField:[ the sub template with {VALUE} placeholders ]} If
        the field has repeating values, the sub template will be repeated in the output. NOTE: DO NOT nest the same multi-value field
        in the sub template!
     </Template>

     <!-- ============================================================================= -->
     <!-- Templates can use IResultRenderers to fill in the template section IF         -->
     <!-- the section name is prepended with a "RENDERER:[name]" pattern. In this case, -->
     <!-- there must be a child IResultRenderer defined with the given name             -->
     <!-- ============================================================================= -->
     <FieldRenderers>

       <FieldRenderer name="[ name of this renderer ]"
                         class="[ class of com.raritantechnologies.searchApp.taglibrary.IResultRenderer ]" >

       </FieldRenderer>

     </FieldRenderers>

   </Formatter>
 

Developed by Raritan Technologies Inc..

Author:
Ted Sullivan

Field Summary
 
Fields inherited from interface com.raritantechnologies.searchApp.IFieldFormatter
TEMPLATE
 
Constructor Summary
PatternResultFormatter()
           
 
Method Summary
 java.lang.String formatField(java.lang.String fieldVal)
          Reformats a field value.
 java.lang.String formatField(java.lang.String sessionID, java.lang.String fieldVal)
          Reformats a field value.
 void formatResultField(IResult res)
          Formats a result field "in place".
 void formatResultField(java.lang.String sessionID, IResult result)
          Formats a result field "in place", incorporating session context.
 java.lang.String getConfigurationXML()
           
 java.lang.String getConfigurationXML(java.lang.String configurationTemplate)
           
 java.lang.String getFieldName()
          Returns the name of the result field that this formatter can reformat.
 java.lang.String getFormattedString(java.lang.String sessionID, IResult result)
          Returns a formatted String for the metadata contained in an IResult.
 java.lang.String getFormattedString(java.lang.String sessionID, IResult result, java.lang.String resultTemplate)
           
 void initialize(org.w3c.dom.Element elem)
          Initializes the formatter from configuration XML element.
 void setResultTemplate(java.lang.String resultTemplate)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PatternResultFormatter

public PatternResultFormatter()
Method Detail

setResultTemplate

public void setResultTemplate(java.lang.String resultTemplate)

formatResultField

public void formatResultField(IResult res)
Description copied from interface: IFieldFormatter
Formats a result field "in place".

Specified by:
formatResultField in interface IFieldFormatter
Parameters:
res - The result object that is to be formatted.

formatResultField

public void formatResultField(java.lang.String sessionID,
                              IResult result)
Description copied from interface: IFieldFormatter
Formats a result field "in place", incorporating session context.

Specified by:
formatResultField in interface IFieldFormatter
Parameters:
sessionID - The session key needed to lookup any session content stored in the session data cache.
result - The result object that is to be formatted.

getFormattedString

public java.lang.String getFormattedString(java.lang.String sessionID,
                                           IResult result)
Returns a formatted String for the metadata contained in an IResult.


getFormattedString

public java.lang.String getFormattedString(java.lang.String sessionID,
                                           IResult result,
                                           java.lang.String resultTemplate)

getFieldName

public java.lang.String getFieldName()
Description copied from interface: IFieldFormatter
Returns the name of the result field that this formatter can reformat.

Specified by:
getFieldName in interface IFieldFormatter

formatField

public java.lang.String formatField(java.lang.String fieldVal)
Reformats a field value.

Specified by:
formatField in interface IFieldFormatter
Parameters:
fieldVal - The field value to be reformatted.
Returns:
The reformatted field value.

formatField

public java.lang.String formatField(java.lang.String sessionID,
                                    java.lang.String fieldVal)
Description copied from interface: IFieldFormatter
Reformats a field value.

Specified by:
formatField in interface IFieldFormatter
Parameters:
sessionID - The session key needed to lookup any session content stored in the session data cache.
fieldVal - The field value to be reformatted.
Returns:
The reformatted field value.

initialize

public void initialize(org.w3c.dom.Element elem)
Description copied from interface: IFieldFormatter
Initializes the formatter from configuration XML element.

Specified by:
initialize in interface IFieldFormatter

getConfigurationXML

public java.lang.String getConfigurationXML()
Specified by:
getConfigurationXML in interface IFieldFormatter

getConfigurationXML

public java.lang.String getConfigurationXML(java.lang.String configurationTemplate)
Specified by:
getConfigurationXML in interface IFieldFormatter