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; }