org.ow2.petals.bc.filetransfer.util
Class FileTransferUtils

java.lang.Object
  extended by org.ow2.petals.bc.filetransfer.util.FileTransferUtils

public class FileTransferUtils
extends java.lang.Object

Author:
Roland NAUDIN - EBM WebSourcing

Constructor Summary
FileTransferUtils()
           
 
Method Summary
static java.lang.String addDateToFileName(java.lang.String filename)
          Add the current time as suffix of the filename
static void addFileAsAttachment(java.io.File file, java.lang.String filename, javax.jbi.messaging.NormalizedMessage message)
          Send the file as an attachment
static ConsumeConfiguration buildConsumeConfiguration(org.ow2.petals.component.framework.api.configuration.ConfigurationExtensions extensions)
          Build the configuration for consume service-unit.
static boolean checkAccess(java.io.File file)
          check if the file can be read
static java.lang.String checkTransferModeInBaseMsg(java.lang.String baseMsg)
          Extract the transfer mode variable in the base message.
static java.lang.String checkTransferModeInSU(java.lang.String suTransferMode)
          Extract the transfer mode described in the jbi.xml of the service unit.
static void copyFileToContent(java.io.File file, javax.jbi.messaging.NormalizedMessage message)
          Send the file as a Source
static org.w3c.dom.Document createMessageOnBaseMsg(java.io.File processedFile, java.lang.String fileName, java.lang.String baseMsg, java.lang.String transferMode)
          Create message based on the xml structure define by the base-msg parameter
static org.w3c.dom.Document createMessageOnDefaultMsg(java.io.File processedFile, java.lang.String fileName, java.lang.String transferMode)
          Create message based on default message structure.
static java.lang.String evaluateFilePath(java.lang.String filePath)
          Evaluate a file path to resolve environment variables (place holders).
static java.lang.String extractFilePattern(org.ow2.petals.component.framework.api.message.Exchange exchange)
          extract in the exchange request the filepattern to use
static org.w3c.dom.Document generateMTOMListResponse(java.util.List<java.lang.String> names, javax.xml.namespace.QName operation)
          Generate a MTOM response structure for a list of files.
static org.w3c.dom.Document generateMTOMResponse(java.lang.String name, javax.xml.namespace.QName operation)
          Generate a MTOM response structure for a single file.
static java.io.File getBackupDirectory(org.ow2.petals.component.framework.api.configuration.ConfigurationExtensions extensions)
          Return the backup directory, null if it is not configured.
static java.io.File getFolderPath(org.ow2.petals.component.framework.api.configuration.ConfigurationExtensions extensions)
          Return the workspace directory
static java.lang.String getValidMepMessageForOperation(java.lang.String operation, org.ow2.petals.component.framework.api.Message.MEPConstants... mep)
          Build a message to indicate the mep available for this operation.
static java.io.File[] listFiles(java.io.File readDir, java.lang.String filePattern)
          return the files contained in the READ DIRECTORY set in the extensions, using the given filePattern
static java.io.File moveFile(java.io.File file, org.ow2.petals.component.framework.api.configuration.ConfigurationExtensions extensions)
          move file to the backup directory specified in the SU
if no backup directory if set, move to the Temp directory.
static void setIOFaultOnExchange(org.ow2.petals.component.framework.api.message.Exchange exchange, java.lang.String ioMessage)
          TODO : create the fault from its WSDL description.
static void setMissingElementFaultOnExchange(org.ow2.petals.component.framework.api.message.Exchange exchange, java.lang.String missingElement)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileTransferUtils

public FileTransferUtils()
Method Detail

addDateToFileName

public static final java.lang.String addDateToFileName(java.lang.String filename)
Add the current time as suffix of the filename

Parameters:
filename -
Returns:

addFileAsAttachment

public static final void addFileAsAttachment(java.io.File file,
                                             java.lang.String filename,
                                             javax.jbi.messaging.NormalizedMessage message)
                                      throws javax.jbi.messaging.MessagingException,
                                             java.io.IOException
Send the file as an attachment

Parameters:
file -
Throws:
javax.jbi.messaging.MessagingException
java.io.IOException

buildConsumeConfiguration

public static ConsumeConfiguration buildConsumeConfiguration(org.ow2.petals.component.framework.api.configuration.ConfigurationExtensions extensions)
                                                      throws javax.jbi.messaging.MessagingException
Build the configuration for consume service-unit. For non-mandatory parameter, default value are set to parameter in this method.

Parameters:
extensions -
Returns:
ConsumeConfiguration instance
Throws:
javax.jbi.messaging.MessagingException

checkAccess

public static final boolean checkAccess(java.io.File file)
check if the file can be read

Parameters:
file -
Returns:
true if the file can be read

checkTransferModeInBaseMsg

public static java.lang.String checkTransferModeInBaseMsg(java.lang.String baseMsg)
                                                   throws javax.jbi.messaging.MessagingException
Extract the transfer mode variable in the base message. If no mode found an exception is throw. Default variable value are : $content | $attachment Override it to use custom behaviour.

Parameters:
baseMsg -
Returns:
Throws:
javax.jbi.messaging.MessagingException

checkTransferModeInSU

public static java.lang.String checkTransferModeInSU(java.lang.String suTransferMode)
                                              throws javax.jbi.messaging.MessagingException
Extract the transfer mode described in the jbi.xml of the service unit. If no mode found an exception is throw. Override it to use custom behaviour.

Parameters:
suTransferMode -
Returns:
Throws:
javax.jbi.messaging.MessagingException

copyFileToContent

public static final void copyFileToContent(java.io.File file,
                                           javax.jbi.messaging.NormalizedMessage message)
                                    throws java.io.IOException,
                                           javax.jbi.messaging.MessagingException
Send the file as a Source

Parameters:
file -
message -
Throws:
java.io.IOException
javax.jbi.messaging.MessagingException

createMessageOnBaseMsg

public static org.w3c.dom.Document createMessageOnBaseMsg(java.io.File processedFile,
                                                          java.lang.String fileName,
                                                          java.lang.String baseMsg,
                                                          java.lang.String transferMode)
                                                   throws java.io.IOException,
                                                          javax.jbi.messaging.MessagingException
Create message based on the xml structure define by the base-msg parameter

Parameters:
processedFile - The processed file.
fileName - When processing file as attachment,filename is the content id(MTOM)
baseMsg - The base msg.
transferMode - Represent the transfer mode to use.(attachment or content)
Returns:
The xml document build on the base message.
Throws:
java.io.IOException
org.xml.sax.SAXException
javax.jbi.messaging.MessagingException

createMessageOnDefaultMsg

public static org.w3c.dom.Document createMessageOnDefaultMsg(java.io.File processedFile,
                                                             java.lang.String fileName,
                                                             java.lang.String transferMode)
                                                      throws java.io.IOException,
                                                             javax.jbi.messaging.MessagingException
Create message based on default message structure.

Parameters:
processedFile - The processed file.
fileName - When processing file as attachment,filename is the content id(MTOM)
transferMode - Represent the transfer mode to use.(attachment or content)
Returns:
The xml document build on the default message.
Throws:
java.io.IOException
javax.jbi.messaging.MessagingException

evaluateFilePath

public static final java.lang.String evaluateFilePath(java.lang.String filePath)
Evaluate a file path to resolve environment variables (place holders).


extractFilePattern

public static java.lang.String extractFilePattern(org.ow2.petals.component.framework.api.message.Exchange exchange)
                                           throws javax.jbi.messaging.MessagingException,
                                                  java.io.FileNotFoundException
extract in the exchange request the filepattern to use

Parameters:
exchange -
Returns:
Throws:
javax.jbi.messaging.MessagingException - error while accessing the Exchange
java.io.FileNotFoundException - element not found in the XML request

generateMTOMListResponse

public static final org.w3c.dom.Document generateMTOMListResponse(java.util.List<java.lang.String> names,
                                                                  javax.xml.namespace.QName operation)
Generate a MTOM response structure for a list of files.

Parameters:
names -
operation -
Returns:

generateMTOMResponse

public static org.w3c.dom.Document generateMTOMResponse(java.lang.String name,
                                                        javax.xml.namespace.QName operation)
Generate a MTOM response structure for a single file.

Parameters:
names -
operation -
Returns:

getBackupDirectory

public static final java.io.File getBackupDirectory(org.ow2.petals.component.framework.api.configuration.ConfigurationExtensions extensions)
                                             throws java.io.IOException
Return the backup directory, null if it is not configured.

Returns:
the backup directory
Throws:
java.io.IOException

getFolderPath

public static final java.io.File getFolderPath(org.ow2.petals.component.framework.api.configuration.ConfigurationExtensions extensions)
                                        throws java.io.IOException
Return the workspace directory

Returns:
Throws:
PEtALSCFException - no working directory specified in the SU
java.io.IOException

getValidMepMessageForOperation

public static final java.lang.String getValidMepMessageForOperation(java.lang.String operation,
                                                                    org.ow2.petals.component.framework.api.Message.MEPConstants... mep)
Build a message to indicate the mep available for this operation. TODO : Move it in the cdk api.

Parameters:
operation -
mep -
Returns:

listFiles

public static final java.io.File[] listFiles(java.io.File readDir,
                                             java.lang.String filePattern)
return the files contained in the READ DIRECTORY set in the extensions, using the given filePattern

Parameters:
extensions -
Returns:

moveFile

public static final java.io.File moveFile(java.io.File file,
                                          org.ow2.petals.component.framework.api.configuration.ConfigurationExtensions extensions)
                                   throws java.io.IOException
move file to the backup directory specified in the SU
if no backup directory if set, move to the Temp directory.
The file need to be moved before being read

Parameters:
file -
Returns:
the moved file
Throws:
java.io.IOException

setIOFaultOnExchange

public static final void setIOFaultOnExchange(org.ow2.petals.component.framework.api.message.Exchange exchange,
                                              java.lang.String ioMessage)
                                       throws javax.jbi.messaging.MessagingException
TODO : create the fault from its WSDL description.

Parameters:
exchange -
ioMessage -
Throws:
javax.jbi.JBIException
javax.jbi.messaging.MessagingException

setMissingElementFaultOnExchange

public static final void setMissingElementFaultOnExchange(org.ow2.petals.component.framework.api.message.Exchange exchange,
                                                          java.lang.String missingElement)
                                                   throws javax.jbi.messaging.MessagingException
Throws:
javax.jbi.messaging.MessagingException


Copyright © 2005-2011 Petals Link (EBM Websourcing). All Rights Reserved.