Search in sources :

Example 1 with XSSAPI

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);
    }
}
Also used : XSSAPI(org.apache.sling.xss.XSSAPI) ServletException(javax.servlet.ServletException) JSONObject(org.apache.sling.commons.json.JSONObject) JSONArray(org.apache.sling.commons.json.JSONArray) JSONException(org.apache.sling.commons.json.JSONException) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

ServletException (javax.servlet.ServletException)1 JSONArray (org.apache.sling.commons.json.JSONArray)1 JSONException (org.apache.sling.commons.json.JSONException)1 JSONObject (org.apache.sling.commons.json.JSONObject)1 XSSAPI (org.apache.sling.xss.XSSAPI)1 ServiceReference (org.osgi.framework.ServiceReference)1