summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMelek Zribi2013-09-18 12:51:23 (EDT)
committer Stephan Born2013-10-23 08:00:25 (EDT)
commita8560a4cc9762af85296fe5766dc0a1911a4386d (patch)
treee0521a49f21556ca17c025334f81cb1308059fdd
parentf4d70af7ec57d551ff6b8bcf713faf6c55da173b (diff)
downloadorg.eclipse.stardust.engine-a8560a4cc9762af85296fe5766dc0a1911a4386d.zip
org.eclipse.stardust.engine-a8560a4cc9762af85296fe5766dc0a1911a4386d.tar.gz
org.eclipse.stardust.engine-a8560a4cc9762af85296fe5766dc0a1911a4386d.tar.bz2
Jira-ID: CRNT-30512
Camel Trigger(File Trigger): TIF file should be opened in TIFF viewer / (CRNT-30511 Unable to Parse if input type is PDF) git-svn-id: https://svn.csa.sungard.com/repos/ipp2/product/trunk/stardust/engine@67380 8100b5e0-4d52-466c-ae9c-bdeccbdeaf6b Signed-off-by: Melek Zribi <Melek.Zribi@sungard.com>
-rw-r--r--stardust-engine-camel/src/main/java/org/eclipse/stardust/engine/extensions/camel/converter/DocumentDataConverter.java323
1 files changed, 220 insertions, 103 deletions
diff --git a/stardust-engine-camel/src/main/java/org/eclipse/stardust/engine/extensions/camel/converter/DocumentDataConverter.java b/stardust-engine-camel/src/main/java/org/eclipse/stardust/engine/extensions/camel/converter/DocumentDataConverter.java
index adba0a7..5274028 100644
--- a/stardust-engine-camel/src/main/java/org/eclipse/stardust/engine/extensions/camel/converter/DocumentDataConverter.java
+++ b/stardust-engine-camel/src/main/java/org/eclipse/stardust/engine/extensions/camel/converter/DocumentDataConverter.java
@@ -11,124 +11,241 @@ import org.apache.camel.Converter;
import org.apache.camel.Exchange;
import org.apache.camel.Handler;
import org.apache.camel.component.file.GenericFile;
+import org.apache.commons.lang.StringUtils;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
+import org.eclipse.stardust.engine.api.runtime.DmsUtils;
import org.eclipse.stardust.engine.api.runtime.Document;
import org.eclipse.stardust.engine.extensions.camel.CamelConstants.MessageProperty;
import org.eclipse.stardust.engine.extensions.camel.util.DmsFileArchiver;
import org.eclipse.stardust.engine.extensions.camel.util.client.ClientEnvironment;
+
@Converter
-public class DocumentDataConverter implements DataConverter
-{
- private static final Logger logger = LogManager.getLogger(DocumentDataConverter.class);
+public class DocumentDataConverter implements DataConverter {
+ private static final Logger logger = LogManager
+ .getLogger(DocumentDataConverter.class);
+ DmsUtils dmsUtils;
+ private String fromEndpoint;
+ private String targetType;
+
+ /**
+ * @return fromEndpoint
+ */
+ public String getFromEndpoint() {
+ return fromEndpoint;
+ }
- private String fromEndpoint;
- private String targetType;
+ /**
+ * @param fromEndpoint
+ */
+ public void setFromEndpoint(String fromEndpoint) {
+ this.fromEndpoint = fromEndpoint;
+ }
- /**
- * @return fromEndpoint
- */
- public String getFromEndpoint()
- {
- return fromEndpoint;
- }
+ /**
+ * @return targetType
+ */
+ public String getTargetType() {
+ return targetType;
+ }
- /**
- * @param fromEndpoint
- */
- public void setFromEndpoint(String fromEndpoint)
- {
- this.fromEndpoint = fromEndpoint;
- }
+ /**
+ * @param targetType
+ */
+ public void setTargetType(String targetType) {
+ this.targetType = targetType;
+ }
- /**
- * @return targetType
- */
- public String getTargetType()
- {
- return targetType;
- }
+ /**
+ * create a document from a generic file
+ *
+ * @param file
+ * input file
+ * @param exchange
+ * Camel exchange
+ * @return document from the input file
+ * @throws IOException
+ * @throws MessagingException
+ */
+ @Converter
+ @Handler
+ public Document genericFileToDocument(Object messageContent,
+ Exchange exchange) throws IOException, MessagingException {
+ byte[] jcrDocumentContent = null;
+ if (exchange != null) {
+ if (messageContent instanceof GenericFile<?>) {
+ ((GenericFile) messageContent).getBinding().loadContent(
+ exchange, ((GenericFile) messageContent));
+ jcrDocumentContent = exchange
+ .getContext()
+ .getTypeConverter()
+ .convertTo(byte[].class, exchange,
+ //.convertTo(String.class, exchange,
+ ((GenericFile) messageContent).getBody());
+ logger.debug("*** FileLength = " +((GenericFile) messageContent).getFileLength());
+ } else if (messageContent instanceof String) {
+ jcrDocumentContent = (byte[]) messageContent;
+ }
+ DmsFileArchiver dmsFileArchiver = new DmsFileArchiver(
+ ClientEnvironment.getCurrentServiceFactory());
+ dmsFileArchiver.setRootFolderPath("/");
+ String folder = "documents";
+ long scopeProcessInstanceOID = -1;
+ if (exchange.getIn().getHeader("ippProcessInstanceOid") != null) {
+ scopeProcessInstanceOID = (Long) exchange.getIn().getHeader(
+ "ippProcessInstanceOid");
+ }
+ logger.debug("scopeProcessInstanceOID = "+ scopeProcessInstanceOID);
+ Date scopeProcessInstanceStartTime = (Date) exchange.getIn().getHeader("CamelFileLastModified");
+ if ((scopeProcessInstanceStartTime != null)
+ && (!("-1".equals(Long.toString(scopeProcessInstanceOID))))) {
+ folder = dmsUtils.composeDefaultPath(scopeProcessInstanceOID,scopeProcessInstanceStartTime);
+ }
+
+ String path = "";
+ if (exchange.getIn().getHeader(MessageProperty.PROCESS_ID,
+ String.class) != null)
+ path += exchange.getIn().getHeader(MessageProperty.PROCESS_ID,
+ String.class)
+ + "_";
+ if (exchange.getIn().getHeader("CamelFileNameOnly") != null)
+ path += exchange.getIn().getHeader("CamelFileNameOnly") + "_";
+ else {
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd-hhmmsss");
+ if (exchange.getIn().getHeader("breadcrumbId") != null)
+ path += ((String) exchange.getIn()
+ .getHeader("breadcrumbId")).replaceAll("-", "_")
+ .replaceAll(":", "_")
+ + "_" + df.format(new Date());
+ }
+ MimeMultipart mimeMultipart = null;
+ if (jcrDocumentContent == null) {
+ mimeMultipart = (MimeMultipart) exchange.getIn().getBody();
+ if (mimeMultipart != null) {
+ try {
+ jcrDocumentContent = (byte[]) mimeMultipart
+ .getBodyPart(1).getContent();
+ } catch (Exception e) {
+ e.printStackTrace();
+ jcrDocumentContent = "".getBytes();
+ }
+ } else {
+ jcrDocumentContent ="".getBytes();
+ }
+ }
+ Document newDocument = dmsFileArchiver.archiveFile(
+ jcrDocumentContent, path, folder);
+ newDocument.setProperties(null);
+ String fileName = (String) exchange.getIn().getHeader("CamelFileNameOnly");
+ newDocument.setContentType(getDocumentType(fileName));
- /**
- * @param targetType
- */
- public void setTargetType(String targetType)
- {
- this.targetType = targetType;
- }
+ return newDocument;
- /**
- * create a document from a generic file
- *
- * @param file
- * input file
- * @param exchange
- * Camel exchange
- * @return document from the input file
- * @throws IOException
- * @throws MessagingException
- */
- @Converter
- @Handler
- public Document genericFileToDocument(Object messageContent, Exchange exchange) throws IOException
- {
- String jcrDocumentContent = null;
- if (exchange != null)
- {
- if (messageContent instanceof GenericFile< ? >)
- {
- ((GenericFile) messageContent).getBinding().loadContent(exchange, ((GenericFile) messageContent));
- jcrDocumentContent = exchange.getContext().getTypeConverter()
- .convertTo(String.class, exchange, ((GenericFile) messageContent).getBody());
- }
- else if (messageContent instanceof String)
- {
- jcrDocumentContent = (String) messageContent;
- }
- DmsFileArchiver dmsFileArchiver = new DmsFileArchiver(ClientEnvironment.getCurrentServiceFactory());
- dmsFileArchiver.setRootFolderPath("/");
- String folder = "documents";
+ } else {
+ return null;
+ }
+ }
+
+ private String getDocumentType(String filename){
+
+ String extension = StringUtils.substringAfterLast(filename, ".");
+
+ if ("pdf".equalsIgnoreCase(extension)) //PDF
+ return "application/pdf";
+
+ if ("tiff".equalsIgnoreCase(extension) || "tif".equalsIgnoreCase(extension)) //TIFF
+ return "image/tiff";
+
+ if ("xml".equalsIgnoreCase(extension) || "xpdl".equalsIgnoreCase(extension)) //XML
+ return "text/xml";
+
+ if ("xhtml".equalsIgnoreCase(extension) || "htm".equalsIgnoreCase(extension)) //XHTML
+ return "text/xhtml";
+
+ if ("html".equalsIgnoreCase(extension) || "htm".equalsIgnoreCase(extension))//HTML
+ return "text/html";
+
+ if ("jpg".equalsIgnoreCase(extension) || "jpeg".equalsIgnoreCase(extension)) //JPG
+ return "image/jpeg";
+
+ if ("jpg".equalsIgnoreCase(extension) || "jpeg".equalsIgnoreCase(extension)) //PJPG
+ return "image/jpeg";
- String path = "";
- if (exchange.getIn().getHeader(MessageProperty.PROCESS_ID, String.class) != null)
- path += exchange.getIn().getHeader(MessageProperty.PROCESS_ID, String.class) + "_";
- if (exchange.getIn().getHeader("CamelFileNameOnly") != null)
- path += exchange.getIn().getHeader("CamelFileNameOnly") + "_";
- else
- {
- SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd-hhmmsss");
- if (exchange.getIn().getHeader("breadcrumbId") != null)
- path += ((String) exchange.getIn().getHeader("breadcrumbId")).replaceAll("-", "_").replaceAll(":", "_")
- + "_"+df.format(new Date());
- }
+ if ("jpg".equalsIgnoreCase(extension))//XPNG
+ return "image/x-png";
- MimeMultipart mimeMultipart = null;
- if (jcrDocumentContent == null){
- mimeMultipart = (MimeMultipart) exchange.getIn().getBody();
- if (mimeMultipart != null){
- try {
- jcrDocumentContent = (String) mimeMultipart.getBodyPart(1).getContent();
- } catch (Exception e) {
- e.printStackTrace();
- jcrDocumentContent = "";
- }
- }
- else {
- jcrDocumentContent = "";
- }
- }
- logger.debug("*** jcrDocumentContent = "+jcrDocumentContent);
- Document newDocument = dmsFileArchiver.archiveFile(jcrDocumentContent.getBytes(), path, folder);
- newDocument.setProperties(null);
-
- // }
- return newDocument;
+ if ("gif".equalsIgnoreCase(extension))//GIF
+ return "image/gif";
+
+ if ("rtf".equalsIgnoreCase(extension))//RTF
+ return "text/rtf";
+
+ if ("doc".equalsIgnoreCase(extension))//DOC
+ return "application/msword";
+
+ if ("mov".equalsIgnoreCase(extension))//MOV
+ return "video/quicktime";
+
+ if ("wmf".equalsIgnoreCase(extension))//WMF
+ return "video/x-ms-wmv";
+
+ if ("avi".equalsIgnoreCase(extension))//AVI
+ return "video/x-msvideo";
+
+ if ("swf".equalsIgnoreCase(extension))//SWF
+ return "application/x-shockwave-flash";
+
+ if ("wma".equalsIgnoreCase(extension))//WMA
+ return "audio/x-ms-wma";
+
+ if ("mp3".equalsIgnoreCase(extension))//MP3
+ return "audio/mpeg";
+
+ if ("zip".equalsIgnoreCase(extension))//ZIP
+ return "application/zip";
+
+ if ("txt".equalsIgnoreCase(extension))//TXT
+ return "text/plain";
+
+ if ("zip".equalsIgnoreCase(extension))//ZIP
+ return "application/zip";
+
+ if ("ppt".equalsIgnoreCase(extension))//PPT
+ return "application/vnd.ms-powerpoint";
+
+ if ("xls".equalsIgnoreCase(extension))//XLS
+ return "application/vnd.ms-excel";
+
+ if ("png".equalsIgnoreCase(extension))//PNG
+ return "image/png";
+
+ if ("".equalsIgnoreCase(extension))//DEFAULT
+ return "application/octet-stream";
+
+ if ("docx".equalsIgnoreCase(extension))//MS2007_DOC
+ return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
+
+ if ("xlsx".equalsIgnoreCase(extension))//MS2007_XLS
+ return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
+
+ if ("pptx".equalsIgnoreCase(extension))//MS2007_PPT
+ return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
+
+ if ("rptdesign".equalsIgnoreCase(extension))//RPT_DESIGN
+ return "application/rptdesign";
+
+ if ("css".equalsIgnoreCase(extension))//CSS
+ return "text/css";
+
+ if ("mp3".equalsIgnoreCase(extension))//X_MPEG
+ return "audio/x-mpeg";
+
+ if ("csv".equalsIgnoreCase(extension))//CSV
+ return "text/csv";
+
+ return "text/plain";
+
+ }
- }
- else
- {
- return null;
- }
- }
}