Class DefaultContentTransformerFactory
- java.lang.Object
-
- com.atlassian.confluence.content.render.xhtml.storage.DefaultContentTransformerFactory
-
- All Implemented Interfaces:
ContentTransformerFactory
public class DefaultContentTransformerFactory extends Object implements ContentTransformerFactory
Default implementation of theContentTransformerFactory, typically used by macro developers to obtain and optionally modifyMacroDefinitionobjects 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 Summary
Constructors Constructor Description DefaultContentTransformerFactory(Unmarshaller<MacroDefinition> macroDefinitionUnmarshaller, Marshaller<MacroDefinition> macroDefinitionMarshaller, XmlEventReaderFactory xmlEventReaderFactory, XmlOutputFactory xmlOutputFactory, com.atlassian.event.api.EventPublisher eventPublisher)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TransformergetTransformer(MacroDefinitionHandler macroDefinitionHandler)Returns a Transformer.TransformergetTransformer(MacroDefinitionHandler handler, MacroDefinitionMarshallingStrategy strategy)Returns a Transformer.TransformergetTransformer(MacroDefinitionReplacer macroDefinitionReplacer)Returns a Transformer.TransformergetTransformer(MacroDefinitionUpdater macroDefinitionUpdater)Returns a Transformer.
-
-
-
Constructor Detail
-
DefaultContentTransformerFactory
public DefaultContentTransformerFactory(Unmarshaller<MacroDefinition> macroDefinitionUnmarshaller, Marshaller<MacroDefinition> macroDefinitionMarshaller, XmlEventReaderFactory xmlEventReaderFactory, XmlOutputFactory xmlOutputFactory, com.atlassian.event.api.EventPublisher eventPublisher)
-
-
Method Detail
-
getTransformer
public Transformer getTransformer(MacroDefinitionUpdater macroDefinitionUpdater)
Returns a Transformer. The Transformer will read the content (normally in XHTML storage format) to createMacroDefinitionobjects which will be passed to themacroDefinitionUpdaterand the resulting MacroDefinition will then be written back to the same content format.- Specified by:
getTransformerin interfaceContentTransformerFactory- Parameters:
macroDefinitionUpdater- that will be called each time a macro is found in the content.- Returns:
- a transformer.
-
getTransformer
public Transformer getTransformer(MacroDefinitionReplacer macroDefinitionReplacer)
Description copied from interface:ContentTransformerFactoryReturns a Transformer.- Specified by:
getTransformerin interfaceContentTransformerFactory- Parameters:
macroDefinitionReplacer- that will be called each time a macro is found in the content.- Returns:
- a transformer.
-
getTransformer
public Transformer getTransformer(MacroDefinitionHandler macroDefinitionHandler)
Description copied from interface:ContentTransformerFactoryReturns a Transformer.- Specified by:
getTransformerin interfaceContentTransformerFactory- Parameters:
macroDefinitionHandler- that will be called each time a macro is found in the content.- Returns:
- a transformer.
-
getTransformer
public Transformer getTransformer(MacroDefinitionHandler handler, MacroDefinitionMarshallingStrategy strategy)
Description copied from interface:ContentTransformerFactoryReturns a Transformer.- Specified by:
getTransformerin interfaceContentTransformerFactory- Parameters:
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.- Returns:
- a transformer.
-
-