OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [classpath/] [javax/] [swing/] [text/] [rtf/] [RTFParser.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* RTFParser.java --
2
   Copyright (C) 2005  Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
 
39
package javax.swing.text.rtf;
40
 
41
import java.io.IOException;
42
import java.io.InputStream;
43
import java.io.Reader;
44
 
45
import javax.swing.text.BadLocationException;
46
import javax.swing.text.Document;
47
 
48
/**
49
 * Parses an RTF file into a {@link Document}. The parser utilizes
50
 * {@link RTFScanner}.
51
 *
52
 * @author Roman Kennke (roman@ontographics.com)
53
 */
54
class RTFParser
55
{
56
 
57
  /**
58
   * Our scanner.
59
   */
60
  private RTFScanner scanner;
61
 
62
  /**
63
   * The document into which we parse.
64
   */
65
  private Document doc;
66
 
67
  /**
68
   * The current position.
69
   */
70
  private int pos;
71
 
72
  /**
73
   * Constructs a new RTFParser for the specified document and position,
74
   * without initializing the scanner. This is only used internally.
75
   *
76
   * @param doc the {@link Document} into which we should parse
77
   * @param pos the position to start
78
   */
79
  private RTFParser(Document doc, int pos)
80
  {
81
    this.doc = doc;
82
    this.pos = pos;
83
  }
84
 
85
  /**
86
   * Constructs a new RTFParser for the specified <code>stream</code>.
87
   *
88
   * @param stream the stream from which we parse
89
   * @param doc the {@link Document} into which we should parse
90
   * @param pos the position to start
91
   */
92
  public RTFParser(InputStream stream, Document doc, int pos)
93
  {
94
    this(doc, pos);
95
    scanner = new RTFScanner(stream);
96
  }
97
 
98
  /**
99
   * Constructs a new RTFParser for the specified <code>reader</code>.
100
   *
101
   * @param reader the reader from which we parse
102
   * @param doc the {@link Document} into which we should parse
103
   * @param pos the position to start
104
   */
105
  public RTFParser(Reader reader, Document doc, int pos)
106
  {
107
    this(doc, pos);
108
    scanner = new RTFScanner(reader);
109
  }
110
 
111
  /**
112
   * Returns the {@link Document} in which we parsed the RTF data.
113
   *
114
   * @return the {@link Document} in which we parsed the RTF data
115
   */
116
  public Document getDocument()
117
  {
118
    return doc;
119
  }
120
 
121
  /**
122
   * Starts the parsing process.
123
   */
124
  public void parse()
125
    throws IOException, BadLocationException
126
  {
127
    parseFile();
128
  }
129
 
130
  /**
131
   * The parse rules for &lt;file&gt;.
132
   */
133
  private void parseFile()
134
    throws IOException, BadLocationException
135
  {
136
    Token t1 = scanner.readToken();
137
    if (t1.type != Token.LCURLY)
138
      throw new RTFParseException("expected left curly braces");
139
 
140
    parseHeader();
141
    parseDocument();
142
 
143
    Token t2 = scanner.readToken();
144
    if (t2.type != Token.RCURLY)
145
      throw new RTFParseException("expected right curly braces");
146
 
147
  }
148
 
149
  /**
150
   * The parse rules for &lt;header&gt;.
151
   *
152
   * TODO: implement this properly
153
   */
154
  private void parseHeader()
155
  //throws IOException, BadLocationException
156
  {
157
    // TODO add parse rules here
158
  }
159
 
160
 
161
  /**
162
   * The parse rules for &lt;document&gt;.
163
   *
164
   * TODO: implement this properly
165
   */
166
  private void parseDocument()
167
    throws IOException, BadLocationException
168
  {
169
    //  !!! TODO !!!
170
    // This simply emits every TEXT Token as text to the document
171
    // which is plain stupid
172
 
173
    boolean eof = false;
174
 
175
    do {
176
      Token token = scanner.readToken();
177
      switch (token.type)
178
        {
179
        case Token.TEXT:
180
          TextToken textToken = (TextToken) token;
181
          doc.insertString(pos, textToken.text, null);
182
          pos += textToken.text.length();
183
          break;
184
        case Token.EOF:
185
          eof = true;
186
          break;
187
        default:
188
          // FIXME
189
          break;
190
        }
191
    } while (!eof);
192
 
193
  }
194
 
195
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.