com.filenet.wcm.toolkit.util
Class WcmXMLEncode

java.lang.Object
  extended bycom.filenet.wcm.toolkit.util.WcmXMLEncode

public class WcmXMLEncode
extends java.lang.Object

Class for encoding a string for XML.


Nested Class Summary
static class WcmXMLEncode.XmlDecodeException
          Exception to indicate an error when decoding text from XML.
static class WcmXMLEncode.XmlEncodeResult
          The result of an encode operation.
 
Field Summary
static int DECODEERROR_INVALIDCHAR
          Decode error: invalid character
static int DECODEERROR_INVALIDENCODING
          Decode error: invalid encoding
static int DECODEERROR_INVALIDLENGTH
          Decode error: invalid length
static int ENCODING_BASE64
          Use the attribute: encoding="base64"
static int ENCODING_NONE
          No attribute needed
 
Constructor Summary
WcmXMLEncode()
           
 
Method Summary
static java.lang.String decodeBase64(java.util.Locale locale, java.lang.String inStr)
          Explicitly decode text from base64.
static java.lang.String decodeBase64(java.lang.String inStr)
          Explicitly decode text from base64.
static java.lang.String decodeFromXml(int howEncoded, java.lang.String inString)
          This decodes strings that have been encoded with EncodeForXML.
static java.lang.String decodeFromXml(java.util.Locale locale, int howEncoded, java.lang.String inString)
          This decodes strings that have been encoded with EncodeForXML.
static java.lang.String encodeBase64(java.lang.String inStr)
          Explicitly encode text as base64.
static java.lang.String encodeEntities(java.lang.String inString)
          This does only normal encoding of entities.
static WcmXMLEncode.XmlEncodeResult encodeForXml(java.lang.String inString, WcmXMLEncode.XmlEncodeResult result)
          This encodes a string for XML.
static boolean isAllValidXmlChars(java.lang.String inString)
          Indicates if all the characters in an input string are valid XML characters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENCODING_NONE

public static final int ENCODING_NONE
No attribute needed

See Also:
Constant Field Values

ENCODING_BASE64

public static final int ENCODING_BASE64
Use the attribute: encoding="base64"

See Also:
Constant Field Values

DECODEERROR_INVALIDCHAR

public static final int DECODEERROR_INVALIDCHAR
Decode error: invalid character

See Also:
Constant Field Values

DECODEERROR_INVALIDLENGTH

public static final int DECODEERROR_INVALIDLENGTH
Decode error: invalid length

See Also:
Constant Field Values

DECODEERROR_INVALIDENCODING

public static final int DECODEERROR_INVALIDENCODING
Decode error: invalid encoding

See Also:
Constant Field Values
Constructor Detail

WcmXMLEncode

public WcmXMLEncode()
Method Detail

encodeForXml

public static WcmXMLEncode.XmlEncodeResult encodeForXml(java.lang.String inString,
                                                        WcmXMLEncode.XmlEncodeResult result)
This encodes a string for XML. If the chars in inString are all valid, inString is returned. Chars such as > are changed to > and so on, if necessary, and a copy of the string returned. result.encoding is set to ENCODING_NONE. If there are invalid chars (per production [2] of the XML 1.0 spec), the returned string is inString, base64 encoded. result.encoding is set to ENCODING_BASE64.

Parameters:
inString - The input string.
result - If not null, is filled on output. Otherwise a new instance is created.
Returns:
A XmlEncodeResult instance with the output string and encoding type. This is the same instance passed in result if supplied; otherwise, a new instance is returned.

decodeFromXml

public static java.lang.String decodeFromXml(java.util.Locale locale,
                                             int howEncoded,
                                             java.lang.String inString)
                                      throws WcmXMLEncode.XmlDecodeException
This decodes strings that have been encoded with EncodeForXML. Entities such as & are assumed to have been decoded by the parser. The decoded string is returned. It may be the same as inString if no decoding is necessary.

Parameters:
locale - the client locale
howEncoded - The type of encoding; can be ENCODING_NONE.
inString - The string to decode.
Returns:
The decoded string. It may be the same as inString.
Throws:
WcmXMLEncode.XmlDecodeException

decodeFromXml

public static java.lang.String decodeFromXml(int howEncoded,
                                             java.lang.String inString)
                                      throws WcmXMLEncode.XmlDecodeException
This decodes strings that have been encoded with EncodeForXML. Entities such as & are assumed to have been decoded by the parser. The decoded string is returned. It may be the same as inString if no decoding is necessary.

Parameters:
howEncoded - The type of encoding; can be ENCODING_NONE.
inString - The string to decode.
Returns:
The decoded string. It may be the same as inString.
Throws:
WcmXMLEncode.XmlDecodeException

encodeEntities

public static java.lang.String encodeEntities(java.lang.String inString)
This does only normal encoding of entities. Useful when encoding values that shouldn't be base64 encoded, such as attribute values.

Parameters:
inString - The input string.
Returns:
The encoded string.

isAllValidXmlChars

public static boolean isAllValidXmlChars(java.lang.String inString)
Indicates if all the characters in an input string are valid XML characters.

Parameters:
inString - The string to validate.
Returns:
True if valid.

encodeBase64

public static java.lang.String encodeBase64(java.lang.String inStr)
Explicitly encode text as base64. Typically you would call encodeForXml and only encode if necessary.

Parameters:
inStr - The input string.
Returns:
The encoded string.

decodeBase64

public static java.lang.String decodeBase64(java.util.Locale locale,
                                            java.lang.String inStr)
                                     throws WcmXMLEncode.XmlDecodeException
Explicitly decode text from base64. Typically you would call decodeFromXml based on what was encoded previously.

Parameters:
inStr - The input string.
Returns:
The decoded string.
Throws:
WcmXMLEncode.XmlDecodeException

decodeBase64

public static java.lang.String decodeBase64(java.lang.String inStr)
                                     throws WcmXMLEncode.XmlDecodeException
Explicitly decode text from base64. Typically you would call decodeFromXml based on what was encoded previously.

Parameters:
inStr - The input string.
Returns:
The decoded string.
Throws:
WcmXMLEncode.XmlDecodeException


© Copyright IBM Corp. 2002, 2007. All Rights Reserved.