Class MacroDefinitionTransformerImpl
- java.lang.Object
-
- com.atlassian.confluence.impl.content.render.xhtml.MacroDefinitionTransformerImpl
-
- All Implemented Interfaces:
MacroDefinitionTransformer
public final class MacroDefinitionTransformerImpl extends Object implements MacroDefinitionTransformer
An implementation ofMacroDefinitionTransformer
based upon aContentTransformerFactory
.- Since:
- 7.6
- See Also:
DefaultXhtmlContent
-
-
Constructor Summary
Constructors Constructor Description MacroDefinitionTransformerImpl(ContentTransformerFactory contentTransformerFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
handleMacroDefinitions(String storageFragment, ConversionContext context, MacroDefinitionHandler handler)
Perform an operation onMacroDefinition
s in the suppliedstorageFragment
without making changes to the storage representation.void
handleMacroDefinitions(String storageFragment, ConversionContext context, MacroDefinitionHandler handler, MacroDefinitionMarshallingStrategy strategy)
Perform an operation onMacroDefinition
s in the suppliedstorageFragment
, with optional changes to the storage representation defined by theMacroDefinitionMarshallingStrategy
.String
replaceMacroDefinitionsWithString(String storageFragment, ConversionContext context, MacroDefinitionReplacer replacer)
ReplacesMacroDefinition
s in the suppliedstorageFragment
with a String.String
updateMacroDefinitions(String storageFragment, ConversionContext context, MacroDefinitionUpdater updater)
UpdatesMacroDefinition
s in the suppliedstorageFragment
.
-
-
-
Constructor Detail
-
MacroDefinitionTransformerImpl
public MacroDefinitionTransformerImpl(ContentTransformerFactory contentTransformerFactory)
-
-
Method Detail
-
updateMacroDefinitions
public String updateMacroDefinitions(String storageFragment, ConversionContext context, MacroDefinitionUpdater updater) throws XhtmlException
Description copied from interface:MacroDefinitionTransformer
UpdatesMacroDefinition
s in the suppliedstorageFragment
.// Changes the name of all "mice" macros to "cheese". page.setBodyAsString(xhtmlContent.updateMacroDefinitions(page.getBodyAsString(), context, new XhtmlContent.MacroDefinitionUpdater() { public MacroDefinition update(MacroDefinition macroDefinition) { if ("mice".equals(macroDefinition.getName())) macroDefinition.setName("cheese"); return macroDefinition; } }));
- Specified by:
updateMacroDefinitions
in interfaceMacroDefinitionTransformer
- Parameters:
storageFragment
- or more typically the storage representation of a completeContentEntityObject
which might contain macro definitions.context
- for the conversion.updater
- which is called to update each MacroDefinition found.- Returns:
- the storage representation of the modified fragment.
- Throws:
XhtmlException
- if there was a problem reading the storage fragment, creating the MacroDefinition or creating the modified fragment.
-
replaceMacroDefinitionsWithString
public String replaceMacroDefinitionsWithString(String storageFragment, ConversionContext context, MacroDefinitionReplacer replacer) throws XhtmlException
Description copied from interface:MacroDefinitionTransformer
ReplacesMacroDefinition
s in the suppliedstorageFragment
with a String. Use {link #updateMacroDefinitions} rather than this method if you wish to replace or update one definition with another.// Replaces "cheese" macros with some XHTML. page.setBodyAsString(xhtmlContent.replaceMacroDefinitionsWithString(page.getBodyAsString(), context, new MacroDefinitionReplacer() { public String replace(MacroDefinition macroDefinition) throws XhtmlException { if ("cheese".equals(macroDefinition.getName())) return "
I hate cheese!
"; return xhtmlContent.convertMacroDefinitionToStorage(macroDefinition, context); } }));- Specified by:
replaceMacroDefinitionsWithString
in interfaceMacroDefinitionTransformer
- Parameters:
storageFragment
- or more typically the storage representation of a completeContentEntityObject
which might contain macro definitions.context
- for the conversion.replacer
- which is called to replace each MacroDefinition found with a replacement in storage format (typically XHTML).- Returns:
- the storage representation of the modified fragment.
- Throws:
XhtmlException
- if there was a problem reading the storage fragment, creating the MacroDefinition or creating the modified fragment.
-
handleMacroDefinitions
public void handleMacroDefinitions(String storageFragment, ConversionContext context, MacroDefinitionHandler handler) throws XhtmlException
Description copied from interface:MacroDefinitionTransformer
Perform an operation onMacroDefinition
s in the suppliedstorageFragment
without making changes to the storage representation.// Finds the last macro on a page final AtomicReference
atomicMacroDefinition = new AtomicReference (); xhtmlContent.handleMacroDefinitions(page.getBodyAsString(), context, new MacroDefinitionHandler() { public void handle(MacroDefinition macroDefinition) { atomicMacroDefinition.set(macroDefinition); } }); MacroDefinition lastMacro = atomicMacroDefinition.get(); - Specified by:
handleMacroDefinitions
in interfaceMacroDefinitionTransformer
- Parameters:
storageFragment
- or more typically the storage representation of a completeContentEntityObject
which might contain macro definitions.context
- for the conversion.handler
- which is called each MacroDefinition found.- Throws:
XhtmlException
- if there was a problem reading the storage fragment or creating the MacroDefinition.
-
handleMacroDefinitions
public void handleMacroDefinitions(String storageFragment, ConversionContext context, MacroDefinitionHandler handler, MacroDefinitionMarshallingStrategy strategy) throws XhtmlException
Description copied from interface:MacroDefinitionTransformer
Perform an operation onMacroDefinition
s in the suppliedstorageFragment
, with optional changes to the storage representation defined by theMacroDefinitionMarshallingStrategy
.// Finds the last macro on a page, maintaining any nested macros within the MacroDefinition body final AtomicReference
atomicMacroDefinition = new AtomicReference (); xhtmlContent.handleMacroDefinitions(page.getBodyAsString(), context, new MacroDefinitionHandler() { public void handle(MacroDefinition macroDefinition) { atomicMacroDefinition.set(macroDefinition); } }, MacroDefinitionMarshallingStrategy.MARSHALL_MACRO); MacroDefinition lastMacro = atomicMacroDefinition.get(); - Specified by:
handleMacroDefinitions
in interfaceMacroDefinitionTransformer
- Parameters:
storageFragment
- or more typically the storage representation of a completeContentEntityObject
which might contain macro definitions.context
- for the conversion.handler
- which is called each MacroDefinition found.strategy
- the strategy used to transform the body of the handled macros- Throws:
XhtmlException
- if there was a problem reading the storage fragment or creating the MacroDefinition.
-
-