List of usage examples for org.apache.commons.io Document Document
Document
From source file:webhooks.core.services.impl.DocumentServiceImp.java
@Override public Document getMetaData(String documentID) { String path = DocumentUtil.getLocationFromDocId(documentID); File targetFile = new File(path); if (targetFile.exists()) { try {//www.j ava 2 s . c o m Document doc = new Document(); doc.setId(documentID); doc.setMimeType(new Tika().detect(targetFile)); doc.setLocation(path); doc.setKind(targetFile.isFile() ? Document.TYPE_FILE : Document.TYPE_FOLDER); doc.setSize(targetFile.length()); doc.setLastModified(targetFile.lastModified()); doc.setName(targetFile.getName()); return doc; } catch (IOException e) { return null; } } return null; }
From source file:webhooks.core.services.impl.DocumentServiceImp.java
@Override public Document uploadStart(String parentDocumentId, String documentName) throws DocumentExistsException { String path = DocumentUtil.getLocationFromDocId(parentDocumentId); // make the path for the new document path += File.separator + documentName; File file = new File(path); if (file.exists()) throw new DocumentExistsException(path); Document doc = new Document(); doc.setKind(Document.TYPE_FILE); //doc.getMimeType(); doc.setId(DocumentUtil.GenerateDocId(path)); return doc;/*from ww w. ja v a 2 s . c om*/ }
From source file:webhooks.core.services.impl.DocumentServiceImp.java
private Document convertToDocument(File fileEntry) { Document doc = null;//w w w. j a v a 2s. c om if (!fileEntry.isHidden()) { doc = new Document(); doc.setName(fileEntry.getName()); //doc.setLocation(fileEntry.getPath()); String now = String.valueOf(new Date().getTime()); // fullpath + # + timestamp(long) doc.setId(CipherUtil.encrypt(fileEntry.getPath() + "#" + now)); // get mime type of a document if (fileEntry.isFile()) { try { String mimeType = getMimeType(fileEntry.toPath()); doc.setMimeType(mimeType); } catch (IOException e) { e.printStackTrace(); } doc.setSize(fileEntry.length()); doc.setKind(Document.TYPE_FILE); } else { doc.setKind(Document.TYPE_FOLDER); } doc.setLastModified(fileEntry.lastModified()); } return doc; }