|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.xml.serializer.CharInfo
final class CharInfo
This class provides services that tell if a character should have special treatement, such as entity reference substitution or normalization of a newline character. It also provides character to entity reference lookup. DEVELOPERS: See Known Issue in the constructor.
Nested Class Summary | |
---|---|
private static class |
CharInfo.CharKey
Simple class for fast lookup of char values, when used with hashtables. |
Field Summary | |
---|---|
private int[] |
array_of_bits
An array of bits to record if the character is in the set. |
(package private) static int |
ASCII_MAX
Copy the first 0,1 ... |
private int |
firstWordNotUsed
|
static java.lang.String |
HTML_ENTITIES_RESOURCE
The name of the HTML entities file. |
private static int |
LOW_ORDER_BITMASK
|
private CharInfo.CharKey |
m_charKey
A utility object, just used to map characters to output Strings, needed because a HashMap needs to map an object as a key, not a Java primitive type, like a char, so this object gets around that and it is reusable. |
private java.util.HashMap |
m_charToString
Given a character, lookup a String to output (e.g. |
private static java.util.Hashtable |
m_getCharInfoCache
Table of user-specified char infos. |
(package private) boolean |
onlyQuotAmpLtGt
This flag is an optimization for HTML entities. |
(package private) static char |
S_CARRIAGERETURN
The carriage return character, which the parser should always normalize. |
(package private) static char |
S_GT
|
(package private) static char |
S_HORIZONAL_TAB
The horizontal tab character, which the parser should always normalize. |
(package private) static char |
S_LINE_SEPARATOR
|
(package private) static char |
S_LINEFEED
The linefeed character, which the parser should always normalize. |
(package private) static char |
S_LT
|
(package private) static char |
S_NEL
|
(package private) static char |
S_QUOTE
|
(package private) static char |
S_SPACE
|
private static int |
SHIFT_PER_WORD
|
private boolean[] |
shouldMapAttrChar_ASCII
Array of values is faster access than a set of bits to quickly check ASCII characters in attribute values, the value is true if the character in an attribute value should be mapped to a String. |
private boolean[] |
shouldMapTextChar_ASCII
Array of values is faster access than a set of bits to quickly check ASCII characters in text nodes, the value is true if the character in a text node should be mapped to a String. |
static java.lang.String |
XML_ENTITIES_RESOURCE
The name of the XML entities file. |
Constructor Summary | |
---|---|
private |
CharInfo()
A base constructor just to explicitly create the fields, with the exception of m_charToString which is handled by the constructor that delegates base construction to this one. |
private |
CharInfo(java.lang.String entitiesResource,
java.lang.String method,
boolean internal)
|
Method Summary | |
---|---|
private static int |
arrayIndex(int i)
Returns the array element holding the bit value for the given integer |
private static int |
bit(int i)
For a given integer in the set it returns the single bit value used within a given word that represents whether the integer is in the set or not. |
private int[] |
createEmptySetOfIntegers(int max)
Creates a new empty set of integers (characters) |
(package private) boolean |
defineChar2StringMapping(java.lang.String outputString,
char inputChar)
Call this method to register a char to String mapping, for example to map '<' to "<". |
private boolean |
defineEntity(java.lang.String name,
char value)
Defines a new character reference. |
private boolean |
extraEntity(java.lang.String outputString,
int charToMap)
This method returns true if there are some non-standard mappings to entities other than quot, amp, lt, gt, and its only purpose is for performance. |
private boolean |
get(int i)
Return true if the integer (character)is in the set of integers. |
(package private) static CharInfo |
getCharInfo(java.lang.String entitiesFileName,
java.lang.String method)
Factory that reads in a resource file that describes the mapping of characters to entity references. |
private static CharInfo |
getCharInfoBasedOnPrivilege(java.lang.String entitiesFileName,
java.lang.String method,
boolean internal)
|
(package private) java.lang.String |
getOutputStringForChar(char value)
Map a character to a String. |
private static CharInfo |
mutableCopyOf(CharInfo charInfo)
Create a mutable copy of the cached one. |
private void |
set(int i)
Adds the integer (character) to the set of integers. |
private void |
setASCIIattrDirty(int j)
If the character is in the ASCII range then mark it as needing replacement with a String on output if it occurs in a attribute value. |
private void |
setASCIItextDirty(int j)
If the character is in the ASCII range then mark it as needing replacement with a String on output if it occurs in a text node. |
(package private) boolean |
shouldMapAttrChar(int value)
Tell if the character argument that is from an attribute value has a mapping to a String. |
(package private) boolean |
shouldMapTextChar(int value)
Tell if the character argument that is from a text node has a mapping to a String, for example to map '<' to "<". |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private java.util.HashMap m_charToString
public static final java.lang.String HTML_ENTITIES_RESOURCE
public static final java.lang.String XML_ENTITIES_RESOURCE
static final char S_HORIZONAL_TAB
static final char S_LINEFEED
static final char S_CARRIAGERETURN
static final char S_SPACE
static final char S_QUOTE
static final char S_LT
static final char S_GT
static final char S_NEL
static final char S_LINE_SEPARATOR
boolean onlyQuotAmpLtGt
static final int ASCII_MAX
private final boolean[] shouldMapAttrChar_ASCII
private final boolean[] shouldMapTextChar_ASCII
private final int[] array_of_bits
private static final int SHIFT_PER_WORD
private static final int LOW_ORDER_BITMASK
private int firstWordNotUsed
private final CharInfo.CharKey m_charKey
private static java.util.Hashtable m_getCharInfoCache
Constructor Detail |
---|
private CharInfo()
m_charToString is not created here only for performance reasons,
to avoid creating a Hashtable that will be replaced when
making a mutable copy, mutableCopyOf(CharInfo)
.
private CharInfo(java.lang.String entitiesResource, java.lang.String method, boolean internal)
Method Detail |
---|
private boolean defineEntity(java.lang.String name, char value)
Unlike internal entities, character references are a string to single character mapping. They are used to map non-ASCII characters both on parsing and printing, primarily for HTML documents. '<' is an example of a character reference.
name
- The entity's namevalue
- The entity's value
java.lang.String getOutputStringForChar(char value)
value
- The character that should be resolved to
a String, e.g. resolve '>' to "<".
final boolean shouldMapAttrChar(int value)
value
- the value of a character that is in an attribute value
final boolean shouldMapTextChar(int value)
value
- the value of a character that is in a text node
private static CharInfo getCharInfoBasedOnPrivilege(java.lang.String entitiesFileName, java.lang.String method, boolean internal)
static CharInfo getCharInfo(java.lang.String entitiesFileName, java.lang.String method)
# First char # is a comment Entity numericValue quot 34 amp 38(Note: Why don't we just switch to .properties files? Oct-01 -sc)
entitiesResource
- Name of entities resource file that should
be loaded, which describes that mapping of characters to entity references.method
- the output method type, which should be one of "xml", "html", "text"...private static CharInfo mutableCopyOf(CharInfo charInfo)
charInfo
- The cached one.
private static int arrayIndex(int i)
i
- the integer that might be in the set of integersprivate static int bit(int i)
private int[] createEmptySetOfIntegers(int max)
max
- the maximum integer to be in the set.private final void set(int i)
i
- the integer to add to the set, valid values are
0, 1, 2 ... up to the maximum that was specified at
the creation of the set.private final boolean get(int i)
i
- an integer that is tested to see if it is the
set of integers, or not.private boolean extraEntity(java.lang.String outputString, int charToMap)
charToMap
- The value of the character that is mapped to a StringoutputString
- The String to which the character is mapped, usually
an entity reference such as "<".
private void setASCIItextDirty(int j)
ch
- private void setASCIIattrDirty(int j)
ch
- boolean defineChar2StringMapping(java.lang.String outputString, char inputChar)
outputString
- The String to map to.inputChar
- The char to map from.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |