LEONARDI Application Composer - 8.9.0.40 by W4 S.A.

leon.control.print
Class LyContentReplacer

java.lang.Object
  extended by leon.control.print.LyContentReplacer

public class LyContentReplacer
extends java.lang.Object

This class Reads a file (Ascii, XML, RTF, HTML ...) and replace some keys inside the file pattern like $KEY$ to produce an output file with content.


Field Summary
static java.lang.String __VERSION
          File version
static int DISPLAY_VALUE_INTERNAL
          Display parameter to indicate what to display in the value of a field : internal value (fieldValue.getString()).
static int DISPLAY_VALUE_NAME
          Display parameter to indicate what to display in the value of a field : default is value name (fieldValue.getName()).
static int DISPLAY_VALUE_SHORT_NAME
          Display parameter to indicate what to display in the value of a field : short name value (fieldValue.getShortName()).
static java.lang.String ESCAPE_ENCODE_SEP
          Escape encode character
static java.lang.String FIELDINFO_SEP
          Fieldinfo separator
static java.lang.String FIELDNAME_SEP
          Field name separator
static java.lang.String IF_FIRST_OBJECT_END
          IF_FIRST_OBJECT_END Tag
static java.lang.String IF_FIRST_OBJECT_START
          IF_FIRST_OBJECT_START Tag
static java.lang.String IF_LAST_OBJECT_END
          IF_LAST_OBJECT_END Tag
static java.lang.String IF_LAST_OBJECT_START
          IF_LAST_OBJECT_START tag
static java.lang.String IF_NOT_FIRST_OBJECT_END
          IF_NOT_FIRST_OBJECT_END Tag
static java.lang.String IF_NOT_FIRST_OBJECT_START
          IF_NOT_FIRST_OBJECT_START Tag
static java.lang.String IF_NOT_LAST_OBJECT_END
          IF_NOT_LAST_OBJECT_END Tag
static java.lang.String IF_NOT_LAST_OBJECT_START
          IF_NOT_LAST_OBJECT_START Tag
static int MODE_HTML
          Replacing mode for encoding : HTML (html encoding).
static int MODE_RTF
          Replacing mode for encoding : RTF (rtf encoding).
static int MODE_TEXT
          Replacing mode for encoding : text (no encoding).
static int MODE_XML
          Replacing mode for encoding : XML (xml encoding).
static java.lang.String REPEAT_OBJECT_END
          REPEAT_OBJECT_ENDt Tag
static java.lang.String REPEAT_OBJECT_START
          REPEAT_OBJECT_START Tag
static java.lang.String SORT_ID
           
 
Constructor Summary
LyContentReplacer(LyEnvironment environment)
          Constructor.
 
Method Summary
 java.lang.String clearIndexFromKey(java.lang.String key)
          Get the Key name without the index information index is like fieldInfoId[index].
 java.lang.String encodeString(java.lang.String value)
          Encode the string for the target output.
 java.lang.String format(java.lang.String text, int step)
          Format the given text
 java.lang.String format(java.lang.String text, int step, boolean fill, char filling_char, boolean replace_cr)
          Format a string to a maximum width with new lines inserted every 'step' position.
 int generateContentFromModel(LyObjectList objects, java.io.PrintWriter writer)
          Generate the content for the specified object and write it to the output.
 java.lang.String getContentFromModel(LyObject object)
          Get the content fromt the model.
 java.lang.String getContentFromModel(LyObjectList objects)
          Get the result of the transformation as a String.
 int getIndexFromKey(java.lang.String key)
          Get the specified index for the key index is like fieldInfoId[index].
 int getMode()
          Accessor to Current mode file.
 java.lang.String getModelFile()
          Accessor to Current model file.
 LyObjectList getObjectListFromInterpreter(java.lang.String[] keys, LyObjectList objects, int depth)
          get the list of value from the interpreter within current context.
 java.util.Hashtable<java.lang.String,java.lang.String> getRootDictionnary()
          accessor to the original dictionnary.
 java.lang.String getString(LyValue value, java.lang.String separator)
          Utility method to get a multipleValue as a String with a separator.
 java.lang.String getValueFromInterpreter(java.lang.String[] keys, LyObjectList objects, java.util.Vector<LyObjectList> parentContextStack, int depth, int display)
          get the value from the interpreter within current context.
 boolean isDisplayed(LyFieldInfo fieldInfo)
          Utility method to know if a fieldInfo is displayed in this result or not.
 int matchPatterns(LyObjectList objects, java.lang.String model, java.io.PrintWriter writer, java.util.Hashtable<java.lang.String,java.lang.String> dict, char tag, java.util.Vector<LyObjectList> parentContextStack, int writeOutputDisabled)
          Enables pattern matching in a file.
 void setModelFile(java.lang.String modelFile)
          Accessor to Current model file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

__VERSION

public static final java.lang.String __VERSION
File version

See Also:
Constant Field Values

ESCAPE_ENCODE_SEP

public static java.lang.String ESCAPE_ENCODE_SEP
Escape encode character


FIELDINFO_SEP

public static java.lang.String FIELDINFO_SEP
Fieldinfo separator


FIELDNAME_SEP

public static java.lang.String FIELDNAME_SEP
Field name separator


REPEAT_OBJECT_START

public static java.lang.String REPEAT_OBJECT_START
REPEAT_OBJECT_START Tag


REPEAT_OBJECT_END

public static java.lang.String REPEAT_OBJECT_END
REPEAT_OBJECT_ENDt Tag


IF_LAST_OBJECT_START

public static java.lang.String IF_LAST_OBJECT_START
IF_LAST_OBJECT_START tag


IF_LAST_OBJECT_END

public static java.lang.String IF_LAST_OBJECT_END
IF_LAST_OBJECT_END Tag


IF_NOT_LAST_OBJECT_START

public static java.lang.String IF_NOT_LAST_OBJECT_START
IF_NOT_LAST_OBJECT_START Tag


IF_NOT_LAST_OBJECT_END

public static java.lang.String IF_NOT_LAST_OBJECT_END
IF_NOT_LAST_OBJECT_END Tag


IF_FIRST_OBJECT_START

public static java.lang.String IF_FIRST_OBJECT_START
IF_FIRST_OBJECT_START Tag


IF_FIRST_OBJECT_END

public static java.lang.String IF_FIRST_OBJECT_END
IF_FIRST_OBJECT_END Tag


IF_NOT_FIRST_OBJECT_START

public static java.lang.String IF_NOT_FIRST_OBJECT_START
IF_NOT_FIRST_OBJECT_START Tag


IF_NOT_FIRST_OBJECT_END

public static java.lang.String IF_NOT_FIRST_OBJECT_END
IF_NOT_FIRST_OBJECT_END Tag


SORT_ID

public static java.lang.String SORT_ID

MODE_TEXT

public static final int MODE_TEXT
Replacing mode for encoding : text (no encoding).

See Also:
Constant Field Values

MODE_HTML

public static final int MODE_HTML
Replacing mode for encoding : HTML (html encoding).

See Also:
Constant Field Values

MODE_RTF

public static final int MODE_RTF
Replacing mode for encoding : RTF (rtf encoding).

See Also:
Constant Field Values

MODE_XML

public static final int MODE_XML
Replacing mode for encoding : XML (xml encoding).

See Also:
Constant Field Values

DISPLAY_VALUE_NAME

public static final int DISPLAY_VALUE_NAME
Display parameter to indicate what to display in the value of a field : default is value name (fieldValue.getName()).

See Also:
Constant Field Values

DISPLAY_VALUE_SHORT_NAME

public static final int DISPLAY_VALUE_SHORT_NAME
Display parameter to indicate what to display in the value of a field : short name value (fieldValue.getShortName()).

See Also:
Constant Field Values

DISPLAY_VALUE_INTERNAL

public static final int DISPLAY_VALUE_INTERNAL
Display parameter to indicate what to display in the value of a field : internal value (fieldValue.getString()).

See Also:
Constant Field Values
Constructor Detail

LyContentReplacer

public LyContentReplacer(LyEnvironment environment)
Constructor.

Parameters:
environment - the current environment
Method Detail

getContentFromModel

public java.lang.String getContentFromModel(LyObject object)
Get the content fromt the model.

Parameters:
object - current model
Returns:
the result as a String

getContentFromModel

public java.lang.String getContentFromModel(LyObjectList objects)
Get the result of the transformation as a String.

Parameters:
objects - current value to build replacement dictionnary
Returns:
the result as a String

getRootDictionnary

public java.util.Hashtable<java.lang.String,java.lang.String> getRootDictionnary()
accessor to the original dictionnary.

Returns:
default dictionnary

generateContentFromModel

public int generateContentFromModel(LyObjectList objects,
                                    java.io.PrintWriter writer)
                             throws java.io.IOException
Generate the content for the specified object and write it to the output.

Parameters:
objects - current objects used for content replacement
writer - current writer for the output
Returns:
number of objects generated in the output
Throws:
java.io.IOException

getModelFile

public java.lang.String getModelFile()
Accessor to Current model file.

Returns:
current model file

setModelFile

public void setModelFile(java.lang.String modelFile)
Accessor to Current model file.

Parameters:
modelFile - current model file

isDisplayed

public boolean isDisplayed(LyFieldInfo fieldInfo)
Utility method to know if a fieldInfo is displayed in this result or not. Returns false if the fieldInfo is marked with LyFieldInfo.MARK_SECRET

These fields should never be shown to the user.

Parameters:
fieldInfo - the fieldInfo which is tested for addition in the view.
Returns:
true if the field should be added, false if it should be skipped.

getString

public java.lang.String getString(LyValue value,
                                  java.lang.String separator)
Utility method to get a multipleValue as a String with a separator.

Parameters:
value - value to convert as a String
separator - separator between values
Returns:
the result String

format

public java.lang.String format(java.lang.String text,
                               int step,
                               boolean fill,
                               char filling_char,
                               boolean replace_cr)
Format a string to a maximum width with new lines inserted every 'step' position.

Parameters:
text - char string to display
step - nmber of characters for new line insert
fill - indicates if the string is filled at the end with filling_char
filling_char - filling char for the end of the String
replace_cr - indicate if \n are replaced by blanks or not.
Returns:
the formatted string or null if an error occured

format

public java.lang.String format(java.lang.String text,
                               int step)
Format the given text

Parameters:
text - the text
step - a step
Returns:
the formatted text

matchPatterns

public int matchPatterns(LyObjectList objects,
                         java.lang.String model,
                         java.io.PrintWriter writer,
                         java.util.Hashtable<java.lang.String,java.lang.String> dict,
                         char tag,
                         java.util.Vector<LyObjectList> parentContextStack,
                         int writeOutputDisabled)
Enables pattern matching in a file. The output file is identical as the original file but with replacement of marks with the value found in a dictionnary Marks use the following syntax Substitution may keep on processing if : if string length is greater than lg, the string is cut.
If + is found then the remaining chars in the string will be used in the next patter. If not, the string is cut.
If lg is not specified, the entire string is used for substitution.

Parameters:
objects - a list of objects
model - original content for substitution
writer - result stream
dict - pattern matching dictionnary
tag - tag delimiter -it is *2 in the model, like '@@')
parentContextStack - this is the stack of context (null by default at root level) for loops.
writeOutputDisabled - counters for write disable requesters : must be 0 at root level
Returns:
nb of char read

getValueFromInterpreter

public java.lang.String getValueFromInterpreter(java.lang.String[] keys,
                                                LyObjectList objects,
                                                java.util.Vector<LyObjectList> parentContextStack,
                                                int depth,
                                                int display)
get the value from the interpreter within current context.

Parameters:
keys - the tags to extract from context
objects - current context
parentContextStack - the stack of all parent context (to go up with '..' in interpreter)
depth - current depth in analysis of keys
display - indicates what to display:one of the DISPLAY_VALUE_xxx constants
Returns:
the value or the tag if it makes no sense or "" if the value is empty.

getObjectListFromInterpreter

public LyObjectList getObjectListFromInterpreter(java.lang.String[] keys,
                                                 LyObjectList objects,
                                                 int depth)
get the list of value from the interpreter within current context.

Parameters:
keys - the tag to extract from context
objects - current context
depth - current depth in analysis of keys
Returns:
the value or the tag if it makes no sense or "" if the value is empty.

getIndexFromKey

public int getIndexFromKey(java.lang.String key)
Get the specified index for the key index is like fieldInfoId[index].

Parameters:
key - the key to parse
Returns:
0 if first index, -1 if within loop

clearIndexFromKey

public java.lang.String clearIndexFromKey(java.lang.String key)
Get the Key name without the index information index is like fieldInfoId[index].

Parameters:
key - the key to parse
Returns:
the key

encodeString

public java.lang.String encodeString(java.lang.String value)
Encode the string for the target output.

Parameters:
value - the value to encode
Returns:
the encoded string depending on current MODE_xxx which is set by setMode or autodetect

getMode

public int getMode()
Accessor to Current mode file.

Returns:
current mode file

(c) January 2013 - W4 S.A.

Website: W4 S.A., contact us: support@w4global.com