/*
   Copyright 2013 Nationale-Nederlanden

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
package nl.nn.adapterframework.pipes;

import nl.nn.adapterframework.configuration.ConfigurationException;
import nl.nn.adapterframework.core.IPipeLineSession;
import nl.nn.adapterframework.core.PipeRunException;
import nl.nn.adapterframework.core.PipeRunResult;
import nl.nn.adapterframework.util.FileHandler;


/**
 * <p>See {@link FileHandler}</p>
 * 
 * <p><b>Exits:</b>
 * <table border="1">
 * <tr><th>state</th><th>condition</th></tr>
 * <tr><td>"success"</td><td>default</td></tr>
 * <tr><td><i>{@link #setForwardName(String) forwardName}</i></td><td>if specified</td></tr>
 * </table>
 * </p>
 * 
 * @author J. Dekker
 * @author Jaco de Groot (***@dynasol.nl)
 *
 */
public class FilePipe extends FixedForwardPipe {
	FileHandler fileHandler;

	public FilePipe() {
		fileHandler = new FileHandler();
	}
	
	public void configure() throws ConfigurationException {
		super.configure();
		fileHandler.configure();
	}
	
	/** 
* @see nl.nn.adapterframework.core.IPipe#doPipe(Object, IPipeLineSession)
	 */
	public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
		try {
			return new PipeRunResult(getForward(), fileHandler.handle(input, session, getParameterList()));
		}
		catch(Exception e) {
			throw new PipeRunException(this, getLogPrefix(session)+"Error while executing file action(s)", e); 
		}
	}

	public void setCharset(String charset) {
		fileHandler.setCharset(charset);
	}

	public void setOutputType(String outputType) {
		fileHandler.setOutputType(outputType);
	}

	public void setActions(String actions) {
		fileHandler.setActions(actions);
	}

	public void setFileSource(String fileSource) {
		fileHandler.setFileSource(fileSource);
	}

	public void setDirectory(String directory) {
		fileHandler.setDirectory(directory);
	}

	public void setWriteSuffix(String suffix) {
		fileHandler.setWriteSuffix(suffix);
	}

	public void setFileName(String filename) {
		fileHandler.setFileName(filename);
	}

	public void setFileNameSessionKey(String filenameSessionKey) {
		fileHandler.setFileNameSessionKey(filenameSessionKey);
	}

	public void setCreateDirectory(boolean b) {
		fileHandler.setCreateDirectory(b);
	}

	public void setWriteLineSeparator(boolean b) {
		fileHandler.setWriteLineSeparator(b);
	}

	public void setTestCanWrite(boolean b) {
		fileHandler.setTestCanWrite(b);
	}

	public void setSkipBOM(boolean b) {
		fileHandler.setSkipBOM(b);
	}

	public void setDeleteEmptyDirectory(boolean b) {
		fileHandler.setDeleteEmptyDirectory(b);
	}

	public void setStreamResultToServlet(boolean b) {
		fileHandler.setStreamResultToServlet(b);
	}
}

@@ -13,16 +13,28 @@
 ght 2013
+, 2015, 2018
  Nationa
@@ -48,16 +48,16 @@
 rlanden%0A
-
 %0A   Lice
@@ -1181,24 +1181,86 @@
 d%3C/td%3E%3C/tr%3E%0A
+ * %3Ctr%3E%3Ctd%3E%22exception%22%3C/td%3E%3Ctd%3Eif an error occurred%3C/td%3E%3C/tr%3E%0A
  * %3C/table%3E%0A
@@ -1902,16 +1902,135 @@
 on e) %7B%0A
+%09%09%09if (findForward(%22exception%22) != null) %7B%0A%09%09%09%09return new PipeRunResult(findForward(%22exception%22), input);%0A%09%09%09%7D else %7B%0A%09
 %09%09%09throw
@@ -2122,17 +2122,21 @@
 s)%22, e);
- 
+%0A%09%09%09%7D
 %0A%09%09%7D%0A%09%7D%0A
@@ -3391,10 +3391,9 @@
 (b);%0A%09%7D%0A
+
 %7D
-%0A

Add exitState exception to FilePipe