001: /*
002: *
003: * The DbUnit Database Testing Framework
004: * Copyright (C)2002-2004, DbUnit.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: */
021:
022: package org.dbunit.dataset.csv.handlers;
023:
024: import org.slf4j.Logger;
025: import org.slf4j.LoggerFactory;
026:
027: import org.dbunit.dataset.csv.IllegalInputCharacterException;
028:
029: public class IsAlnumHandler extends AbstractPipelineComponent {
030:
031: /**
032: * Logger for this class
033: */
034: private static final Logger logger = LoggerFactory
035: .getLogger(IsAlnumHandler.class);
036:
037: private IsAlnumHandler() {
038: }
039:
040: public static final PipelineComponent ACCEPT() {
041: logger.debug("ACCEPT() - start");
042:
043: return createPipelineComponent(new IsAlnumHandler(),
044: new ACCEPT());
045: }
046:
047: public static final PipelineComponent IGNORE() {
048: logger.debug("IGNORE() - start");
049:
050: return createPipelineComponent(new IsAlnumHandler(),
051: new IGNORE());
052: }
053:
054: public static final PipelineComponent QUOTE() {
055: logger.debug("QUOTE() - start");
056:
057: return createPipelineComponent(new IsAlnumHandler(),
058: new QUOTE());
059: }
060:
061: /*
062: public static final PipelineComponent UNQUOTE () {
063: return createPipelineComponent(new IsAlnumHandler(), new UNQUOTE());
064: }
065: */
066:
067: public boolean canHandle(char c)
068: throws IllegalInputCharacterException {
069: logger.debug("canHandle(c=" + c + ") - start");
070:
071: if (c != SeparatorHandler.SEPARATOR_CHAR
072: && !Character.isWhitespace(c)
073: && c != EscapeHandler.ESCAPE_CHAR) {
074: return true;
075: }
076: return false;
077: }
078:
079: static protected class QUOTE extends Helper {
080:
081: /**
082: * Logger for this class
083: */
084: private static final Logger logger = LoggerFactory
085: .getLogger(QUOTE.class);
086:
087: private boolean add = true;
088:
089: public void helpWith(char c) {
090: logger.debug("helpWith(c=" + c + ") - start");
091:
092: getHandler().getPipeline().putFront(
093: SeparatorHandler.ENDPIECE());
094: getHandler().getPipeline()
095: .putFront(IsAlnumHandler.ACCEPT());
096: getHandler().getPipeline().putFront(
097: WhitespacesHandler.ACCEPT());
098: //getHandler().getPipeline().putFront(IsAlnumHandler.UNQUOTE());
099:
100: getHandler().accept(c);
101: }
102: }
103:
104: static protected class UNQUOTE extends Helper {
105:
106: /**
107: * Logger for this class
108: */
109: private static final Logger logger = LoggerFactory
110: .getLogger(UNQUOTE.class);
111:
112: public void helpWith(char c) {
113: logger.debug("helpWith(c=" + c + ") - start");
114:
115: try {
116: getHandler().getPipeline().removeFront();
117: getHandler().getPipeline().removeFront();
118: getHandler().getPipeline().removeFront();
119: getHandler().getPipeline().removeFront();
120: } catch (PipelineException e) {
121: logger.error("helpWith()", e);
122:
123: throw new RuntimeException(e.getMessage());
124: }
125: // ignore the char
126: }
127: }
128:
129: }
|