org.mmbase.util
Class Encode

java.lang.Object
  |
  +--org.mmbase.util.Encode

public class Encode
extends java.lang.Object

Class to convert from/to a string from/to a encoded string.

Author:
Eduard Witteveen, Michiel Meeuwissen Supported encodings are at this moment: Usage:
  Encode encoder = new Encode("ESCAPE_XML");
  System.out.println(  encoder.decode( encoder.encode("& \" < >") )  );
  

Constructor Summary
Encode(java.lang.String encoding)
          Created a encode instance of a certain type of encoding
 
Method Summary
 java.lang.String decode(java.lang.String toDecode)
          This function will decode a given string to it's decoded variant
static java.lang.String decode(java.lang.String encoding, java.lang.String toDecode)
          This function will decode a given string to it's decoded variant
 java.lang.String encode(java.lang.String toEncode)
          This function will encode a given string to it's encoded variant
static java.lang.String encode(java.lang.String encoding, java.lang.String toEncode)
          This function will encode a given string to it's encoded variant
static void main(java.lang.String[] argv)
          Invocation of the class from the commandline for testing.
static java.lang.String richToXML(java.lang.String data)
          Defines a kind of 'rich' text format.
static java.lang.String XMLEscape(java.lang.String xml)
          Utility class for escaping and unescaping (XML)data
static java.lang.String XMLToRich(java.lang.String data)
          Inverse of richToXML (untested).
static java.lang.String XMLUnescape(java.lang.String data)
          Utility class for escaping and unescaping (XML)data
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Encode

public Encode(java.lang.String encoding)
Created a encode instance of a certain type of encoding
Parameters:
encoding - a string that describes which encoding should be used.
Method Detail

encode

public static java.lang.String encode(java.lang.String encoding,
                                      java.lang.String toEncode)
This function will encode a given string to it's encoded variant
Parameters:
encoding - a string that describes which encoding should be used.
toEncode - a string which is the value which should be encoded.
Returns:
a string which is the encoded representation of toEncode with the given encoding

decode

public static java.lang.String decode(java.lang.String encoding,
                                      java.lang.String toDecode)
This function will decode a given string to it's decoded variant
Parameters:
decoding - a string that describes which decoding should be used.
toDecode - a string which is the value which should be encoded.
Returns:
a string which is the encoded representation of toEncode with the given encoding

encode

public java.lang.String encode(java.lang.String toEncode)
This function will encode a given string to it's encoded variant
Parameters:
toEncode - a string which is the value which should be encoded.
Returns:
a string which is the encoded representation of toEncode with the given encoding

decode

public java.lang.String decode(java.lang.String toDecode)
This function will decode a given string to it's decoded variant
Parameters:
toDecode - a string which is the value which should be encoded.
Returns:
a string which is the encoded representation of toEncode with the given encoding

XMLEscape

public static java.lang.String XMLEscape(java.lang.String xml)
Utility class for escaping and unescaping (XML)data
Parameters:
xml - the xml to encode
Returns:
the encoded xml data
  • & is replaced by &amp;
  • " is replaced by &quot;
  • < is replaced by &lt;
  • > is replaced by &gt;

XMLUnescape

public static java.lang.String XMLUnescape(java.lang.String data)
Utility class for escaping and unescaping (XML)data
Parameters:
data - the data to decode to (html/xml) where
  • & was replaced by &amp;
  • " was replaced by &quot;
  • < was replaced by &lt;
  • > was replaced by &gt;
Returns:
the decoded xml data

richToXML

public static java.lang.String richToXML(java.lang.String data)
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 do similar duties, but hopefully this one is better, and more powerfull too. The following things are recognized: Test with commandline: java org.mmbase.util.Encode RICH_TEXT (reads from STDIN)
Parameters:
data - text to convert
Returns:
the converted text

XMLToRich

public static java.lang.String XMLToRich(java.lang.String data)
Inverse of richToXML (untested).

main

public static void main(java.lang.String[] argv)
Invocation of the class from the commandline for testing.


MMBase 2001