1 6 7 package org.contineo.core.text.parser; 8 9 import java.io.File ; 10 import java.io.FileInputStream ; 11 import javax.swing.JEditorPane ; 12 import javax.swing.text.rtf.RTFEditorKit ; 13 import org.apache.log4j.Level; 14 import org.apache.log4j.Logger; 15 import org.contineo.core.LoggingManager; 16 20 public class RTFParser implements Parser { 21 22 25 private StringBuffer content = new StringBuffer (); 26 27 31 private Logger logger; 32 33 34 35 public RTFParser(File file) { 36 logger = LoggingManager.getLogger(this.getClass()); 37 init(file); 38 } 39 40 protected void init(File file) { 41 try { 42 RTFEditorKit rtf = new RTFEditorKit (); 43 JEditorPane editor = new JEditorPane (); 44 editor.setEditorKit( rtf ); 45 46 FileInputStream fis = new FileInputStream (file); 47 rtf.read( fis, editor.getDocument(), 0 ); 48 49 content = new StringBuffer (editor.getDocument().getText(0,editor.getDocument().getLength())); 50 fis.close(); 51 } 52 catch (Exception ex) { 53 if (logger.isEnabledFor(Level.ERROR)) 54 logger.error(ex.getMessage()); 55 } 56 } 57 58 62 public StringBuffer getContent() { 63 return content; 64 } 65 66 67 public String getVersion() { 68 return ""; 69 } 70 71 74 public String getAuthor() { 75 return ""; 76 } 77 78 81 public String getSourceDate() { 82 return ""; 83 } 84 85 88 public String getKeywords() { 89 return ""; 90 } 91 92 95 public String getTitle() { 96 return ""; 97 } 98 99 } 100 | Popular Tags |