de.tuberlin.cs.flp.jspwiki.util
Class WikiToolbox

java.lang.Object
  extended byde.tuberlin.cs.flp.jspwiki.util.WikiToolbox

public class WikiToolbox
extends java.lang.Object

Collection of tool functions used by package de.tuberlin.cs.flp.jspwiki.*.


Constructor Summary
WikiToolbox()
           
 
Method Summary
static java.lang.String capitalize(java.lang.String s)
          Sets the first charcater in s to upper case.
static int[] determineImageSize(java.io.InputStream in)
           
static java.lang.String escape(java.lang.String s, char c)
          Escapes all occurrences of c in s by a backslash.
static Attachment findImageAttachment(WikiEngine engine, java.lang.String pagename)
          Returns first image-attachment, or null if no attachment is an image or no attachments at all exist.
static Attachment findImageAttachment(WikiEngine engine, java.lang.String pagename, java.util.Collection attachments)
          Returns first image-attachment, or null if no attachment is an image or no attachments at all exist.
static java.lang.String format(java.util.Map m, java.lang.String f)
          Entries starting with % will be replaced by values in map.
static java.lang.String getProperty(WikiEngine engine, java.lang.String propertyName, java.lang.String defaultPagename)
           
static boolean isImage(WikiEngine engine, java.lang.String name)
           
static java.lang.String keyByValue(java.util.Properties p, java.lang.String v)
          Gets the key of a property entry by the given value.
static java.lang.String makePagename(WikiEngine engine, java.lang.String s)
          Creates a valid wiki page name from s.
static java.lang.String normalizeLF(java.lang.String s)
          Makes sure only '\n' is used as linebreak, not '\r\n'.
static java.lang.String normalizeName(java.lang.String name)
          Makes sure that an entry's name can be used as a filename.
static boolean parseBoolean(java.lang.String s)
           
static boolean parseBoolean(java.lang.String s, boolean deflt)
           
static java.util.Collection parseList(java.lang.String s)
          Parses a comma-seperated list of strings.
static java.util.Collection parseMultiParameter(HttpServletRequest request, java.lang.String name)
           
static java.util.Properties parseProperties(java.lang.String s, java.lang.String entryDelim)
           
static java.util.Collection parseWikiLinks(java.lang.String pagedata)
          Parses Wiki-markup and returns a collection of all links included in the page.
static java.util.Collection parseWikiLinks(WikiEngine engine, java.lang.String pagename)
          Returns all Wiki-link targets included in a page.
static byte[] readInputStream(java.io.InputStream in)
           
static java.lang.String repeat(int cnt, char c)
          Creates a string in which c is repeated cnt times.
static java.lang.String replace(java.lang.String s, java.lang.String search, java.lang.String repl)
           
static java.util.Collection split(java.lang.String s)
          Split at commas (',').
static java.util.Collection split(java.lang.String s, char c)
          Splits a string at the specified character occurrences.
static java.util.Collection split(java.lang.String s, java.lang.String delim)
          Splits a string at the specified substring occurrences.
static java.util.List splitCamelCase(java.lang.String s)
           
static java.util.Collection splitLines(java.lang.String s)
          Split at line-feed ('\n').
static java.util.Map subMap(java.util.Map map, java.lang.String prefix)
           
static java.lang.String toCamelCase(java.lang.String s)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WikiToolbox

public WikiToolbox()
Method Detail

split

public static java.util.Collection split(java.lang.String s,
                                         char c)
Splits a string at the specified character occurrences.

Parameters:
s - The string to be split.
c - The character at the occurrences of which the splitting is performed.
Returns:
Collection of all substrings between the occurrences of c. Contains a single element (whole s) if c is not contained in s.

split

public static java.util.Collection split(java.lang.String s,
                                         java.lang.String delim)
Splits a string at the specified substring occurrences.

Parameters:
s - The string to be split.
delim - The substring at the occurrences of which the splitting is performed.
Returns:
Collection of all substrings between the occurrences of c. Contains a single element (whole s) if c is not contained in s.

split

public static java.util.Collection split(java.lang.String s)
Split at commas (',').

Parameters:
s -
Returns:

splitLines

public static java.util.Collection splitLines(java.lang.String s)
Split at line-feed ('\n').

Parameters:
s -
Returns:

capitalize

public static java.lang.String capitalize(java.lang.String s)
Sets the first charcater in s to upper case.

Parameters:
s - The string to be capitalized.
Returns:
Capitalized string.

repeat

public static java.lang.String repeat(int cnt,
                                      char c)
Creates a string in which c is repeated cnt times.

Parameters:
cnt - Number of repetitions.
c - The characater to be repeated.
Returns:
The string conatining the repeated character.

escape

public static java.lang.String escape(java.lang.String s,
                                      char c)
Escapes all occurrences of c in s by a backslash.

Parameters:
s - The string to be escaped.
c - The character to be escaped.
Returns:
The escaped string.

replace

public static java.lang.String replace(java.lang.String s,
                                       java.lang.String search,
                                       java.lang.String repl)
Parameters:
s -
search -
repl -
Returns:

subMap

public static java.util.Map subMap(java.util.Map map,
                                   java.lang.String prefix)
Parameters:
map -
prefix -
Returns:

keyByValue

public static java.lang.String keyByValue(java.util.Properties p,
                                          java.lang.String v)
Gets the key of a property entry by the given value.

Parameters:
p - The properties.
v - The value string.
Returns:
The key, or null if the value was not found.

readInputStream

public static byte[] readInputStream(java.io.InputStream in)
                              throws java.io.IOException
Parameters:
in -
Returns:
Throws:
java.io.IOException

makePagename

public static java.lang.String makePagename(WikiEngine engine,
                                            java.lang.String s)
Creates a valid wiki page name from s. I.e., blanks are removes and the string is converted to CamelCase. ### Is there any corresponding function available in JSPWiki?

Parameters:
engine -
s -
Returns:

splitCamelCase

public static java.util.List splitCamelCase(java.lang.String s)
Parameters:
s -
Returns:

toCamelCase

public static java.lang.String toCamelCase(java.lang.String s)
Parameters:
s -
Returns:

parseWikiLinks

public static java.util.Collection parseWikiLinks(java.lang.String pagedata)
Parses Wiki-markup and returns a collection of all links included in the page. The links are capitalized (first letter upper case), in order to be usable as page-names, which seem to be all uppercase in JSPWiki. (I.e., all strings that are enclosed by "[]".)

Parameters:
pagedata - The page text.
Returns:
The names of all pages referenced by the Wiki-links in the page text.

parseWikiLinks

public static java.util.Collection parseWikiLinks(WikiEngine engine,
                                                  java.lang.String pagename)
Returns all Wiki-link targets included in a page. These are all pages referenced by the specified page.

Parameters:
engine - The WikiEngine
pagename - name of the page to retrieve links from.
Returns:
all links contained in the page

parseList

public static java.util.Collection parseList(java.lang.String s)
Parses a comma-seperated list of strings.

Parameters:
s - comma-seperated list of string
Returns:
Collection with individual strings, each one trimmed.

parseBoolean

public static boolean parseBoolean(java.lang.String s)
Parameters:
s -
Returns:

parseBoolean

public static boolean parseBoolean(java.lang.String s,
                                   boolean deflt)
Parameters:
s -
deflt -
Returns:

parseMultiParameter

public static java.util.Collection parseMultiParameter(HttpServletRequest request,
                                                       java.lang.String name)
Parameters:
request -
name -
Returns:

getProperty

public static java.lang.String getProperty(WikiEngine engine,
                                           java.lang.String propertyName,
                                           java.lang.String defaultPagename)
Parameters:
engine -
propertyName -
defaultPagename -
Returns:

normalizeName

public static java.lang.String normalizeName(java.lang.String name)
Makes sure that an entry's name can be used as a filename.

Parameters:
name - The entry name.
Returns:
A normalized representation of the name.

normalizeLF

public static java.lang.String normalizeLF(java.lang.String s)
Makes sure only '\n' is used as linebreak, not '\r\n'.

Parameters:
s -
Returns:

format

public static java.lang.String format(java.util.Map m,
                                      java.lang.String f)
Entries starting with % will be replaced by values in map.

Parameters:
m - The map.
f - Template string including %xxx-substrings that will be replaced by map values.
Returns:
String with %xxx-substrings resolved.

parseProperties

public static java.util.Properties parseProperties(java.lang.String s,
                                                   java.lang.String entryDelim)
Parameters:
s -
entryDelim -
Returns:

findImageAttachment

public static Attachment findImageAttachment(WikiEngine engine,
                                             java.lang.String pagename)
Returns first image-attachment, or null if no attachment is an image or no attachments at all exist.

Parameters:
engine -
pagename -
Returns:

findImageAttachment

public static Attachment findImageAttachment(WikiEngine engine,
                                             java.lang.String pagename,
                                             java.util.Collection attachments)
Returns first image-attachment, or null if no attachment is an image or no attachments at all exist.

Parameters:
engine -
pagename -
attachments -
Returns:

determineImageSize

public static int[] determineImageSize(java.io.InputStream in)
Parameters:
in -
Returns:

isImage

public static boolean isImage(WikiEngine engine,
                              java.lang.String name)
Parameters:
engine -
name -
Returns: