April 1, 2020
Estimated Post Reading Time ~

How to check run mode

import java.io.IOException;
import java.io.Writer;
import java.util.Set;


import javax.servlet.ServletException;


import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.apache.sling.settings.SlingSettingsService;


@SlingServlet(paths="/bin/outputrunmodes")
@SuppressWarnings("serial")
public class RunmodeOutputServlet extends SlingSafeMethodsServlet {


@Reference
private SlingSettingsService settingsService;


@Override
protected void doGet(SlingHttpServletRequest request,
SlingHttpServletResponse response) throws ServletException,
IOException {
response.setContentType("text/plain");


final Set<String> runmodes = settingsService.getRunModes();


Writer w = response.getWriter();
w.write("Current runmodes:\n");
for (String runmode : runmodes) {
w.write(runmode);
w.write("\n");
}
w.flush();

}

}


//For client side run mode check you can use
//https://github.com/davidegiannella/cq-misc/blob/master/EditMode.js or $.cq.isAuthor() or http://labs.sixdimensions.com/blog/2013-04-02/what-my-cq-mode/


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.