use of org.apache.sling.xss.XSSAPI in project acs-aem-commons by Adobe-Consulting-Services.
the class CustomPollingImporterListServlet method doGet.
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
XSSAPI xssApi = request.adaptTo(XSSAPI.class);
try {
JSONObject result = new JSONObject();
JSONArray list = new JSONArray();
result.put("list", list);
ServiceReference[] services = tracker.getServiceReferences();
if (services != null) {
for (ServiceReference service : services) {
String displayName = PropertiesUtil.toString(service.getProperty("displayName"), null);
String[] schemes = PropertiesUtil.toStringArray(service.getProperty(Importer.SCHEME_PROPERTY));
if (displayName != null && schemes != null) {
for (String scheme : schemes) {
JSONObject obj = new JSONObject();
obj.put("qtip", "");
obj.put("text", displayName);
obj.put("text_xss", xssApi.encodeForJSString(displayName));
obj.put("value", scheme);
list.put(obj);
}
}
}
}
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json");
result.write(response.getWriter());
} catch (JSONException e) {
throw new ServletException("Unable to generate importer list", e);
}
}
Aggregations