public final class MacroDefinitionTransformerImpl extends Object implements MacroDefinitionTransformer
MacroDefinitionTransformer based upon a ContentTransformerFactory.DefaultXhtmlContent| Constructor and Description |
|---|
MacroDefinitionTransformerImpl(ContentTransformerFactory contentTransformerFactory) |
| Modifier and Type | Method and Description |
|---|---|
void |
handleMacroDefinitions(String storageFragment,
ConversionContext context,
MacroDefinitionHandler handler)
Perform an operation on
MacroDefinitions in the supplied storageFragment without making changes
to the storage representation. |
void |
handleMacroDefinitions(String storageFragment,
ConversionContext context,
MacroDefinitionHandler handler,
MacroDefinitionMarshallingStrategy strategy)
Perform an operation on
MacroDefinitions in the supplied storageFragment, with optional changes
to the storage representation defined by the MacroDefinitionMarshallingStrategy. |
String |
replaceMacroDefinitionsWithString(String storageFragment,
ConversionContext context,
MacroDefinitionReplacer replacer)
Replaces
MacroDefinitions in the supplied storageFragment with a String. |
String |
updateMacroDefinitions(String storageFragment,
ConversionContext context,
MacroDefinitionUpdater updater)
Updates
MacroDefinitions in the supplied storageFragment. |
public MacroDefinitionTransformerImpl(ContentTransformerFactory contentTransformerFactory)
public String updateMacroDefinitions(String storageFragment, ConversionContext context, MacroDefinitionUpdater updater) throws XhtmlException
MacroDefinitionTransformerMacroDefinitions in the supplied storageFragment.
// 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;
}
}));
updateMacroDefinitions in interface MacroDefinitionTransformerstorageFragment - or more typically the storage representation of a complete ContentEntityObject
which might contain macro definitions.context - for the conversion.updater - which is called to update each MacroDefinition found.XhtmlException - if there was a problem reading the storage fragment, creating the MacroDefinition or
creating the modified fragment.public String replaceMacroDefinitionsWithString(String storageFragment, ConversionContext context, MacroDefinitionReplacer replacer) throws XhtmlException
MacroDefinitionTransformerMacroDefinitions in the supplied storageFragment 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);
}
}));
replaceMacroDefinitionsWithString in interface MacroDefinitionTransformerstorageFragment - or more typically the storage representation of a complete ContentEntityObject
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).XhtmlException - if there was a problem reading the storage fragment, creating the MacroDefinition or
creating the modified fragment.public void handleMacroDefinitions(String storageFragment, ConversionContext context, MacroDefinitionHandler handler) throws XhtmlException
MacroDefinitionTransformerMacroDefinitions in the supplied storageFragment without making changes
to the storage representation.
// Finds the last macro on a page final AtomicReferenceatomicMacroDefinition = new AtomicReference (); xhtmlContent.handleMacroDefinitions(page.getBodyAsString(), context, new MacroDefinitionHandler() { public void handle(MacroDefinition macroDefinition) { atomicMacroDefinition.set(macroDefinition); } }); MacroDefinition lastMacro = atomicMacroDefinition.get();
handleMacroDefinitions in interface MacroDefinitionTransformerstorageFragment - or more typically the storage representation of a complete ContentEntityObject
which might contain macro definitions.context - for the conversion.handler - which is called each MacroDefinition found.XhtmlException - if there was a problem reading the storage fragment or creating the MacroDefinition.public void handleMacroDefinitions(String storageFragment, ConversionContext context, MacroDefinitionHandler handler, MacroDefinitionMarshallingStrategy strategy) throws XhtmlException
MacroDefinitionTransformerMacroDefinitions in the supplied storageFragment, with optional changes
to the storage representation defined by the MacroDefinitionMarshallingStrategy.
// Finds the last macro on a page, maintaining any nested macros within the MacroDefinition body final AtomicReferenceatomicMacroDefinition = new AtomicReference (); xhtmlContent.handleMacroDefinitions(page.getBodyAsString(), context, new MacroDefinitionHandler() { public void handle(MacroDefinition macroDefinition) { atomicMacroDefinition.set(macroDefinition); } }, MacroDefinitionMarshallingStrategy.MARSHALL_MACRO); MacroDefinition lastMacro = atomicMacroDefinition.get();
handleMacroDefinitions in interface MacroDefinitionTransformerstorageFragment - or more typically the storage representation of a complete ContentEntityObject
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 macrosXhtmlException - if there was a problem reading the storage fragment or creating the MacroDefinition.Copyright © 2003–2021 Atlassian. All rights reserved.