net.sf.saxon.event

Class Stripper

Implemented Interfaces:
Receiver, Result
Known Direct Subclasses:
AllElementStripper, StylesheetStripper

public class Stripper
extends ProxyReceiver

The Stripper class maintains details of which elements need to be stripped. The code is written to act as a SAX-like filter to do the stripping.
Author:
Michael H. Kay

Field Summary

static byte
ALWAYS_PRESERVE
static byte
ALWAYS_STRIP
static byte
CANNOT_STRIP
static byte
PRESERVE_PARENT
static byte
STRIP_DEFAULT

Fields inherited from class net.sf.saxon.event.ProxyReceiver

nextReceiver

Fields inherited from class net.sf.saxon.event.SequenceReceiver

pipelineConfiguration, previousAtomic, systemId

Constructor Summary

Stripper()
Default constructor for use in subclasses
Stripper(Mode stripperRules)
create a Stripper and initialise variables

Method Summary

void
attribute(int nameCode, int typeCode, CharSequence value, int locationId, int properties)
void
characters(CharSequence chars, int locationId, int properties)
Handle a text node
void
endElement()
Handle an end-of-element event
Stripper
getAnother()
Get a clean copy of this stripper
boolean
getStripAll()
Determine if all whitespace is to be stripped (in this case, no further testing is needed)
byte
isSpacePreserving(int nameCode)
Decide whether an element is in the set of white-space preserving element types
byte
isSpacePreserving(NodeInfo element)
Decide whether an element is in the set of white-space preserving element types.
void
open()
Callback interface for SAX: not for application use
void
setPipelineConfiguration(PipelineConfiguration pipe)
void
setStripAll()
Specify that all whitespace nodes are to be stripped
void
setXPathContext(XPathContext context)
Set the XPath context
void
startElement(int nameCode, int typeCode, int locationId, int properties)

Methods inherited from class net.sf.saxon.event.ProxyReceiver

append, attribute, characters, close, comment, endDocument, endElement, getConfiguration, getDocumentLocator, getNamePool, getUnderlyingReceiver, namespace, open, processingInstruction, setPipelineConfiguration, setSystemId, setUnderlyingReceiver, setUnparsedEntity, startContent, startDocument, startElement

Methods inherited from class net.sf.saxon.event.SequenceReceiver

append, getConfiguration, getNamePool, getPipelineConfiguration, getSystemId, open, setPipelineConfiguration, setSystemId, setUnparsedEntity

Field Details

ALWAYS_PRESERVE

public static final byte ALWAYS_PRESERVE
Field Value:
1

ALWAYS_STRIP

public static final byte ALWAYS_STRIP
Field Value:
2

CANNOT_STRIP

public static final byte CANNOT_STRIP
Field Value:
8

PRESERVE_PARENT

public static final byte PRESERVE_PARENT
Field Value:
4

STRIP_DEFAULT

public static final byte STRIP_DEFAULT
Field Value:
0

Constructor Details

Stripper

protected Stripper()
Default constructor for use in subclasses

Stripper

public Stripper(Mode stripperRules)
create a Stripper and initialise variables
Parameters:
stripperRules - defines which elements have whitespace stripped. If null, all whitespace is preserved.

Method Details

attribute

public void attribute(int nameCode,
                      int typeCode,
                      CharSequence value,
                      int locationId,
                      int properties)
            throws XPathException
Specified by:
attribute in interface Receiver
Overrides:
attribute in interface ProxyReceiver

characters

public void characters(CharSequence chars,
                       int locationId,
                       int properties)
            throws XPathException
Handle a text node
Specified by:
characters in interface Receiver
Overrides:
characters in interface ProxyReceiver

endElement

public void endElement()
            throws XPathException
Handle an end-of-element event
Specified by:
endElement in interface Receiver
Overrides:
endElement in interface ProxyReceiver

getAnother

public Stripper getAnother()
Get a clean copy of this stripper

getStripAll

public boolean getStripAll()
Determine if all whitespace is to be stripped (in this case, no further testing is needed)

isSpacePreserving

public byte isSpacePreserving(int nameCode)
            throws XPathException
Decide whether an element is in the set of white-space preserving element types
Parameters:
nameCode - Identifies the name of the element whose whitespace is to be preserved
Returns:
ALWAYS_PRESERVE if the element is in the set of white-space preserving element types, ALWAYS_STRIP if the element is to be stripped regardless of the xml:space setting, and STRIP_DEFAULT otherwise

isSpacePreserving

public byte isSpacePreserving(NodeInfo element)
            throws XPathException
Decide whether an element is in the set of white-space preserving element types. This version of the method is useful in cases where getting the namecode of the element is potentially expensive, e.g. with DOM nodes.
Parameters:
element - Identifies the element whose whitespace is possibly to be preserved
Returns:
ALWAYS_PRESERVE if the element is in the set of white-space preserving element types, ALWAYS_STRIP if the element is to be stripped regardless of the xml:space setting, and STRIP_DEFAULT otherwise

open

public void open()
            throws XPathException
Callback interface for SAX: not for application use
Specified by:
open in interface Receiver
Overrides:
open in interface ProxyReceiver

setPipelineConfiguration

public void setPipelineConfiguration(PipelineConfiguration pipe)
Specified by:
setPipelineConfiguration in interface Receiver
Overrides:
setPipelineConfiguration in interface ProxyReceiver

setStripAll

public void setStripAll()
Specify that all whitespace nodes are to be stripped

setXPathContext

public void setXPathContext(XPathContext context)
Set the XPath context

startElement

public void startElement(int nameCode,
                         int typeCode,
                         int locationId,
                         int properties)
            throws XPathException
Specified by:
startElement in interface Receiver
Overrides:
startElement in interface ProxyReceiver