Class DefaultContentTransformerFactory

  • All Implemented Interfaces:
    ContentTransformerFactory

    public class DefaultContentTransformerFactory
    extends Object
    implements ContentTransformerFactory
    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();
        }