Class DefaultXhtmlContent
- java.lang.Object
-
- com.atlassian.confluence.content.render.xhtml.DefaultXhtmlContent
-
- All Implemented Interfaces:
MacroDefinitionTransformer
,WikiToStorageConverter
,XhtmlContent
public class DefaultXhtmlContent extends Object implements XhtmlContent
-
-
Constructor Summary
Constructors Constructor Description DefaultXhtmlContent(Marshaller<MacroDefinition> viewMacroMarshaller, Marshaller<MacroDefinition> storageMacroMarshaller, Marshaller<Link> viewLinkMarshaller, Marshaller<Link> storageLinkMarshaller, Marshaller<EmbeddedImage> viewEmbeddedImageMarshaller, Marshaller<EmbeddedImage> storageEmbeddedImageMarshaller, Marshaller<InlineTaskList> viewInlineTaskMarshaller, Marshaller<InlineTaskList> storageInlineTaskMarshaller, Renderer viewRenderer, XmlEventReaderFactory xmlEventReaderFactory, ContentTransformerFactory contentTransformerFactory, ExceptionTolerantMigrator wikiToXhtmlMigrator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
convertEmbeddedImageToStorage(EmbeddedImage embeddedImage, ConversionContext context)
Returns a storage format fragment for the suppliedembeddedImage
.String
convertEmbeddedImageToView(EmbeddedImage embeddedImage, ConversionContext context)
Returns a view format fragment for the suppliedembeddedImage
.String
convertInlineTaskListToStorage(InlineTaskList inlineTaskList, ConversionContext context)
Returns a storage format fragment for the suppliedinlineTaskList
.String
convertInlineTaskListToView(InlineTaskList inlineTaskList, ConversionContext context)
Returns a view format fragment for the suppliedinlineTaskList
.String
convertLinkToStorage(Link link, ConversionContext context)
Returns a storage format fragment for the suppliedlink
.String
convertLinkToView(Link link, ConversionContext context)
Returns a view format fragment for the suppliedlink
.String
convertMacroDefinitionToStorage(MacroDefinition macroDefinition, ConversionContext context)
Returns an storage format fragment for the suppliedmacroDefinition
.String
convertMacroDefinitionToView(MacroDefinition macroDefinition, ConversionContext context)
Returns a view format fragment for the suppliedmacroDefinition
.List<BatchedRenderResult>
convertStorageToView(BatchedRenderRequest... renderRequests)
Returns a view format fragments for the suppliedrenderRequests
.String
convertStorageToView(String storageFragment, ConversionContext context)
Returns a view format fragment for the suppliedstorageFragment
.<T extends ContentEntityObject>
TconvertWikiBodyToStorage(T ceo)
Convert the body of the supplied ContentEntityObject to Confluence Storage Format XHTML (if necessary).String
convertWikiToStorage(String wikiContent, ConversionContext context, List<RuntimeException> migrationExceptions)
Returns the XHTML storage format equivalent of the suppliedwikiContent
(wiki markup).String
convertWikiToView(String wikiContent, ConversionContext context, List<RuntimeException> migrationExceptions)
Returns the HTML view format equivalent of the suppliedwikiContent
.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
.void
handleXhtmlElements(String storageFragment, ConversionContext context, List<? extends XhtmlVisitor> visitors)
Provides a mechanism for finding arbitrary Xhtml elements in the suppliedstorageFormat
.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
-
DefaultXhtmlContent
public DefaultXhtmlContent(Marshaller<MacroDefinition> viewMacroMarshaller, Marshaller<MacroDefinition> storageMacroMarshaller, Marshaller<Link> viewLinkMarshaller, Marshaller<Link> storageLinkMarshaller, Marshaller<EmbeddedImage> viewEmbeddedImageMarshaller, Marshaller<EmbeddedImage> storageEmbeddedImageMarshaller, Marshaller<InlineTaskList> viewInlineTaskMarshaller, Marshaller<InlineTaskList> storageInlineTaskMarshaller, Renderer viewRenderer, XmlEventReaderFactory xmlEventReaderFactory, ContentTransformerFactory contentTransformerFactory, ExceptionTolerantMigrator wikiToXhtmlMigrator)
-
-
Method Detail
-
convertWikiToStorage
public String convertWikiToStorage(String wikiContent, ConversionContext context, List<RuntimeException> migrationExceptions)
Description copied from interface:XhtmlContent
Returns the XHTML storage format equivalent of the suppliedwikiContent
(wiki markup).- Specified by:
convertWikiToStorage
in interfaceWikiToStorageConverter
- Specified by:
convertWikiToStorage
in interfaceXhtmlContent
- Parameters:
wikiContent
- to be converted.context
- for the conversion.migrationExceptions
- that will be populated with any exceptions that take place during the migration. There may be multiple exceptions if there are multiple wiki markup sections.- Returns:
- the XHTML storage format equivalent.
-
convertWikiBodyToStorage
public <T extends ContentEntityObject> T convertWikiBodyToStorage(T ceo)
Description copied from interface:XhtmlContent
Convert the body of the supplied ContentEntityObject to Confluence Storage Format XHTML (if necessary).
Since for now and the near future Confluence may have both wiki formatted and XHTML formatted ContentEntityObjects in the system (wiki formatted historical versions may be present in an upgraded installation) this method provides a convenient way to ensure you only need to handle ContentEntityObjects with the new XHTML format of body.
Note that the returned ceo is a clone of the passed in version, even if no conversion was necessary.
- Specified by:
convertWikiBodyToStorage
in interfaceWikiToStorageConverter
- Specified by:
convertWikiBodyToStorage
in interfaceXhtmlContent
- Parameters:
ceo
- the ContentEntityObject to be converted (if necessary).- Returns:
- a clone of the provided ContentEntityObject with its wiki formatted body converted.
-
convertWikiToView
public String convertWikiToView(String wikiContent, ConversionContext context, List<RuntimeException> migrationExceptions) throws XMLStreamException, XhtmlException
Description copied from interface:XhtmlContent
Returns the HTML view format equivalent of the suppliedwikiContent
.- Specified by:
convertWikiToView
in interfaceXhtmlContent
- Parameters:
wikiContent
- to be converted.context
- for the conversion.migrationExceptions
- that will be populated with any exceptions that take place during the migration. There may be multiple exceptions if there are multiple wiki markup sections.- Returns:
- the HTML view format equivalent.
- Throws:
XMLStreamException
- if there was a problem reading intermediate storage format data that is created during the conversion.XhtmlException
- if there was a problem creating the view format output.
-
convertStorageToView
public String convertStorageToView(String storageFragment, ConversionContext context) throws XMLStreamException, XhtmlException
Description copied from interface:XhtmlContent
Returns a view format fragment for the suppliedstorageFragment
.- Specified by:
convertStorageToView
in interfaceXhtmlContent
- Parameters:
storageFragment
- to be converted (for example the body of a macro).context
- for the conversion.- Returns:
- the view format fragment.
- Throws:
XMLStreamException
- if there was a problem reading the storage fragment.XhtmlException
- if there was a problem creating the view fragment.
-
convertStorageToView
public List<BatchedRenderResult> convertStorageToView(BatchedRenderRequest... renderRequests)
Description copied from interface:XhtmlContent
Returns a view format fragments for the suppliedrenderRequests
.Failed renders will be flagged in the results, rather than throwing an XMLStreamException or XhtmlException.
- Specified by:
convertStorageToView
in interfaceXhtmlContent
- Parameters:
renderRequests
- batches of storageFragments to be converted with their associated contexts- Returns:
- a list of batch results.
-
convertMacroDefinitionToView
public String convertMacroDefinitionToView(MacroDefinition macroDefinition, ConversionContext context) throws XhtmlException
Description copied from interface:XhtmlContent
Returns a view format fragment for the suppliedmacroDefinition
.- Specified by:
convertMacroDefinitionToView
in interfaceXhtmlContent
- Parameters:
macroDefinition
- that describes the macro.context
- for the conversion.- Returns:
- the view format fragment.
- Throws:
XhtmlException
- if there was a problem creating the fragment.
-
convertLinkToView
public String convertLinkToView(Link link, ConversionContext context) throws XhtmlException
Description copied from interface:XhtmlContent
Returns a view format fragment for the suppliedlink
.- Specified by:
convertLinkToView
in interfaceXhtmlContent
- Parameters:
link
- that describes the link.context
- for the conversion.- Returns:
- the view format fragment.
- Throws:
XhtmlException
- if there was a problem creating the fragment.
-
convertEmbeddedImageToView
public String convertEmbeddedImageToView(EmbeddedImage embeddedImage, ConversionContext context) throws XhtmlException
Description copied from interface:XhtmlContent
Returns a view format fragment for the suppliedembeddedImage
.- Specified by:
convertEmbeddedImageToView
in interfaceXhtmlContent
- Parameters:
embeddedImage
- that describes the embedded image.context
- for the conversion.- Returns:
- the view format fragment.
- Throws:
XhtmlException
- if there was a problem creating the fragment.
-
convertInlineTaskListToView
public String convertInlineTaskListToView(InlineTaskList inlineTaskList, ConversionContext context) throws XhtmlException
Description copied from interface:XhtmlContent
Returns a view format fragment for the suppliedinlineTaskList
.- Specified by:
convertInlineTaskListToView
in interfaceXhtmlContent
- Parameters:
inlineTaskList
- that describes the inline task list.context
- for the conversion.- Returns:
- the view format fragment.
- Throws:
XhtmlException
- if there was a problem creating the fragment.
-
convertMacroDefinitionToStorage
public String convertMacroDefinitionToStorage(MacroDefinition macroDefinition, ConversionContext context) throws XhtmlException
Description copied from interface:XhtmlContent
Returns an storage format fragment for the suppliedmacroDefinition
.- Specified by:
convertMacroDefinitionToStorage
in interfaceXhtmlContent
- Parameters:
macroDefinition
- that describes the macro.context
- for the conversion.- Returns:
- the storage format fragment.
- Throws:
XhtmlException
- if there was a problem creating the fragment.
-
convertLinkToStorage
public String convertLinkToStorage(Link link, ConversionContext context) throws XhtmlException
Description copied from interface:XhtmlContent
Returns a storage format fragment for the suppliedlink
.- Specified by:
convertLinkToStorage
in interfaceXhtmlContent
- Parameters:
link
- that describes the link.context
- for the conversion.- Returns:
- the storage format fragment.
- Throws:
XhtmlException
- if there was a problem creating the fragment.
-
convertEmbeddedImageToStorage
public String convertEmbeddedImageToStorage(EmbeddedImage embeddedImage, ConversionContext context) throws XhtmlException
Description copied from interface:XhtmlContent
Returns a storage format fragment for the suppliedembeddedImage
.- Specified by:
convertEmbeddedImageToStorage
in interfaceXhtmlContent
- Parameters:
embeddedImage
- that describes the embedded image.context
- for the conversion.- Returns:
- the storage format fragment.
- Throws:
XhtmlException
- if there was a problem creating the fragment.
-
convertInlineTaskListToStorage
public String convertInlineTaskListToStorage(InlineTaskList inlineTaskList, ConversionContext context) throws XhtmlException
Description copied from interface:XhtmlContent
Returns a storage format fragment for the suppliedinlineTaskList
.- Specified by:
convertInlineTaskListToStorage
in interfaceXhtmlContent
- Parameters:
inlineTaskList
- that describes the inline task list.context
- for the conversion.- Returns:
- the storage format fragment.
- Throws:
XhtmlException
- if there was a problem creating the fragment.
-
updateMacroDefinitions
public String updateMacroDefinitions(String storageFragment, ConversionContext context, MacroDefinitionUpdater updater) throws XhtmlException
Description copied from interface:XhtmlContent
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
- Specified by:
updateMacroDefinitions
in interfaceXhtmlContent
- 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:XhtmlContent
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
- Specified by:
replaceMacroDefinitionsWithString
in interfaceXhtmlContent
- 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:XhtmlContent
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
- Specified by:
handleMacroDefinitions
in interfaceXhtmlContent
- 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:XhtmlContent
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
- Specified by:
handleMacroDefinitions
in interfaceXhtmlContent
- 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.
-
handleXhtmlElements
public void handleXhtmlElements(String storageFragment, ConversionContext context, List<? extends XhtmlVisitor> visitors) throws XhtmlException
Description copied from interface:XhtmlContent
Provides a mechanism for finding arbitrary Xhtml elements in the suppliedstorageFormat
.- Specified by:
handleXhtmlElements
in interfaceXhtmlContent
- Parameters:
storageFragment
- or more typically the storage representation of a completeContentEntityObject
context
- for the conversionvisitors
- a list of visitors- Throws:
XhtmlException
-
-