1 21 22 package org.dbunit.dataset.csv.handlers; 23 24 import org.dbunit.dataset.csv.IllegalInputCharacterException; 25 26 public class QuoteHandler extends AbstractPipelineComponent { 27 28 private QuoteHandler() { 29 } 30 31 public static final PipelineComponent ACCEPT() { 32 return createPipelineComponent(new QuoteHandler(), new ACCEPT()); 33 } 34 35 public static final PipelineComponent IGNORE() { 36 return createPipelineComponent(new QuoteHandler(), new IGNORE()); 37 } 38 39 public static final PipelineComponent QUOTE() { 40 return createPipelineComponent(new QuoteHandler(), new QUOTE()); 41 } 42 43 public static final PipelineComponent UNQUOTE() { 44 return createPipelineComponent(new QuoteHandler(), new UNQUOTE()); 45 } 46 47 public static final char QUOTE_CHAR = '"'; 48 49 public boolean canHandle(char c) throws IllegalInputCharacterException { 50 51 if (c == QUOTE_CHAR) { 52 return true; 53 } 54 return false; 55 } 56 57 58 static protected class QUOTE extends Helper { 59 60 public void helpWith(char c) { 61 getHandler().getPipeline().putFront(SeparatorHandler.ACCEPT()); 62 getHandler().getPipeline().putFront(WhitespacesHandler.ACCEPT()); 63 getHandler().getPipeline().putFront(IsAlnumHandler.ACCEPT()); 64 getHandler().getPipeline().putFront(QuoteHandler.UNQUOTE()); 65 getHandler().getPipeline().putFront(EscapeHandler.ESCAPE()); 66 } 68 69 } 70 71 static protected class UNQUOTE extends Helper { 72 73 public void helpWith(char c) { 74 try { 75 getHandler().getPipeline().removeFront(); 76 getHandler().getPipeline().removeFront(); 77 getHandler().getPipeline().removeFront(); 78 getHandler().getPipeline().removeFront(); 79 getHandler().getPipeline().removeFront(); 80 } catch (PipelineException e) { 81 throw new RuntimeException (e.getMessage()); 82 } 83 } 85 86 public boolean allowForNoMoreInput() { 87 throw new IllegalStateException ("end of input while waiting for a closing quote"); 88 } 89 } 90 91 } 92 | Popular Tags |