org.allcolor.yahp.cl.converter.utils
Class CPadawan

java.lang.Object
  extended by org.allcolor.yahp.cl.converter.utils.CPadawan

public final class CPadawan
extends java.lang.Object

A text validation class.

Version:
0.94
Author:
Quentin Anciaux

Field Summary
private static java.lang.String[][] entity
          html entity list
private  java.lang.String entityDecl
          handle to entity declaration
private static CPadawan handle
          handle to the singleton
private  long lastModified
          last modification date of the config file
private  java.util.Map mapFilter
          contains known filters
private static CMutex mutex
          use for thread safety access
 
Constructor Summary
CPadawan()
           
 
Method Summary
 java.lang.String createEntityDeclaration()
          Create the padawan doctype
 java.lang.String decode(java.lang.String toDecode)
          decode entity in the string
 java.lang.String encode(java.lang.String toEncode)
          encode entity in the string
 java.lang.String escape(java.lang.String in)
          Escape the given string to be a valid content for an xml text node content
 java.lang.String escapeAttribute(java.lang.String in)
          Escape the given string to be a valid content for an xml attribute
 java.lang.String getEntityDeclaration()
          return the padawan doctype
private  java.util.List getFilter(java.lang.String type)
          return the filters of type 'type'
static CPadawan getInstance()
          Return an instance of the padawan
private  java.util.List getMerge(java.lang.String type)
          return the merge list of type 'type'
private  java.util.List getTags(java.lang.String type)
          return the tag list of type 'type'
private  void init()
          Initialize the class
private  boolean isAlone(java.lang.String tagName, java.lang.String[] aloneTags)
          return true if the given tag name is an empty tag
private  void parseDocument(org.w3c.dom.Node currentNode)
          parse the configuration file
private  void renderXMLRecurs(java.io.PrintWriter out, org.w3c.dom.Node node, java.lang.String[] aloneTags)
          rewrite the given xmlfile
 java.lang.String replaceExpr(java.lang.String message, java.lang.String type)
          Replace the input message using the rules 'type' found in the xml configuration file
 java.lang.String rewriteXml(org.w3c.dom.Node xmlDoc, java.lang.String[] aloneTags)
          rewrite the given xmlfile
 java.lang.String rewriteXml(org.w3c.dom.Node xmlDoc, java.lang.String[] aloneTags, boolean outputXmlHeader)
          rewrite the given xmlfile
 java.lang.String rewriteXml(java.lang.String xmlFile, java.lang.String[] aloneTags)
          rewrite the given xmlfile
 java.lang.String rewriteXml(java.lang.String xmlFile, java.lang.String[] aloneTags, boolean outputXmlHeader)
          rewrite the given xmlfile
 void rewriteXml(java.io.Writer out, org.w3c.dom.Node xmlDoc, java.lang.String[] aloneTags)
          rewrite the given xmlfile
 void rewriteXml(java.io.Writer out, org.w3c.dom.Node xmlDoc, java.lang.String[] aloneTags, boolean outputXmlHeader)
          rewrite the given xmlfile
 void rewriteXml(java.io.Writer out, java.lang.String xmlFile, java.lang.String[] aloneTags)
          rewrite the given xmlfile
 void rewriteXml(java.io.Writer out, java.lang.String xmlFile, java.lang.String[] aloneTags, boolean outputXmlHeader)
          rewrite the given xmlfile
 java.lang.String stringReplace(java.lang.String toBeReplaced, java.lang.String toReplace, java.lang.String replacement)
          A replace string method
 java.lang.String validate(java.lang.String in, java.lang.String type)
          validate for xml the string in using the rules type 'type'
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

handle

private static CPadawan handle
handle to the singleton


entity

private static final java.lang.String[][] entity
html entity list


mutex

private static final CMutex mutex
use for thread safety access


lastModified

private long lastModified
last modification date of the config file


mapFilter

private java.util.Map mapFilter
contains known filters


entityDecl

private java.lang.String entityDecl
handle to entity declaration

Constructor Detail

CPadawan

public CPadawan()
Method Detail

replaceExpr

public final java.lang.String replaceExpr(java.lang.String message,
                                          java.lang.String type)
Replace the input message using the rules 'type' found in the xml configuration file

Parameters:
message - message to replace
type - rule type
Returns:
the replaced message

init

private final void init()
Initialize the class


getInstance

public static final CPadawan getInstance()
Return an instance of the padawan

Returns:
may the force be with you !

getFilter

private final java.util.List getFilter(java.lang.String type)
return the filters of type 'type'

Parameters:
type - type of filters to get
Returns:
the filters of type 'type'

getTags

private final java.util.List getTags(java.lang.String type)
return the tag list of type 'type'

Parameters:
type - type of tag list to get
Returns:
the tag list of type 'type'

getMerge

private final java.util.List getMerge(java.lang.String type)
return the merge list of type 'type'

Parameters:
type - type of merge list to get
Returns:
the merge list of type 'type'!

parseDocument

private final void parseDocument(org.w3c.dom.Node currentNode)
parse the configuration file

Parameters:
currentNode - current analysed node

validate

public final java.lang.String validate(java.lang.String in,
                                       java.lang.String type)
validate for xml the string in using the rules type 'type'

Parameters:
in - the string to validate
type - rule type
Returns:
the validated string

createEntityDeclaration

public final java.lang.String createEntityDeclaration()
                                               throws java.io.UnsupportedEncodingException
Create the padawan doctype

Returns:
the padawan doctype
Throws:
java.io.UnsupportedEncodingException - should not happen

getEntityDeclaration

public final java.lang.String getEntityDeclaration()
return the padawan doctype

Returns:
the padawan doctype

decode

public final java.lang.String decode(java.lang.String toDecode)
decode entity in the string

Parameters:
toDecode - the string to decode
Returns:
the decoded string

encode

public final java.lang.String encode(java.lang.String toEncode)
encode entity in the string

Parameters:
toEncode - the string to encode
Returns:
the encoded string

stringReplace

public final java.lang.String stringReplace(java.lang.String toBeReplaced,
                                            java.lang.String toReplace,
                                            java.lang.String replacement)
A replace string method

Parameters:
toBeReplaced - string to replace
toReplace - regex to match
replacement - string replacement for each match
Returns:
the replaced string

rewriteXml

public final java.lang.String rewriteXml(java.lang.String xmlFile,
                                         java.lang.String[] aloneTags)
rewrite the given xmlfile

Parameters:
xmlFile - xml file as a string
aloneTags - a string array of empty tags
Returns:
the rewrited xml.

rewriteXml

public final java.lang.String rewriteXml(java.lang.String xmlFile,
                                         java.lang.String[] aloneTags,
                                         boolean outputXmlHeader)
rewrite the given xmlfile

Parameters:
xmlFile - xml file as a string
aloneTags - a string array of empty tags
outputXmlHeader - true to output xml header
Returns:
the rewrited xml.

rewriteXml

public final void rewriteXml(java.io.Writer out,
                             java.lang.String xmlFile,
                             java.lang.String[] aloneTags)
rewrite the given xmlfile

Parameters:
out - the writer to write the xml
xmlFile - xml file as a string
aloneTags - a string array of empty tags

rewriteXml

public final void rewriteXml(java.io.Writer out,
                             java.lang.String xmlFile,
                             java.lang.String[] aloneTags,
                             boolean outputXmlHeader)
rewrite the given xmlfile

Parameters:
out - the writer to write the xml
xmlFile - xml file as a string
aloneTags - a string array of empty tags
outputXmlHeader - true to output xml header

rewriteXml

public final java.lang.String rewriteXml(org.w3c.dom.Node xmlDoc,
                                         java.lang.String[] aloneTags)
rewrite the given xmlfile

Parameters:
xmlDoc - xml file as a dom node
aloneTags - a string array of empty tags
Returns:
the rewrited xml.

rewriteXml

public final java.lang.String rewriteXml(org.w3c.dom.Node xmlDoc,
                                         java.lang.String[] aloneTags,
                                         boolean outputXmlHeader)
rewrite the given xmlfile

Parameters:
xmlDoc - xml file as a dom node
aloneTags - a string array of empty tags
outputXmlHeader - true to output xml header
Returns:
the rewrited xml.

rewriteXml

public final void rewriteXml(java.io.Writer out,
                             org.w3c.dom.Node xmlDoc,
                             java.lang.String[] aloneTags)
rewrite the given xmlfile

Parameters:
out - the writer to write the xml
xmlDoc - xml file as a dom node
aloneTags - a string array of empty tags

rewriteXml

public final void rewriteXml(java.io.Writer out,
                             org.w3c.dom.Node xmlDoc,
                             java.lang.String[] aloneTags,
                             boolean outputXmlHeader)
rewrite the given xmlfile

Parameters:
out - the writer to write the xml
xmlDoc - xml file as a dom node
aloneTags - a string array of empty tags
outputXmlHeader - true to output xml header

renderXMLRecurs

private final void renderXMLRecurs(java.io.PrintWriter out,
                                   org.w3c.dom.Node node,
                                   java.lang.String[] aloneTags)
rewrite the given xmlfile

Parameters:
out - the writer to write the xml
node - current writed node
aloneTags - a string array of empty tags

isAlone

private final boolean isAlone(java.lang.String tagName,
                              java.lang.String[] aloneTags)
return true if the given tag name is an empty tag

Parameters:
tagName - tag name to lookup
aloneTags - a string array of empty tags
Returns:
true if the given tag name is an empty tag

escapeAttribute

public final java.lang.String escapeAttribute(java.lang.String in)
Escape the given string to be a valid content for an xml attribute

Parameters:
in - the string to escape
Returns:
the escaped string

escape

public final java.lang.String escape(java.lang.String in)
Escape the given string to be a valid content for an xml text node content

Parameters:
in - the string to escape
Returns:
the escaped string