Author: glandais Date: 2008-03-12 17:03:51 +0000 (Wed, 12 Mar 2008) New Revision: 1317 Modified: trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDownload.java trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementPageDetail.java trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/tools/WebEntityVisitor.java Log: Download files (attachments) Modified: trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDownload.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDownload.java 2008-03-11 00:25:18 UTC (rev 1316) +++ trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDownload.java 2008-03-12 17:03:51 UTC (rev 1317) @@ -87,38 +87,8 @@ return response; } - /** - * On download file. - * - * @param context the context - * - * @return the object - * @throws SimExplorerException - */ - public Object onDownloadFile(String context) throws SimExplorerException { - StreamResponse response = null; + - StringTokenizer st = new StringTokenizer(context, ","); - String uuid = st.nextToken(); - String version = st.nextToken(); - String attachmentUniqueId = st.nextToken(); - - LoggableElement loggableElement = RemoteStorageService.getStorageService().getLoggableElement(getToken(), uuid, - version); - List<Attachment> attachments = loggableElement.getAttachments(); - for (Attachment attachment : attachments) { - if (attachment.getUniqueId().equals(attachmentUniqueId)) { - InputStream stream = RemoteStorageService.getStorageService().retrieveElementData(getToken(), uuid, - version, attachment); - - response = new AttachmentStreamResponse(stream, attachment.getFileName()); - return response; - } - } - - return response; - } - /** * Headers of tree grid. * Modified: trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementPageDetail.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementPageDetail.java 2008-03-11 00:25:18 UTC (rev 1316) +++ trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementPageDetail.java 2008-03-12 17:03:51 UTC (rev 1317) @@ -17,19 +17,26 @@ * ##% */ package fr.cemagref.simexplorer.is.ui.web.pages; +import static org.codelutin.i18n.I18n._; + +import java.io.InputStream; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; import org.apache.tapestry.Link; +import org.apache.tapestry.StreamResponse; import org.apache.tapestry.annotations.InjectPage; import org.codelutin.tapestry.beans.TreeNode; import fr.cemagref.simexplorer.is.entities.attachment.Attachment; import fr.cemagref.simexplorer.is.entities.data.Descriptor; +import fr.cemagref.simexplorer.is.entities.data.LoggableElement; import fr.cemagref.simexplorer.is.entities.metadata.MetaData; import fr.cemagref.simexplorer.is.exceptions.SimExplorerException; +import fr.cemagref.simexplorer.is.service.remote.RemoteStorageService; +import fr.cemagref.simexplorer.is.ui.web.tools.AttachmentStreamResponse; /** * The Class ElementPageDetail. @@ -153,6 +160,38 @@ } /** + * On download file. + * + * @param context the context + * + * @return the object + * @throws SimExplorerException + */ + public Object onDownloadFile(String context) throws SimExplorerException { + StreamResponse response = null; + + StringTokenizer st = new StringTokenizer(context, ","); + String uuid = st.nextToken(); + String version = st.nextToken(); + String attachmentUniqueId = st.nextToken(); + + LoggableElement loggableElement = RemoteStorageService.getStorageService().getLoggableElement(getToken(), uuid, + version); + List<Attachment> attachments = loggableElement.getAttachments(); + for (Attachment attachment : attachments) { + if (attachment.getUniqueId().equals(attachmentUniqueId)) { + InputStream stream = RemoteStorageService.getStorageService().retrieveElementData(getToken(), uuid, + version, attachment); + + response = new AttachmentStreamResponse(stream, attachment.getFileName()); + return response; + } + } + + return response; + } + + /** * Generate string. * * @param actionCaption the action caption @@ -311,7 +350,7 @@ for (Attachment attachment : attachments) { StringBuffer description = new StringBuffer(); if (attachment.getContentType() != null) { - description.append(attachment.getContentType().getDescription()).append(" - "); + description.append(_(attachment.getContentType().getDescription())).append(" - "); } if (attachment.getContentType() != null) { description.append("MD5 : ").append(attachment.getDataHash()); Modified: trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/tools/WebEntityVisitor.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/tools/WebEntityVisitor.java 2008-03-11 00:25:18 UTC (rev 1316) +++ trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/tools/WebEntityVisitor.java 2008-03-12 17:03:51 UTC (rev 1317) @@ -32,6 +32,7 @@ import fr.cemagref.simexplorer.is.entities.EntityVisitorTreeNode; import fr.cemagref.simexplorer.is.entities.EntityHelper.Action; import fr.cemagref.simexplorer.is.entities.EntityHelper.ActionAvailabilty; +import fr.cemagref.simexplorer.is.entities.attachment.Attachment; import fr.cemagref.simexplorer.is.entities.data.LoggableElement; import fr.cemagref.simexplorer.is.entities.metadata.MetaData; @@ -41,6 +42,8 @@ private Messages messages; + private LoggableElement lastLE; + public WebEntityVisitor(ComponentResources resources, Messages messages) { super(); this.resources = resources; @@ -103,25 +106,38 @@ } } + StringBuffer sb = new StringBuffer(); + if (v instanceof LoggableElement) { - LoggableElement le = (LoggableElement) v; - StringBuffer sb = new StringBuffer(); + LoggableElement le; + le = (LoggableElement) v; + lastLE = le; Action[] actions = EntityHelper.Action.values(); for (Action action : actions) { if ((action.getAvailabilty() == ActionAvailabilty.WEB || action.getAvailabilty() == ActionAvailabilty.BOTH) - && action.accept(le)) { + && action.accept(v)) { sb.append("<br>"); sb.append(generateString(messages.get("simexplorer.ui.web." + action.getActionName() + ".action"), action.getActionName(), le.getMetaData())); } } - if (sb.length() > 0) { - asArray[3] = sb.substring(4).toString(); - } } + if (v instanceof Attachment) { + LoggableElement le; + le = lastLE; + String context = le.getMetaData().getUuid() + "," + le.getMetaData().getVersion() + "," + + ((Attachment) v).getUniqueId(); + sb.append("<br>"); + sb.append(generateString(messages.get("simexplorer.ui.web.export.action"), "downloadFile", context)); + } + + if (sb.length() > 0) { + asArray[3] = sb.substring(4).toString(); + } + treeNode.setColumns(asArray); if (getCurrentParent() != null) { @@ -130,5 +146,4 @@ return treeNode; } - }