Class ElementTransformingFragmentTransformer
- All Implemented Interfaces:
FragmentTransformer
A FragmentTransformer that can be configured to transform individual Elements it reads.
Typically you would configure ElementTransformers directly on the DefaultFragmentTransformer to transform individual elements but this FragmentTransformer can be used when you want to reduce the scope of the ElementTransform to just a Fragment of the full XML document being read.
This FragmentTransformer makes use of the ConversionContext to store a flag which ensures that this transformer instance will only apply once per ConversionContext. (There is no point in transforming elements multiple times and it could lead to infinite loops if we didn't consume the triggering event. If we do consume the triggering event then the mainFragmentTransformer will fail because it will encounter the closing event without having seen the opening event.)
Rather than having multiple ElementTransformingFragmentTransformer in the pipeline it would be preferable to have only a single one if possible but instead with multiple ElementTransformers configured.
-
Constructor Summary
ConstructorDescriptionElementTransformingFragmentTransformer
(List<ElementTransformer> elementTransformers, Set<QName> handledNames) -
Method Summary
Modifier and TypeMethodDescriptionboolean
handles
(StartElement startElementEvent, ConversionContext conversionContext) transform
(XMLEventReader reader, FragmentTransformer mainFragmentTransformer, ConversionContext conversionContext) Wraps the supplied reader in an ElementTransformingXmlEventReader and then applies the mainFragmentTransformer.
-
Constructor Details
-
ElementTransformingFragmentTransformer
public ElementTransformingFragmentTransformer(List<ElementTransformer> elementTransformers, Set<QName> handledNames)
-
-
Method Details
-
handles
- Specified by:
handles
in interfaceFragmentTransformer
- Returns:
- true for any StartElement QName that is returned by the configured Set of ElementTransformer.
-
transform
public Streamable transform(XMLEventReader reader, FragmentTransformer mainFragmentTransformer, ConversionContext conversionContext) throws XhtmlException Wraps the supplied reader in an ElementTransformingXmlEventReader and then applies the mainFragmentTransformer.- Specified by:
transform
in interfaceFragmentTransformer
- Throws:
XhtmlException
-