class FilenameSwitch extends AbstractPipe {

	@Override
	public PipeRunResult doPipe(Message message, IPipeLineSession session) throws PipeRunException {
		String forward="";
		String sInput;
		try {
			sInput = message.asString();
		} catch (IOException e) {
			throw new PipeRunException(this, getLogPrefix(session)+"cannot open stream", e);
		}
	    PipeForward pipeForward=null;

		int slashPos=sInput.lastIndexOf('/');
		if (slashPos>0) {
			sInput=sInput.substring(slashPos+1);
		}
		slashPos=sInput.lastIndexOf('\\');
		if (slashPos>0) {
			sInput=sInput.substring(slashPos+1);
		}
		forward=sInput;
		if (isToLowercase()) {
			forward=forward.toLowerCase();
		}
		log.debug(getLogPrefix(session)+ "determined forward ["+forward+"]");

		if (findForward(forward) != null) 
			pipeForward=findForward(forward);
		else {
			log.info(getLogPrefix(session)+"determined forward ["+forward+"], which is not defined. Will use ["+getNotFoundForwardName()+"] instead");
			pipeForward=findForward(getNotFoundForwardName());
		}
		
		if (pipeForward==null) {
			  throw new PipeRunException (this, getLogPrefix(session)+"cannot find forward or pipe named ["+forward+"]");
		}
		return new PipeRunResult(pipeForward, message);
	}

}