01: /*
02: *
03: * The DbUnit Database Testing Framework
04: * Copyright (C)2002-2004, DbUnit.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: *
20: */
21:
22: package org.dbunit.dataset.csv.handlers;
23:
24: import org.slf4j.Logger;
25: import org.slf4j.LoggerFactory;
26:
27: import org.dbunit.dataset.csv.IllegalInputCharacterException;
28:
29: public class EscapeHandler extends AbstractPipelineComponent {
30:
31: /**
32: * Logger for this class
33: */
34: private static final Logger logger = LoggerFactory
35: .getLogger(EscapeHandler.class);
36:
37: public static final char ESCAPE_CHAR = '\\';
38:
39: private EscapeHandler() {
40: }
41:
42: public static final PipelineComponent ACCEPT() {
43: logger.debug("ACCEPT() - start");
44:
45: return createPipelineComponent(new EscapeHandler(),
46: new ACCEPT());
47: }
48:
49: // @todo: make sense?
50: public static final PipelineComponent IGNORE() {
51: logger.debug("IGNORE() - start");
52:
53: return createPipelineComponent(new EscapeHandler(),
54: new IGNORE());
55: }
56:
57: public static final PipelineComponent ESCAPE() {
58: logger.debug("ESCAPE() - start");
59:
60: return createPipelineComponent(new EscapeHandler(),
61: new ESCAPE());
62: }
63:
64: public boolean canHandle(char c)
65: throws IllegalInputCharacterException {
66: logger.debug("canHandle(c=" + c + ") - start");
67:
68: if (c == ESCAPE_CHAR) {
69: return true;
70: }
71: return false;
72: }
73:
74: static private class ESCAPE extends Helper {
75:
76: /**
77: * Logger for this class
78: */
79: private static final Logger logger = LoggerFactory
80: .getLogger(ESCAPE.class);
81:
82: public void helpWith(char c) {
83: logger.debug("helpWith(c=" + c + ") - start");
84:
85: getHandler().getPipeline().putFront(
86: EnforceHandler.ENFORCE(new PipelineComponent[] {
87: QuoteHandler.ACCEPT(),
88: EscapeHandler.ACCEPT() }));
89: // ignore the char
90: }
91: }
92:
93: }
|