Javolution 6.0.0 java
javolution.xml.internal.stream.EntitiesImpl Class Reference
Collaboration diagram for javolution.xml.internal.stream.EntitiesImpl:
[legend]

Public Member Functions

int getMaxLength ()
 
int replaceEntity (char[] buffer, int start, int length) throws XMLStreamException
 
void setEntitiesMapping (Map< String, String > entityToReplacementText)
 
Map< String, String > getEntitiesMapping ()
 
void reset ()
 

Package Functions

 EntitiesImpl ()
 

Private Attributes

int _maxLength = 1
 
Map< String, String > _entitiesMapping
 
CharArray _tmp = new CharArray()
 

Detailed Description

Defines entities while parsing.

Author
Jean-Marie Dautelle
Version
4.0, June 16, 2006

Definition at line 24 of file EntitiesImpl.java.

Constructor & Destructor Documentation

◆ EntitiesImpl()

javolution.xml.internal.stream.EntitiesImpl.EntitiesImpl ( )
package

Default constructor.

Definition at line 39 of file EntitiesImpl.java.

39 {}

Member Function Documentation

◆ getEntitiesMapping()

Map<String, String> javolution.xml.internal.stream.EntitiesImpl.getEntitiesMapping ( )

Returns the custom entity mapping or

null

if none.

Definition at line 145 of file EntitiesImpl.java.

145  {
146  return _entitiesMapping;
147  }

References javolution.xml.internal.stream.EntitiesImpl._entitiesMapping.

Referenced by javolution.xml.internal.stream.XMLStreamReaderImpl.getProperty().

Here is the caller graph for this function:

◆ getMaxLength()

int javolution.xml.internal.stream.EntitiesImpl.getMaxLength ( )

Returns the length of the largest entity defined (default

1

).

Definition at line 44 of file EntitiesImpl.java.

44  {
45  return _maxLength;
46  }

References javolution.xml.internal.stream.EntitiesImpl._maxLength.

Referenced by javolution.xml.internal.stream.XMLStreamReaderImpl.replaceEntity().

Here is the caller graph for this function:

◆ replaceEntity()

int javolution.xml.internal.stream.EntitiesImpl.replaceEntity ( char[]  buffer,
int  start,
int  length 
) throws XMLStreamException

Replaces the entity at the specified position. The five predefined XML entities "&#38;lt;", "&#38;gt;", "&#38;apos;", "&#38;quot;", "&#38;amp;" as well as character refererences (decimal or hexadecimal) are always recognized.

Parameters
bufferthe data buffer.
startthe index of entity first character (index of '&')
Returns
the length of the replacement entity (including ';')
Exceptions
XMLStreamExceptionif the entity is not recognized.

Definition at line 59 of file EntitiesImpl.java.

60  {
61 
62  // Checks for character references.
63  if (buffer[start + 1] == '#') {
64  char c = buffer[start + 2];
65  int base = (c == 'x') ? 16 : 10;
66  int i = (c == 'x') ? 3 : 2;
67  int charValue = 0;
68  for (; i < length - 1; i++) {
69  c = buffer[start + i];
70  charValue *= base;
71  charValue += (c <= '9') ? (c - '0') : (c <= 'Z') ? c - 'A'
72  : c - 'a';
73  }
74  buffer[start] = (char) charValue;
75  return 1;
76  }
77 
78  if ((buffer[start + 1] == 'l') && (buffer[start + 2] == 't')
79  && (buffer[start + 3] == ';')) {
80  buffer[start] = '<';
81  return 1;
82  }
83 
84  if ((buffer[start + 1] == 'g') && (buffer[start + 2] == 't')
85  && (buffer[start + 3] == ';')) {
86  buffer[start] = '>';
87  return 1;
88  }
89 
90  if ((buffer[start + 1] == 'a') && (buffer[start + 2] == 'p')
91  && (buffer[start + 3] == 'o') && (buffer[start + 4] == 's')
92  && (buffer[start + 5] == ';')) {
93  buffer[start] = '\'';
94  return 1;
95  }
96 
97  if ((buffer[start + 1] == 'q') && (buffer[start + 2] == 'u')
98  && (buffer[start + 3] == 'o') && (buffer[start + 4] == 't')
99  && (buffer[start + 5] == ';')) {
100  buffer[start] = '"';
101  return 1;
102  }
103 
104  if ((buffer[start + 1] == 'a') && (buffer[start + 2] == 'm')
105  && (buffer[start + 3] == 'p') && (buffer[start + 4] == ';')) {
106  buffer[start] = '&';
107  return 1;
108  }
109 
110  // Searches user defined entities.
111  _tmp.setArray(buffer, start + 1, length - 2);
112  CharSequence replacementText = (_entitiesMapping != null) ? _entitiesMapping
113  .get(_tmp) : null;
114  if (replacementText == null)
115  throw new XMLStreamException("Entity " + _tmp + " not recognized");
116  int replacementTextLength = replacementText.length();
117  for (int i = 0; i < replacementTextLength; i++) {
118  buffer[start + i] = replacementText.charAt(i);
119  }
120  return replacementTextLength;
121  }

References javolution.xml.internal.stream.EntitiesImpl._entitiesMapping, javolution.xml.internal.stream.EntitiesImpl._tmp, and javolution.text.CharArray.setArray().

Referenced by javolution.xml.internal.stream.XMLStreamReaderImpl.replaceEntity().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset()

void javolution.xml.internal.stream.EntitiesImpl.reset ( )

Definition at line 150 of file EntitiesImpl.java.

150  {
151  _maxLength = 1;
152  _entitiesMapping = null;
153  }

References javolution.xml.internal.stream.EntitiesImpl._entitiesMapping, and javolution.xml.internal.stream.EntitiesImpl._maxLength.

Referenced by javolution.xml.internal.stream.XMLStreamReaderImpl.reset().

Here is the caller graph for this function:

◆ setEntitiesMapping()

void javolution.xml.internal.stream.EntitiesImpl.setEntitiesMapping ( Map< String, String >  entityToReplacementText)

Sets the current custom entity mapping. For example:

new FastMap().put("copy", "©")

to define the copyright entity.

Definition at line 129 of file EntitiesImpl.java.

129  {
130  FastTable<String> values = new FastTable<String>();
131  values.addAll(entityToReplacementText.values());
132  _maxLength = values.mapped(new Function<CharSequence, Integer>() {
133 
134  @Override
135  public Integer apply(CharSequence csq) {
136  return csq.length();
137  }}).max();
138 
139  _entitiesMapping = entityToReplacementText;
140  }

References javolution.xml.internal.stream.EntitiesImpl._entitiesMapping, javolution.xml.internal.stream.EntitiesImpl._maxLength, javolution.util.FastTable< E >.addAll(), and javolution.util.FastCollection< E >.mapped().

Referenced by javolution.xml.internal.stream.XMLStreamReaderImpl.setEntities().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _entitiesMapping

Map<String, String> javolution.xml.internal.stream.EntitiesImpl._entitiesMapping
private

◆ _maxLength

int javolution.xml.internal.stream.EntitiesImpl._maxLength = 1
private

◆ _tmp

CharArray javolution.xml.internal.stream.EntitiesImpl._tmp = new CharArray()
private

The documentation for this class was generated from the following file:
javolution.xml.internal.stream.EntitiesImpl._maxLength
int _maxLength
Definition: EntitiesImpl.java:29
javolution.xml.internal.stream.EntitiesImpl._tmp
CharArray _tmp
Definition: EntitiesImpl.java:123
javolution.xml.internal.stream.EntitiesImpl._entitiesMapping
Map< String, String > _entitiesMapping
Definition: EntitiesImpl.java:34
javolution.text.CharArray.setArray
CharArray setArray(char[] array, int offset, int length)
Definition: CharArray.java:116