[jboss-svn-commits] JBL Code SVN: r10934 - labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/notification.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Apr 12 13:51:04 EDT 2007


Author: derek.adams
Date: 2007-04-12 13:51:04 -0400 (Thu, 12 Apr 2007)
New Revision: 10934

Modified:
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyFTP.java
Log:
Added ability to inject message property values into outgoing filename.

Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyFTP.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyFTP.java	2007-04-12 17:30:56 UTC (rev 10933)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyFTP.java	2007-04-12 17:51:04 UTC (rev 10934)
@@ -15,8 +15,8 @@
 import org.jboss.soa.esb.util.RemoteFileSystemFactory;
 
 /**
- * Sends a message to an outgoing FTP server. The notification-details property looks 
- * something like:
+ * Sends a message to an outgoing FTP server. The notification-details property
+ * looks something like:
  * 
  * <code>
  *		<NotificationList type="OK" xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd">
@@ -75,18 +75,62 @@
 	 * 
 	 * @return
 	 */
-	protected String getFileName() throws NotificationException {
+	protected String getFileName(Message message) throws NotificationException {
 		if (fileName == null) {
 			ConfigTree ftpConfig = getFtpConfig();
 			fileName = ftpConfig.getAttribute(ATTR_FILENAME);
 			if (StringUtils.isEmpty(fileName)) {
 				throw new NotificationException("NotifyFTP: Filename attribute is required.");
 			}
+			fileName = replaceArguments(fileName, message);
 		}
 		return fileName;
 	}
 
 	/**
+	 * Replaces any arguments in the form '{prop.name}' with corresponding
+	 * message property values.
+	 * 
+	 * @param value
+	 * @param message
+	 * @return
+	 */
+	protected String replaceArguments(String value, Message message) {
+		String current = value;
+		String replaced = replaceArgument(value, message);
+		while (!current.equals(replaced)) {
+			current = replaced;
+			replaced = replaceArgument(current, message);
+		}
+		return replaced;
+	}
+
+	/**
+	 * Look for arguments in the form '{prop.name}' and replace them with
+	 * corresponding message properties.
+	 * 
+	 * @param value
+	 * @param message
+	 * @return
+	 */
+	protected String replaceArgument(String value, Message message) {
+		int startIndex = value.indexOf('{');
+		if (startIndex == -1) {
+			return value;
+		}
+		int endIndex = value.indexOf('}');
+		if (endIndex == -1) {
+			return value;
+		}
+		String propName = value.substring(startIndex + 1, endIndex);
+		Object propValue = message.getProperties().getProperty(propName);
+		if (propValue == null) {
+			return value;
+		}
+		return value.substring(0, startIndex) + propValue + value.substring(endIndex + 1);
+	}
+
+	/**
 	 * Builds an FTP EPR from the configutation data.
 	 * 
 	 * @param config
@@ -120,7 +164,7 @@
 			IOUtils.write(message.getBody().getContents(), stream);
 			stream.close();
 			rfs = RemoteFileSystemFactory.getRemoteFileSystem(getFtpEpr(), true);
-			rfs.uploadFile(tmpFile, getFileName());
+			rfs.uploadFile(tmpFile, getFileName(message));
 		} catch (RemoteFileSystemException e) {
 			throw new NotificationException("Could not complete FTP notification", e);
 		} catch (IOException e) {




More information about the jboss-svn-commits mailing list