Code snippets – XML Add-On


Document State transitions

Get allowed Document State transitions for an asset.The API will return next allowed document state transitions for the user identified by userID attribute

JSONObject jsonResponse = ProfileService.getdocstateinfo(new String[] { assetPath }, userID, resourceResolver);
LOG.debug("Profile service response: {} for asset: {}", jsonResponse, assetPath);

JSONArray jsonArray = jsonResponse.getJSONObject(assetPath).getJSONArray(DOCSTATEJSON_ALLOWEDSTATES_KEY);

for (int i = 0; i < jsonArray.length(); i++) {
	LOG.info("Valid transition: {}", jsonArray.getString(i));
}

Post-processing event handler

XML Documentation solution exposes com/adobe/fmdita/postprocess/complete event that is
used to perform any post-processing operations. This event is triggered whenever an operation is
performed on a DITA file. The following operations on a DITA file trigger this event:
• Upload
• Creation
• Modification
• Deletion

For more details, please refer to page 19 on https://helpx.adobe.com/content/dam/help/en/xml-documentation-solution/3-4/XML-Documentation-for-Adobe-Experience-Manager_API-Reference_EN.pdf

package com.techrevel.dam.core.fmdita.listeners;
import java.util.HashMap;
import java.util.Map;
import org.apache.jackrabbit.JcrConstants;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.day.cq.dam.api.DamConstants;
/**
* Appends path property to DITA Assets. Needed for Fluid Topic Integration
*
*/
@Component(service = EventHandler.class, property = {
EventConstants.EVENT_TOPIC + "=com/adobe/fmdita/postprocess/complete", EventConstants.EVENT_FILTER
+ "=(|(operation=org/apache/sling/api/resource/Resource/ADDED)(operation=org/apache/sling/api/resource/Resource/CHANGED))" })
public class PostProcessingEventHandler implements EventHandler {
private static final Logger LOG = LoggerFactory.getLogger(PostProcessingEventHandler.class);
@Reference
private ResourceResolverFactory resolverFactory;
@Override
public void handleEvent(Event event) {
LOG.debug("Processing the JOB *******");
// The path of the file that triggered this event. Typically, this is the file
// on which an operation has been performed.
String path = (String) event.getProperty("path");
// Fetch resource resolver
Map<String, Object> serviceParams = new HashMap<>();
serviceParams.put(ResourceResolverFactory.SUBSERVICE, "subServiceName");
ResourceResolver resolver = null;
try {
resolver = resolverFactory.getServiceResourceResolver(serviceParams);
// Resolve path of DITA Asset
String ditaResourcePath = path.substring(0, path.indexOf(JcrConstants.JCR_CONTENT) 1);
// Resolve metadata resource of DITA Asset
String metadataResourcePath = path.substring(0, path.indexOf(DamConstants.RENDITIONS_FOLDER))
+ DamConstants.METADATA_FOLDER;
} catch (LoginException e) {
LOG.error("Exception while commiting path property ", e);
} finally {
if (resolver != null) {
resolver.close();
}
}
}
}

Fetch all DITA Map dependencies

Please refer to link: https://techrevel.blog/2020/09/09/api-fetch-all-dita-map-dependencies/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s