1 package org.contineo.core.text.parser; 2 3 import java.io.File ; 4 import java.io.FileInputStream ; 5 import javax.swing.JEditorPane ; 6 import javax.swing.text.DefaultEditorKit ; 7 import org.apache.log4j.Level; 8 import org.apache.log4j.Logger; 9 import org.contineo.core.LoggingManager; 10 11 16 public class TXTParser implements Parser { 17 18 21 private StringBuffer content = new StringBuffer (); 22 23 27 private Logger logger; 28 29 30 31 public TXTParser(File file) { 32 logger = LoggingManager.getLogger(this.getClass()); 33 init(file); 34 } 35 36 protected void init(File file) { 37 try { 38 DefaultEditorKit editorkit = new DefaultEditorKit (); 39 JEditorPane editor = new JEditorPane (); 40 editor.setEditorKit( editorkit ); 41 42 FileInputStream fis = new FileInputStream (file); 43 editorkit.read( fis, editor.getDocument(), 0 ); 44 45 content = new StringBuffer (editor.getDocument().getText(0,editor.getDocument().getLength())); 46 fis.close(); 47 } 48 catch (Exception ex) { 49 if (logger.isEnabledFor(Level.ERROR)) 50 logger.error(ex.getMessage()); 51 } 52 } 53 54 58 public StringBuffer getContent() { 59 return content; 60 } 61 62 63 public String getVersion() { 64 return ""; 65 } 66 67 70 public String getAuthor() { 71 return ""; 72 } 73 74 77 public String getSourceDate() { 78 return ""; 79 } 80 81 84 public String getKeywords() { 85 return ""; 86 } 87 88 91 public String getTitle() { 92 return ""; 93 } 94 95 } 96 | Popular Tags |