org.ceryle.wiki.plugin.util
Class PluginTextUtils

java.lang.Object
  extended by org.ceryle.wiki.plugin.util.PluginTextUtils

public class PluginTextUtils
extends Object

Some text processing utilities for wiki plugin use.

Notes

Author:
Murray Altheim, John Volkar (john.volkar at gmail.com)

Field Summary
static int OUTPUT_BAR
          An int constant (indicated by "bar") directing that output should be formatted as a vertical bar-delimited list.
static int OUTPUT_BULLET
          An int constant (indicated by "bullet") directing that output should be formatted as a bulleted list.
static int OUTPUT_COLON
          An int constant (indicated by "colon") directing that output should be formatted as a colon-delimited list.
static int OUTPUT_COMMA
          An int constant (indicated by "comma") directing that output should be formatted as a comma-delimited list.
static int OUTPUT_COUNT
          An int constant (indicated by "count") directing that output should only contain the list size (page count).
static int OUTPUT_LIST
          An int constant (indicated by "list") directing that output should be formatted as a simple vertical list.
static int OUTPUT_NONE
          An int constant (indicated by "none") directing that output should be suppressed (no list output).
static int OUTPUT_NUMBER
          An int constant (indicated by "number") directing that output should be formatted as a numbered list.
static String[] OUTPUT_PARAMS
          A String array containing the output format parameter names.
static int OUTPUT_SPACE
          An int constant (indicated by "space") directing that output should be formatted as a space-delimited list.
static int OUTPUT_TABLE
          An int constant (indicated by "table") directing that output should be formatted as a table.
 
Constructor Summary
PluginTextUtils()
           
 
Method Summary
static String beautifyTitle(WikiPage page, WikiContext context)
           
static int convertOutputFormat(String format)
          Returns an int value for the output format, based on a string match of the parameter format.
static String entify(String s, boolean asNumeric)
          Return a string with markup-sensitive characters (LT,GT,AMP,APOS and QUOT) expressed as either numeric or named character entities, depending on the boolean asNumeric.
static String extractSectionData(int sectionNumber, String pageData, String sectionDivider)
          Returns a section of wiki text from pageData.
static String formatOutput(WikiEngine engine, Collection content, int format, boolean addLinks)
          Format the Iterator containing plugin results (expected as a list of page names, otherwise the Object's toString() is called) into XHTML output suitable for display on the page.
static Locale getLocale(WikiContext context)
          Returns the locale of the HTTP request if available, otherwise returns the default Locale of the server.
static boolean isDigit(char c)
          Returns true if char c is a digit, using the Java method Character.isDigit(char).
static boolean isLetter(char c)
          Returns true if char c is an alphabet characer, using the Java method Character.isDigit(char).
static boolean isName(String s)
          Returns true if String s conforms to Name [XML 1.1 production 5].
static boolean isNameChar(char c)
          Returns true if char c is a member of NameChar [XML 1.1 production 4a].
static boolean isNameStartChar(char c)
          Returns true if char c is an allowed first character of an XML 1.1 Name [XML 1.1 production 4].
static boolean isSpace(char c)
          Returns true if char c is a member of S (space) [XML 1.1 production 3].
static boolean isSpace(String s)
          Returns true if the String s is completely composed of whitespace.
static boolean isURL(String s)
          Returns true if the supplied String s can be made into URL.
static void outputMap(StringBuffer out, Map map)
          Print the Map as a key="value" list to the provided StringBuffer.
static String stripBrackets(String s)
          If the String s both starts and ends with square brackets, this strips them, otherwise returns the String unmodified.
static String stripShebang(String s)
          Strips the wiki 'she-bang' from the beginning of a String.
static String wordWrap(String text, int length)
          Word wraps the textual content at the provided line length.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OUTPUT_NONE

public static final int OUTPUT_NONE
An int constant (indicated by "none") directing that output should be suppressed (no list output).

See Also:
Constant Field Values

OUTPUT_COUNT

public static final int OUTPUT_COUNT
An int constant (indicated by "count") directing that output should only contain the list size (page count).

See Also:
Constant Field Values

OUTPUT_LIST

public static final int OUTPUT_LIST
An int constant (indicated by "list") directing that output should be formatted as a simple vertical list.

See Also:
Constant Field Values

OUTPUT_BULLET

public static final int OUTPUT_BULLET
An int constant (indicated by "bullet") directing that output should be formatted as a bulleted list.

See Also:
Constant Field Values

OUTPUT_NUMBER

public static final int OUTPUT_NUMBER
An int constant (indicated by "number") directing that output should be formatted as a numbered list.

See Also:
Constant Field Values

OUTPUT_SPACE

public static final int OUTPUT_SPACE
An int constant (indicated by "space") directing that output should be formatted as a space-delimited list.

See Also:
Constant Field Values

OUTPUT_COMMA

public static final int OUTPUT_COMMA
An int constant (indicated by "comma") directing that output should be formatted as a comma-delimited list.

See Also:
Constant Field Values

OUTPUT_COLON

public static final int OUTPUT_COLON
An int constant (indicated by "colon") directing that output should be formatted as a colon-delimited list.

See Also:
Constant Field Values

OUTPUT_BAR

public static final int OUTPUT_BAR
An int constant (indicated by "bar") directing that output should be formatted as a vertical bar-delimited list.

See Also:
Constant Field Values

OUTPUT_TABLE

public static final int OUTPUT_TABLE
An int constant (indicated by "table") directing that output should be formatted as a table. This is not currently implemented for this class, and is included here for future use, to permit the parameter to be specified using a common constant.

See Also:
Constant Field Values

OUTPUT_PARAMS

public static final String[] OUTPUT_PARAMS
A String array containing the output format parameter names. Note that there is a contract that the array indices of the parameter names match the int value of each format contant.

Constructor Detail

PluginTextUtils

public PluginTextUtils()
Method Detail

getLocale

public static Locale getLocale(WikiContext context)
Returns the locale of the HTTP request if available, otherwise returns the default Locale of the server.


beautifyTitle

public static String beautifyTitle(WikiPage page,
                                   WikiContext context)

stripBrackets

public static String stripBrackets(String s)
If the String s both starts and ends with square brackets, this strips them, otherwise returns the String unmodified. A null returns null.


extractSectionData

public static String extractSectionData(int sectionNumber,
                                        String pageData,
                                        String sectionDivider)
Returns a section of wiki text from pageData. Sections are delimited by provided string, first section is number 1.

Parameters:
sectionNumber - Must be greater than or equal to 1.
pageData - must not be null
sectionDivider - The delimiter of sections in the pageData.
Returns:
May return an empty string if there aren't sectionNumber of sections in pageData.

wordWrap

public static String wordWrap(String text,
                              int length)
Word wraps the textual content at the provided line length.


entify

public static final String entify(String s,
                                  boolean asNumeric)
Return a string with markup-sensitive characters (LT,GT,AMP,APOS and QUOT) expressed as either numeric or named character entities, depending on the boolean asNumeric. Since either are intrinsically part of XML, no additional DTD declarations are necessary.

Note that use of numeric entities allows for more "entification" than simply XML's five built-in entities. While not currently supported, use of numeric entities may in the future mean support for characters not included in the current encoding.

If the provided String is either null or empty, an empty String is returned.


stripShebang

public static String stripShebang(String s)
Strips the wiki 'she-bang' from the beginning of a String.


outputMap

public static void outputMap(StringBuffer out,
                             Map map)
Print the Map as a key="value" list to the provided StringBuffer. This can be used to print the plugin parameters.


convertOutputFormat

public static int convertOutputFormat(String format)
Returns an int value for the output format, based on a string match of the parameter format. The default returned on a null or non-matching parameter is OUTPUT_LIST.


formatOutput

public static String formatOutput(WikiEngine engine,
                                  Collection content,
                                  int format,
                                  boolean addLinks)
Format the Collection containing plugin results (expected as a list of page names, otherwise the Object's toString() is called) into XHTML output suitable for display on the page. Note that a null Collection parameter returns an empty String.

Output Formatting

The specific format is controlled by the output parameter:
OUTPUT_NONE
Indicates that output should be suppressed.
OUTPUT_COUNT
Indicates that the result include only the page count (as a string e.g., "33 pages.").
OUTPUT_LIST
Indicates that the result should be formatted as a simple vertical list.
OUTPUT_BULLET
Indicates that the result should be formatted as a bulleted list.
OUTPUT_NUMBER
Indicates that the result should be formatted as a numbered list.
OUTPUT_SPACE
Indicates that the result should be formatted as a space-delimited list.
OUTPUT_COMMA
Indicates that the result should be formatted as a comma-delimited list.
OUTPUT_COLON
Indicates that the result should be formatted as a colon-delimited list.
OUTPUT_BAR
Indicates that the result should be formatted as a vertical bar-delimited list.
OUTPUT_TABLE
Indicates that the result should be formatted as a table. This is not implemented for this class, and is likely to be handled externally (given that only one column of data is available, unless the Collection is permitted to contain other than Strings; something for the future).

Parameters:
engine - The WikiEngine used.
content - A Collection containing the output contents to be formatted.
format - The int constant indicating the output format.
addLinks - If true and the Collection contains Strings, the list items will be treated as Wiki page names and link markup will be added accordingly. If false or the Collection contains other Object types, only the content necessary to fulfill the needs of the format will be added.
Returns:
XHTML-compliant fragment, all tags to be closed and balanced.

isName

public static boolean isName(String s)
Returns true if String s conforms to Name [XML 1.1 production 5].
See note on XML 1.1 changes.


isNameStartChar

public static boolean isNameStartChar(char c)
Returns true if char c is an allowed first character of an XML 1.1 Name [XML 1.1 production 4].
CHANGED.
See note on XML 1.1 changes.


isNameChar

public static boolean isNameChar(char c)
Returns true if char c is a member of NameChar [XML 1.1 production 4a].
CHANGED.
See note on XML 1.1 changes.


isLetter

public static boolean isLetter(char c)
Returns true if char c is an alphabet characer, using the Java method Character.isDigit(char).


isDigit

public static boolean isDigit(char c)
Returns true if char c is a digit, using the Java method Character.isDigit(char).


isSpace

public static boolean isSpace(String s)
Returns true if the String s is completely composed of whitespace.


isSpace

public static boolean isSpace(char c)
Returns true if char c is a member of S (space) [XML 1.1 production 3].


isURL

public static final boolean isURL(String s)
Returns true if the supplied String s can be made into URL.



The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.