Package com.composum.ai.aem.core.impl
Class AemApproximateMarkdownServicePlugin
- java.lang.Object
-
- com.composum.ai.aem.core.impl.AemApproximateMarkdownServicePlugin
-
- All Implemented Interfaces:
com.composum.ai.backend.slingbase.ApproximateMarkdownServicePlugin
public class AemApproximateMarkdownServicePlugin extends Object implements com.composum.ai.backend.slingbase.ApproximateMarkdownServicePlugin
Special handling for cq:PageContent and components
-
-
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<com.composum.ai.backend.slingbase.ApproximateMarkdownService.Link>
getMasterLinks(org.apache.sling.api.resource.Resource resource)
protected boolean
handleContentFragment(org.apache.sling.api.resource.Resource resource, PrintWriter out, com.composum.ai.backend.slingbase.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, com.composum.ai.backend.slingbase.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, com.composum.ai.backend.slingbase.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)
com.composum.ai.backend.slingbase.ApproximateMarkdownServicePlugin.PluginResult
maybeHandle(org.apache.sling.api.resource.Resource resource, PrintWriter out, com.composum.ai.backend.slingbase.ApproximateMarkdownService service, org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response)
protected boolean
pageHandling(org.apache.sling.api.resource.Resource resource, PrintWriter out, com.composum.ai.backend.slingbase.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, com.composum.ai.backend.slingbase.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.
-
-
-
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 com.composum.ai.backend.slingbase.ApproximateMarkdownServicePlugin.PluginResult maybeHandle(@Nonnull org.apache.sling.api.resource.Resource resource, @Nonnull PrintWriter out, @Nonnull com.composum.ai.backend.slingbase.ApproximateMarkdownService service, @Nonnull org.apache.sling.api.SlingHttpServletRequest request, @Nonnull org.apache.sling.api.SlingHttpServletResponse response)
- Specified by:
maybeHandle
in interfacecom.composum.ai.backend.slingbase.ApproximateMarkdownServicePlugin
-
pageHandling
protected boolean pageHandling(org.apache.sling.api.resource.Resource resource, PrintWriter out, @Nonnull com.composum.ai.backend.slingbase.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, com.composum.ai.backend.slingbase.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, com.composum.ai.backend.slingbase.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, com.composum.ai.backend.slingbase.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, com.composum.ai.backend.slingbase.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 interfacecom.composum.ai.backend.slingbase.ApproximateMarkdownServicePlugin
-
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<com.composum.ai.backend.slingbase.ApproximateMarkdownService.Link> getMasterLinks(org.apache.sling.api.resource.Resource resource)
- Specified by:
getMasterLinks
in interfacecom.composum.ai.backend.slingbase.ApproximateMarkdownServicePlugin
-
-