Package com.composum.ai.aem.core.impl
Class AemApproximateMarkdownServicePlugin
- java.lang.Object
-
- com.composum.ai.aem.core.impl.AemApproximateMarkdownServicePlugin
-
- All Implemented Interfaces:
ApproximateMarkdownServicePlugin
public class AemApproximateMarkdownServicePlugin extends Object implements ApproximateMarkdownServicePlugin
Special handling for cq:PageContent and components
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.composum.ai.backend.slingbase.ApproximateMarkdownServicePlugin
ApproximateMarkdownServicePlugin.PluginResult
-
-
Field Summary
Fields Modifier and Type Field Description protected static Pattern
CONTENTFRAGMENT_TYPES
protected static Pattern
EXPERIENCEFRAGMENT_TYPES
protected static Pattern
FULLY_IGNORED_TYPES
If a resource renders as a resource type matching that pattern, we ignore it completely, including child nodes.protected static Pattern
TEASER_TYPES
-
Constructor Summary
Constructors Constructor Description AemApproximateMarkdownServicePlugin()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
findElementLabels(org.apache.sling.api.resource.Resource dataNode, Map<String,String> labels, Map<String,Integer> listOrder)
Looks for the cq:model and determines the labels.String
getImageUrl(org.apache.sling.api.resource.Resource imageResource)
Retrieves the imageURL in a way useable for ChatGPT - usually data:image/jpeg;base64,{base64_image}protected org.apache.sling.api.resource.Resource
getLinkedPage(org.apache.sling.api.resource.Resource action)
Collection<ApproximateMarkdownService.Link>
getMasterLinks(org.apache.sling.api.resource.Resource resource)
If applicable: this returns links to the master from which the current page was created - e.g.protected boolean
handleContentFragment(org.apache.sling.api.resource.Resource resource, PrintWriter out, ApproximateMarkdownService service)
Creates markdown for core/wcm/components/contentfragment/v1/contentfragment and derived components.protected boolean
handleExperienceFragment(org.apache.sling.api.resource.Resource resource, PrintWriter out, ApproximateMarkdownService service, org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response)
Creates markdown for core/wcm/components/experiencefragment/v1/experiencefragment and derived components.protected boolean
handleTeaser(org.apache.sling.api.resource.Resource resource, PrintWriter out, ApproximateMarkdownService service)
Creates markdown for core/wcm/components/teaser/v1/teaser and derived components.protected List<org.apache.sling.api.resource.Resource>
listModelResources(List<org.apache.sling.api.resource.Resource> list, org.apache.sling.api.resource.Resource traversed)
ApproximateMarkdownServicePlugin.PluginResult
maybeHandle(org.apache.sling.api.resource.Resource resource, PrintWriter out, ApproximateMarkdownService service, org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response)
Checks whether the resource should be handled by this plugin and if so, handles it by printing an appropriate markdown representation to the PrintWriter.protected boolean
pageHandling(org.apache.sling.api.resource.Resource resource, PrintWriter out, ApproximateMarkdownService service)
Prints title and meta attributes, then continues to normal handling.protected boolean
renderDamAssets(org.apache.sling.api.resource.Resource resource, PrintWriter out, org.apache.sling.api.SlingHttpServletResponse response)
If the resource is a dam:Asset or a dam:AssetContent jcr:content then we return an image linkprotected void
renderReferencedContentFragment(org.apache.sling.api.resource.Resource resource, PrintWriter out, ApproximateMarkdownService service, org.apache.sling.api.resource.Resource referencedResource, String variation, String reference, String[] elementNames)
protected byte[]
resizeToMaxSize(byte[] imageData, String mimeType, int maxSize)
We resize the image to a maximum width and height of maxSize, keeping the aspect ratio.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.composum.ai.backend.slingbase.ApproximateMarkdownServicePlugin
cacheMarkdown, resourceRendersAsComponentMatching
-
-
-
-
Field Detail
-
FULLY_IGNORED_TYPES
protected static final Pattern FULLY_IGNORED_TYPES
If a resource renders as a resource type matching that pattern, we ignore it completely, including child nodes.
-
TEASER_TYPES
protected static final Pattern TEASER_TYPES
-
EXPERIENCEFRAGMENT_TYPES
protected static final Pattern EXPERIENCEFRAGMENT_TYPES
-
CONTENTFRAGMENT_TYPES
protected static final Pattern CONTENTFRAGMENT_TYPES
-
-
Method Detail
-
maybeHandle
@Nonnull public ApproximateMarkdownServicePlugin.PluginResult maybeHandle(@Nonnull org.apache.sling.api.resource.Resource resource, @Nonnull PrintWriter out, @Nonnull ApproximateMarkdownService service, @Nonnull org.apache.sling.api.SlingHttpServletRequest request, @Nonnull org.apache.sling.api.SlingHttpServletResponse response)
Description copied from interface:ApproximateMarkdownServicePlugin
Checks whether the resource should be handled by this plugin and if so, handles it by printing an appropriate markdown representation to the PrintWriter.- Specified by:
maybeHandle
in interfaceApproximateMarkdownServicePlugin
- Returns:
- what is already handled by this plugin. It is possible to write to the PrintWriter in any case.
-
pageHandling
protected boolean pageHandling(org.apache.sling.api.resource.Resource resource, PrintWriter out, @Nonnull ApproximateMarkdownService service)
Prints title and meta attributes, then continues to normal handling.??? pageTitle vs. jcr:title , shortDescription
-
handleTeaser
protected boolean handleTeaser(org.apache.sling.api.resource.Resource resource, PrintWriter out, ApproximateMarkdownService service)
Creates markdown for core/wcm/components/teaser/v1/teaser and derived components.- See Also:
- "https://github.com/adobe/aem-core-wcm-components/blob/main/content/src/content/jcr_root/apps/core/wcm/components/teaser/v1/teaser/README.md"
-
getLinkedPage
@Nullable protected org.apache.sling.api.resource.Resource getLinkedPage(org.apache.sling.api.resource.Resource action)
-
handleExperienceFragment
protected boolean handleExperienceFragment(org.apache.sling.api.resource.Resource resource, PrintWriter out, ApproximateMarkdownService service, org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response)
Creates markdown for core/wcm/components/experiencefragment/v1/experiencefragment and derived components.- See Also:
- "https://github.com/adobe/aem-core-wcm-components/blob/main/content/src/content/jcr_root/apps/core/wcm/components/experiencefragment/v2/experiencefragment/README.md"
-
handleContentFragment
protected boolean handleContentFragment(org.apache.sling.api.resource.Resource resource, PrintWriter out, ApproximateMarkdownService service)
Creates markdown for core/wcm/components/contentfragment/v1/contentfragment and derived components.- See Also:
- "https://github.com/adobe/aem-core-wcm-components/blob/main/content/src/content/jcr_root/apps/core/wcm/components/contentfragment/v1/contentfragment/README.md"
-
renderReferencedContentFragment
protected void renderReferencedContentFragment(org.apache.sling.api.resource.Resource resource, PrintWriter out, ApproximateMarkdownService service, org.apache.sling.api.resource.Resource referencedResource, String variation, String reference, String[] elementNames)
-
findElementLabels
protected void findElementLabels(org.apache.sling.api.resource.Resource dataNode, Map<String,String> labels, Map<String,Integer> listOrder)
Looks for the cq:model and determines the labels.
-
listModelResources
protected List<org.apache.sling.api.resource.Resource> listModelResources(List<org.apache.sling.api.resource.Resource> list, org.apache.sling.api.resource.Resource traversed)
-
renderDamAssets
protected boolean renderDamAssets(org.apache.sling.api.resource.Resource resource, PrintWriter out, org.apache.sling.api.SlingHttpServletResponse response)
If the resource is a dam:Asset or a dam:AssetContent jcr:content then we return an image link
-
getImageUrl
@Nullable public String getImageUrl(@Nullable org.apache.sling.api.resource.Resource imageResource)
Retrieves the imageURL in a way useable for ChatGPT - usually data:image/jpeg;base64,{base64_image}- Specified by:
getImageUrl
in interfaceApproximateMarkdownServicePlugin
-
resizeToMaxSize
protected byte[] resizeToMaxSize(@Nonnull byte[] imageData, String mimeType, int maxSize) throws IOException
We resize the image to a maximum width and height of maxSize, keeping the aspect ratio. If it's smaller, it's returned as is. It could be of types image/jpeg, image/png or image/gif .- Throws:
IOException
-
getMasterLinks
@Nonnull public Collection<ApproximateMarkdownService.Link> getMasterLinks(org.apache.sling.api.resource.Resource resource)
Description copied from interface:ApproximateMarkdownServicePlugin
If applicable: this returns links to the master from which the current page was created - e.g. an AEM live copy.- Specified by:
getMasterLinks
in interfaceApproximateMarkdownServicePlugin
-
-