public void writeNodes( SlingHttpServletRequest request, JSONWriter write, Aggregator aggregator, RowIterator iterator) throws JSONException, RepositoryException { Session session = request.getResourceResolver().adaptTo(Session.class); // TODO Get size from somewhere else. long total = iterator.getSize(); long start = SearchUtil.getPaging(request, total); iterator.skip(start); for (long i = 0; i < start && iterator.hasNext(); i++) { Row row = iterator.nextRow(); String path = row.getValue("jcr:path").getString(); Node node = (Node) session.getItem(path); if (aggregator != null) { aggregator.add(node); } ExtendedJSONWriter.writeNodeToWriter(write, node); } }
@Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { // get current user String user = request.getRemoteUser(); if (user == null) { response.sendError( HttpServletResponse.SC_UNAUTHORIZED, "User must be logged in to check their status"); } LOGGER.info("GET to PresenceContactsServlet (" + user + ")"); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); try { Writer writer = response.getWriter(); ExtendedJSONWriter output = new ExtendedJSONWriter(writer); // start JSON object output.object(); PresenceUtils.makePresenceJSON(output, user, presenceService, true); // add in the list of contacts info Session session = request.getResourceResolver().adaptTo(Session.class); List<String> userIds = connectionManager.getConnectedUsers(user, ConnectionState.ACCEPTED); output.key("contacts"); output.array(); for (String userId : userIds) { output.object(); // put in the basics PresenceUtils.makePresenceJSON(output, userId, presenceService, true); // add in the profile output.key("profile"); Authorizable au = PersonalUtils.getAuthorizable(session, userId); Node profileNode = (Node) session.getItem(PersonalUtils.getProfilePath(au)); ExtendedJSONWriter.writeNodeToWriter(output, profileNode); output.endObject(); } output.endArray(); // finish it output.endObject(); } catch (JSONException e) { LOGGER.error(e.getMessage(), e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } catch (RepositoryException e) { LOGGER.error(e.getMessage(), e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } return; }
private void writeDefaultNode( JSONWriter write, Aggregator aggregator, Row row, Node siteNode, Session session) throws JSONException, RepositoryException { Node node = RowUtils.getNode(row, session); if (aggregator != null) { aggregator.add(node); } write.object(); write.key("path"); write.value(node.getPath()); write.key("site"); siteSearchResultProcessor.writeNode(write, siteNode); write.key("excerpt"); write.value(RowUtils.getDefaultExcerpt(row)); write.key("data"); ExtendedJSONWriter.writeNodeToWriter(write, node); write.endObject(); }
public void node(Node node) throws JSONException, RepositoryException { ExtendedJSONWriter.writeNodeToWriter(this, node); }