Author: kmorin Date: 2014-10-10 17:19:24 +0200 (Fri, 10 Oct 2014) New Revision: 676 Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/676 Log: - refs #5940 Page web de d?\195?\169tail d'un ?\195?\169l?\195?\169ment archiv?\195?\169 Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIHandler.java trunk/faxtomail-ui-web/pom.xml trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/DemandDetailAction.java trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/demand-detail.jsp trunk/pom.xml Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIHandler.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIHandler.java 2014-10-10 09:40:02 UTC (rev 675) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIHandler.java 2014-10-10 15:19:24 UTC (rev 676) @@ -26,16 +26,12 @@ import static org.nuiton.i18n.I18n.t; -import java.awt.Component; -import java.awt.Cursor; -import java.awt.Dimension; -import java.awt.Image; -import java.awt.Insets; -import java.awt.Rectangle; +import java.awt.*; import java.awt.event.ContainerEvent; import java.awt.event.ContainerListener; import java.awt.event.MouseEvent; import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; import java.awt.image.RenderedImage; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -53,6 +49,7 @@ import java.util.Date; import java.util.List; +import javax.imageio.ImageIO; import javax.media.jai.PlanarImage; import javax.swing.JComponent; import javax.swing.JPanel; @@ -377,10 +374,10 @@ int width = (int) (zoom * rect.width); int height = (int) (zoom * rect.height); Image image = page.getImage(width, height, // width & height - rect, // clip rect - null, // null for the ImageObserver - true, // fill background with white - true // block until drawing is done + rect, // clip rect + null, // null for the ImageObserver + true, // fill background with white + true // block until drawing is done ); JPanel container = getUI().getContainer(); Modified: trunk/faxtomail-ui-web/pom.xml =================================================================== --- trunk/faxtomail-ui-web/pom.xml 2014-10-10 09:40:02 UTC (rev 675) +++ trunk/faxtomail-ui-web/pom.xml 2014-10-10 15:19:24 UTC (rev 676) @@ -303,6 +303,12 @@ <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> + + <dependency> + <groupId>org.jsoup</groupId> + <artifactId>jsoup</artifactId> + </dependency> + </dependencies> <build> Modified: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/DemandDetailAction.java =================================================================== --- trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/DemandDetailAction.java 2014-10-10 09:40:02 UTC (rev 675) +++ trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/DemandDetailAction.java 2014-10-10 15:19:24 UTC (rev 676) @@ -21,6 +21,7 @@ import com.google.common.collect.Collections2; import com.google.common.collect.Lists; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; @@ -30,6 +31,9 @@ import org.apache.struts2.convention.annotation.InterceptorRef; import org.apache.struts2.convention.annotation.InterceptorRefs; import org.apache.struts2.convention.annotation.Result; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; import org.nuiton.decorator.Decorator; import org.nuiton.topia.persistence.TopiaNoResultException; @@ -47,6 +51,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; @@ -76,6 +81,7 @@ protected String id; protected boolean original; + protected int index; protected Email demand; @@ -132,6 +138,36 @@ return SUCCESS; } + @Action(value = "reply-attachment-download", + results = {@Result(name = "success", + type = "stream", + params = { + "contentType", "${contentType}", + "inputName", "attachmentFileInputStream", + "contentDisposition", "attachment;filename=\"${fileName}\"", + "bufferSize", "1024" + }) + }) + public String dlReplyAttachment() throws Exception { + ReplyContent replyContent = emailService.getReplyContent(id); + + Message message = new MimeMessage(null, new ByteArrayInputStream(replyContent.getSource())); + EmailUIModel replyModel = new EmailUIModel(); + if (message.isMimeType("multipart/*")) { + decomposeMultipartEmail(message, replyModel); + } else { + String content = IOUtils.toString(message.getInputStream()); + replyModel.setPlainContent(content); + } + + AttachmentFile attachmentFile = replyModel.getAttachments().get(index); + File file = attachmentFile.getFile(); + fileName = attachmentFile.getFilename(); + contentType = Files.probeContentType(file.toPath()); + attachmentFileInputStream = new FileInputStream(file); + return SUCCESS; + } + public String getId() { return id; } @@ -144,6 +180,10 @@ this.original = original; } + public void setIndex(int index) { + this.index = index; + } + public Email getDemand() { return demand; } @@ -184,6 +224,7 @@ Message message = new MimeMessage(null, new ByteArrayInputStream(replyContent.getSource())); EmailUIModel replyModel = new EmailUIModel(); + replyModel.setId(reply.getTopiaId()); replyModel.setSubject(message.getSubject()); String toRecipient = message.getRecipients(MimeMessage.RecipientType.TO)[0].toString(); @@ -357,6 +398,7 @@ public static class EmailUIModel { + protected String id; protected String subject; protected String sender; protected String toRecipients; @@ -365,6 +407,14 @@ protected String content; protected List<AttachmentFile> attachments = new ArrayList<>(); + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + public String getSubject() { return subject; } @@ -412,13 +462,20 @@ } public void setHtmlContent(String htmlContent) { - this.content = htmlContent; + Document document = Jsoup.parse(htmlContent); + Element body = document.body(); + Element head = document.head(); + this.content = head.html() + body.outerHtml().replaceAll("<body", "<div").replaceAll("</body>", "</div>"); } public String getContent() { return content; } + public List<AttachmentFile> getAttachments() { + return attachments; + } + public void addAttachmentFile(AttachmentFile attachmentFile) { attachments.add(attachmentFile); } Modified: trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/demand-detail.jsp =================================================================== --- trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/demand-detail.jsp 2014-10-10 09:40:02 UTC (rev 675) +++ trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/demand-detail.jsp 2014-10-10 15:19:24 UTC (rev 676) @@ -134,7 +134,7 @@ <s:else> <li><span> <span class="fa fa-eye float-right" title="Élément courant"></span> - <span class="margin-right-1-icon"><s:property value="#email.title"/></span> + <span class="margin-right-1-icon"><s:property value="demand.title"/></span> </span></li> </s:else> </ul> @@ -221,7 +221,7 @@ <dt>Sujet</dt> <dd><s:property value="emailUIModel.subject" /></dd> <dt>Contenu de l'email reçu</dt> - <dd><s:property value="emailUIModel.content" escapeHtml="false"/></dd> + <dd class="well well-sm"><s:property value="emailUIModel.content" escapeHtml="false"/></dd> <dt>Message</dt> <dd><s:text name="%{decorate(demand.comment)}" /> </dl> @@ -254,15 +254,15 @@ <dt>Sujet</dt> <dd>{{currentReply.subject}}</dd> </dl> - <hr/> - <p ng-bind-html="currentReply.content"></p> - <hr/> - Pièces jointes - <ul> - <li ng-repeat="attachment in currentReply.attachments"> - {{attachment.filename}} - </li> - </ul> + <p class="well" ng-bind-html="currentReply.content"></p> + <div> + Pièces jointes + <ul> + <li ng-repeat="attachment in currentReply.attachments"> + <a href="reply-attachment-download.action?id={{currentReply.id}}&index={{$index}}" title="Ouvrir la pive jointe">{{attachment.filename}}</a> + </li> + </ul> + </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button> Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2014-10-10 09:40:02 UTC (rev 675) +++ trunk/pom.xml 2014-10-10 15:19:24 UTC (rev 676) @@ -635,6 +635,13 @@ <artifactId>flying-saucer-pdf-itext5</artifactId> <version>9.0.6</version> </dependency> + + <dependency> + <groupId>org.jsoup</groupId> + <artifactId>jsoup</artifactId> + <version>1.8.1</version> + </dependency> + </dependencies> </dependencyManagement>