org.javalite.common
Class XmlEntities

java.lang.Object
  extended by org.javalite.common.XmlEntities

public class XmlEntities
extends Object

Provides XML entity utilities.

This code was taken from Apache Commons in order to avoid adding a new dependency.

Since:
2.0
Version:
$Id: Entities.java 911986 2010-02-19 21:19:05Z niallp $
Author:
Alexander Day Chaffee, Gary Gregory

Field Summary
static XmlEntities XML
           The set of entities supported by standard XML.
 
Constructor Summary
XmlEntities()
          Default constructor.
 
Method Summary
 void addEntities(String[][] entityArray)
           Adds entities to this entity.
 void addEntity(String name, int value)
           Add an entity to this entity.
 String entityName(int value)
           Returns the name of the entity identified by the specified value.
 int entityValue(String name)
           Returns the value of the entity identified by the specified name.
 String escape(String str)
           Escapes the characters in a String.
 void escape(Writer writer, String str)
           Escapes the characters in the String passed and writes the result to the Writer passed.
 String unescape(String str)
           Unescapes the entities in a String.
 void unescape(Writer writer, String str)
           Unescapes the escaped entities in the String passed and writes the result to the Writer passed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XML

public static final XmlEntities XML

The set of entities supported by standard XML.

Constructor Detail

XmlEntities

public XmlEntities()
Default constructor.

Method Detail

addEntities

public void addEntities(String[][] entityArray)

Adds entities to this entity.

Parameters:
entityArray - array of entities to be added

addEntity

public void addEntity(String name,
                      int value)

Add an entity to this entity.

Parameters:
name - name of the entity
value - vale of the entity

entityName

public String entityName(int value)

Returns the name of the entity identified by the specified value.

Parameters:
value - the value to locate
Returns:
entity name associated with the specified value

entityValue

public int entityValue(String name)

Returns the value of the entity identified by the specified name.

Parameters:
name - the name to locate
Returns:
entity value associated with the specified name

escape

public String escape(String str)

Escapes the characters in a String.

For example, if you have called addEntity("foo", 0xA1), escape("¡") will return "&foo;"

Parameters:
str - The String to escape.
Returns:
A new escaped String.

escape

public void escape(Writer writer,
                   String str)
            throws IOException

Escapes the characters in the String passed and writes the result to the Writer passed.

Parameters:
writer - The Writer to write the results of the escaping to. Assumed to be a non-null value.
str - The String to escape. Assumed to be a non-null value.
Throws:
IOException - when Writer passed throws the exception from calls to the Writer.write(int) methods.
See Also:
escape(String), Writer

unescape

public String unescape(String str)

Unescapes the entities in a String.

For example, if you have called addEntity("foo", 0xA1), unescape("&foo;") will return "¡"

Parameters:
str - The String to escape.
Returns:
A new escaped String.

unescape

public void unescape(Writer writer,
                     String str)
              throws IOException

Unescapes the escaped entities in the String passed and writes the result to the Writer passed.

Parameters:
writer - The Writer to write the results to; assumed to be non-null.
str - The source String to unescape; assumed to be non-null.
Throws:
IOException - when Writer passed throws the exception from calls to the Writer.write(int) methods.
See Also:
escape(String), Writer


Copyright © 2013. All Rights Reserved.