@Test public void testTemplateResolver() throws RenderingEngineMissingException { ThymeleafInlineContentItemsResolver resolver = new ThymeleafInlineContentItemsResolver(); ViewResolverConfiguration configuration = new ViewResolverConfiguration() .addPrefixes("customTemplateLocation/") .setSuffix(".template"); resolver.getTemplateEngine().setViewResolverConfiguration(configuration); TemplateEngineConfig templateEngineConfig = new TemplateEngineConfig(); templateEngineConfig.setResolvers(Collections.singletonList(resolver)); StronglyTypedContentItemConverter stronglyTypedContentItemConverter = new StronglyTypedContentItemConverter(); stronglyTypedContentItemConverter.registerType(CustomItem.class); RichTextElementConverter converter = new RichTextElementConverter( null, null, null, templateEngineConfig, stronglyTypedContentItemConverter); RichTextElement original = new RichTextElement(); original.setLinkedItems(Collections.singletonList("donate_with_us")); ContentItem contentItem = new ContentItem(); contentItem.setLinkedItemProvider(() -> { ContentItem donateWithUs = new ContentItem(); System system = new System(); system.setType("item"); donateWithUs.setSystem(system); TextElement textElement = new TextElement(); textElement.setValue("Please donate with us."); HashMap<String, Element> elements = new HashMap<>(); elements.put("message_text", textElement); donateWithUs.setElements(elements); donateWithUs.setLinkedItemProvider(HashMap::new); donateWithUs.setStronglyTypedContentItemConverter(stronglyTypedContentItemConverter); HashMap<String, ContentItem> linkedItems = new HashMap<>(); linkedItems.put("donate_with_us", donateWithUs); return linkedItems; }); contentItem.setStronglyTypedContentItemConverter(stronglyTypedContentItemConverter); original.parent = contentItem; original.setValue( "<p><object type=\"application/kenticocloud\" data-type=\"item\" data-codename=\"donate_with_us\"></object></p>"); RichTextElement converted = converter.convert(original); Assert.assertEquals( "<p><custom>Please donate with us.</custom></p>", converted.getValue()); }
public RichTextElement convert(RichTextElement orig) { if (orig.getValue() == null) { return orig; } orig.setValue(resolveLinks(orig)); orig.setValue(resolveLinkedItems(orig)); if (richTextElementResolver != null) { orig.setValue(richTextElementResolver.resolve(orig.getValue())); } return orig; }
RichTextElementConverter { public RichTextElement convert(RichTextElement orig) { if (orig.getValue() == null) { return orig; } orig.setValue(resolveLinks(orig)); orig.setValue(resolveLinkedItems(orig)); if (richTextElementResolver != null) { orig.setValue(richTextElementResolver.resolve(orig.getValue())); } return orig; } }
RichTextElementConverter { public RichTextElement convert(RichTextElement orig) { if (orig.getValue() == null) { return orig; } orig.setValue(resolveLinks(orig)); orig.setValue(resolveLinkedItems(orig)); if (richTextElementResolver != null) { orig.setValue(richTextElementResolver.resolve(orig.getValue())); } return orig; } RichTextElementConverter(
            ContentLinkUrlResolver contentLinkUrlResolver,
            BrokenLinkUrlResolver brokenLinkUrlResolver,
            RichTextElementResolver richTextElementResolver,
            TemplateEngineConfig templateEngineConfig,
            StronglyTypedContentItemConverter stronglyTypedContentItemConverter); }
RichTextElementConverter { public RichTextElement convert(RichTextElement orig) { if (orig.getValue() == null) { return orig; } orig.setValue(resolveLinks(orig)); orig.setValue(resolveLinkedItems(orig)); if (richTextElementResolver != null) { orig.setValue(richTextElementResolver.resolve(orig.getValue())); } return orig; } RichTextElementConverter(
            ContentLinkUrlResolver contentLinkUrlResolver,
            BrokenLinkUrlResolver brokenLinkUrlResolver,
            RichTextElementResolver richTextElementResolver,
            TemplateEngineConfig templateEngineConfig,
            StronglyTypedContentItemConverter stronglyTypedContentItemConverter); void process(List<ContentItem> orig); void process(ContentItem orig); RichTextElement convert(RichTextElement orig); }
RichTextElementConverter { public RichTextElement convert(RichTextElement orig) { if (orig.getValue() == null) { return orig; } orig.setValue(resolveLinks(orig)); orig.setValue(resolveLinkedItems(orig)); if (richTextElementResolver != null) { orig.setValue(richTextElementResolver.resolve(orig.getValue())); } return orig; } RichTextElementConverter(
            ContentLinkUrlResolver contentLinkUrlResolver,
            BrokenLinkUrlResolver brokenLinkUrlResolver,
            RichTextElementResolver richTextElementResolver,
            TemplateEngineConfig templateEngineConfig,
            StronglyTypedContentItemConverter stronglyTypedContentItemConverter); void process(List<ContentItem> orig); void process(ContentItem orig); RichTextElement convert(RichTextElement orig);  }