TXTParser.java :  » Content-Management-System » contineo » org » contineo » core » text » parser » Java Open Source

Java Open Source » Content Management System » contineo 
contineo » org » contineo » core » text » parser » TXTParser.java
package org.contineo.core.text.parser;

import java.io.File;
import java.io.FileInputStream;

import javax.swing.JEditorPane;
import javax.swing.text.DefaultEditorKit;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Class for parsing text (*.txt) files. Created on 5. November 2003, 18:14
 * 
 * @author Michael Scholz
 */
public class TXTParser implements Parser {
  /**
   * @uml.property name="content"
   */
  private StringBuffer content = new StringBuffer();

  protected static Log logger = LogFactory.getLog(RTFParser.class);

  public TXTParser(File file) {
    init(file);
  }

  protected void init(File file) {
    try {
      DefaultEditorKit editorkit = new DefaultEditorKit();
      JEditorPane editor = new JEditorPane();
      editor.setEditorKit(editorkit);

      FileInputStream fis = new FileInputStream(file);
      editorkit.read(fis, editor.getDocument(), 0);

      content = new StringBuffer(editor.getDocument().getText(0, editor.getDocument().getLength()));
      fis.close();
    } catch (Exception ex) {
      logger.error(ex.getMessage(), ex);
    }
  }

  /**
   * 
   * @uml.property name="content"
   */
  public StringBuffer getContent() {
    return content;
  }

  public String getVersion() {
    return "";
  }

  /*
   * (non-Javadoc)
   * 
   * @see org.contineo.core.text.parser.Parser#getAuthor()
   */
  public String getAuthor() {
    return "";
  }

  /*
   * (non-Javadoc)
   * 
   * @see org.contineo.core.text.parser.Parser#getSourceDate()
   */
  public String getSourceDate() {
    return "";
  }

  /*
   * (non-Javadoc)
   * 
   * @see org.contineo.core.text.parser.Parser#getKeywords()
   */
  public String getKeywords() {
    return "";
  }

  /*
   * (non-Javadoc)
   * 
   * @see org.contineo.core.text.parser.Parser#getTitle()
   */
  public String getTitle() {
    return "";
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.