Пример #1
0
  /**
   * Writes all the properties of a sakai/file node. Also checks what the permissions are for a
   * session and where the links are.
   *
   * @param node
   * @param write
   * @param objectInProgress Whether object creation is in progress. If false, object is started and
   *     ended in this method call.
   * @throws JSONException
   * @throws RepositoryException
   */
  public static void writeFileNode(Node node, Session session, JSONWriter write, int maxDepth)
      throws JSONException, RepositoryException {

    write.object();

    // dump all the properties.
    ExtendedJSONWriter.writeNodeTreeToWriter(write, node, true, maxDepth);
    // The permissions for this session.
    writePermissions(node, session, write);

    if (node.hasNode(JcrConstants.JCR_CONTENT)) {
      Node contentNode = node.getNode(JcrConstants.JCR_CONTENT);
      write.key(JcrConstants.JCR_LASTMODIFIED);
      Calendar cal = contentNode.getProperty(JcrConstants.JCR_LASTMODIFIED).getDate();
      write.value(DateUtils.iso8601(cal));
      write.key(JcrConstants.JCR_MIMETYPE);
      write.value(contentNode.getProperty(JcrConstants.JCR_MIMETYPE).getString());

      if (contentNode.hasProperty(JcrConstants.JCR_DATA)) {
        write.key(JcrConstants.JCR_DATA);
        write.value(contentNode.getProperty(JcrConstants.JCR_DATA).getLength());
      }
    }

    write.endObject();
  }
  /**
   * Represent an entire JCR tree in JSON format.
   *
   * @param write The {@link JSONWriter writer} to send the data to.
   * @param node The node and it's subtree to output. Note: The properties of this node will be
   *     outputted as well.
   * @param objectInProgress use true if you don't want the method to enclose the output in fresh
   *     object braces
   * @param maxDepth Maximum depth of subnodes to traverse. The properties on {@link node} are
   *     processed before this is taken into account.
   * @param currentLevel Internal parameter to track the current processing level.
   * @throws RepositoryException
   * @throws JSONException
   */
  protected static void writeNodeTreeToWriter(
      JSONWriter write, Node node, boolean objectInProgress, int maxDepth, int currentLevel)
      throws RepositoryException, JSONException {
    // Write this node's properties.
    if (!objectInProgress) {
      write.object();
    }
    writeNodeContentsToWriter(write, node);

    if (maxDepth == -1 || currentLevel < maxDepth) {
      // Write all the child nodes.
      NodeIterator iterator = node.getNodes();
      while (iterator.hasNext()) {
        Node childNode = iterator.nextNode();
        write.key(childNode.getName());
        writeNodeTreeToWriter(write, childNode, false, maxDepth, currentLevel + 1);
      }
    }

    if (!objectInProgress) {
      write.endObject();
    }
  }
 /**
  * Represent an entire JCR tree in JSON format. Convenience method for
  * writeNodeTreeToWriter(write, node, false, maxDepth, 0).
  *
  * @param write The {@link JSONWriter writer} to send the data to.
  * @param node The node and it's subtree to output. Note: The properties of this node will be
  *     outputted as well.
  * @param maxDepth Maximum depth of subnodes to traverse. The properties on {@link node} are
  *     processed before this is taken into account.
  * @throws RepositoryException
  * @throws JSONException
  */
 public static void writeNodeTreeToWriter(JSONWriter write, Node node, int maxDepth)
     throws RepositoryException, JSONException {
   writeNodeTreeToWriter(write, node, false, maxDepth, 0);
 }
 /**
  * Represent an entire JCR tree in JSON format.
  * <p>
  * if maxDepth == 0 and objectInProgress == false, same as calling
  * {@link #writeNodeToWriter(JSONWriter, Node).
  * <p>
  * if maxDepth == 0 and objectInfProgress == true, same as calling
  * {@link #writeNodeContentsToWriter(JSONWriter, Node).
  *
  * @param write
  *          The {@link JSONWriter writer} to send the data to.
  * @param node
  *          The node and it's subtree to output. Note: The properties of this node will
  *          be outputted as well.
  * @param objectInProgress
  *          use true if you don't want the method to enclose the output in fresh object
  *          braces
  * @param maxDepth
  *          Maximum depth of subnodes to traverse. The properties on {@link node} are
  *          processed before this is taken into account.
  * @throws RepositoryException
  * @throws JSONException
  */
 public static void writeNodeTreeToWriter(
     JSONWriter write, Node node, boolean objectInProgress, int maxDepth)
     throws RepositoryException, JSONException {
   writeNodeTreeToWriter(write, node, objectInProgress, maxDepth, 0);
 }
 /**
  * Represent an entire JCR tree in JSON format. Convenience method for
  * writeNodeTreeToWriter(write, node, false, -1, -1).
  *
  * @param write The {@link JSONWriter writer} to send the data to.
  * @param node The node and it's subtree to output. Note: The properties of this node will be
  *     outputted as well.
  * @throws RepositoryException
  * @throws JSONException
  */
 public static void writeNodeTreeToWriter(JSONWriter write, Node node)
     throws RepositoryException, JSONException {
   writeNodeTreeToWriter(write, node, false, -1, -1);
 }