org.mmbase.util.transformers
Class XmlField

Package class diagram package XmlField
java.lang.Object
  extended by org.mmbase.util.transformers.StringTransformer
      extended by org.mmbase.util.transformers.ConfigurableStringTransformer
          extended by org.mmbase.util.transformers.XmlField
All Implemented Interfaces:
Serializable, CharTransformer, ConfigurableTransformer, Transformer

public class XmlField
extends ConfigurableStringTransformer
implements CharTransformer

XMLFields in MMBase. This class can encode such a field to several other formats.

Version:
$Id: XmlField.java 45318 2011-02-19 08:58:53Z michiel $
Author:
Michiel Meeuwissen
See Also:
Serialized Form

Nested Class Summary
(package private) static class XmlField.ErrorHandler
           
protected static class XmlField.FormatException
           
 
Field Summary
static int ASCII
           
static int HTML_BLOCK
           
static int HTML_BLOCK_BR
           
static int HTML_BLOCK_BR_NOSURROUNDINGP
           
static int HTML_BLOCK_LIST
           
static int HTML_BLOCK_LIST_BR
           
static int HTML_BLOCK_LIST_BR_NOSURROUNDINGP
           
static int HTML_BLOCK_LIST_NOSURROUNDINGP
           
static int HTML_BLOCK_NOSURROUNDINGP
           
static int HTML_INLINE
           
protected static boolean LEAVE_NEWLINES
           
protected static boolean LISTS_INSIDE_P
           
protected static boolean LISTS_OUTSIDE_P
           
protected static boolean NO_SECTIONS
           
protected static boolean NO_SURROUNDING_P
           
static int POORBODY
           
protected static boolean REMOVE_NEWLINES
           
static int RICHBODY
           
protected static boolean SECTIONS
          Constant for use as argument of handleRich(java.lang.StringBuilder, boolean, boolean, boolean)
protected static boolean SURROUNDING_P
           
static int XHTML
           
 
Fields inherited from class org.mmbase.util.transformers.ConfigurableStringTransformer
to
 
Constructor Summary
XmlField()
           
XmlField(int to)
           
 
Method Summary
(package private) static void cleanupText(StringBuilder obj)
          Removes all new lines and space which are too much.
 String getEncoding()
          Returns the encoding that is currently active
(package private) static void handleEmph(StringBuilder obj, char ch, String tag)
          If you want to add a _ in your text, that should be possible too...
protected static void handleFormat(StringBuilder obj, boolean format)
          Only escape, clean up.
(package private) static void handleHeaders(StringBuilder obj)
          Some paragraphs are are really \sections.
(package private) static void handleList(StringBuilder obj)
          Takes a string object, finds list structures and changes those to XML
protected static void handleNewlines(StringBuilder obj)
           
(package private) static void handleParagraphs(StringBuilder obj, boolean leaveExtraNewLines, boolean surroundingP)
          Make
(package private) static void handleParagraphs(StringBuilder obj, boolean leaveExtraNewLines, boolean surroundingP, boolean placeListsInsideP)
          Make <p> </p> tags.
protected static void handleRich(StringBuilder obj, boolean sections, boolean leaveExtraNewLines, boolean surroundingP)
           
protected static void handleRich(StringBuilder obj, boolean sections, boolean leaveExtraNewLines, boolean surroundingP, boolean placeListsInsideP)
           
(package private) static void handleTables(StringBuilder obj)
          Wikipedia syntax for tables.
static String poorToHTMLInline(String data)
          So poor, that it actually generates pieces of XHTML 1.1 inlines (so, no use of section, br, p).
static String poorToXML(String data)
           
static String poorToXML(String data, boolean format)
           
static String poorToXML(String data, boolean format, boolean placeListsInsideP)
          As richToXML but a little less rich.
(package private) static void preHandleHeaders(StringBuilder obj)
          Makes sure that lines indicating headers (starting with $), are followed by at least 2 newlines, if followed by some list.
protected static StringBuilder prepareData(String data)
           
protected static String prepareDataString(String data)
           
static void replaceAll(StringBuilder builder, String from, String to)
           
static String richToHTMLBlock(String data)
           
static String richToHTMLBlock(String data, boolean multipibleBrs, boolean surroundingP)
           
static String richToHTMLBlock(String data, boolean multipibleBrs, boolean surroundingP, boolean placeListsInsideP)
          So poor, that it actually generates pieces of XHTML 1.1 blocks (so, no use of sections).
static String richToXML(String data)
           
static String richToXML(String data, boolean format)
           
static String richToXML(String data, boolean format, boolean placeListsInsideP)
          Defines a kind of 'rich' text format.
 String transform(String data)
           
 String transformBack(String r)
           
 Map<String,Config> transformers()
          Returns which transformations can be done by an object of this class.
protected static void validate(String incoming)
           
protected static String XSLTransform(String xslFile, String data)
          Base function for XSL conversions.
 
Methods inherited from class org.mmbase.util.transformers.ConfigurableStringTransformer
configure, toString
 
Methods inherited from class org.mmbase.util.transformers.StringTransformer
transform, transform, transformBack, transformBack
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mmbase.util.transformers.CharTransformer
transform, transform, transformBack, transformBack
 
Methods inherited from interface org.mmbase.util.transformers.Transformer
toString
 

Field Detail

POORBODY

public static final int POORBODY
See Also:
Constant Field Values

RICHBODY

public static final int RICHBODY
See Also:
Constant Field Values

HTML_INLINE

public static final int HTML_INLINE
See Also:
Constant Field Values

HTML_BLOCK

public static final int HTML_BLOCK
See Also:
Constant Field Values

HTML_BLOCK_BR

public static final int HTML_BLOCK_BR
See Also:
Constant Field Values

HTML_BLOCK_NOSURROUNDINGP

public static final int HTML_BLOCK_NOSURROUNDINGP
See Also:
Constant Field Values

HTML_BLOCK_BR_NOSURROUNDINGP

public static final int HTML_BLOCK_BR_NOSURROUNDINGP
See Also:
Constant Field Values

HTML_BLOCK_LIST

public static final int HTML_BLOCK_LIST
See Also:
Constant Field Values

HTML_BLOCK_LIST_BR

public static final int HTML_BLOCK_LIST_BR
See Also:
Constant Field Values

HTML_BLOCK_LIST_NOSURROUNDINGP

public static final int HTML_BLOCK_LIST_NOSURROUNDINGP
See Also:
Constant Field Values

HTML_BLOCK_LIST_BR_NOSURROUNDINGP

public static final int HTML_BLOCK_LIST_BR_NOSURROUNDINGP
See Also:
Constant Field Values

ASCII

public static final int ASCII
See Also:
Constant Field Values

XHTML

public static final int XHTML
See Also:
Constant Field Values

SECTIONS

protected static final boolean SECTIONS
Constant for use as argument of handleRich(java.lang.StringBuilder, boolean, boolean, boolean)

Since:
MMBase-1.9
See Also:
Constant Field Values

NO_SECTIONS

protected static final boolean NO_SECTIONS
See Also:
Constant Field Values

LEAVE_NEWLINES

protected static final boolean LEAVE_NEWLINES
See Also:
Constant Field Values

REMOVE_NEWLINES

protected static final boolean REMOVE_NEWLINES
See Also:
Constant Field Values

SURROUNDING_P

protected static final boolean SURROUNDING_P
See Also:
Constant Field Values

NO_SURROUNDING_P

protected static final boolean NO_SURROUNDING_P
See Also:
Constant Field Values

LISTS_INSIDE_P

protected static final boolean LISTS_INSIDE_P
See Also:
Constant Field Values

LISTS_OUTSIDE_P

protected static final boolean LISTS_OUTSIDE_P
See Also:
Constant Field Values
Constructor Detail

XmlField

public XmlField()

XmlField

public XmlField(int to)
Method Detail

handleList

static void handleList(StringBuilder obj)
Takes a string object, finds list structures and changes those to XML


replaceAll

public static void replaceAll(StringBuilder builder,
                              String from,
                              String to)

handleEmph

static void handleEmph(StringBuilder obj,
                       char ch,
                       String tag)
If you want to add a _ in your text, that should be possible too... Should be done last, because no tags can appear in

Parameters:
ch - This is '_' or e.g. '*'
tag - The tag to produce, e.g. "em" or "strong"

preHandleHeaders

static void preHandleHeaders(StringBuilder obj)
Makes sure that lines indicating headers (starting with $), are followed by at least 2 newlines, if followed by some list.

Since:
MMBase-1.8.6

handleHeaders

static void handleHeaders(StringBuilder obj)
Some paragraphs are are really \sections. So this handler can be done after handleParagraphs. It will search the paragraphs which are really headers, and changes them. A header, in our 'rich' text format, is a paragraph starting with one or more $. If there are more then one, the resulting
tags are going to be nested.


handleParagraphs

static void handleParagraphs(StringBuilder obj,
                             boolean leaveExtraNewLines,
                             boolean surroundingP)
Make

tags.

Parameters:
leaveExtraNewLines - (defaults to false) if false, 2 or more newlines starts a new p. If true, every 2 newlines starts new p, and every extra new line simply stays (inside the p).
surroundingP - (defaults to true) wether the surrounding <p> should be included too.

handleParagraphs

static void handleParagraphs(StringBuilder obj,
                             boolean leaveExtraNewLines,
                             boolean surroundingP,
                             boolean placeListsInsideP)
Make <p> </p> tags. Note that if placeListsInsideP is false, the code generated with lists becomes akin to: <p>...</p><ul>...</ul><p>...</p> If placeListsInsideP is true, the code becomes: <p>...<ul>...</ul>...</p> If there is no content in front of the first list, or after the last list, those paragraphs are empty and may not be added.

Parameters:
leaveExtraNewLines - (defaults to false) if false, 2 or more newlines starts a new p. If true, every 2 newlines starts new p, and every extra new line simply stays (inside the p).
surroundingP - (defaults to true) whether the surrounding <p> should be included too.
placeListsInsideP - (defaults to false) whether a list should be placed inside a <p> (as allowed by xhtml2).

handleTables

static void handleTables(StringBuilder obj)
Wikipedia syntax for tables. (simplified)
 {|
 | a || b || c
 |-
 | d || e || f
 |}
 
or e.g.
 {|-
 |+ caption
 ! A !! B !! C
 |-
 | d
 | e
 | f
 |}
 

Since:
MMBase 1.8

cleanupText

static void cleanupText(StringBuilder obj)
Removes all new lines and space which are too much.


handleFormat

protected static void handleFormat(StringBuilder obj,
                                   boolean format)
Only escape, clean up.

Since:
MMBase-1.7

prepareDataString

protected static String prepareDataString(String data)

prepareData

protected static StringBuilder prepareData(String data)

handleRich

protected static void handleRich(StringBuilder obj,
                                 boolean sections,
                                 boolean leaveExtraNewLines,
                                 boolean surroundingP)

handleRich

protected static void handleRich(StringBuilder obj,
                                 boolean sections,
                                 boolean leaveExtraNewLines,
                                 boolean surroundingP,
                                 boolean placeListsInsideP)

handleNewlines

protected static void handleNewlines(StringBuilder obj)

richToXML

public static String richToXML(String data,
                               boolean format,
                               boolean placeListsInsideP)
Defines a kind of 'rich' text format. This is a way to easily type structured text in XML. The XML tags which can be produced by this are all HTML as well. This is a generalisation of the MMBase html() functions which does similar duties, but hopefully this one is better, and more powerfull too. The following things are recognized:
  • Firstly, XMLEscape is called.
  • A line starting with an asterix (*) will start an unnumberd list. The first new line not starting with a space or an other asterix will end the list
  • Underscores are translated to the emphasize HTML-tag
  • You can create a header tag by by starting a line with a dollar signs
  • A paragraph can be begun (and ended) with an empty line.
Test with commandline: java org.mmbase.util.Encode RICH_TEXT (reads from STDIN)

Parameters:
data - text to convert
format - if the resulting XML must be nicely formatted (default: false)
Returns:
the converted text

richToXML

public static String richToXML(String data,
                               boolean format)

richToXML

public static String richToXML(String data)

poorToXML

public static String poorToXML(String data,
                               boolean format,
                               boolean placeListsInsideP)
As richToXML but a little less rich. Which means that only one new line is non significant.

See Also:
richToXML(java.lang.String, boolean, boolean)

poorToXML

public static String poorToXML(String data,
                               boolean format)

poorToXML

public static String poorToXML(String data)

richToHTMLBlock

public static String richToHTMLBlock(String data,
                                     boolean multipibleBrs,
                                     boolean surroundingP,
                                     boolean placeListsInsideP)
So poor, that it actually generates pieces of XHTML 1.1 blocks (so, no use of sections).

Since:
MMBase-1.7
See Also:
richToXML(java.lang.String, boolean, boolean)

richToHTMLBlock

public static String richToHTMLBlock(String data)

richToHTMLBlock

public static String richToHTMLBlock(String data,
                                     boolean multipibleBrs,
                                     boolean surroundingP)

poorToHTMLInline

public static String poorToHTMLInline(String data)
So poor, that it actually generates pieces of XHTML 1.1 inlines (so, no use of section, br, p).

Since:
MMBase-1.7

XSLTransform

protected static String XSLTransform(String xslFile,
                                     String data)
Base function for XSL conversions.


validate

protected static void validate(String incoming)
                        throws XmlField.FormatException
Throws:
XmlField.FormatException

transformers

public Map<String,Config> transformers()
Description copied from interface: ConfigurableTransformer
Returns which transformations can be done by an object of this class.

Specified by:
transformers in interface ConfigurableTransformer
Specified by:
transformers in class ConfigurableStringTransformer
Returns:
A Map with String Integer/Class pairs.

transform

public String transform(String data)
Specified by:
transform in interface CharTransformer
Specified by:
transform in class StringTransformer

transformBack

public String transformBack(String r)
Specified by:
transformBack in interface CharTransformer
Overrides:
transformBack in class StringTransformer

getEncoding

public String getEncoding()
Description copied from interface: ConfigurableTransformer
Returns the encoding that is currently active

Specified by:
getEncoding in interface ConfigurableTransformer
Specified by:
getEncoding in class ConfigurableStringTransformer
Returns:
An String representing the coding that is currently used.


MMBase2 Utils 2.0-SNAPSHOT - 2013-05-29T22:03