@Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); response.setCharacterEncoding("utf-8"); String[] prefixes; try { Session session = (Session) request.getResourceResolver().adaptTo(Session.class); prefixes = session.getNamespacePrefixes(); } catch (RepositoryException re) { prefixes = new String[] {""}; } try { TidyJSONWriter out = new TidyJSONWriter(response.getWriter()); out.setTidy("true".equals(request.getParameter(TIDY))); out.object(); out.key("namespaces"); out.array(); for (String p : prefixes) { out.value(p); } out.endArray(); out.endObject(); } catch (JSONException e) { // todo... } }
@Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); response.setCharacterEncoding("utf-8"); TidyJSONWriter writer = new TidyJSONWriter(response.getWriter()); writer.setTidy("true".equals(request.getParameter(TIDY))); ResourceResolver resolver = request.getResourceResolver(); Session session = resolver.adaptTo(Session.class); String paths[] = request.getParameterValues(PATH); List<Reference> allReferences = new ArrayList<Reference>(); if (paths != null) { // search all refs that may be contained in one of the passed paths for (String path : paths) { if (path.length() > 0) { // get content node Resource r = resolver.getResource(path + "/" + JcrConstants.JCR_CONTENT); if (r == null) { r = resolver.getResource(path); } if (r == null) { continue; } for (ReferenceProvider referenceProvider : referenceProviders) { allReferences.addAll(referenceProvider.findReferences(r)); } } } } try { writer.object(); writer.key("assets"); writer.array(); for (Reference reference : allReferences) { boolean published = false; boolean outdated = false; ReplicationStatus replStatus = null; final Resource resource = reference.getResource(); boolean canReplicate = canReplicate(reference.getResource().getPath(), session); long lastPublished = 0; if (resource != null) { replStatus = resource.adaptTo(ReplicationStatus.class); if (replStatus != null) { published = replStatus.isDelivered() || replStatus.isActivated(); if (published) { lastPublished = replStatus.getLastPublished().getTimeInMillis(); outdated = lastPublished < reference.getLastModified(); } } log.debug( "Considering reference at {} . Published: {}, outdated: {} ( lastPublished: {}, lastModified: {} )", new Object[] { reference.getResource().getPath(), published, outdated, new Date(lastPublished), new Date(reference.getLastModified()) }); } if (!published || outdated) { writer.object(); writer.key("type").value(reference.getType()); writer.key("path").value(reference.getResource().getPath()); writer.key("name").value(reference.getName()); if (replStatus != null) { writer.key("published").value(published); } writer.key("outdated").value(outdated); writer.key("status").value(outdated ? "outdated" : "not available"); writer.key("disabled").value(!canReplicate); writer.endObject(); } } writer.endArray(); writer.endObject(); } catch (Exception e) { throw new ServletException(e); } }