com.atlassian.confluence.xhtml.api
Interface XhtmlContent

All Known Implementing Classes:
DefaultXhtmlContent

public interface XhtmlContent

Provides methods that manipulate XHTML storage format content, convert between view and storage formats or from old style wiki markup to storage format.


Method Summary
 String convertEmbeddedImageToStorage(EmbeddedImage embeddedImage, ConversionContext context)
          Returns a storage format fragment for the supplied embeddedImage.
 String convertEmbeddedImageToView(EmbeddedImage embeddedImage, ConversionContext context)
          Returns a view format fragment for the supplied embeddedImage.
 String convertLinkToStorage(Link link, ConversionContext context)
          Returns a storage format fragment for the supplied link.
 String convertLinkToView(Link link, ConversionContext context)
          Returns a view format fragment for the supplied link.
 String convertMacroDefinitionToStorage(MacroDefinition macroDefinition, ConversionContext context)
          Returns an storage format fragment for the supplied macroDefinition.
 String convertMacroDefinitionToView(MacroDefinition macroDefinition, ConversionContext context)
          Returns a view format fragment for the supplied macroDefinition.
 String convertStorageToView(String storageFragment, ConversionContext context)
          Returns a view format fragment for the supplied storageFragment.
<T extends ContentEntityObject>
T
convertWikiBodyToStorage(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 supplied wikiContent (wiki markup).
 String convertWikiToView(String wikiContent, ConversionContext context, List<RuntimeException> migrationExceptions)
          Returns the HTML view format equivalent of the supplied wikiContent.
 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 handleXhtmlElements(String storageFragment, ConversionContext context, List<? extends XhtmlVisitor> visitors)
          Provides a mechanism for finding arbitrary Xhtml elements in the supplied storageFormat.
 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.
 

Method Detail

convertWikiToStorage

String convertWikiToStorage(String wikiContent,
                            ConversionContext context,
                            List<RuntimeException> migrationExceptions)
Returns the XHTML storage format equivalent of the supplied wikiContent (wiki markup).

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

<T extends ContentEntityObject> T convertWikiBodyToStorage(T ceo)

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.

Parameters:
ceo - the ContentEntityObject to be converted (if necessary).
Returns:
a clone of the provided ContentEntityObject with its wiki formatted body converted.

convertWikiToView

String convertWikiToView(String wikiContent,
                         ConversionContext context,
                         List<RuntimeException> migrationExceptions)
                         throws XMLStreamException,
                                XhtmlException
Returns the HTML view format equivalent of the supplied wikiContent.

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

String convertStorageToView(String storageFragment,
                            ConversionContext context)
                            throws XMLStreamException,
                                   XhtmlException
Returns a view format fragment for the supplied storageFragment.

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.

convertMacroDefinitionToView

String convertMacroDefinitionToView(MacroDefinition macroDefinition,
                                    ConversionContext context)
                                    throws XhtmlException
Returns a view format fragment for the supplied macroDefinition.

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

String convertLinkToView(Link link,
                         ConversionContext context)
                         throws XhtmlException
Returns a view format fragment for the supplied link.

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

String convertEmbeddedImageToView(EmbeddedImage embeddedImage,
                                  ConversionContext context)
                                  throws XhtmlException
Returns a view format fragment for the supplied embeddedImage.

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.

convertMacroDefinitionToStorage

String convertMacroDefinitionToStorage(MacroDefinition macroDefinition,
                                       ConversionContext context)
                                       throws XhtmlException
Returns an storage format fragment for the supplied macroDefinition.

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

String convertLinkToStorage(Link link,
                            ConversionContext context)
                            throws XhtmlException
Returns a storage format fragment for the supplied link.

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

String convertEmbeddedImageToStorage(EmbeddedImage embeddedImage,
                                     ConversionContext context)
                                     throws XhtmlException
Returns a storage format fragment for the supplied embeddedImage.

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.

updateMacroDefinitions

String updateMacroDefinitions(String storageFragment,
                              ConversionContext context,
                              MacroDefinitionUpdater updater)
                              throws XhtmlException
Updates MacroDefinitions 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;
        }
    }));
 

Parameters:
storageFragment - 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.
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

String replaceMacroDefinitionsWithString(String storageFragment,
                                         ConversionContext context,
                                         MacroDefinitionReplacer replacer)
                                         throws XhtmlException
Replaces MacroDefinitions 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); } }));

Parameters:
storageFragment - 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).
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

void handleMacroDefinitions(String storageFragment,
                            ConversionContext context,
                            MacroDefinitionHandler handler)
                            throws XhtmlException
Perform an operation on MacroDefinitions in the supplied storageFragment 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();
 

Parameters:
storageFragment - 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.
Throws:
XhtmlException - if there was a problem reading the storage fragment or creating the MacroDefinition.

handleXhtmlElements

void handleXhtmlElements(String storageFragment,
                         ConversionContext context,
                         List<? extends XhtmlVisitor> visitors)
                         throws XhtmlException
Provides a mechanism for finding arbitrary Xhtml elements in the supplied storageFormat.

Parameters:
storageFragment - or more typically the storage representation of a complete ContentEntityObject
context - for the conversion
visitors - a list of visitors
Throws:
XhtmlException


Copyright © 2003-2012 Atlassian. All Rights Reserved.