public class

DefaultContentTransformerFactory

extends Object
implements ContentTransformerFactory
java.lang.Object
   ↳ com.atlassian.confluence.content.render.xhtml.storage.DefaultContentTransformerFactory

Class Overview

Default implementation of the 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 AtomicReference atomicMacroDefinition = 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();
    }
 

Summary

Public Constructors
DefaultContentTransformerFactory(Unmarshaller<MacroDefinition> macroDefinitionUnmarshaller, Marshaller<MacroDefinition> macroDefinitionMarshaller, XmlEventReaderFactory xmlEventReaderFactory, XMLOutputFactory xmlOutputFactory)
Public Methods
Transformer getTransformer(MacroDefinitionUpdater macroDefinitionUpdater)
Returns a Transformer. The Transformer will read the content (normally in XHTML storage format) to create MacroDefinition objects which will be passed to the macroDefinitionUpdater and the resulting MacroDefinition will then be written back to the same content format.
Transformer getTransformer(MacroDefinitionReplacer macroDefinitionReplacer)
Returns a Transformer.
Transformer getTransformer(MacroDefinitionHandler macroDefinitionHandler)
Returns a Transformer.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.atlassian.confluence.content.render.xhtml.storage.ContentTransformerFactory

Public Constructors

public DefaultContentTransformerFactory (Unmarshaller<MacroDefinition> macroDefinitionUnmarshaller, Marshaller<MacroDefinition> macroDefinitionMarshaller, XmlEventReaderFactory xmlEventReaderFactory, XMLOutputFactory xmlOutputFactory)

Public Methods

public Transformer getTransformer (MacroDefinitionUpdater macroDefinitionUpdater)

Returns a Transformer. The Transformer will read the content (normally in XHTML storage format) to create MacroDefinition objects which will be passed to the macroDefinitionUpdater and the resulting MacroDefinition will then be written back to the same content format.

Parameters
macroDefinitionUpdater
Returns
  • a transformer.

public Transformer getTransformer (MacroDefinitionReplacer macroDefinitionReplacer)

Returns a Transformer.

Parameters
macroDefinitionReplacer that will be called each time a macro is found in the content.
Returns
  • a transformer.

public Transformer getTransformer (MacroDefinitionHandler macroDefinitionHandler)

Returns a Transformer.

Parameters
macroDefinitionHandler that will be called each time a macro is found in the content.
Returns
  • a transformer.