01: package org.contineo.core.text.parser;
02:
03: import java.io.File;
04: import java.io.FileInputStream;
05:
06: import javax.swing.JEditorPane;
07: import javax.swing.text.DefaultEditorKit;
08:
09: import org.apache.commons.logging.Log;
10: import org.apache.commons.logging.LogFactory;
11:
12: /**
13: * Class for parsing text (*.txt) files. Created on 5. November 2003, 18:14
14: *
15: * @author Michael Scholz
16: */
17: public class TXTParser implements Parser {
18: /**
19: * @uml.property name="content"
20: */
21: private StringBuffer content = new StringBuffer();
22:
23: protected static Log logger = LogFactory.getLog(RTFParser.class);
24:
25: public TXTParser(File file) {
26: init(file);
27: }
28:
29: protected void init(File file) {
30: try {
31: DefaultEditorKit editorkit = new DefaultEditorKit();
32: JEditorPane editor = new JEditorPane();
33: editor.setEditorKit(editorkit);
34:
35: FileInputStream fis = new FileInputStream(file);
36: editorkit.read(fis, editor.getDocument(), 0);
37:
38: content = new StringBuffer(editor.getDocument().getText(0,
39: editor.getDocument().getLength()));
40: fis.close();
41: } catch (Exception ex) {
42: logger.error(ex.getMessage(), ex);
43: }
44: }
45:
46: /**
47: *
48: * @uml.property name="content"
49: */
50: public StringBuffer getContent() {
51: return content;
52: }
53:
54: public String getVersion() {
55: return "";
56: }
57:
58: /*
59: * (non-Javadoc)
60: *
61: * @see org.contineo.core.text.parser.Parser#getAuthor()
62: */
63: public String getAuthor() {
64: return "";
65: }
66:
67: /*
68: * (non-Javadoc)
69: *
70: * @see org.contineo.core.text.parser.Parser#getSourceDate()
71: */
72: public String getSourceDate() {
73: return "";
74: }
75:
76: /*
77: * (non-Javadoc)
78: *
79: * @see org.contineo.core.text.parser.Parser#getKeywords()
80: */
81: public String getKeywords() {
82: return "";
83: }
84:
85: /*
86: * (non-Javadoc)
87: *
88: * @see org.contineo.core.text.parser.Parser#getTitle()
89: */
90: public String getTitle() {
91: return "";
92: }
93: }
|