You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ay...@apache.org on 2008/07/13 23:45:56 UTC
svn commit: r676446 - in
/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common:
javax/swing/text/rtf/ org/apache/harmony/x/swing/text/rtf/
Author: ayza
Date: Sun Jul 13 14:45:56 2008
New Revision: 676446
URL: http://svn.apache.org/viewvc?rev=676446&view=rev
Log:
Committing intial RTF parser implementation from HARMONY-5903 ([classlib][rtf] RTF parser initial implementation)
Added:
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/rtf/
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/rtf/RTFEditorKit.java (with props)
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/ParseException.java (with props)
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParser.java (with props)
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParser.jj (with props)
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParserConstants.java (with props)
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParserHandler.java (with props)
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParserTokenManager.java (with props)
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/SimpleCharStream.java (with props)
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/Token.java (with props)
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/TokenMgrError.java (with props)
Added: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/rtf/RTFEditorKit.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/rtf/RTFEditorKit.java?rev=676446&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/rtf/RTFEditorKit.java (added)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/rtf/RTFEditorKit.java Sun Jul 13 14:45:56 2008
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package javax.swing.text.rtf;
+
+import org.apache.harmony.x.swing.text.rtf.RTFParser;
+import org.apache.harmony.x.swing.text.rtf.ParseException;
+
+import javax.swing.text.StyledEditorKit;
+import javax.swing.text.Document;
+import javax.swing.text.BadLocationException;
+import java.io.*;
+
+/**
+ * @author ayzen
+ */
+public class RTFEditorKit extends StyledEditorKit {
+
+ public RTFEditorKit() {
+ super();
+ }
+
+ public String getContentType() {
+ return "text/rtf";
+ }
+
+ public void read(InputStream in, Document doc, int pos) throws IOException, BadLocationException {
+ RTFParser parser = new RTFParser(in);
+ try {
+ parser.parse(doc, pos);
+ }
+ catch (ParseException e) {
+ IOException ioex = new IOException(e.toString());
+
+ ioex.initCause(e);
+ throw ioex;
+ }
+ }
+
+ public void read(Reader in, Document doc, int pos) {
+
+ }
+
+ public void write(OutputStream out, Document doc, int pos, int len) {
+
+ }
+
+ public void write(Writer out, Document doc, int pos, int len) {
+
+ }
+
+}
Propchange: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/rtf/RTFEditorKit.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/ParseException.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/ParseException.java?rev=676446&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/ParseException.java (added)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/ParseException.java Sun Jul 13 14:45:56 2008
@@ -0,0 +1,192 @@
+/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */
+package org.apache.harmony.x.swing.text.rtf;
+
+/**
+ * This exception is thrown when parse errors are encountered.
+ * You can explicitly create objects of this exception type by
+ * calling the method generateParseException in the generated
+ * parser.
+ *
+ * You can modify this class to customize your error reporting
+ * mechanisms so long as you retain the public fields.
+ */
+public class ParseException extends Exception {
+
+ /**
+ * This constructor is used by the method "generateParseException"
+ * in the generated parser. Calling this constructor generates
+ * a new object of this type with the fields "currentToken",
+ * "expectedTokenSequences", and "tokenImage" set. The boolean
+ * flag "specialConstructor" is also set to true to indicate that
+ * this constructor was used to create this object.
+ * This constructor calls its super class with the empty string
+ * to force the "toString" method of parent class "Throwable" to
+ * print the error message in the form:
+ * ParseException: <result of getMessage>
+ */
+ public ParseException(Token currentTokenVal,
+ int[][] expectedTokenSequencesVal,
+ String[] tokenImageVal
+ )
+ {
+ super("");
+ specialConstructor = true;
+ currentToken = currentTokenVal;
+ expectedTokenSequences = expectedTokenSequencesVal;
+ tokenImage = tokenImageVal;
+ }
+
+ /**
+ * The following constructors are for use by you for whatever
+ * purpose you can think of. Constructing the exception in this
+ * manner makes the exception behave in the normal way - i.e., as
+ * documented in the class "Throwable". The fields "errorToken",
+ * "expectedTokenSequences", and "tokenImage" do not contain
+ * relevant information. The JavaCC generated code does not use
+ * these constructors.
+ */
+
+ public ParseException() {
+ super();
+ specialConstructor = false;
+ }
+
+ public ParseException(String message) {
+ super(message);
+ specialConstructor = false;
+ }
+
+ /**
+ * This variable determines which constructor was used to create
+ * this object and thereby affects the semantics of the
+ * "getMessage" method (see below).
+ */
+ protected boolean specialConstructor;
+
+ /**
+ * This is the last token that has been consumed successfully. If
+ * this object has been created due to a parse error, the token
+ * followng this token will (therefore) be the first error token.
+ */
+ public Token currentToken;
+
+ /**
+ * Each entry in this array is an array of integers. Each array
+ * of integers represents a sequence of tokens (by their ordinal
+ * values) that is expected at this point of the parse.
+ */
+ public int[][] expectedTokenSequences;
+
+ /**
+ * This is a reference to the "tokenImage" array of the generated
+ * parser within which the parse error occurred. This array is
+ * defined in the generated ...Constants interface.
+ */
+ public String[] tokenImage;
+
+ /**
+ * This method has the standard behavior when this object has been
+ * created using the standard constructors. Otherwise, it uses
+ * "currentToken" and "expectedTokenSequences" to generate a parse
+ * error message and returns it. If this object has been created
+ * due to a parse error, and you do not catch it (it gets thrown
+ * from the parser), then this method is called during the printing
+ * of the final stack trace, and hence the correct error message
+ * gets displayed.
+ */
+ public String getMessage() {
+ if (!specialConstructor) {
+ return super.getMessage();
+ }
+ StringBuffer expected = new StringBuffer();
+ int maxSize = 0;
+ for (int i = 0; i < expectedTokenSequences.length; i++) {
+ if (maxSize < expectedTokenSequences[i].length) {
+ maxSize = expectedTokenSequences[i].length;
+ }
+ for (int j = 0; j < expectedTokenSequences[i].length; j++) {
+ expected.append(tokenImage[expectedTokenSequences[i][j]]).append(" ");
+ }
+ if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
+ expected.append("...");
+ }
+ expected.append(eol).append(" ");
+ }
+ String retval = "Encountered \"";
+ Token tok = currentToken.next;
+ for (int i = 0; i < maxSize; i++) {
+ if (i != 0) retval += " ";
+ if (tok.kind == 0) {
+ retval += tokenImage[0];
+ break;
+ }
+ retval += add_escapes(tok.image);
+ tok = tok.next;
+ }
+ retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
+ retval += "." + eol;
+ if (expectedTokenSequences.length == 1) {
+ retval += "Was expecting:" + eol + " ";
+ } else {
+ retval += "Was expecting one of:" + eol + " ";
+ }
+ retval += expected.toString();
+ return retval;
+ }
+
+ /**
+ * The end of line string for this machine.
+ */
+ protected String eol = System.getProperty("line.separator", "\n");
+
+ /**
+ * Used to convert raw characters to their escaped version
+ * when these raw version cannot be used as part of an ASCII
+ * string literal.
+ */
+ protected String add_escapes(String str) {
+ StringBuffer retval = new StringBuffer();
+ char ch;
+ for (int i = 0; i < str.length(); i++) {
+ switch (str.charAt(i))
+ {
+ case 0 :
+ continue;
+ case '\b':
+ retval.append("\\b");
+ continue;
+ case '\t':
+ retval.append("\\t");
+ continue;
+ case '\n':
+ retval.append("\\n");
+ continue;
+ case '\f':
+ retval.append("\\f");
+ continue;
+ case '\r':
+ retval.append("\\r");
+ continue;
+ case '\"':
+ retval.append("\\\"");
+ continue;
+ case '\'':
+ retval.append("\\\'");
+ continue;
+ case '\\':
+ retval.append("\\\\");
+ continue;
+ default:
+ if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
+ String s = "0000" + Integer.toString(ch, 16);
+ retval.append("\\u" + s.substring(s.length() - 4, s.length()));
+ } else {
+ retval.append(ch);
+ }
+ continue;
+ }
+ }
+ return retval.toString();
+ }
+
+}
Propchange: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/ParseException.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParser.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParser.java?rev=676446&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParser.java (added)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParser.java Sun Jul 13 14:45:56 2008
@@ -0,0 +1,637 @@
+/* Generated By:JavaCC: Do not edit this line. RTFParser.java */
+package org.apache.harmony.x.swing.text.rtf;
+
+import java.io.*;
+import javax.swing.text.Document;
+import javax.swing.text.DefaultStyledDocument;
+
+public class RTFParser implements RTFParserConstants {
+
+ private static RTFParserHandler handler;
+
+ public static void main(String args[]) throws Exception {
+ InputStream in;
+
+ if (args.length > 0)
+ in = new FileInputStream(args[0]);
+ else
+ in = System.in;
+
+ RTFParser parser = new RTFParser(in);
+ parser.parse(new DefaultStyledDocument(), 0);
+ }
+
+ static final public void parse(Document doc, int position) throws ParseException {
+ handler = new RTFParserHandler(doc, position);
+ file();
+ jj_consume_token(0);
+ }
+
+ static final private int parameter() throws ParseException {
+ Token param = null;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case PARAM:
+ param = jj_consume_token(PARAM);
+ break;
+ default:
+ jj_la1[0] = jj_gen;
+ ;
+ }
+ {if (true) return param == null ? -1 : Integer.parseInt(param.image);}
+ throw new Error("Missing return statement in function");
+ }
+
+ static final private void unknownControlWord() throws ParseException {
+ jj_consume_token(CONTROL_WORD);
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case PARAM:
+ jj_consume_token(PARAM);
+ break;
+ default:
+ jj_la1[1] = jj_gen;
+ ;
+ }
+ }
+
+/**
+ * Catches all unhandled control symbols.
+ */
+ static final public void unknownControlSymbol() throws ParseException {
+ jj_consume_token(CONTROL_SYMBOL);
+ }
+
+ static final public void text() throws ParseException {
+ Token text;
+ text = jj_consume_token(TEXT);
+ handler.addText(text.image);
+ }
+
+ static final public void file() throws ParseException {
+ jj_consume_token(OPEN_BRACE);
+ header();
+ document();
+ jj_consume_token(CLOSE_BRACE);
+ }
+
+ static final public void header() throws ParseException {
+ jj_consume_token(RTF);
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case PARAM:
+ jj_consume_token(PARAM);
+ break;
+ default:
+ jj_la1[2] = jj_gen;
+ ;
+ }
+ }
+
+ static final public void document() throws ParseException {
+ label_1:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case B:
+ case I:
+ case UL:
+ paragraph();
+ break;
+ default:
+ jj_la1[3] = jj_gen;
+ if (jj_2_1(2147483647)) {
+ fonttbl();
+ } else if (jj_2_2(2147483647)) {
+ stylesheet();
+ } else if (jj_2_3(2147483647)) {
+ info();
+ } else if (jj_2_4(2147483647)) {
+ ignoredDestination();
+ } else {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case OPEN_BRACE:
+ documentBlock();
+ break;
+ case CONTROL_WORD:
+ unknownControlWord();
+ break;
+ case CONTROL_SYMBOL:
+ unknownControlSymbol();
+ break;
+ case TEXT:
+ text();
+ break;
+ default:
+ jj_la1[4] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ }
+ }
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case OPEN_BRACE:
+ case TEXT:
+ case B:
+ case I:
+ case UL:
+ case CONTROL_WORD:
+ case CONTROL_SYMBOL:
+ ;
+ break;
+ default:
+ jj_la1[5] = jj_gen;
+ break label_1;
+ }
+ }
+ }
+
+/**
+ * A group.
+ */
+ static final public void documentBlock() throws ParseException {
+ jj_consume_token(OPEN_BRACE);
+ handler.startGroup();
+ document();
+ jj_consume_token(CLOSE_BRACE);
+ handler.endGroup();
+ }
+
+/**
+ * Ignored block of RTF file, currently is using to ignore unknown parts
+ * of file.
+ */
+ static final public void ignoredBlock() throws ParseException {
+ label_2:
+ while (true) {
+ if (jj_2_5(2147483647)) {
+ ignoredDestination();
+ } else {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case B:
+ case I:
+ case UL:
+ characterFormat();
+ break;
+ case CONTROL_WORD:
+ unknownControlWord();
+ break;
+ case CONTROL_SYMBOL:
+ unknownControlSymbol();
+ break;
+ case TEXT:
+ jj_consume_token(TEXT);
+ break;
+ case OPEN_BRACE:
+ jj_consume_token(OPEN_BRACE);
+ ignoredBlock();
+ jj_consume_token(CLOSE_BRACE);
+ break;
+ default:
+ jj_la1[6] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ }
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case OPEN_BRACE:
+ case TEXT:
+ case B:
+ case I:
+ case UL:
+ case CONTROL_WORD:
+ case CONTROL_SYMBOL:
+ ;
+ break;
+ default:
+ jj_la1[7] = jj_gen;
+ break label_2;
+ }
+ }
+ }
+
+/**
+ * Group which starts with "{\*" and describes destination, currently this part
+ * is ignored.
+ */
+ static final public void ignoredDestination() throws ParseException {
+ jj_consume_token(OPEN_BRACE);
+ jj_consume_token(IGNORED_DESTINATION);
+ ignoredBlock();
+ jj_consume_token(CLOSE_BRACE);
+ }
+
+/**
+ * Part which describes font table group.
+ */
+ static final public void fonttbl() throws ParseException {
+ jj_consume_token(OPEN_BRACE);
+ jj_consume_token(FONTTBL);
+ ignoredBlock();
+ jj_consume_token(CLOSE_BRACE);
+ }
+
+/**
+ * Part which describes the style sheet group.
+ */
+ static final public void stylesheet() throws ParseException {
+ jj_consume_token(OPEN_BRACE);
+ jj_consume_token(STYLESHEET);
+ ignoredBlock();
+ jj_consume_token(CLOSE_BRACE);
+ }
+
+/**
+ * Part which describes the information group inside document area.
+ */
+ static final public void info() throws ParseException {
+ jj_consume_token(OPEN_BRACE);
+ jj_consume_token(INFO);
+ ignoredBlock();
+ jj_consume_token(CLOSE_BRACE);
+ }
+
+ static final public void paragraph() throws ParseException {
+ characterFormat();
+ }
+
+ static final public void characterFormat() throws ParseException {
+ int param;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case B:
+ jj_consume_token(B);
+ param = parameter();
+ handler.setBold(param != 0);
+ break;
+ case I:
+ jj_consume_token(I);
+ param = parameter();
+ handler.setItalic(param != 0);
+ break;
+ case UL:
+ jj_consume_token(UL);
+ param = parameter();
+ handler.setUnderline(param != 0);
+ break;
+ default:
+ jj_la1[8] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ }
+
+ static final private boolean jj_2_1(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ try { return !jj_3_1(); }
+ catch(LookaheadSuccess ls) { return true; }
+ finally { jj_save(0, xla); }
+ }
+
+ static final private boolean jj_2_2(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ try { return !jj_3_2(); }
+ catch(LookaheadSuccess ls) { return true; }
+ finally { jj_save(1, xla); }
+ }
+
+ static final private boolean jj_2_3(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ try { return !jj_3_3(); }
+ catch(LookaheadSuccess ls) { return true; }
+ finally { jj_save(2, xla); }
+ }
+
+ static final private boolean jj_2_4(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ try { return !jj_3_4(); }
+ catch(LookaheadSuccess ls) { return true; }
+ finally { jj_save(3, xla); }
+ }
+
+ static final private boolean jj_2_5(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ try { return !jj_3_5(); }
+ catch(LookaheadSuccess ls) { return true; }
+ finally { jj_save(4, xla); }
+ }
+
+ static final private boolean jj_3_3() {
+ if (jj_scan_token(OPEN_BRACE)) return true;
+ if (jj_scan_token(INFO)) return true;
+ return false;
+ }
+
+ static final private boolean jj_3_2() {
+ if (jj_scan_token(OPEN_BRACE)) return true;
+ if (jj_scan_token(STYLESHEET)) return true;
+ return false;
+ }
+
+ static final private boolean jj_3_5() {
+ if (jj_scan_token(OPEN_BRACE)) return true;
+ if (jj_scan_token(IGNORED_DESTINATION)) return true;
+ return false;
+ }
+
+ static final private boolean jj_3_1() {
+ if (jj_scan_token(OPEN_BRACE)) return true;
+ if (jj_scan_token(FONTTBL)) return true;
+ return false;
+ }
+
+ static final private boolean jj_3_4() {
+ if (jj_scan_token(OPEN_BRACE)) return true;
+ if (jj_scan_token(IGNORED_DESTINATION)) return true;
+ return false;
+ }
+
+ static private boolean jj_initialized_once = false;
+ static public RTFParserTokenManager token_source;
+ static SimpleCharStream jj_input_stream;
+ static public Token token, jj_nt;
+ static private int jj_ntk;
+ static private Token jj_scanpos, jj_lastpos;
+ static private int jj_la;
+ static public boolean lookingAhead = false;
+ static private boolean jj_semLA;
+ static private int jj_gen;
+ static final private int[] jj_la1 = new int[9];
+ static private int[] jj_la1_0;
+ static {
+ jj_la1_0();
+ }
+ private static void jj_la1_0() {
+ jj_la1_0 = new int[] {0x400000,0x400000,0x400000,0x70000,0x3000a0,0x3700a0,0x3700a0,0x3700a0,0x70000,};
+ }
+ static final private JJCalls[] jj_2_rtns = new JJCalls[5];
+ static private boolean jj_rescan = false;
+ static private int jj_gc = 0;
+
+ public RTFParser(java.io.InputStream stream) {
+ this(stream, null);
+ }
+ public RTFParser(java.io.InputStream stream, String encoding) {
+ if (jj_initialized_once) {
+ System.out.println("ERROR: Second call to constructor of static parser. You must");
+ System.out.println(" either use ReInit() or set the JavaCC option STATIC to false");
+ System.out.println(" during parser generation.");
+ throw new Error();
+ }
+ jj_initialized_once = true;
+ try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
+ token_source = new RTFParserTokenManager(jj_input_stream);
+ token = new Token();
+ jj_ntk = -1;
+ jj_gen = 0;
+ for (int i = 0; i < 9; i++) jj_la1[i] = -1;
+ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
+ }
+
+ static public void ReInit(java.io.InputStream stream) {
+ ReInit(stream, null);
+ }
+ static public void ReInit(java.io.InputStream stream, String encoding) {
+ try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
+ token_source.ReInit(jj_input_stream);
+ token = new Token();
+ jj_ntk = -1;
+ jj_gen = 0;
+ for (int i = 0; i < 9; i++) jj_la1[i] = -1;
+ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
+ }
+
+ public RTFParser(java.io.Reader stream) {
+ if (jj_initialized_once) {
+ System.out.println("ERROR: Second call to constructor of static parser. You must");
+ System.out.println(" either use ReInit() or set the JavaCC option STATIC to false");
+ System.out.println(" during parser generation.");
+ throw new Error();
+ }
+ jj_initialized_once = true;
+ jj_input_stream = new SimpleCharStream(stream, 1, 1);
+ token_source = new RTFParserTokenManager(jj_input_stream);
+ token = new Token();
+ jj_ntk = -1;
+ jj_gen = 0;
+ for (int i = 0; i < 9; i++) jj_la1[i] = -1;
+ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
+ }
+
+ static public void ReInit(java.io.Reader stream) {
+ jj_input_stream.ReInit(stream, 1, 1);
+ token_source.ReInit(jj_input_stream);
+ token = new Token();
+ jj_ntk = -1;
+ jj_gen = 0;
+ for (int i = 0; i < 9; i++) jj_la1[i] = -1;
+ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
+ }
+
+ public RTFParser(RTFParserTokenManager tm) {
+ if (jj_initialized_once) {
+ System.out.println("ERROR: Second call to constructor of static parser. You must");
+ System.out.println(" either use ReInit() or set the JavaCC option STATIC to false");
+ System.out.println(" during parser generation.");
+ throw new Error();
+ }
+ jj_initialized_once = true;
+ token_source = tm;
+ token = new Token();
+ jj_ntk = -1;
+ jj_gen = 0;
+ for (int i = 0; i < 9; i++) jj_la1[i] = -1;
+ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
+ }
+
+ public void ReInit(RTFParserTokenManager tm) {
+ token_source = tm;
+ token = new Token();
+ jj_ntk = -1;
+ jj_gen = 0;
+ for (int i = 0; i < 9; i++) jj_la1[i] = -1;
+ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
+ }
+
+ static final private Token jj_consume_token(int kind) throws ParseException {
+ Token oldToken;
+ if ((oldToken = token).next != null) token = token.next;
+ else token = token.next = token_source.getNextToken();
+ jj_ntk = -1;
+ if (token.kind == kind) {
+ jj_gen++;
+ if (++jj_gc > 100) {
+ jj_gc = 0;
+ for (int i = 0; i < jj_2_rtns.length; i++) {
+ JJCalls c = jj_2_rtns[i];
+ while (c != null) {
+ if (c.gen < jj_gen) c.first = null;
+ c = c.next;
+ }
+ }
+ }
+ return token;
+ }
+ token = oldToken;
+ jj_kind = kind;
+ throw generateParseException();
+ }
+
+ static private final class LookaheadSuccess extends java.lang.Error { }
+ static final private LookaheadSuccess jj_ls = new LookaheadSuccess();
+ static final private boolean jj_scan_token(int kind) {
+ if (jj_scanpos == jj_lastpos) {
+ jj_la--;
+ if (jj_scanpos.next == null) {
+ jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken();
+ } else {
+ jj_lastpos = jj_scanpos = jj_scanpos.next;
+ }
+ } else {
+ jj_scanpos = jj_scanpos.next;
+ }
+ if (jj_rescan) {
+ int i = 0; Token tok = token;
+ while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; }
+ if (tok != null) jj_add_error_token(kind, i);
+ }
+ if (jj_scanpos.kind != kind) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls;
+ return false;
+ }
+
+ static final public Token getNextToken() {
+ if (token.next != null) token = token.next;
+ else token = token.next = token_source.getNextToken();
+ jj_ntk = -1;
+ jj_gen++;
+ return token;
+ }
+
+ static final public Token getToken(int index) {
+ Token t = lookingAhead ? jj_scanpos : token;
+ for (int i = 0; i < index; i++) {
+ if (t.next != null) t = t.next;
+ else t = t.next = token_source.getNextToken();
+ }
+ return t;
+ }
+
+ static final private int jj_ntk() {
+ if ((jj_nt=token.next) == null)
+ return (jj_ntk = (token.next=token_source.getNextToken()).kind);
+ else
+ return (jj_ntk = jj_nt.kind);
+ }
+
+ static private java.util.Vector jj_expentries = new java.util.Vector();
+ static private int[] jj_expentry;
+ static private int jj_kind = -1;
+ static private int[] jj_lasttokens = new int[100];
+ static private int jj_endpos;
+
+ static private void jj_add_error_token(int kind, int pos) {
+ if (pos >= 100) return;
+ if (pos == jj_endpos + 1) {
+ jj_lasttokens[jj_endpos++] = kind;
+ } else if (jj_endpos != 0) {
+ jj_expentry = new int[jj_endpos];
+ for (int i = 0; i < jj_endpos; i++) {
+ jj_expentry[i] = jj_lasttokens[i];
+ }
+ boolean exists = false;
+ for (java.util.Enumeration e = jj_expentries.elements(); e.hasMoreElements();) {
+ int[] oldentry = (int[])(e.nextElement());
+ if (oldentry.length == jj_expentry.length) {
+ exists = true;
+ for (int i = 0; i < jj_expentry.length; i++) {
+ if (oldentry[i] != jj_expentry[i]) {
+ exists = false;
+ break;
+ }
+ }
+ if (exists) break;
+ }
+ }
+ if (!exists) jj_expentries.addElement(jj_expentry);
+ if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind;
+ }
+ }
+
+ static public ParseException generateParseException() {
+ jj_expentries.removeAllElements();
+ boolean[] la1tokens = new boolean[24];
+ for (int i = 0; i < 24; i++) {
+ la1tokens[i] = false;
+ }
+ if (jj_kind >= 0) {
+ la1tokens[jj_kind] = true;
+ jj_kind = -1;
+ }
+ for (int i = 0; i < 9; i++) {
+ if (jj_la1[i] == jj_gen) {
+ for (int j = 0; j < 32; j++) {
+ if ((jj_la1_0[i] & (1<<j)) != 0) {
+ la1tokens[j] = true;
+ }
+ }
+ }
+ }
+ for (int i = 0; i < 24; i++) {
+ if (la1tokens[i]) {
+ jj_expentry = new int[1];
+ jj_expentry[0] = i;
+ jj_expentries.addElement(jj_expentry);
+ }
+ }
+ jj_endpos = 0;
+ jj_rescan_token();
+ jj_add_error_token(0, 0);
+ int[][] exptokseq = new int[jj_expentries.size()][];
+ for (int i = 0; i < jj_expentries.size(); i++) {
+ exptokseq[i] = (int[])jj_expentries.elementAt(i);
+ }
+ return new ParseException(token, exptokseq, tokenImage);
+ }
+
+ static final public void enable_tracing() {
+ }
+
+ static final public void disable_tracing() {
+ }
+
+ static final private void jj_rescan_token() {
+ jj_rescan = true;
+ for (int i = 0; i < 5; i++) {
+ try {
+ JJCalls p = jj_2_rtns[i];
+ do {
+ if (p.gen > jj_gen) {
+ jj_la = p.arg; jj_lastpos = jj_scanpos = p.first;
+ switch (i) {
+ case 0: jj_3_1(); break;
+ case 1: jj_3_2(); break;
+ case 2: jj_3_3(); break;
+ case 3: jj_3_4(); break;
+ case 4: jj_3_5(); break;
+ }
+ }
+ p = p.next;
+ } while (p != null);
+ } catch(LookaheadSuccess ls) { }
+ }
+ jj_rescan = false;
+ }
+
+ static final private void jj_save(int index, int xla) {
+ JJCalls p = jj_2_rtns[index];
+ while (p.gen > jj_gen) {
+ if (p.next == null) { p = p.next = new JJCalls(); break; }
+ p = p.next;
+ }
+ p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla;
+ }
+
+ static final class JJCalls {
+ int gen;
+ Token first;
+ int arg;
+ JJCalls next;
+ }
+
+}
Propchange: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParser.jj
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParser.jj?rev=676446&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParser.jj (added)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParser.jj Sun Jul 13 14:45:56 2008
@@ -0,0 +1,311 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+//options {
+// DEBUG_PARSER = true;
+// DEBUG_TOKEN_MANAGER=true;
+//}
+
+PARSER_BEGIN(RTFParser)
+package org.apache.harmony.x.swing.text.rtf;
+
+import java.io.*;
+import javax.swing.text.Document;
+import javax.swing.text.DefaultStyledDocument;
+
+public class RTFParser {
+
+ private static RTFParserHandler handler;
+
+ public static void main(String args[]) throws Exception {
+ InputStream in;
+
+ if (args.length > 0)
+ in = new FileInputStream(args[0]);
+ else
+ in = System.in;
+
+ RTFParser parser = new RTFParser(in);
+ parser.parse(new DefaultStyledDocument(), 0);
+ }
+
+}
+
+PARSER_END(RTFParser)
+
+/*<*> MORE :
+{
+ "\\" : InControlWord
+}
+
+<InControlWord> TOKEN :
+{
+ <RTF: "rtf"<PARAM>> {System.out.println("rtf");} : DEFAULT
+}
+ (
+ documentBlock()
+<InControlWord> TOKEN :
+{
+ {System.out.println("param");} <PARAM: "123">
+}
+
+<InControlWord> MORE:
+{
+ <~[]> : DEFAULT
+}*/
+
+<*>
+MORE:
+{
+ <BACKSLASH: "\\"> : IN_CONTROL
+}
+
+<DEFAULT>
+SKIP :
+{
+ "\n"
+| "\r"
+| "\t"
+}
+
+<*>
+TOKEN:
+{
+ <OPEN_BRACE: "{"> : DEFAULT
+| <CLOSE_BRACE: "}"> : DEFAULT
+}
+
+<DEFAULT>
+TOKEN:
+{
+ <TEXT: (~["\\","{","}","\n","\r", "\t"])+>
+}
+
+<IN_CONTROL>
+SKIP:
+{
+ " " : DEFAULT
+| "\n" : DEFAULT
+| "\r" : DEFAULT
+| "\t" : DEFAULT
+}
+
+<IN_CONTROL>
+TOKEN:
+{
+ <RTF: "rtf">
+| <FONTTBL: "fonttbl">
+| <STYLESHEET: "stylesheet">
+| <INFO: "info">
+| <B: "b">
+| <I: "i">
+| <UL: "ul">
+//| <SECT: "sect">
+//| <SUBDOCUMENT: "subdocument">
+//| <PAR: "par">
+}
+
+<IN_CONTROL>
+TOKEN:
+{
+ <IGNORED_DESTINATION: "*">
+}
+
+<IN_CONTROL>
+TOKEN:
+{
+ <CONTROL_WORD: (["a"-"z", "A"-"Z"])+>
+| <CONTROL_SYMBOL: ~["a"-"z", "A"-"Z", "0"-"9", " ", "\t",
+ "{", "}", "\n", "\r", "\\"]>
+}
+
+<IN_CONTROL>
+TOKEN:
+{
+ <PARAM: (["-"])? (["0"-"9"])+>
+}
+
+<IN_CONTROL>
+SKIP:
+{
+ <~[]> : DEFAULT
+}
+
+
+
+public void parse(Document doc, int position) :
+{}
+{
+ {
+ handler = new RTFParserHandler(doc, position);
+ }
+ file() <EOF>
+}
+
+private int parameter() :
+{
+ Token param = null;
+}
+{
+ [param=<PARAM>]
+ {
+ return param == null ? -1 : Integer.parseInt(param.image);
+ }
+}
+
+/**
+ * Catches all unhandled control words.
+ */
+private void unknownControlWord() :
+{}
+{
+ <CONTROL_WORD> [<PARAM>]
+}
+
+/**
+ * Catches all unhandled control symbols.
+ */
+void unknownControlSymbol() :
+{}
+{
+ <CONTROL_SYMBOL>
+}
+
+void text() :
+{
+ Token text;
+}
+{
+ text=<TEXT>
+ {
+ handler.addText(text.image);
+ }
+}
+
+void file() :
+{}
+{
+ <OPEN_BRACE> header() document() <CLOSE_BRACE>
+}
+
+void header() :
+{}
+{
+ <RTF>[<PARAM>]
+}
+
+void document() :
+{}
+{
+ (
+ paragraph()
+ | LOOKAHEAD(<OPEN_BRACE> <FONTTBL>)
+ fonttbl()
+ | LOOKAHEAD(<OPEN_BRACE> <STYLESHEET>)
+ stylesheet()
+ | LOOKAHEAD(<OPEN_BRACE> <INFO>)
+ info()
+ | LOOKAHEAD(<OPEN_BRACE> <IGNORED_DESTINATION>)
+ ignoredDestination()
+ | documentBlock()
+ | unknownControlWord()
+ | unknownControlSymbol()
+ | text()
+ )+
+}
+
+/**
+ * A group.
+ */
+void documentBlock() :
+{}
+{
+ <OPEN_BRACE> { handler.startGroup(); }
+ document()
+ <CLOSE_BRACE> { handler.endGroup(); }
+}
+
+/**
+ * Ignored block of RTF file, currently is using to ignore unknown parts
+ * of file.
+ */
+void ignoredBlock() :
+{}
+{
+ (
+ LOOKAHEAD(<OPEN_BRACE> <IGNORED_DESTINATION>)
+ ignoredDestination()
+ | characterFormat() //TODO: Need to find a way to ignore control words declared as TOKENS
+ | unknownControlWord()
+ | unknownControlSymbol()
+ | <TEXT>
+ | <OPEN_BRACE> ignoredBlock() <CLOSE_BRACE>
+ )+
+}
+
+/**
+ * Group which starts with "{\*" and describes destination, currently this part
+ * is ignored.
+ */
+void ignoredDestination() :
+{}
+{
+ <OPEN_BRACE> <IGNORED_DESTINATION> ignoredBlock() <CLOSE_BRACE>
+}
+
+/**
+ * Part which describes font table group.
+ */
+void fonttbl() :
+{}
+{
+ <OPEN_BRACE> <FONTTBL> ignoredBlock() <CLOSE_BRACE>
+}
+
+/**
+ * Part which describes the style sheet group.
+ */
+void stylesheet() :
+{}
+{
+ <OPEN_BRACE> <STYLESHEET> ignoredBlock() <CLOSE_BRACE>
+}
+
+/**
+ * Part which describes the information group inside document area.
+ */
+void info() :
+{}
+{
+ <OPEN_BRACE> <INFO> ignoredBlock() <CLOSE_BRACE>
+}
+
+void paragraph() :
+{}
+{
+ characterFormat()
+}
+
+void characterFormat() :
+{
+ int param;
+}
+{
+ <B> param = parameter() { handler.setBold(param != 0); }
+| <I> param = parameter() { handler.setItalic(param != 0); }
+| <UL> param = parameter() { handler.setUnderline(param != 0); }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParser.jj
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParserConstants.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParserConstants.java?rev=676446&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParserConstants.java (added)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParserConstants.java Sun Jul 13 14:45:56 2008
@@ -0,0 +1,53 @@
+/* Generated By:JavaCC: Do not edit this line. RTFParserConstants.java */
+package org.apache.harmony.x.swing.text.rtf;
+
+public interface RTFParserConstants {
+
+ int EOF = 0;
+ int BACKSLASH = 1;
+ int OPEN_BRACE = 5;
+ int CLOSE_BRACE = 6;
+ int TEXT = 7;
+ int RTF = 12;
+ int FONTTBL = 13;
+ int STYLESHEET = 14;
+ int INFO = 15;
+ int B = 16;
+ int I = 17;
+ int UL = 18;
+ int IGNORED_DESTINATION = 19;
+ int CONTROL_WORD = 20;
+ int CONTROL_SYMBOL = 21;
+ int PARAM = 22;
+
+ int IN_CONTROL = 0;
+ int DEFAULT = 1;
+
+ String[] tokenImage = {
+ "<EOF>",
+ "\"\\\\\"",
+ "\"\\n\"",
+ "\"\\r\"",
+ "\"\\t\"",
+ "\"{\"",
+ "\"}\"",
+ "<TEXT>",
+ "\" \"",
+ "\"\\n\"",
+ "\"\\r\"",
+ "\"\\t\"",
+ "\"rtf\"",
+ "\"fonttbl\"",
+ "\"stylesheet\"",
+ "\"info\"",
+ "\"b\"",
+ "\"i\"",
+ "\"ul\"",
+ "\"*\"",
+ "<CONTROL_WORD>",
+ "<CONTROL_SYMBOL>",
+ "<PARAM>",
+ "<token of kind 23>",
+ };
+
+}
Propchange: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParserConstants.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParserHandler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParserHandler.java?rev=676446&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParserHandler.java (added)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParserHandler.java Sun Jul 13 14:45:56 2008
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.harmony.x.swing.text.rtf;
+
+import javax.swing.text.*;
+import java.util.Stack;
+
+/**
+ * @author ayzen
+ */
+public class RTFParserHandler {
+
+ private StyledDocument sdoc;
+ private Document doc;
+
+ private int offset;
+
+ private Stack<MutableAttributeSet> stylesStack;
+ private MutableAttributeSet currentStyle;
+
+ public RTFParserHandler(Document doc, int position) {
+ stylesStack = new Stack<MutableAttributeSet>();
+ currentStyle = new SimpleAttributeSet();
+ StyleConstants.setBidiLevel(currentStyle, 1);
+
+ if (doc instanceof StyledDocument)
+ sdoc = (StyledDocument) doc;
+ else
+ this.doc = doc;
+
+ offset = position;
+ }
+
+ public void addText(String text) {
+ try {
+ if (sdoc != null)
+ sdoc.insertString(offset, text, currentStyle);
+ else
+ doc.insertString(offset, text, null);
+
+ offset += text.length();
+ }
+ catch (BadLocationException e) {
+ //todo: throw it to RTFEditorKit?
+ }
+ }
+
+ public void startGroup() {
+ stylesStack.push(currentStyle);
+ currentStyle = new SimpleAttributeSet(currentStyle);
+ }
+
+ public void endGroup() {
+ currentStyle = stylesStack.pop();
+ }
+
+ public void setBold(boolean enable) {
+ StyleConstants.setBold(currentStyle, enable);
+ }
+
+ public void setItalic(boolean enable) {
+ StyleConstants.setItalic(currentStyle, enable);
+ }
+
+ public void setUnderline(boolean enable) {
+ StyleConstants.setUnderline(currentStyle, enable);
+ }
+
+}
Propchange: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParserHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParserTokenManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParserTokenManager.java?rev=676446&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParserTokenManager.java (added)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParserTokenManager.java Sun Jul 13 14:45:56 2008
@@ -0,0 +1,774 @@
+/* Generated By:JavaCC: Do not edit this line. RTFParserTokenManager.java */
+package org.apache.harmony.x.swing.text.rtf;
+import java.io.*;
+import javax.swing.text.Document;
+import javax.swing.text.DefaultStyledDocument;
+
+public class RTFParserTokenManager implements RTFParserConstants
+{
+ public static java.io.PrintStream debugStream = System.out;
+ public static void setDebugStream(java.io.PrintStream ds) { debugStream = ds; }
+private static final int jjStopStringLiteralDfa_1(int pos, long active0)
+{
+ switch (pos)
+ {
+ default :
+ return -1;
+ }
+}
+private static final int jjStartNfa_1(int pos, long active0)
+{
+ return jjMoveNfa_1(jjStopStringLiteralDfa_1(pos, active0), pos + 1);
+}
+static private final int jjStopAtPos(int pos, int kind)
+{
+ jjmatchedKind = kind;
+ jjmatchedPos = pos;
+ return pos + 1;
+}
+static private final int jjStartNfaWithStates_1(int pos, int kind, int state)
+{
+ jjmatchedKind = kind;
+ jjmatchedPos = pos;
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) { return pos + 1; }
+ return jjMoveNfa_1(state, pos + 1);
+}
+static private final int jjMoveStringLiteralDfa0_1()
+{
+ switch(curChar)
+ {
+ case 92:
+ return jjStopAtPos(0, 1);
+ case 123:
+ return jjStopAtPos(0, 5);
+ case 125:
+ return jjStopAtPos(0, 6);
+ default :
+ return jjMoveNfa_1(0, 0);
+ }
+}
+static private final void jjCheckNAdd(int state)
+{
+ if (jjrounds[state] != jjround)
+ {
+ jjstateSet[jjnewStateCnt++] = state;
+ jjrounds[state] = jjround;
+ }
+}
+static private final void jjAddStates(int start, int end)
+{
+ do {
+ jjstateSet[jjnewStateCnt++] = jjnextStates[start];
+ } while (start++ != end);
+}
+static private final void jjCheckNAddTwoStates(int state1, int state2)
+{
+ jjCheckNAdd(state1);
+ jjCheckNAdd(state2);
+}
+static private final void jjCheckNAddStates(int start, int end)
+{
+ do {
+ jjCheckNAdd(jjnextStates[start]);
+ } while (start++ != end);
+}
+static private final void jjCheckNAddStates(int start)
+{
+ jjCheckNAdd(jjnextStates[start]);
+ jjCheckNAdd(jjnextStates[start + 1]);
+}
+static final long[] jjbitVec0 = {
+ 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL
+};
+static private final int jjMoveNfa_1(int startState, int curPos)
+{
+ int[] nextStates;
+ int startsAt = 0;
+ jjnewStateCnt = 1;
+ int i = 1;
+ jjstateSet[0] = startState;
+ int j, kind = 0x7fffffff;
+ for (;;)
+ {
+ if (++jjround == 0x7fffffff)
+ ReInitRounds();
+ if (curChar < 64)
+ {
+ long l = 1L << curChar;
+ MatchLoop: do
+ {
+ switch(jjstateSet[--i])
+ {
+ case 0:
+ if ((0xffffffffffffd9ffL & l) == 0L)
+ break;
+ kind = 7;
+ jjstateSet[jjnewStateCnt++] = 0;
+ break;
+ default : break;
+ }
+ } while(i != startsAt);
+ }
+ else if (curChar < 128)
+ {
+ long l = 1L << (curChar & 077);
+ MatchLoop: do
+ {
+ switch(jjstateSet[--i])
+ {
+ case 0:
+ if ((0xd7ffffffefffffffL & l) == 0L)
+ break;
+ kind = 7;
+ jjstateSet[jjnewStateCnt++] = 0;
+ break;
+ default : break;
+ }
+ } while(i != startsAt);
+ }
+ else
+ {
+ int i2 = (curChar & 0xff) >> 6;
+ long l2 = 1L << (curChar & 077);
+ MatchLoop: do
+ {
+ switch(jjstateSet[--i])
+ {
+ case 0:
+ if ((jjbitVec0[i2] & l2) == 0L)
+ break;
+ if (kind > 7)
+ kind = 7;
+ jjstateSet[jjnewStateCnt++] = 0;
+ break;
+ default : break;
+ }
+ } while(i != startsAt);
+ }
+ if (kind != 0x7fffffff)
+ {
+ jjmatchedKind = kind;
+ jjmatchedPos = curPos;
+ kind = 0x7fffffff;
+ }
+ ++curPos;
+ if ((i = jjnewStateCnt) == (startsAt = 1 - (jjnewStateCnt = startsAt)))
+ return curPos;
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) { return curPos; }
+ }
+}
+private static final int jjStopStringLiteralDfa_0(int pos, long active0)
+{
+ switch (pos)
+ {
+ case 0:
+ if ((active0 & 0x38000L) != 0L)
+ return 0;
+ if ((active0 & 0x47000L) != 0L)
+ {
+ jjmatchedKind = 20;
+ return 0;
+ }
+ return -1;
+ case 1:
+ if ((active0 & 0x40000L) != 0L)
+ return 0;
+ if ((active0 & 0xf000L) != 0L)
+ {
+ jjmatchedKind = 20;
+ jjmatchedPos = 1;
+ return 0;
+ }
+ return -1;
+ case 2:
+ if ((active0 & 0x1000L) != 0L)
+ return 0;
+ if ((active0 & 0xe000L) != 0L)
+ {
+ jjmatchedKind = 20;
+ jjmatchedPos = 2;
+ return 0;
+ }
+ return -1;
+ case 3:
+ if ((active0 & 0x8000L) != 0L)
+ return 0;
+ if ((active0 & 0x6000L) != 0L)
+ {
+ jjmatchedKind = 20;
+ jjmatchedPos = 3;
+ return 0;
+ }
+ return -1;
+ case 4:
+ if ((active0 & 0x6000L) != 0L)
+ {
+ jjmatchedKind = 20;
+ jjmatchedPos = 4;
+ return 0;
+ }
+ return -1;
+ case 5:
+ if ((active0 & 0x6000L) != 0L)
+ {
+ jjmatchedKind = 20;
+ jjmatchedPos = 5;
+ return 0;
+ }
+ return -1;
+ case 6:
+ if ((active0 & 0x4000L) != 0L)
+ {
+ jjmatchedKind = 20;
+ jjmatchedPos = 6;
+ return 0;
+ }
+ if ((active0 & 0x2000L) != 0L)
+ return 0;
+ return -1;
+ case 7:
+ if ((active0 & 0x4000L) != 0L)
+ {
+ jjmatchedKind = 20;
+ jjmatchedPos = 7;
+ return 0;
+ }
+ return -1;
+ case 8:
+ if ((active0 & 0x4000L) != 0L)
+ {
+ jjmatchedKind = 20;
+ jjmatchedPos = 8;
+ return 0;
+ }
+ return -1;
+ default :
+ return -1;
+ }
+}
+private static final int jjStartNfa_0(int pos, long active0)
+{
+ return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1);
+}
+static private final int jjStartNfaWithStates_0(int pos, int kind, int state)
+{
+ jjmatchedKind = kind;
+ jjmatchedPos = pos;
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) { return pos + 1; }
+ return jjMoveNfa_0(state, pos + 1);
+}
+static private final int jjMoveStringLiteralDfa0_0()
+{
+ switch(curChar)
+ {
+ case 9:
+ return jjStopAtPos(0, 11);
+ case 10:
+ return jjStopAtPos(0, 9);
+ case 13:
+ return jjStopAtPos(0, 10);
+ case 32:
+ return jjStopAtPos(0, 8);
+ case 42:
+ return jjStopAtPos(0, 19);
+ case 92:
+ return jjStopAtPos(0, 1);
+ case 98:
+ return jjStartNfaWithStates_0(0, 16, 0);
+ case 102:
+ return jjMoveStringLiteralDfa1_0(0x2000L);
+ case 105:
+ jjmatchedKind = 17;
+ return jjMoveStringLiteralDfa1_0(0x8000L);
+ case 114:
+ return jjMoveStringLiteralDfa1_0(0x1000L);
+ case 115:
+ return jjMoveStringLiteralDfa1_0(0x4000L);
+ case 117:
+ return jjMoveStringLiteralDfa1_0(0x40000L);
+ case 123:
+ return jjStopAtPos(0, 5);
+ case 125:
+ return jjStopAtPos(0, 6);
+ default :
+ return jjMoveNfa_0(1, 0);
+ }
+}
+static private final int jjMoveStringLiteralDfa1_0(long active0)
+{
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(0, active0);
+ return 1;
+ }
+ switch(curChar)
+ {
+ case 108:
+ if ((active0 & 0x40000L) != 0L)
+ return jjStartNfaWithStates_0(1, 18, 0);
+ break;
+ case 110:
+ return jjMoveStringLiteralDfa2_0(active0, 0x8000L);
+ case 111:
+ return jjMoveStringLiteralDfa2_0(active0, 0x2000L);
+ case 116:
+ return jjMoveStringLiteralDfa2_0(active0, 0x5000L);
+ default :
+ break;
+ }
+ return jjStartNfa_0(0, active0);
+}
+static private final int jjMoveStringLiteralDfa2_0(long old0, long active0)
+{
+ if (((active0 &= old0)) == 0L)
+ return jjStartNfa_0(0, old0);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(1, active0);
+ return 2;
+ }
+ switch(curChar)
+ {
+ case 102:
+ if ((active0 & 0x1000L) != 0L)
+ return jjStartNfaWithStates_0(2, 12, 0);
+ return jjMoveStringLiteralDfa3_0(active0, 0x8000L);
+ case 110:
+ return jjMoveStringLiteralDfa3_0(active0, 0x2000L);
+ case 121:
+ return jjMoveStringLiteralDfa3_0(active0, 0x4000L);
+ default :
+ break;
+ }
+ return jjStartNfa_0(1, active0);
+}
+static private final int jjMoveStringLiteralDfa3_0(long old0, long active0)
+{
+ if (((active0 &= old0)) == 0L)
+ return jjStartNfa_0(1, old0);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(2, active0);
+ return 3;
+ }
+ switch(curChar)
+ {
+ case 108:
+ return jjMoveStringLiteralDfa4_0(active0, 0x4000L);
+ case 111:
+ if ((active0 & 0x8000L) != 0L)
+ return jjStartNfaWithStates_0(3, 15, 0);
+ break;
+ case 116:
+ return jjMoveStringLiteralDfa4_0(active0, 0x2000L);
+ default :
+ break;
+ }
+ return jjStartNfa_0(2, active0);
+}
+static private final int jjMoveStringLiteralDfa4_0(long old0, long active0)
+{
+ if (((active0 &= old0)) == 0L)
+ return jjStartNfa_0(2, old0);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(3, active0);
+ return 4;
+ }
+ switch(curChar)
+ {
+ case 101:
+ return jjMoveStringLiteralDfa5_0(active0, 0x4000L);
+ case 116:
+ return jjMoveStringLiteralDfa5_0(active0, 0x2000L);
+ default :
+ break;
+ }
+ return jjStartNfa_0(3, active0);
+}
+static private final int jjMoveStringLiteralDfa5_0(long old0, long active0)
+{
+ if (((active0 &= old0)) == 0L)
+ return jjStartNfa_0(3, old0);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(4, active0);
+ return 5;
+ }
+ switch(curChar)
+ {
+ case 98:
+ return jjMoveStringLiteralDfa6_0(active0, 0x2000L);
+ case 115:
+ return jjMoveStringLiteralDfa6_0(active0, 0x4000L);
+ default :
+ break;
+ }
+ return jjStartNfa_0(4, active0);
+}
+static private final int jjMoveStringLiteralDfa6_0(long old0, long active0)
+{
+ if (((active0 &= old0)) == 0L)
+ return jjStartNfa_0(4, old0);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(5, active0);
+ return 6;
+ }
+ switch(curChar)
+ {
+ case 104:
+ return jjMoveStringLiteralDfa7_0(active0, 0x4000L);
+ case 108:
+ if ((active0 & 0x2000L) != 0L)
+ return jjStartNfaWithStates_0(6, 13, 0);
+ break;
+ default :
+ break;
+ }
+ return jjStartNfa_0(5, active0);
+}
+static private final int jjMoveStringLiteralDfa7_0(long old0, long active0)
+{
+ if (((active0 &= old0)) == 0L)
+ return jjStartNfa_0(5, old0);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(6, active0);
+ return 7;
+ }
+ switch(curChar)
+ {
+ case 101:
+ return jjMoveStringLiteralDfa8_0(active0, 0x4000L);
+ default :
+ break;
+ }
+ return jjStartNfa_0(6, active0);
+}
+static private final int jjMoveStringLiteralDfa8_0(long old0, long active0)
+{
+ if (((active0 &= old0)) == 0L)
+ return jjStartNfa_0(6, old0);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(7, active0);
+ return 8;
+ }
+ switch(curChar)
+ {
+ case 101:
+ return jjMoveStringLiteralDfa9_0(active0, 0x4000L);
+ default :
+ break;
+ }
+ return jjStartNfa_0(7, active0);
+}
+static private final int jjMoveStringLiteralDfa9_0(long old0, long active0)
+{
+ if (((active0 &= old0)) == 0L)
+ return jjStartNfa_0(7, old0);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(8, active0);
+ return 9;
+ }
+ switch(curChar)
+ {
+ case 116:
+ if ((active0 & 0x4000L) != 0L)
+ return jjStartNfaWithStates_0(9, 14, 0);
+ break;
+ default :
+ break;
+ }
+ return jjStartNfa_0(8, active0);
+}
+static private final int jjMoveNfa_0(int startState, int curPos)
+{
+ int[] nextStates;
+ int startsAt = 0;
+ jjnewStateCnt = 4;
+ int i = 1;
+ jjstateSet[0] = startState;
+ int j, kind = 0x7fffffff;
+ for (;;)
+ {
+ if (++jjround == 0x7fffffff)
+ ReInitRounds();
+ if (curChar < 64)
+ {
+ long l = 1L << curChar;
+ MatchLoop: do
+ {
+ switch(jjstateSet[--i])
+ {
+ case 1:
+ if ((0xfc00fffeffffd9ffL & l) != 0L)
+ {
+ if (kind > 21)
+ kind = 21;
+ }
+ else if ((0x3ff000000000000L & l) != 0L)
+ {
+ if (kind > 22)
+ kind = 22;
+ jjCheckNAdd(3);
+ }
+ if (curChar == 45)
+ jjCheckNAdd(3);
+ break;
+ case 2:
+ if (curChar == 45)
+ jjCheckNAdd(3);
+ break;
+ case 3:
+ if ((0x3ff000000000000L & l) == 0L)
+ break;
+ kind = 22;
+ jjCheckNAdd(3);
+ break;
+ default : break;
+ }
+ } while(i != startsAt);
+ }
+ else if (curChar < 128)
+ {
+ long l = 1L << (curChar & 077);
+ MatchLoop: do
+ {
+ switch(jjstateSet[--i])
+ {
+ case 1:
+ if ((0x7fffffe07fffffeL & l) != 0L)
+ {
+ if (kind > 20)
+ kind = 20;
+ jjCheckNAdd(0);
+ }
+ else if ((0xd0000001e8000001L & l) != 0L)
+ {
+ if (kind > 21)
+ kind = 21;
+ }
+ break;
+ case 0:
+ if ((0x7fffffe07fffffeL & l) == 0L)
+ break;
+ kind = 20;
+ jjCheckNAdd(0);
+ break;
+ default : break;
+ }
+ } while(i != startsAt);
+ }
+ else
+ {
+ int i2 = (curChar & 0xff) >> 6;
+ long l2 = 1L << (curChar & 077);
+ MatchLoop: do
+ {
+ switch(jjstateSet[--i])
+ {
+ case 1:
+ if ((jjbitVec0[i2] & l2) != 0L && kind > 21)
+ kind = 21;
+ break;
+ default : break;
+ }
+ } while(i != startsAt);
+ }
+ if (kind != 0x7fffffff)
+ {
+ jjmatchedKind = kind;
+ jjmatchedPos = curPos;
+ kind = 0x7fffffff;
+ }
+ ++curPos;
+ if ((i = jjnewStateCnt) == (startsAt = 4 - (jjnewStateCnt = startsAt)))
+ return curPos;
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) { return curPos; }
+ }
+}
+static final int[] jjnextStates = {
+};
+public static final String[] jjstrLiteralImages = {
+null, null, null, null, null, null, null, null, null, null, null, null, null,
+null, null, null, null, null, null, null, null, null, null, null, };
+public static final String[] lexStateNames = {
+ "IN_CONTROL",
+ "DEFAULT",
+};
+public static final int[] jjnewLexState = {
+ -1, 0, -1, -1, -1, 1, 1, -1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1,
+};
+static final long[] jjtoToken = {
+ 0x7ff0e1L,
+};
+static final long[] jjtoSkip = {
+ 0x800f1cL,
+};
+static final long[] jjtoMore = {
+ 0x2L,
+};
+static protected SimpleCharStream input_stream;
+static private final int[] jjrounds = new int[4];
+static private final int[] jjstateSet = new int[8];
+static protected char curChar;
+public RTFParserTokenManager(SimpleCharStream stream){
+ if (input_stream != null)
+ throw new TokenMgrError("ERROR: Second call to constructor of static lexer. You must use ReInit() to initialize the static variables.", TokenMgrError.STATIC_LEXER_ERROR);
+ input_stream = stream;
+}
+public RTFParserTokenManager(SimpleCharStream stream, int lexState){
+ this(stream);
+ SwitchTo(lexState);
+}
+static public void ReInit(SimpleCharStream stream)
+{
+ jjmatchedPos = jjnewStateCnt = 0;
+ curLexState = defaultLexState;
+ input_stream = stream;
+ ReInitRounds();
+}
+static private final void ReInitRounds()
+{
+ int i;
+ jjround = 0x80000001;
+ for (i = 4; i-- > 0;)
+ jjrounds[i] = 0x80000000;
+}
+static public void ReInit(SimpleCharStream stream, int lexState)
+{
+ ReInit(stream);
+ SwitchTo(lexState);
+}
+static public void SwitchTo(int lexState)
+{
+ if (lexState >= 2 || lexState < 0)
+ throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE);
+ else
+ curLexState = lexState;
+}
+
+static protected Token jjFillToken()
+{
+ Token t = Token.newToken(jjmatchedKind);
+ t.kind = jjmatchedKind;
+ String im = jjstrLiteralImages[jjmatchedKind];
+ t.image = (im == null) ? input_stream.GetImage() : im;
+ t.beginLine = input_stream.getBeginLine();
+ t.beginColumn = input_stream.getBeginColumn();
+ t.endLine = input_stream.getEndLine();
+ t.endColumn = input_stream.getEndColumn();
+ return t;
+}
+
+static int curLexState = 1;
+static int defaultLexState = 1;
+static int jjnewStateCnt;
+static int jjround;
+static int jjmatchedPos;
+static int jjmatchedKind;
+
+public static Token getNextToken()
+{
+ int kind;
+ Token specialToken = null;
+ Token matchedToken;
+ int curPos = 0;
+
+ EOFLoop :
+ for (;;)
+ {
+ try
+ {
+ curChar = input_stream.BeginToken();
+ }
+ catch(java.io.IOException e)
+ {
+ jjmatchedKind = 0;
+ matchedToken = jjFillToken();
+ return matchedToken;
+ }
+
+ for (;;)
+ {
+ switch(curLexState)
+ {
+ case 0:
+ jjmatchedKind = 0x7fffffff;
+ jjmatchedPos = 0;
+ curPos = jjMoveStringLiteralDfa0_0();
+ if (jjmatchedPos == 0 && jjmatchedKind > 23)
+ {
+ jjmatchedKind = 23;
+ }
+ break;
+ case 1:
+ try { input_stream.backup(0);
+ while (curChar <= 13 && (0x2600L & (1L << curChar)) != 0L)
+ curChar = input_stream.BeginToken();
+ }
+ catch (java.io.IOException e1) { continue EOFLoop; }
+ jjmatchedKind = 0x7fffffff;
+ jjmatchedPos = 0;
+ curPos = jjMoveStringLiteralDfa0_1();
+ break;
+ }
+ if (jjmatchedKind != 0x7fffffff)
+ {
+ if (jjmatchedPos + 1 < curPos)
+ input_stream.backup(curPos - jjmatchedPos - 1);
+ if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)
+ {
+ matchedToken = jjFillToken();
+ if (jjnewLexState[jjmatchedKind] != -1)
+ curLexState = jjnewLexState[jjmatchedKind];
+ return matchedToken;
+ }
+ else if ((jjtoSkip[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)
+ {
+ if (jjnewLexState[jjmatchedKind] != -1)
+ curLexState = jjnewLexState[jjmatchedKind];
+ continue EOFLoop;
+ }
+ if (jjnewLexState[jjmatchedKind] != -1)
+ curLexState = jjnewLexState[jjmatchedKind];
+ curPos = 0;
+ jjmatchedKind = 0x7fffffff;
+ try {
+ curChar = input_stream.readChar();
+ continue;
+ }
+ catch (java.io.IOException e1) { }
+ }
+ int error_line = input_stream.getEndLine();
+ int error_column = input_stream.getEndColumn();
+ String error_after = null;
+ boolean EOFSeen = false;
+ try { input_stream.readChar(); input_stream.backup(1); }
+ catch (java.io.IOException e1) {
+ EOFSeen = true;
+ error_after = curPos <= 1 ? "" : input_stream.GetImage();
+ if (curChar == '\n' || curChar == '\r') {
+ error_line++;
+ error_column = 0;
+ }
+ else
+ error_column++;
+ }
+ if (!EOFSeen) {
+ input_stream.backup(1);
+ error_after = curPos <= 1 ? "" : input_stream.GetImage();
+ }
+ throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR);
+ }
+ }
+}
+
+}
Propchange: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/RTFParserTokenManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/SimpleCharStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/SimpleCharStream.java?rev=676446&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/SimpleCharStream.java (added)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/SimpleCharStream.java Sun Jul 13 14:45:56 2008
@@ -0,0 +1,443 @@
+/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 4.0 */
+package org.apache.harmony.x.swing.text.rtf;
+
+/**
+ * An implementation of interface CharStream, where the stream is assumed to
+ * contain only ASCII characters (without unicode processing).
+ */
+
+public class SimpleCharStream
+{
+ public static final boolean staticFlag = true;
+ static int bufsize;
+ static int available;
+ static int tokenBegin;
+ static public int bufpos = -1;
+ static protected int bufline[];
+ static protected int bufcolumn[];
+
+ static protected int column = 0;
+ static protected int line = 1;
+
+ static protected boolean prevCharIsCR = false;
+ static protected boolean prevCharIsLF = false;
+
+ static protected java.io.Reader inputStream;
+
+ static protected char[] buffer;
+ static protected int maxNextCharInd = 0;
+ static protected int inBuf = 0;
+ static protected int tabSize = 8;
+
+ static protected void setTabSize(int i) { tabSize = i; }
+ static protected int getTabSize(int i) { return tabSize; }
+
+
+ static protected void ExpandBuff(boolean wrapAround)
+ {
+ char[] newbuffer = new char[bufsize + 2048];
+ int newbufline[] = new int[bufsize + 2048];
+ int newbufcolumn[] = new int[bufsize + 2048];
+
+ try
+ {
+ if (wrapAround)
+ {
+ System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
+ System.arraycopy(buffer, 0, newbuffer,
+ bufsize - tokenBegin, bufpos);
+ buffer = newbuffer;
+
+ System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
+ System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
+ bufline = newbufline;
+
+ System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
+ System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
+ bufcolumn = newbufcolumn;
+
+ maxNextCharInd = (bufpos += (bufsize - tokenBegin));
+ }
+ else
+ {
+ System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
+ buffer = newbuffer;
+
+ System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
+ bufline = newbufline;
+
+ System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
+ bufcolumn = newbufcolumn;
+
+ maxNextCharInd = (bufpos -= tokenBegin);
+ }
+ }
+ catch (Throwable t)
+ {
+ throw new Error(t.getMessage());
+ }
+
+
+ bufsize += 2048;
+ available = bufsize;
+ tokenBegin = 0;
+ }
+
+ static protected void FillBuff() throws java.io.IOException
+ {
+ if (maxNextCharInd == available)
+ {
+ if (available == bufsize)
+ {
+ if (tokenBegin > 2048)
+ {
+ bufpos = maxNextCharInd = 0;
+ available = tokenBegin;
+ }
+ else if (tokenBegin < 0)
+ bufpos = maxNextCharInd = 0;
+ else
+ ExpandBuff(false);
+ }
+ else if (available > tokenBegin)
+ available = bufsize;
+ else if ((tokenBegin - available) < 2048)
+ ExpandBuff(true);
+ else
+ available = tokenBegin;
+ }
+
+ int i;
+ try {
+ if ((i = inputStream.read(buffer, maxNextCharInd,
+ available - maxNextCharInd)) == -1)
+ {
+ inputStream.close();
+ throw new java.io.IOException();
+ }
+ else
+ maxNextCharInd += i;
+ return;
+ }
+ catch(java.io.IOException e) {
+ --bufpos;
+ backup(0);
+ if (tokenBegin == -1)
+ tokenBegin = bufpos;
+ throw e;
+ }
+ }
+
+ static public char BeginToken() throws java.io.IOException
+ {
+ tokenBegin = -1;
+ char c = readChar();
+ tokenBegin = bufpos;
+
+ return c;
+ }
+
+ static protected void UpdateLineColumn(char c)
+ {
+ column++;
+
+ if (prevCharIsLF)
+ {
+ prevCharIsLF = false;
+ line += (column = 1);
+ }
+ else if (prevCharIsCR)
+ {
+ prevCharIsCR = false;
+ if (c == '\n')
+ {
+ prevCharIsLF = true;
+ }
+ else
+ line += (column = 1);
+ }
+
+ switch (c)
+ {
+ case '\r' :
+ prevCharIsCR = true;
+ break;
+ case '\n' :
+ prevCharIsLF = true;
+ break;
+ case '\t' :
+ column--;
+ column += (tabSize - (column % tabSize));
+ break;
+ default :
+ break;
+ }
+
+ bufline[bufpos] = line;
+ bufcolumn[bufpos] = column;
+ }
+
+ static public char readChar() throws java.io.IOException
+ {
+ if (inBuf > 0)
+ {
+ --inBuf;
+
+ if (++bufpos == bufsize)
+ bufpos = 0;
+
+ return buffer[bufpos];
+ }
+
+ if (++bufpos >= maxNextCharInd)
+ FillBuff();
+
+ char c = buffer[bufpos];
+
+ UpdateLineColumn(c);
+ return (c);
+ }
+
+ /**
+ * @deprecated
+ * @see #getEndColumn
+ */
+
+ static public int getColumn() {
+ return bufcolumn[bufpos];
+ }
+
+ /**
+ * @deprecated
+ * @see #getEndLine
+ */
+
+ static public int getLine() {
+ return bufline[bufpos];
+ }
+
+ static public int getEndColumn() {
+ return bufcolumn[bufpos];
+ }
+
+ static public int getEndLine() {
+ return bufline[bufpos];
+ }
+
+ static public int getBeginColumn() {
+ return bufcolumn[tokenBegin];
+ }
+
+ static public int getBeginLine() {
+ return bufline[tokenBegin];
+ }
+
+ static public void backup(int amount) {
+
+ inBuf += amount;
+ if ((bufpos -= amount) < 0)
+ bufpos += bufsize;
+ }
+
+ public SimpleCharStream(java.io.Reader dstream, int startline,
+ int startcolumn, int buffersize)
+ {
+ if (inputStream != null)
+ throw new Error("\n ERROR: Second call to the constructor of a static SimpleCharStream. You must\n" +
+ " either use ReInit() or set the JavaCC option STATIC to false\n" +
+ " during the generation of this class.");
+ inputStream = dstream;
+ line = startline;
+ column = startcolumn - 1;
+
+ available = bufsize = buffersize;
+ buffer = new char[buffersize];
+ bufline = new int[buffersize];
+ bufcolumn = new int[buffersize];
+ }
+
+ public SimpleCharStream(java.io.Reader dstream, int startline,
+ int startcolumn)
+ {
+ this(dstream, startline, startcolumn, 4096);
+ }
+
+ public SimpleCharStream(java.io.Reader dstream)
+ {
+ this(dstream, 1, 1, 4096);
+ }
+ public void ReInit(java.io.Reader dstream, int startline,
+ int startcolumn, int buffersize)
+ {
+ inputStream = dstream;
+ line = startline;
+ column = startcolumn - 1;
+
+ if (buffer == null || buffersize != buffer.length)
+ {
+ available = bufsize = buffersize;
+ buffer = new char[buffersize];
+ bufline = new int[buffersize];
+ bufcolumn = new int[buffersize];
+ }
+ prevCharIsLF = prevCharIsCR = false;
+ tokenBegin = inBuf = maxNextCharInd = 0;
+ bufpos = -1;
+ }
+
+ public void ReInit(java.io.Reader dstream, int startline,
+ int startcolumn)
+ {
+ ReInit(dstream, startline, startcolumn, 4096);
+ }
+
+ public void ReInit(java.io.Reader dstream)
+ {
+ ReInit(dstream, 1, 1, 4096);
+ }
+ public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline,
+ int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
+ {
+ this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
+ }
+
+ public SimpleCharStream(java.io.InputStream dstream, int startline,
+ int startcolumn, int buffersize)
+ {
+ this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
+ }
+
+ public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline,
+ int startcolumn) throws java.io.UnsupportedEncodingException
+ {
+ this(dstream, encoding, startline, startcolumn, 4096);
+ }
+
+ public SimpleCharStream(java.io.InputStream dstream, int startline,
+ int startcolumn)
+ {
+ this(dstream, startline, startcolumn, 4096);
+ }
+
+ public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
+ {
+ this(dstream, encoding, 1, 1, 4096);
+ }
+
+ public SimpleCharStream(java.io.InputStream dstream)
+ {
+ this(dstream, 1, 1, 4096);
+ }
+
+ public void ReInit(java.io.InputStream dstream, String encoding, int startline,
+ int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
+ {
+ ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
+ }
+
+ public void ReInit(java.io.InputStream dstream, int startline,
+ int startcolumn, int buffersize)
+ {
+ ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
+ }
+
+ public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
+ {
+ ReInit(dstream, encoding, 1, 1, 4096);
+ }
+
+ public void ReInit(java.io.InputStream dstream)
+ {
+ ReInit(dstream, 1, 1, 4096);
+ }
+ public void ReInit(java.io.InputStream dstream, String encoding, int startline,
+ int startcolumn) throws java.io.UnsupportedEncodingException
+ {
+ ReInit(dstream, encoding, startline, startcolumn, 4096);
+ }
+ public void ReInit(java.io.InputStream dstream, int startline,
+ int startcolumn)
+ {
+ ReInit(dstream, startline, startcolumn, 4096);
+ }
+ static public String GetImage()
+ {
+ if (bufpos >= tokenBegin)
+ return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
+ else
+ return new String(buffer, tokenBegin, bufsize - tokenBegin) +
+ new String(buffer, 0, bufpos + 1);
+ }
+
+ static public char[] GetSuffix(int len)
+ {
+ char[] ret = new char[len];
+
+ if ((bufpos + 1) >= len)
+ System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
+ else
+ {
+ System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
+ len - bufpos - 1);
+ System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
+ }
+
+ return ret;
+ }
+
+ static public void Done()
+ {
+ buffer = null;
+ bufline = null;
+ bufcolumn = null;
+ }
+
+ /**
+ * Method to adjust line and column numbers for the start of a token.
+ */
+ static public void adjustBeginLineColumn(int newLine, int newCol)
+ {
+ int start = tokenBegin;
+ int len;
+
+ if (bufpos >= tokenBegin)
+ {
+ len = bufpos - tokenBegin + inBuf + 1;
+ }
+ else
+ {
+ len = bufsize - tokenBegin + bufpos + 1 + inBuf;
+ }
+
+ int i = 0, j = 0, k = 0;
+ int nextColDiff = 0, columnDiff = 0;
+
+ while (i < len &&
+ bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
+ {
+ bufline[j] = newLine;
+ nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
+ bufcolumn[j] = newCol + columnDiff;
+ columnDiff = nextColDiff;
+ i++;
+ }
+
+ if (i < len)
+ {
+ bufline[j] = newLine++;
+ bufcolumn[j] = newCol + columnDiff;
+
+ while (i++ < len)
+ {
+ if (bufline[j = start % bufsize] != bufline[++start % bufsize])
+ bufline[j] = newLine++;
+ else
+ bufline[j] = newLine;
+ }
+ }
+
+ line = bufline[j];
+ column = bufcolumn[j];
+ }
+
+}
Propchange: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/SimpleCharStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/Token.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/Token.java?rev=676446&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/Token.java (added)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/Token.java Sun Jul 13 14:45:56 2008
@@ -0,0 +1,81 @@
+/* Generated By:JavaCC: Do not edit this line. Token.java Version 3.0 */
+package org.apache.harmony.x.swing.text.rtf;
+
+/**
+ * Describes the input token stream.
+ */
+
+public class Token {
+
+ /**
+ * An integer that describes the kind of this token. This numbering
+ * system is determined by JavaCCParser, and a table of these numbers is
+ * stored in the file ...Constants.java.
+ */
+ public int kind;
+
+ /**
+ * beginLine and beginColumn describe the position of the first character
+ * of this token; endLine and endColumn describe the position of the
+ * last character of this token.
+ */
+ public int beginLine, beginColumn, endLine, endColumn;
+
+ /**
+ * The string image of the token.
+ */
+ public String image;
+
+ /**
+ * A reference to the next regular (non-special) token from the input
+ * stream. If this is the last token from the input stream, or if the
+ * token manager has not read tokens beyond this one, this field is
+ * set to null. This is true only if this token is also a regular
+ * token. Otherwise, see below for a description of the contents of
+ * this field.
+ */
+ public Token next;
+
+ /**
+ * This field is used to access special tokens that occur prior to this
+ * token, but after the immediately preceding regular (non-special) token.
+ * If there are no such special tokens, this field is set to null.
+ * When there are more than one such special token, this field refers
+ * to the last of these special tokens, which in turn refers to the next
+ * previous special token through its specialToken field, and so on
+ * until the first special token (whose specialToken field is null).
+ * The next fields of special tokens refer to other special tokens that
+ * immediately follow it (without an intervening regular token). If there
+ * is no such token, this field is null.
+ */
+ public Token specialToken;
+
+ /**
+ * Returns the image.
+ */
+ public String toString()
+ {
+ return image;
+ }
+
+ /**
+ * Returns a new Token object, by default. However, if you want, you
+ * can create and return subclass objects based on the value of ofKind.
+ * Simply add the cases to the switch for all those special cases.
+ * For example, if you have a subclass of Token called IDToken that
+ * you want to create if ofKind is ID, simlpy add something like :
+ *
+ * case MyParserConstants.ID : return new IDToken();
+ *
+ * to the following switch statement. Then you can cast matchedToken
+ * variable to the appropriate type and use it in your lexical actions.
+ */
+ public static final Token newToken(int ofKind)
+ {
+ switch(ofKind)
+ {
+ default : return new Token();
+ }
+ }
+
+}
Propchange: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/Token.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/TokenMgrError.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/TokenMgrError.java?rev=676446&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/TokenMgrError.java (added)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/TokenMgrError.java Sun Jul 13 14:45:56 2008
@@ -0,0 +1,133 @@
+/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
+package org.apache.harmony.x.swing.text.rtf;
+
+public class TokenMgrError extends Error
+{
+ /*
+ * Ordinals for various reasons why an Error of this type can be thrown.
+ */
+
+ /**
+ * Lexical error occured.
+ */
+ static final int LEXICAL_ERROR = 0;
+
+ /**
+ * An attempt wass made to create a second instance of a static token manager.
+ */
+ static final int STATIC_LEXER_ERROR = 1;
+
+ /**
+ * Tried to change to an invalid lexical state.
+ */
+ static final int INVALID_LEXICAL_STATE = 2;
+
+ /**
+ * Detected (and bailed out of) an infinite loop in the token manager.
+ */
+ static final int LOOP_DETECTED = 3;
+
+ /**
+ * Indicates the reason why the exception is thrown. It will have
+ * one of the above 4 values.
+ */
+ int errorCode;
+
+ /**
+ * Replaces unprintable characters by their espaced (or unicode escaped)
+ * equivalents in the given string
+ */
+ protected static final String addEscapes(String str) {
+ StringBuffer retval = new StringBuffer();
+ char ch;
+ for (int i = 0; i < str.length(); i++) {
+ switch (str.charAt(i))
+ {
+ case 0 :
+ continue;
+ case '\b':
+ retval.append("\\b");
+ continue;
+ case '\t':
+ retval.append("\\t");
+ continue;
+ case '\n':
+ retval.append("\\n");
+ continue;
+ case '\f':
+ retval.append("\\f");
+ continue;
+ case '\r':
+ retval.append("\\r");
+ continue;
+ case '\"':
+ retval.append("\\\"");
+ continue;
+ case '\'':
+ retval.append("\\\'");
+ continue;
+ case '\\':
+ retval.append("\\\\");
+ continue;
+ default:
+ if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
+ String s = "0000" + Integer.toString(ch, 16);
+ retval.append("\\u" + s.substring(s.length() - 4, s.length()));
+ } else {
+ retval.append(ch);
+ }
+ continue;
+ }
+ }
+ return retval.toString();
+ }
+
+ /**
+ * Returns a detailed message for the Error when it is thrown by the
+ * token manager to indicate a lexical error.
+ * Parameters :
+ * EOFSeen : indicates if EOF caused the lexicl error
+ * curLexState : lexical state in which this error occured
+ * errorLine : line number when the error occured
+ * errorColumn : column number when the error occured
+ * errorAfter : prefix that was seen before this error occured
+ * curchar : the offending character
+ * Note: You can customize the lexical error message by modifying this method.
+ */
+ protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
+ return("Lexical error at line " +
+ errorLine + ", column " +
+ errorColumn + ". Encountered: " +
+ (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
+ "after : \"" + addEscapes(errorAfter) + "\"");
+ }
+
+ /**
+ * You can also modify the body of this method to customize your error messages.
+ * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
+ * of end-users concern, so you can return something like :
+ *
+ * "Internal Error : Please file a bug report .... "
+ *
+ * from this method for such cases in the release version of your parser.
+ */
+ public String getMessage() {
+ return super.getMessage();
+ }
+
+ /*
+ * Constructors of various flavors follow.
+ */
+
+ public TokenMgrError() {
+ }
+
+ public TokenMgrError(String message, int reason) {
+ super(message);
+ errorCode = reason;
+ }
+
+ public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
+ this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/rtf/TokenMgrError.java
------------------------------------------------------------------------------
svn:eol-style = native