r57 - in trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment: . handler type
Author: glandais Date: 2007-12-10 15:18:35 +0000 (Mon, 10 Dec 2007) New Revision: 57 Added: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/handler/ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/handler/AttachmentHandler.java Removed: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/fs/ Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/handler/FileSystemAttachmentHandler.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/ContentType.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/RawType.java Log: Refactoring Conversion des Data en Metadata Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java 2007-12-07 16:39:19 UTC (rev 56) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java 2007-12-10 15:18:35 UTC (rev 57) @@ -1,54 +0,0 @@ -package fr.cemagref.simexplorer.is.storage.attachment; - -import java.io.InputStream; - -import fr.cemagref.simexplorer.is.storage.entities.FileEntity; - -/** - * Store, retrieve and delete content - * - * @author landais - * - */ -public abstract class AttachmentHandler { - - /** - * Store content - * - * @param entity - * Entity related to content - * @param field - * Unique field for content - * @param is - * Content - * @throws Exception - */ - public abstract void storeData(FileEntity entity, String field, - InputStream is) throws Exception; - - /** - * Retrieve content - * - * @param entity - * Entity related to content - * @param field - * Unique field for content - * @return Content - * @throws Exception - */ - public abstract InputStream retrieveData(FileEntity entity, String field) - throws Exception; - - /** - * Delete content - * - * @param entity - * Entity related to content - * @param field - * Unique field for content - * @throws Exception - */ - public abstract void deleteData(FileEntity entity, String field) - throws Exception; - -} \ No newline at end of file Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/handler (from rev 55, trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/fs) Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/handler/AttachmentHandler.java (from rev 55, trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java) =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/handler/AttachmentHandler.java (rev 0) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/handler/AttachmentHandler.java 2007-12-10 15:18:35 UTC (rev 57) @@ -0,0 +1,55 @@ +package fr.cemagref.simexplorer.is.storage.attachment.handler; + +import java.io.InputStream; + +import fr.cemagref.simexplorer.is.storage.database.Database; +import fr.cemagref.simexplorer.is.storage.entities.metadata.MetaDataEntity; + +/** + * Store, retrieve and delete content + * + * @author landais + * + */ +public abstract class AttachmentHandler { + + /** + * Store content + * + * @param entity + * DataEntity related to content + * @param field + * Unique field for content + * @param is + * Content + * @throws Exception + */ + public abstract void storeData(Database database, MetaDataEntity entity, String field, + InputStream is) throws Exception; + + /** + * Retrieve content + * + * @param entity + * DataEntity related to content + * @param field + * Unique field for content + * @return Content + * @throws Exception + */ + public abstract InputStream retrieveData(MetaDataEntity entity, String field) + throws Exception; + + /** + * Delete content + * + * @param entity + * DataEntity related to content + * @param field + * Unique field for content + * @throws Exception + */ + public abstract void deleteData(Database database, MetaDataEntity entity, String field) + throws Exception; + +} \ No newline at end of file Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/handler/FileSystemAttachmentHandler.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/fs/FileSystemAttachmentHandler.java 2007-12-07 14:36:43 UTC (rev 55) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/handler/FileSystemAttachmentHandler.java 2007-12-10 15:18:35 UTC (rev 57) @@ -1,4 +1,4 @@ -package fr.cemagref.simexplorer.is.storage.attachment.fs; +package fr.cemagref.simexplorer.is.storage.attachment.handler; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -7,9 +7,9 @@ import java.io.FileOutputStream; import java.io.InputStream; -import fr.cemagref.simexplorer.is.storage.attachment.AttachmentHandler; -import fr.cemagref.simexplorer.is.storage.entities.FileEntity; -import fr.cemagref.simexplorer.is.storage.entities.LoggableElement; +import fr.cemagref.simexplorer.is.storage.database.Database; +import fr.cemagref.simexplorer.is.storage.entities.data.LoggableElement; +import fr.cemagref.simexplorer.is.storage.entities.metadata.MetaDataEntity; /** * File system implementation @@ -28,26 +28,18 @@ * Retrieve file associated to content Create directories associated to file * * @param entity - * Entity related to content + * DataEntity related to content * @param field * Unique field for content * @return Instance of file * @throws Exception */ - private File getFile(FileEntity entity, String field) throws Exception { + private File getFile(MetaDataEntity entity, String field) throws Exception { String resultPath = baseFolder; - // If entity has no metadata, use metadata of parent - LoggableElement loggableElement = null; - if (entity instanceof LoggableElement) { - loggableElement = (LoggableElement) entity; - } else { - loggableElement = entity.getOwner(); - } - // Create file path - resultPath = resultPath + loggableElement.getUuid() + "/" - + loggableElement.getVersion().toString() + "/" + field; + resultPath = resultPath + entity.getUuid() + "/" + + entity.getVersion().toString() + "/" + field; File result = new File(resultPath); // Create directories @@ -60,7 +52,7 @@ } @Override - public InputStream retrieveData(FileEntity entity, String field) + public InputStream retrieveData(MetaDataEntity entity, String field) throws Exception { // Simple stream on file FileInputStream fis = new FileInputStream(getFile(entity, field)); @@ -68,8 +60,8 @@ } @Override - public void storeData(FileEntity entity, String field, InputStream is) - throws Exception { + public void storeData(Database database, MetaDataEntity entity, + String field, InputStream is) throws Exception { // Simple stream on file FileOutputStream fos = new FileOutputStream(getFile(entity, field)); @@ -90,7 +82,8 @@ } @Override - public void deleteData(FileEntity entity, String field) throws Exception { + public void deleteData(Database database, MetaDataEntity entity, + String field) throws Exception { // Simple delete on file getFile(entity, field).delete(); } Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/ContentType.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/ContentType.java 2007-12-07 16:39:19 UTC (rev 56) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/ContentType.java 2007-12-10 15:18:35 UTC (rev 57) @@ -1,6 +1,7 @@ package fr.cemagref.simexplorer.is.storage.attachment.type; import java.io.InputStream; +import java.io.Reader; /** * Content handler @@ -26,7 +27,7 @@ * Input stream * @return Indexable text */ - public abstract InputStream renderToText(InputStream is); + public abstract Reader renderToText(InputStream is); /** * @return the mimeType Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/RawType.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/RawType.java 2007-12-07 16:39:19 UTC (rev 56) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/RawType.java 2007-12-10 15:18:35 UTC (rev 57) @@ -1,6 +1,8 @@ package fr.cemagref.simexplorer.is.storage.attachment.type; import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; /** * Raw content type @@ -20,9 +22,9 @@ } @Override - public InputStream renderToText(InputStream is) { + public Reader renderToText(InputStream is) { // No parsing - return is; + return new InputStreamReader(is); } }
participants (1)
-
glandais@users.labs.libre-entreprise.org