private EcmDocument readDocumentByNode(Node node, int readType) throws EcmException {
    EcmDocument doc = null;
    try {
      if (node == null) {
        return doc;
      }
      doc = new EcmDocument();

      Node resNode = node.getNode(Property.JCR_CONTENT);
      if (resNode == null) {
        return doc;
      }
      /** Load the document meta data */
      DocumentMetadata meta = this.loadDocumentMetadata(resNode);

      meta.setFileName(node.getName());
      meta.setIdentifier(node.getIdentifier());

      String createdBy = node.getProperty(Property.JCR_CREATED_BY).getString();
      Calendar createdDate = node.getProperty(Property.JCR_CREATED).getDate();

      meta.setCreated(createdDate.getTime());
      meta.setCreatedBy(createdBy);
      meta.setCheckedOut(node.isCheckedOut());
      meta.setFullPath(node.getPath());

      doc.setMetadata(meta);
      doc.setFileName(meta.getFileName());
      doc.setParentFolder(node.getParent().getName());

      /** Load the file content */
      Property dataProperty = resNode.getProperty(Property.JCR_DATA);
      if (dataProperty != null && readType == 0) {
        doc.setInputStream(dataProperty.getBinary().getStream());
        doc.getMetadata().setSize(dataProperty.getBinary().getSize());
      } else if (dataProperty != null && readType == 1) {
        byte[] contents = convertToByteArray(dataProperty.getBinary());
        doc.setContent(contents);
        doc.getMetadata().setSize(dataProperty.getBinary().getSize());
      }

    } catch (PathNotFoundException e) {
      throw new EcmException(
          "Fail to read document from repository.", e, ErrorCodes.REPOSITROY_ERR_INVALID_PATH);

    } catch (RepositoryException e) {
      throw new EcmException(
          "Fail to read document from repository.", e, ErrorCodes.REPOSITROY_ERR_GENERIC);

    } catch (IOException e) {
      throw new EcmException(
          "Fail to read document from repository.",
          e,
          ErrorCodes.REPOSITROY_ERR_FAIL_TO_READ_CONTENT);
    }

    return doc;
  }
  /**
   * Load the <code>EcmDocument</code> provided by version no
   *
   * @param versionIdentifier the version no of the document
   * @return the generated <code>EcmDocument</code>
   * @throws EcmException if there is any error
   */
  public EcmDocument loadDocumentVersion(String versionIdentifier) throws EcmException {
    logger.debug("Loading document version by identifier:" + versionIdentifier);
    EcmDocument doc = null;
    try {
      Node node = this.session.getNodeByIdentifier(versionIdentifier);
      if (node == null) {
        return doc;
      }
      doc = new EcmDocument();

      Version v = (Version) node;
      DocumentMetadata metaData = this.loadFileVersionMetadata(v);
      doc.setMetadata(metaData);

      Node nContent = this.loadDocumentContentNode(v);

      Property dataProperty = nContent.getProperty(Property.JCR_DATA);
      if (dataProperty != null) {
        byte[] contents = convertToByteArray(dataProperty.getBinary());
        doc.setContent(contents);
      }

    } catch (RepositoryException e) {
      throw new EcmException(
          "Fail to retrieve document version", e, ErrorCodes.REPOSITROY_ERR_GENERIC);

    } catch (IOException e) {
      throw new EcmException(
          "Fail to read document from repository.",
          e,
          ErrorCodes.REPOSITROY_ERR_FAIL_TO_READ_CONTENT);
    }

    logger.debug("Version loaded:" + versionIdentifier);
    return doc;
  }