[kaffe] CVS kaffe (robilad): Resynced with GNU Classpath: javax.swing.text.rtf support

Kaffe CVS cvs-commits at kaffe.org
Tue Mar 8 14:45:42 PST 2005


PatchSet 5505 
Date: 2005/03/08 22:40:36
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: javax.swing.text.rtf support

Members: 
	ChangeLog:1.3679->1.3680 
	libraries/javalib/Makefile.am:1.320->1.321 
	libraries/javalib/Makefile.in:1.406->1.407 
	libraries/javalib/all.files:1.100->1.101 
	libraries/javalib/javax/swing/text/rtf/ControlWordToken.java:INITIAL->1.1 
	libraries/javalib/javax/swing/text/rtf/RTFEditorKit.java:INITIAL->1.1 
	libraries/javalib/javax/swing/text/rtf/RTFParseException.java:INITIAL->1.1 
	libraries/javalib/javax/swing/text/rtf/RTFParser.java:INITIAL->1.1 
	libraries/javalib/javax/swing/text/rtf/RTFScanner.java:INITIAL->1.1 
	libraries/javalib/javax/swing/text/rtf/TextToken.java:INITIAL->1.1 
	libraries/javalib/javax/swing/text/rtf/Token.java:INITIAL->1.1 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3679 kaffe/ChangeLog:1.3680
--- kaffe/ChangeLog:1.3679	Tue Mar  8 22:26:34 2005
+++ kaffe/ChangeLog	Tue Mar  8 22:40:36 2005
@@ -2,6 +2,20 @@
 
 	Resynced with GNU Classpath.
 
+	2005-03-04  Roman Kennke  <roman at ontographics.com>
+
+        * javax/swing/text/rtf/ControlWordToken.java: New file.
+        * javax/swing/text/rtf/RTFEditorKit.java: New file.
+        * javax/swing/text/rtf/RTFParseException.java: New file.
+        * javax/swing/text/rtf/RTFParser.java: New file.
+        * javax/swing/text/rtf/RTFScanner.java: New file.
+        * javax/swing/text/rtf/TextToken.java: New file.
+        * javax/swing/text/rtf/Token.java: New file.
+
+2005-03-08  Dalibor Topic  <robilad at kaffe.org>
+
+	Resynced with GNU Classpath.
+
 	2005-03-08  Audrius Meskauskas  <audriusa at bluewin.ch>
 
         * org/omg/CORBA/BooleanHolder.java,
Index: kaffe/libraries/javalib/Makefile.am
diff -u kaffe/libraries/javalib/Makefile.am:1.320 kaffe/libraries/javalib/Makefile.am:1.321
--- kaffe/libraries/javalib/Makefile.am:1.320	Tue Mar  8 22:26:36 2005
+++ kaffe/libraries/javalib/Makefile.am	Tue Mar  8 22:40:37 2005
@@ -262,6 +262,7 @@
 	$(javax_swing_text_SRCS) \
 	$(javax_swing_text_html_SRCS) \
 	$(javax_swing_text_html_parser_SRCS) \
+	$(javax_swing_text_rtf_SRCS) \
 	$(javax_swing_tree_SRCS) \
 	$(javax_swing_undo_SRCS) \
 	$(javax_transaction_SRCS) \
@@ -3926,6 +3927,14 @@
 	javax/swing/text/html/HTML.java
 javax_swing_text_html_parser_SRCS = \
 	javax/swing/text/html/parser/ParserDelegator.java
+javax_swing_text_rtf_SRCS = \
+	javax/swing/text/rtf/ControlWordToken.java \
+	javax/swing/text/rtf/RTFEditorKit.java \
+	javax/swing/text/rtf/RTFParseException.java \
+	javax/swing/text/rtf/RTFParser.java \
+	javax/swing/text/rtf/RTFScanner.java \
+	javax/swing/text/rtf/TextToken.java \
+	javax/swing/text/rtf/Token.java
 javax_swing_tree_SRCS = \
 	javax/swing/tree/AbstractLayoutCache.java \
 	javax/swing/tree/DefaultMutableTreeNode.java \
Index: kaffe/libraries/javalib/Makefile.in
diff -u kaffe/libraries/javalib/Makefile.in:1.406 kaffe/libraries/javalib/Makefile.in:1.407
--- kaffe/libraries/javalib/Makefile.in:1.406	Tue Mar  8 22:26:39 2005
+++ kaffe/libraries/javalib/Makefile.in	Tue Mar  8 22:40:39 2005
@@ -614,6 +614,7 @@
 	$(javax_swing_text_SRCS) \
 	$(javax_swing_text_html_SRCS) \
 	$(javax_swing_text_html_parser_SRCS) \
+	$(javax_swing_text_rtf_SRCS) \
 	$(javax_swing_tree_SRCS) \
 	$(javax_swing_undo_SRCS) \
 	$(javax_transaction_SRCS) \
@@ -4490,6 +4491,15 @@
 
 javax_swing_text_html_parser_SRCS = \
 	javax/swing/text/html/parser/ParserDelegator.java
+
+javax_swing_text_rtf_SRCS = \
+	javax/swing/text/rtf/ControlWordToken.java \
+	javax/swing/text/rtf/RTFEditorKit.java \
+	javax/swing/text/rtf/RTFParseException.java \
+	javax/swing/text/rtf/RTFParser.java \
+	javax/swing/text/rtf/RTFScanner.java \
+	javax/swing/text/rtf/TextToken.java \
+	javax/swing/text/rtf/Token.java
 
 javax_swing_tree_SRCS = \
 	javax/swing/tree/AbstractLayoutCache.java \
Index: kaffe/libraries/javalib/all.files
diff -u kaffe/libraries/javalib/all.files:1.100 kaffe/libraries/javalib/all.files:1.101
--- kaffe/libraries/javalib/all.files:1.100	Tue Mar  8 22:26:40 2005
+++ kaffe/libraries/javalib/all.files	Tue Mar  8 22:40:40 2005
@@ -3380,6 +3380,13 @@
 javax/swing/text/ViewFactory.java
 javax/swing/text/html/HTML.java
 javax/swing/text/html/parser/ParserDelegator.java
+javax/swing/text/rtf/ControlWordToken.java
+javax/swing/text/rtf/RTFEditorKit.java
+javax/swing/text/rtf/RTFParseException.java
+javax/swing/text/rtf/RTFParser.java
+javax/swing/text/rtf/RTFScanner.java
+javax/swing/text/rtf/TextToken.java
+javax/swing/text/rtf/Token.java
 javax/swing/tree/AbstractLayoutCache.java
 javax/swing/tree/DefaultMutableTreeNode.java
 javax/swing/tree/DefaultTreeCellEditor.java
===================================================================
Checking out kaffe/libraries/javalib/javax/swing/text/rtf/ControlWordToken.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/javax/swing/text/rtf/ControlWordToken.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/javax/swing/text/rtf/ControlWordToken.java	Tue Mar  8 22:45:41 2005
@@ -0,0 +1,86 @@
+/* ControlWordToken.java --
+   Copyright (C) 2005  Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.rtf;
+
+/**
+ * A special {@link Token} that represents a control word in RTF like
+ * '\deff0' where 'deff' is the name of the control word and '0' is an
+ * optional parameter.
+ *
+ * @author Roman Kennke (roman at ontographics.com)
+ */
+class ControlWordToken extends Token
+{
+
+  /**
+   * The name of the control word.
+   */
+  public String name;
+
+  /**
+   * The optional parameter of the control word. Absence of a parameter is
+   * expressed through Integer.MIN_VALUE.
+   */
+  public int param;
+
+  /**
+   * Constructs a new ControlWordToken with the specified name and without
+   * a parameter.
+   *
+   * @param name the name of the control word
+   */
+  public ControlWordToken(String name)
+  {
+    this(name, Integer.MIN_VALUE);
+  }
+
+
+  /**
+   * Constructs a new ControlWordToken with the specified name and parameter.
+   *
+   * @param name the name of the control word
+   */
+  public ControlWordToken(String name, int param)
+  {
+    super(Token.CONTROL_WORD);
+    this.name = name;
+    this.param = param;
+  }
+
+}
===================================================================
Checking out kaffe/libraries/javalib/javax/swing/text/rtf/RTFEditorKit.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/javax/swing/text/rtf/RTFEditorKit.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/javax/swing/text/rtf/RTFEditorKit.java	Tue Mar  8 22:45:42 2005
@@ -0,0 +1,114 @@
+/* RTFEditorKit.java --
+   Copyright (C) 2005  Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.rtf;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import javax.swing.text.StyledEditorKit;
+
+/**
+ * Provides support for RTF data for use in
+ * {@link javax.swing.JEditorPane}s.
+ *
+ * @author Roman Kennke (roman at ontographics.com)
+ */
+public class RTFEditorKit
+  extends StyledEditorKit
+{
+
+  /**
+   * Constructs a new RTFEditorKit.
+   */
+  public RTFEditorKit()
+  {
+    super();
+  }
+
+  /**
+   * Returns the MIME content type. In the case of RTFEditorKit this is
+   * &apos;text/rtf&apos;
+   *
+   * @return the MIME content type for RTFEditorKit
+   */
+  public String getContentType()
+  {
+    return "text/rtf";
+  }
+
+  /**
+   * Reads RTF data from <code>stream</code> into <code>doc</code> at the
+   * specified position <code>pos</code>.
+   *
+   * @param stream the {@link InputStream} from where we read RTF data
+   * @param doc the {@link Document} into which we read the RTF data
+   * @param pos the position where to start
+   *
+   * @throws IOException if an IO error occurs
+   * @throws BadLocationException if the position is not valid
+   */
+  public void read(InputStream stream, Document doc, int pos)
+    throws IOException, BadLocationException
+  {
+    RTFParser parser = new RTFParser(stream, doc, pos);
+    parser.parse();
+  }
+
+
+  /**
+   * Reads RTF data from <code>reader</code> into <code>doc</code> at the
+   * specified position <code>pos</code>.
+   *
+   * @param reader the {@link Reader} from where we read RTF data
+   * @param doc the {@link Document} into which we read the RTF data
+   * @param pos the position where to start
+   *
+   * @throws IOException if an IO error occurs
+   * @throws BadLocationException if the position is not valid
+   */
+  public void read(Reader reader, Document doc, int pos)
+    throws IOException, BadLocationException
+  {
+    RTFParser parser = new RTFParser(reader, doc, pos);
+    parser.parse();
+  }
+}
===================================================================
Checking out kaffe/libraries/javalib/javax/swing/text/rtf/RTFParseException.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/javax/swing/text/rtf/RTFParseException.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/javax/swing/text/rtf/RTFParseException.java	Tue Mar  8 22:45:42 2005
@@ -0,0 +1,65 @@
+/* RTFParseException.java --
+   Copyright (C) 2005  Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.rtf;
+
+/**
+ * Indicates a parsing error during RTF processing.
+ *
+ * @author Roman Kennke (roman at ontographics.com)
+ */
+class RTFParseException
+  extends RuntimeException
+{
+  /**
+   * Constructs a new RTFParseException without message.
+   */
+  public RTFParseException()
+  {
+    super();
+  }
+
+  /**
+   * Constructs a new RTFParseException with the specified message.
+   */
+  public RTFParseException(String message)
+  {
+    super(message);
+  }
+
+}
===================================================================
Checking out kaffe/libraries/javalib/javax/swing/text/rtf/RTFParser.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/javax/swing/text/rtf/RTFParser.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/javax/swing/text/rtf/RTFParser.java	Tue Mar  8 22:45:42 2005
@@ -0,0 +1,194 @@
+/* RTFParser.java --
+   Copyright (C) 2005  Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.rtf;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import javax.swing.text.Document;
+import javax.swing.text.BadLocationException;
+
+/**
+ * Parses an RTF file into a {@link Document}. The parser utilizes
+ * {@link RTFScanner}.
+ *
+ * @author Roman Kennke (roman at ontographics.com)
+ */
+class RTFParser
+{
+
+  /**
+   * Our scanner.
+   */
+  private RTFScanner scanner;
+
+  /**
+   * The document into which we parse.
+   */
+  private Document doc;
+
+  /**
+   * The current position.
+   */
+  private int pos;
+
+  /**
+   * Constructs a new RTFParser for the specified document and position,
+   * without initializing the scanner. This is only used internally.
+   *
+   * @param doc the {@link Document} into which we should parse
+   * @param pos the position to start
+   */
+  private RTFParser(Document doc, int pos)
+  {
+    this.doc = doc;
+    this.pos = pos;
+  }
+
+  /**
+   * Constructs a new RTFParser for the specified <code>stream</code>.
+   *
+   * @param stream the stream from which we parse
+   * @param doc the {@link Document} into which we should parse
+   * @param pos the position to start
+   */
+  public RTFParser(InputStream stream, Document doc, int pos)
+  {
+    this(doc, pos);
+    scanner = new RTFScanner(stream);
+  }
+
+  /**
+   * Constructs a new RTFParser for the specified <code>reader</code>.
+   *
+   * @param reader the reader from which we parse
+   * @param doc the {@link Document} into which we should parse
+   * @param pos the position to start
+   */
+  public RTFParser(Reader reader, Document doc, int pos)
+  {
+    this(doc, pos);
+    scanner = new RTFScanner(reader);
+  }
+
+  /**
+   * Returns the {@link Document} in which we parsed the RTF data.
+   *
+   * @return the {@link Document} in which we parsed the RTF data
+   */
+  public Document getDocument()
+  {
+    return doc;
+  }
+
+  /**
+   * Starts the parsing process.
+   */
+  public void parse()
+    throws IOException, BadLocationException
+  {
+    parseFile();
+  }
+
+  /**
+   * The parse rules for &lt;file&gt;.
+   */
+  private void parseFile()
+    throws IOException, BadLocationException
+  {
+    Token t1 = scanner.readToken();
+    if (t1.type != Token.LCURLY)
+      throw new RTFParseException("expected left curly braces");
+
+    parseHeader();
+    parseDocument();
+  
+    Token t2 = scanner.readToken();
+    if (t2.type != Token.RCURLY)
+      throw new RTFParseException("expected right curly braces");
+
+  }
+
+  /**
+   * The parse rules for &lt;header&gt;.
+   *
+   * TODO: implement this properly
+   */
+  private void parseHeader()
+  //throws IOException, BadLocationException
+  {
+    // TODO add parse rules here
+  }
+
+
+  /**
+   * The parse rules for &lt;document&gt;.
+   *
+   * TODO: implement this properly
+   */
+  private void parseDocument()
+    throws IOException, BadLocationException
+  {
+    //  !!! TODO !!!
+    // This simply emits every TEXT Token as text to the document
+    // which is plain stupid
+
+    boolean eof = false;
+
+    do {
+      Token token = scanner.readToken();
+      switch (token.type)
+        {
+        case Token.TEXT:
+          TextToken textToken = (TextToken) token;
+          doc.insertString(pos, textToken.text, null);
+          pos += textToken.text.length();
+          break;
+        case Token.EOF:
+          eof = true;
+          break;
+        default:
+          // FIXME
+          break;
+        }
+    } while (!eof);
+
+  }
+
+}
===================================================================
Checking out kaffe/libraries/javalib/javax/swing/text/rtf/RTFScanner.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/javax/swing/text/rtf/RTFScanner.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/javax/swing/text/rtf/RTFScanner.java	Tue Mar  8 22:45:42 2005
@@ -0,0 +1,270 @@
+/* RTFScanner.java --
+   Copyright (C) 2005  Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.rtf;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+
+/**
+ * Provides a scanner that scans an {@link InputStream} for tokens of the
+ * RTF syntax.
+ *
+ * This scanner is based upon the RTF specification 1.6
+ * available at:
+ * 
+ * <a
+ * href="http://msdn.microsoft.com/library/en-us/dnrtfspec/html/rtfspec.asp">
+ * RTF specification at MSDN</a>
+ *
+ * @author Roman Kennke (roman at ontographics.com)
+ */
+class RTFScanner
+{
+
+  /**
+   * The reader from which we read the RTF data.
+   */
+  private Reader in;
+
+  /**
+   * This is used to constuct strings from the read in chars.
+   */
+  private StringBuffer buffer;
+
+  /**
+   * Constructs a new RTFScanner without initializing the {@link Reader}.
+   */
+  private RTFScanner()
+  {
+    buffer = new StringBuffer();
+  }
+
+  /**
+   * Constructs a new RTFScanner for the given {@link InputStream}.
+   * The stream is wrapped into an {@link InputStreamReader} and if it's
+   * not yet buffered then the Reader is wrapped in a {@link BufferedReader}
+   *
+   * @param stream the {@link InputStream} to read RTF data from
+   */
+  public RTFScanner(InputStream stream)
+  {
+    this();
+    InputStreamReader reader = new InputStreamReader(stream);
+    in = new BufferedReader(reader);
+  }
+
+  /**
+   * Constructs a new RTFScanner for the given {@link Reader}.
+   *
+   * If the reader is not an instance of {@link BufferedReader} then it
+   * is wrapped into a BufferedReader.
+   *
+   * @param reader the {@link BufferedReader} to read RTF data from
+   */
+  public RTFScanner(Reader reader)
+  {
+    this();
+    if (reader instanceof BufferedReader)
+      {
+        in = reader;
+      }
+    else
+      {
+        in = new BufferedReader(reader);
+      }
+  }
+
+  /**
+   * Reads in the next {@link Token} from the stream.
+   *
+   * @return the read {@link Token}
+   *
+   * @throws IOException if the underlying stream has problems
+   */
+  public Token readToken()
+    throws IOException
+  {
+    Token token = null;
+
+    int c = in.read();
+    switch(c)
+      {
+      case -1:
+        token = new Token(Token.EOF);
+        break;
+
+      case '{':
+        token = new Token(Token.LCURLY);
+        break;
+
+      case '}':
+        token = new Token(Token.RCURLY);
+        break;
+
+      case '\\':
+        buffer.delete(0, buffer.length());
+        buffer.append((char) c);
+        token = readControlWord();
+        break;
+
+      default:
+        buffer.delete(0, buffer.length());
+        buffer.append((char) c);
+        token = readText();
+        break;
+      }
+
+    return token;
+  }
+
+  /**
+   * Reads in a control word and optional parameter.
+   *
+   * @return the read in control word as {@link ControlWordToken}
+   *
+   * @throws IOException if the underlying stream has problems
+   */
+  private Token readControlWord()
+    throws IOException
+  {
+    // this flag indicates if we are still reading the name or are already
+    // in the parameter
+    boolean readingName = true;
+    String name = null;
+    String param = null;
+
+    while (true)
+      {
+        in.mark(1);
+        int c = in.read();
+
+        // check for 'a'..'z'
+        if (readingName && (c >= 'a') && (c <= 'z'))
+          {
+            buffer.append((char) c);
+          }
+        else if ((c >= '0') && (c <= '9'))
+          {
+            // if the last char was in the name, then finish reading the name
+            if (readingName)
+              {
+                name = buffer.toString();
+                buffer.delete(0, buffer.length());
+                readingName = false;
+              }
+            buffer.append((char) c);
+          }
+        else
+          {
+            // if we were in the name, then finish this
+            if (readingName)
+              {
+                name = buffer.toString();
+              }
+            // otherwise finish the parameter
+            else
+              {
+                param = buffer.toString();
+              }
+
+            // clear up
+            buffer.delete(0, buffer.length());
+            // reset input buffer to last char
+            in.reset();
+            // break while loop
+            break;
+          }
+      }
+
+    ControlWordToken token = null;
+
+    if (param == null)
+      token = new ControlWordToken(name);
+    else
+      token =new ControlWordToken(name, Integer.parseInt(param));
+
+    return token;
+
+  }
+
+  /**
+   * Reads in a block of text.
+   *
+   * @return the token for the text
+   */
+  private Token readText()
+    throws IOException
+  {
+
+    boolean readingText = true;
+    while (readingText)
+      {
+        in.mark(1);
+        int c = in.read();
+        switch(c)
+          {
+          case '\\':
+          case '{':
+          case '}':
+          case -1:
+            readingText = false;
+            in.reset();
+            break;
+
+          default:
+            buffer.append((char) c);
+            break;
+          }
+
+      }
+
+    String text = buffer.toString();
+    Token token = new TextToken(text);
+
+    buffer.delete(0, buffer.length());
+
+    return token;
+
+  }
+}
===================================================================
Checking out kaffe/libraries/javalib/javax/swing/text/rtf/TextToken.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/javax/swing/text/rtf/TextToken.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/javax/swing/text/rtf/TextToken.java	Tue Mar  8 22:45:42 2005
@@ -0,0 +1,65 @@
+/* TextToken.java --
+   Copyright (C) 2005  Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.rtf;
+
+/**
+ * A special {@link Token} that represents a piece of text in RTF.
+ *
+ * @author Roman Kennke (roman at ontographics.com)
+ */
+class TextToken extends Token
+{
+
+  /**
+   * The text.
+   */
+  public String text;
+
+  /**
+   * Constructs a new TextToken with the specified textual data.
+   *
+   * @param text the text for this token
+   */
+  public TextToken(String text)
+  {
+    super(Token.TEXT);
+    this.text = text;
+  }
+
+}
===================================================================
Checking out kaffe/libraries/javalib/javax/swing/text/rtf/Token.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/javax/swing/text/rtf/Token.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/javax/swing/text/rtf/Token.java	Tue Mar  8 22:45:42 2005
@@ -0,0 +1,91 @@
+/* Token.java --
+   Copyright (C) 2005  Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that

*** Patch too long, truncated ***




More information about the kaffe mailing list