|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.compass.core.xml.jdom.converter.support.StAXTextModifier
public abstract class StAXTextModifier
Strategy class (used by StAXBuilder that allows for modifying
text content when building a JDOM tree from an XML document using
StAX XMLStreamReader. It is most commonly used to trim out
white space that can not be automatically determined by the parser
(due to not having an associated DTD, usually), but can be used
to do other manipulations as well.
Basic calling sequence is as follows:
allowModificationsAfter(javax.xml.stream.XMLStreamReader, int) is called, to determine if CHARACTERS
elements read after this event may possibly be modified. This
allows builder to ignore calling other methods on this object for
elements that contain text content that should not be modified (like
<pre> element in (X)HTML, for example).
allowModificationsAfter(javax.xml.stream.XMLStreamReader, int) that returned true,
possiblyModifyText(javax.xml.stream.XMLStreamReader, int) is called, to determine if contents of
that event should be modified before being added to the JDOM tree
possiblyModifyText(javax.xml.stream.XMLStreamReader, int) returned true,
textToIncludeBetween(javax.xml.stream.XMLStreamReader, int, int, java.lang.String) is called to figure out resulting text
to add to JDOM tree. This may be the original text (which is passed
as an argument), or something else, including null or empty String
to essentially remove that text event from the tree.
The default implementation of this class implements simple logics that will remove all "indentation" white space from the document. This is done by always enabling modifications in the whole tree, and removing such text events that are all whitespace and start with a line feed character (\r or \n). Extending classes can obviously create much more fine-grained heuristics.
| Constructor Summary | |
|---|---|
protected |
StAXTextModifier()
|
| Method Summary | |
|---|---|
abstract boolean |
allowModificationsAfter(javax.xml.stream.XMLStreamReader r,
int eventType)
Method called to determine whether to possibly remove (indentation) white space after START_ELEMENT or END_ELEMENT that the stream reader currently points to. |
abstract boolean |
possiblyModifyText(javax.xml.stream.XMLStreamReader r,
int prevEvent)
Method called for CHARACTERS and CDATA events when the previous call to allowModificationsAfter(javax.xml.stream.XMLStreamReader, int) returned true. |
abstract String |
textToIncludeBetween(javax.xml.stream.XMLStreamReader r,
int prevEvent,
int nextEvent,
String text)
Method called to determine what to include in place of the preceding text segment (of type CHARACTERS or CDATA), given event types that precede and follow the text segment. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
protected StAXTextModifier()
| Method Detail |
|---|
public abstract boolean allowModificationsAfter(javax.xml.stream.XMLStreamReader r,
int eventType)
throws javax.xml.stream.XMLStreamException
r - Stream reader that currently points to the event referred.eventType - Type of the currently pointed to event (either
START_ELEMENT or END_ELEMENT)
javax.xml.stream.XMLStreamException
public abstract boolean possiblyModifyText(javax.xml.stream.XMLStreamReader r,
int prevEvent)
throws javax.xml.stream.XMLStreamException
allowModificationsAfter(javax.xml.stream.XMLStreamReader, int) returned true. Is used to
determine if there is possibility that this text segment needs
to be modified (up to and including being removed, as is the case
for indentation removal).
Note: StAX stream readers are allowed report CDATA sections as CHARACTERS too, so some implementations may not allow distinguishing between CDATA and other text. Further, when text is to be coalesced, resulting event type will always be CHARACTERS, when segments are combined, even if they all were adjacent CDATA sections.
r - Stream reader that currently points to the CHARACTERS or
CDATA event for which method is called.prevEvent - Type of the event that immediately preceded
the current event.
javax.xml.stream.XMLStreamException
public abstract String textToIncludeBetween(javax.xml.stream.XMLStreamReader r,
int prevEvent,
int nextEvent,
String text)
throws javax.xml.stream.XMLStreamException
The method is only called if the immediately preceding call to
possiblyModifyText(javax.xml.stream.XMLStreamReader, int) returned true; otherwise
text is included as is without calling this method.
Note that when this method is called, the passed in stream reader already points to the event following the text; not the text itself; because of this the text is passed explicitly, as it can NOT be accessed via the stream reader.
javax.xml.stream.XMLStreamException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||