public class DefaultContentTransformerFactory extends Object implements ContentTransformerFactory
ContentTransformerFactory
, typically used by macro developers to obtain
and optionally modify MacroDefinition
objects in page of macro body content.
For following code obtains a reference to the last macro on a page with a given name.
public MacroDefinition getMacroDefinition(ContentEntityObject contentEntityObject, final String macroName) { final AtomicReferenceatomicMacroDefinition = new AtomicReference (); Transformer transformer = contentTransformerFactory.getTransformer(new XhtmlContent.MacroDefinitionUpdater() { public MacroDefinition update(MacroDefinition macroDefinition) { if (macroName.equals(macroDefinition.getName())) { atomicMacroDefinition.set(macroDefinition); } return macroDefinition; } }); String page = contentEntityObject.getBodyAsString(); Reader reader = new StringReader(page); PageContext pageContext = contentEntityObject.toPageContext(); ConversionContext conversionContext = new DefaultConversionContext(pageContext); try { transformer.transform(reader, conversionContext); } catch (XhtmlException e) { e.printStackTrace(); } return atomicMacroDefinition.get(); }
Constructor and Description |
---|
DefaultContentTransformerFactory(Unmarshaller<MacroDefinition> macroDefinitionUnmarshaller,
Marshaller<MacroDefinition> macroDefinitionMarshaller,
XmlEventReaderFactory xmlEventReaderFactory,
XmlOutputFactory xmlOutputFactory,
com.atlassian.event.api.EventPublisher eventPublisher) |
Modifier and Type | Method and Description |
---|---|
Transformer |
getTransformer(MacroDefinitionHandler macroDefinitionHandler)
Returns a Transformer.
|
Transformer |
getTransformer(MacroDefinitionHandler handler,
MacroDefinitionMarshallingStrategy strategy)
Returns a Transformer.
|
Transformer |
getTransformer(MacroDefinitionReplacer macroDefinitionReplacer)
Returns a Transformer.
|
Transformer |
getTransformer(MacroDefinitionUpdater macroDefinitionUpdater)
Returns a Transformer.
|
public DefaultContentTransformerFactory(Unmarshaller<MacroDefinition> macroDefinitionUnmarshaller, Marshaller<MacroDefinition> macroDefinitionMarshaller, XmlEventReaderFactory xmlEventReaderFactory, XmlOutputFactory xmlOutputFactory, com.atlassian.event.api.EventPublisher eventPublisher)
public Transformer getTransformer(MacroDefinitionUpdater macroDefinitionUpdater)
MacroDefinition
objects which will be passed to the macroDefinitionUpdater
and the resulting
MacroDefinition will then be written back to the same content format.getTransformer
in interface ContentTransformerFactory
macroDefinitionUpdater
- that will be called each time a macro is found in the content.public Transformer getTransformer(MacroDefinitionReplacer macroDefinitionReplacer)
ContentTransformerFactory
getTransformer
in interface ContentTransformerFactory
macroDefinitionReplacer
- that will be called each time a macro is found in the content.public Transformer getTransformer(MacroDefinitionHandler macroDefinitionHandler)
ContentTransformerFactory
getTransformer
in interface ContentTransformerFactory
macroDefinitionHandler
- that will be called each time a macro is found in the content.public Transformer getTransformer(MacroDefinitionHandler handler, MacroDefinitionMarshallingStrategy strategy)
ContentTransformerFactory
getTransformer
in interface ContentTransformerFactory
handler
- that will be called each time a macro is found in the content.strategy
- that determines how each macro's MacroDefinition should be marshalled.Copyright © 2003–2020 Atlassian. All rights reserved.