jdk/src/java.desktop/share/classes/javax/swing/text/rtf/RTFReader.java
author prr
Sat, 19 Sep 2015 15:45:59 -0700
changeset 32865 f9cb6e427f9e
parent 32491 7b3783f9484d
permissions -rw-r--r--
8136783: Run blessed-modifier-order script on java.desktop Reviewed-by: martin, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22567
5816a47fa4dd 8032047: Fix static lint warnings in client libraries
darcy
parents: 10419
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing.text.rtf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.lang.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Color;
24157
84ccec128c31 8038962: KSS: javax.swing.text.html[.parser].ResourceLoader
malenkov
parents: 22567
diff changeset
    31
import java.security.AccessController;
84ccec128c31 8038962: KSS: javax.swing.text.html[.parser].ResourceLoader
malenkov
parents: 22567
diff changeset
    32
import java.security.PrivilegedAction;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Takes a sequence of RTF tokens and text and appends the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * described by the RTF to a <code>StyledDocument</code> (the <em>target</em>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * The RTF is lexed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * from the character stream by the <code>RTFParser</code> which is this class's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * superclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * This class is an indirect subclass of OutputStream. It must be closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * in order to guarantee that all of the text has been sent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * the text acceptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *   @see RTFParser
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *   @see java.io.OutputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
class RTFReader extends RTFParser
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
  /** The object to which the parsed text is sent. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
  StyledDocument target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
  /** Miscellaneous information about the parser's state. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
   *  dictionary is saved and restored when an RTF group begins
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
   *  or ends. */
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
    57
  Dictionary<Object, Object> parserState;   /* Current parser state */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
  /** This is the "dst" item from parserState. rtfDestination
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
   *  is the current rtf destination. It is cached in an instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
   *  variable for speed. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
  Destination rtfDestination;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
  /** This holds the current document attributes. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
  MutableAttributeSet documentAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
  /** This Dictionary maps Integer font numbers to String font names. */
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
    66
  Dictionary<Integer, String> fontTable;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
  /** This array maps color indices to Color objects. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
  Color[] colorTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
  /** This array maps character style numbers to Style objects. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
  Style[] characterStyles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
  /** This array maps paragraph style numbers to Style objects. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
  Style[] paragraphStyles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
  /** This array maps section style numbers to Style objects. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
  Style[] sectionStyles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
  /** This is the RTF version number, extracted from the \rtf keyword.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
   *  The version information is currently not used. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
  int rtfversion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
  /** <code>true</code> to indicate that if the next keyword is unknown,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
   *  the containing group should be ignored. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
  boolean ignoreGroupIfUnknownKeyword;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
  /** The parameter of the most recently parsed \\ucN keyword,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
   *  used for skipping alternative representations after a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
   *  Unicode character. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
  int skippingCharacters;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 32491
diff changeset
    89
  private static Dictionary<String, RTFAttribute> straightforwardAttributes;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
  static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
      straightforwardAttributes = RTFAttributes.attributesByKeyword();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
  private MockAttributeSet mockery;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
  /* this should be final, but there's a bug in javac... */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
  /** textKeywords maps RTF keywords to single-character strings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
   *  for those keywords which simply insert some text. */
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
    99
  static Dictionary<String, String> textKeywords = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
  static {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   101
      textKeywords = new Hashtable<String, String>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
      textKeywords.put("\\",         "\\");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
      textKeywords.put("{",          "{");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
      textKeywords.put("}",          "}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
      textKeywords.put(" ",          "\u00A0");  /* not in the spec... */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
      textKeywords.put("~",          "\u00A0");  /* nonbreaking space */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
      textKeywords.put("_",          "\u2011");  /* nonbreaking hyphen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
      textKeywords.put("bullet",     "\u2022");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
      textKeywords.put("emdash",     "\u2014");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
      textKeywords.put("emspace",    "\u2003");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
      textKeywords.put("endash",     "\u2013");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
      textKeywords.put("enspace",    "\u2002");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
      textKeywords.put("ldblquote",  "\u201C");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
      textKeywords.put("lquote",     "\u2018");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
      textKeywords.put("ltrmark",    "\u200E");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
      textKeywords.put("rdblquote",  "\u201D");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
      textKeywords.put("rquote",     "\u2019");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
      textKeywords.put("rtlmark",    "\u200F");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
      textKeywords.put("tab",        "\u0009");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
      textKeywords.put("zwj",        "\u200D");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
      textKeywords.put("zwnj",       "\u200C");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
      /* There is no Unicode equivalent to an optional hyphen, as far as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
         I can tell. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
      textKeywords.put("-",          "\u2027");  /* TODO: optional hyphen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
  /* some entries in parserState */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
  static final String TabAlignmentKey = "tab_alignment";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
  static final String TabLeaderKey = "tab_leader";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   132
  static Dictionary<String, char[]> characterSets;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
  static boolean useNeXTForAnsi = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
  static {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   135
      characterSets = new Hashtable<String, char[]>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
/* TODO: per-font font encodings ( \fcharset control word ) ? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * Creates a new RTFReader instance. Text will be sent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * the specified TextAcceptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * @param destination The TextAcceptor which is to receive the text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
public RTFReader(StyledDocument destination)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    target = destination;
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   151
    parserState = new Hashtable<Object, Object>();
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   152
    fontTable = new Hashtable<Integer, String>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    rtfversion = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    mockery = new MockAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    documentAttributes = new SimpleAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
/** Called when the RTFParser encounters a bin keyword in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 *  RTF stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 *  @see RTFParser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
public void handleBinaryBlob(byte[] data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    if (skippingCharacters > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        /* a blob only counts as one character for skipping purposes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        skippingCharacters --;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /* someday, someone will want to do something with blobs */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * Handles any pure text (containing no control characters) in the input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 * stream. Called by the superclass. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
public void handleText(String text)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    if (skippingCharacters > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        if (skippingCharacters >= text.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            skippingCharacters -= text.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            text = text.substring(skippingCharacters);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            skippingCharacters = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    if (rtfDestination != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        rtfDestination.handleText(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    warning("Text with no destination. oops.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
/** The default color for text which has no specified color. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
Color defaultColor()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    return Color.black;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
/** Called by the superclass when a new RTF group is begun.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 *  This implementation saves the current <code>parserState</code>, and gives
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 *  the current destination a chance to save its own state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 * @see RTFParser#begingroup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
public void begingroup()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    if (skippingCharacters > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        /* TODO this indicates an error in the RTF. Log it? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        skippingCharacters = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /* we do this little dance to avoid cloning the entire state stack and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
       immediately throwing it away. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    Object oldSaveState = parserState.get("_savedState");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    if (oldSaveState != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        parserState.remove("_savedState");
25193
187a455af8f8 8043549: Fix raw and unchecked lint warnings in javax.swing.text.*
darcy
parents: 24157
diff changeset
   223
    @SuppressWarnings("unchecked")
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   224
    Dictionary<String, Object> saveState = (Dictionary<String, Object>)((Hashtable)parserState).clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    if (oldSaveState != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        saveState.put("_savedState", oldSaveState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    parserState.put("_savedState", saveState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    if (rtfDestination != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        rtfDestination.begingroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
/** Called by the superclass when the current RTF group is closed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
 *  This restores the parserState saved by <code>begingroup()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
 *  as well as invoking the endgroup method of the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
 *  destination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
 * @see RTFParser#endgroup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
public void endgroup()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    if (skippingCharacters > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        /* NB this indicates an error in the RTF. Log it? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        skippingCharacters = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
25193
187a455af8f8 8043549: Fix raw and unchecked lint warnings in javax.swing.text.*
darcy
parents: 24157
diff changeset
   246
    @SuppressWarnings("unchecked")
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   247
    Dictionary<Object, Object> restoredState = (Dictionary<Object, Object>)parserState.get("_savedState");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    Destination restoredDestination = (Destination)restoredState.get("dst");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    if (restoredDestination != rtfDestination) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        rtfDestination.close(); /* allow the destination to clean up */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        rtfDestination = restoredDestination;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
25193
187a455af8f8 8043549: Fix raw and unchecked lint warnings in javax.swing.text.*
darcy
parents: 24157
diff changeset
   253
    Dictionary<Object, Object> oldParserState = parserState;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    parserState = restoredState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    if (rtfDestination != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        rtfDestination.endgroup(oldParserState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
protected void setRTFDestination(Destination newDestination)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /* Check that setting the destination won't close the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
       current destination (should never happen) */
25193
187a455af8f8 8043549: Fix raw and unchecked lint warnings in javax.swing.text.*
darcy
parents: 24157
diff changeset
   263
    @SuppressWarnings("unchecked")
187a455af8f8 8043549: Fix raw and unchecked lint warnings in javax.swing.text.*
darcy
parents: 24157
diff changeset
   264
    Dictionary<Object, Object> previousState = (Dictionary)parserState.get("_savedState");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    if (previousState != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        if (rtfDestination != previousState.get("dst")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            warning("Warning, RTF destination overridden, invalid RTF.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            rtfDestination.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    rtfDestination = newDestination;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    parserState.put("dst", rtfDestination);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
/** Called by the user when there is no more input (<i>i.e.</i>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
 * at the end of the RTF file.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
 * @see OutputStream#close
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
public void close()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
{
25193
187a455af8f8 8043549: Fix raw and unchecked lint warnings in javax.swing.text.*
darcy
parents: 24157
diff changeset
   283
    Enumeration<?> docProps = documentAttributes.getAttributeNames();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    while(docProps.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        Object propName = docProps.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        target.putProperty(propName,
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   287
                           documentAttributes.getAttribute(propName));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    /* RTFParser should have ensured that all our groups are closed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    warning("RTF filter done.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    super.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
 * Handles a parameterless RTF keyword. This is called by the superclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
 * (RTFParser) when a keyword is found in the input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
 *
32491
7b3783f9484d 8133807: java.desktop docs: replace some invalid "@returns" tags
avstepan
parents: 25859
diff changeset
   301
 * @return true if the keyword is recognized and handled;
7b3783f9484d 8133807: java.desktop docs: replace some invalid "@returns" tags
avstepan
parents: 25859
diff changeset
   302
 *         false otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
 * @see RTFParser#handleKeyword
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
public boolean handleKeyword(String keyword)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
{
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   307
    String item;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    boolean ignoreGroupIfUnknownKeywordSave = ignoreGroupIfUnknownKeyword;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    if (skippingCharacters > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        skippingCharacters --;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    ignoreGroupIfUnknownKeyword = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    if ((item = textKeywords.get(keyword)) != null) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   318
        handleText(item);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    if (keyword.equals("fonttbl")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        setRTFDestination(new FonttblDestination());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    if (keyword.equals("colortbl")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        setRTFDestination(new ColortblDestination());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    if (keyword.equals("stylesheet")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        setRTFDestination(new StylesheetDestination());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    if (keyword.equals("info")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        setRTFDestination(new InfoDestination());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    if (keyword.equals("mac")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        setCharacterSet("mac");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    if (keyword.equals("ansi")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        if (useNeXTForAnsi)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            setCharacterSet("NeXT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            setCharacterSet("ansi");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    if (keyword.equals("next")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        setCharacterSet("NeXT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    if (keyword.equals("pc")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        setCharacterSet("cpg437"); /* IBM Code Page 437 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    if (keyword.equals("pca")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        setCharacterSet("cpg850"); /* IBM Code Page 850 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    if (keyword.equals("*")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        ignoreGroupIfUnknownKeyword = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    if (rtfDestination != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        if(rtfDestination.handleKeyword(keyword))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    /* this point is reached only if the keyword is unrecognized */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    /* other destinations we don't understand and therefore ignore */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    if (keyword.equals("aftncn") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        keyword.equals("aftnsep") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        keyword.equals("aftnsepc") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        keyword.equals("annotation") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        keyword.equals("atnauthor") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        keyword.equals("atnicn") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        keyword.equals("atnid") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        keyword.equals("atnref") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        keyword.equals("atntime") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        keyword.equals("atrfend") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        keyword.equals("atrfstart") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        keyword.equals("bkmkend") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        keyword.equals("bkmkstart") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        keyword.equals("datafield") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        keyword.equals("do") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        keyword.equals("dptxbxtext") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        keyword.equals("falt") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        keyword.equals("field") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        keyword.equals("file") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        keyword.equals("filetbl") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        keyword.equals("fname") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        keyword.equals("fontemb") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        keyword.equals("fontfile") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        keyword.equals("footer") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        keyword.equals("footerf") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        keyword.equals("footerl") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        keyword.equals("footerr") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        keyword.equals("footnote") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        keyword.equals("ftncn") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        keyword.equals("ftnsep") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        keyword.equals("ftnsepc") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        keyword.equals("header") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        keyword.equals("headerf") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        keyword.equals("headerl") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        keyword.equals("headerr") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        keyword.equals("keycode") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        keyword.equals("nextfile") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        keyword.equals("object") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        keyword.equals("pict") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        keyword.equals("pn") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        keyword.equals("pnseclvl") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        keyword.equals("pntxtb") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        keyword.equals("pntxta") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        keyword.equals("revtbl") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        keyword.equals("rxe") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        keyword.equals("tc") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        keyword.equals("template") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        keyword.equals("txe") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        keyword.equals("xe")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        ignoreGroupIfUnknownKeywordSave = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    if (ignoreGroupIfUnknownKeywordSave) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        setRTFDestination(new DiscardingDestination());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
 * Handles an RTF keyword and its integer parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
 * This is called by the superclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
 * (RTFParser) when a keyword is found in the input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
 *
32491
7b3783f9484d 8133807: java.desktop docs: replace some invalid "@returns" tags
avstepan
parents: 25859
diff changeset
   447
 * @return true if the keyword is recognized and handled;
7b3783f9484d 8133807: java.desktop docs: replace some invalid "@returns" tags
avstepan
parents: 25859
diff changeset
   448
 *         false otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
 * @see RTFParser#handleKeyword
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
public boolean handleKeyword(String keyword, int parameter)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    boolean ignoreGroupIfUnknownKeywordSave = ignoreGroupIfUnknownKeyword;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    if (skippingCharacters > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        skippingCharacters --;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    ignoreGroupIfUnknownKeyword = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    if (keyword.equals("uc")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        /* count of characters to skip after a unicode character */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        parserState.put("UnicodeSkip", Integer.valueOf(parameter));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    if (keyword.equals("u")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        if (parameter < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            parameter = parameter + 65536;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        handleText((char)parameter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        Number skip = (Number)(parserState.get("UnicodeSkip"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        if (skip != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            skippingCharacters = skip.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            skippingCharacters = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    if (keyword.equals("rtf")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        rtfversion = parameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        setRTFDestination(new DocumentDestination());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    if (keyword.startsWith("NeXT") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        keyword.equals("private"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        ignoreGroupIfUnknownKeywordSave = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    if (rtfDestination != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        if(rtfDestination.handleKeyword(keyword, parameter))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    /* this point is reached only if the keyword is unrecognized */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    if (ignoreGroupIfUnknownKeywordSave) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        setRTFDestination(new DiscardingDestination());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
private void setTargetAttribute(String name, Object value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
//    target.changeAttributes(new LFDictionary(LFArray.arrayWithObject(value), LFArray.arrayWithObject(name)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
 * setCharacterSet sets the current translation table to correspond with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
 * the named character set. The character set is loaded if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
 * @see AbstractFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
public void setCharacterSet(String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    Object set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        set = getCharacterSet(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        warning("Exception loading RTF character set \"" + name + "\": " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        set = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    if (set != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        translationTable = (char[])set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        warning("Unknown RTF character set \"" + name + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        if (!name.equals("ansi")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                translationTable = (char[])getCharacterSet("ansi");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            } catch (IOException e) {
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 5506
diff changeset
   534
                throw new InternalError("RTFReader: Unable to find character set resources (" + e + ")", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    setTargetAttribute(Constants.RTFCharacterSet, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
/** Adds a character set to the RTFReader's list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
 *  of known character sets */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
public static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
defineCharacterSet(String name, char[] table)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    if (table.length < 256)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        throw new IllegalArgumentException("Translation table must have 256 entries.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    characterSets.put(name, table);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
/** Looks up a named character set. A character set is a 256-entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
 *  array of characters, mapping unsigned byte values to their Unicode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
 *  equivalents. The character set is loaded if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
 *
32491
7b3783f9484d 8133807: java.desktop docs: replace some invalid "@returns" tags
avstepan
parents: 25859
diff changeset
   556
 *  @return the character set
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
public static Object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
getCharacterSet(final String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
{
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   562
    char[] set = characterSets.get(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    if (set == null) {
24157
84ccec128c31 8038962: KSS: javax.swing.text.html[.parser].ResourceLoader
malenkov
parents: 22567
diff changeset
   564
        InputStream charsetStream = AccessController.doPrivileged(
84ccec128c31 8038962: KSS: javax.swing.text.html[.parser].ResourceLoader
malenkov
parents: 22567
diff changeset
   565
                new PrivilegedAction<InputStream>() {
84ccec128c31 8038962: KSS: javax.swing.text.html[.parser].ResourceLoader
malenkov
parents: 22567
diff changeset
   566
                    public InputStream run() {
84ccec128c31 8038962: KSS: javax.swing.text.html[.parser].ResourceLoader
malenkov
parents: 22567
diff changeset
   567
                        return RTFReader.class.getResourceAsStream("charsets/" + name + ".txt");
84ccec128c31 8038962: KSS: javax.swing.text.html[.parser].ResourceLoader
malenkov
parents: 22567
diff changeset
   568
                    }
84ccec128c31 8038962: KSS: javax.swing.text.html[.parser].ResourceLoader
malenkov
parents: 22567
diff changeset
   569
                });
84ccec128c31 8038962: KSS: javax.swing.text.html[.parser].ResourceLoader
malenkov
parents: 22567
diff changeset
   570
        set = readCharset(charsetStream);
84ccec128c31 8038962: KSS: javax.swing.text.html[.parser].ResourceLoader
malenkov
parents: 22567
diff changeset
   571
        defineCharacterSet(name, set);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    return set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
/** Parses a character set from an InputStream. The character set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
 * must contain 256 decimal integers, separated by whitespace, with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
 * no punctuation. B- and C- style comments are allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
 *
32491
7b3783f9484d 8133807: java.desktop docs: replace some invalid "@returns" tags
avstepan
parents: 25859
diff changeset
   580
 * @return the newly read character set
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
static char[] readCharset(InputStream strm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    char[] values = new char[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    StreamTokenizer in = new StreamTokenizer(new BufferedReader(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            new InputStreamReader(strm, "ISO-8859-1")));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    in.eolIsSignificant(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    in.commentChar('#');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    in.slashSlashComments(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    in.slashStarComments(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    while (i < 256) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        int ttype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            ttype = in.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            throw new IOException("Unable to read from character set file (" + e + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        }
22567
5816a47fa4dd 8032047: Fix static lint warnings in client libraries
darcy
parents: 10419
diff changeset
   603
        if (ttype != StreamTokenizer.TT_NUMBER) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
//          System.out.println("Bad token: type=" + ttype + " tok=" + in.sval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            throw new IOException("Unexpected token in character set file");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
//          continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        values[i] = (char)(in.nval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    return values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
static char[] readCharset(java.net.URL href)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    return readCharset(href.openStream());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
/** An interface (could be an entirely abstract class) describing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
 *  a destination. The RTF reader always has a current destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
 *  which is where text is sent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
 *  @see RTFReader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
interface Destination {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    void handleBinaryBlob(byte[] data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    void handleText(String text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    boolean handleKeyword(String keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    boolean handleKeyword(String keyword, int parameter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    void begingroup();
25193
187a455af8f8 8043549: Fix raw and unchecked lint warnings in javax.swing.text.*
darcy
parents: 24157
diff changeset
   634
    void endgroup(Dictionary<Object, Object> oldState);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    void close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
/** This data-sink class is used to implement ignored destinations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
 *  (e.g. {\*\blegga blah blah blah} )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
 *  It accepts all keywords and text but does nothing with them. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
class DiscardingDestination implements Destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    public void handleBinaryBlob(byte[] data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        /* Discard binary blobs. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    public void handleText(String text)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        /* Discard text. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    public boolean handleKeyword(String text)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        /* Accept and discard keywords. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    public boolean handleKeyword(String text, int parameter)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        /* Accept and discard parameterized keywords. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    public void begingroup()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        /* Ignore groups --- the RTFReader will keep track of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
           current group level as necessary */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
25193
187a455af8f8 8043549: Fix raw and unchecked lint warnings in javax.swing.text.*
darcy
parents: 24157
diff changeset
   672
    public void endgroup(Dictionary<Object, Object> oldState)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        /* Ignore groups */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    public void close()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        /* No end-of-destination cleanup needed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
/** Reads the fonttbl group, inserting fonts into the RTFReader's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
 *  fontTable dictionary. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
class FonttblDestination implements Destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    int nextFontNumber;
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   688
    Integer fontNumberKey = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    String nextFontFamily;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    public void handleBinaryBlob(byte[] data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    { /* Discard binary blobs. */ }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    public void handleText(String text)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        int semicolon = text.indexOf(';');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        String fontName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        if (semicolon > -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            fontName = text.substring(0, semicolon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            fontName = text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        /* TODO: do something with the font family. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        if (nextFontNumber == -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            && fontNumberKey != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            //font name might be broken across multiple calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            fontName = fontTable.get(fontNumberKey) + fontName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            fontNumberKey = Integer.valueOf(nextFontNumber);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        fontTable.put(fontNumberKey, fontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        nextFontNumber = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        nextFontFamily = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    public boolean handleKeyword(String keyword)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        if (keyword.charAt(0) == 'f') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            nextFontFamily = keyword.substring(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    public boolean handleKeyword(String keyword, int parameter)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        if (keyword.equals("f")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            nextFontNumber = parameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    /* Groups are irrelevant. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    public void begingroup() {}
25193
187a455af8f8 8043549: Fix raw and unchecked lint warnings in javax.swing.text.*
darcy
parents: 24157
diff changeset
   742
    public void endgroup(Dictionary<Object, Object> oldState) {}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    /* currently, the only thing we do when the font table ends is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
       dump its contents to the debugging log. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    public void close()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   748
        Enumeration<Integer> nums = fontTable.keys();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        warning("Done reading font table.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        while(nums.hasMoreElements()) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   751
            Integer num = nums.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            warning("Number " + num + ": " + fontTable.get(num));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
/** Reads the colortbl group. Upon end-of-group, the RTFReader's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
 *  color table is set to an array containing the read colors. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
class ColortblDestination implements Destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    int red, green, blue;
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   762
    Vector<Color> proTemTable;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    public ColortblDestination()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        red = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        green = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        blue = 0;
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   769
        proTemTable = new Vector<Color>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    public void handleText(String text)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   774
        int index;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        for (index = 0; index < text.length(); index ++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            if (text.charAt(index) == ';') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                Color newColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                newColor = new Color(red, green, blue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                proTemTable.addElement(newColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    public void close()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        int count = proTemTable.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        warning("Done reading color table, " + count + " entries.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        colorTable = new Color[count];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        proTemTable.copyInto(colorTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    public boolean handleKeyword(String keyword, int parameter)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        if (keyword.equals("red"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            red = parameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        else if (keyword.equals("green"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            green = parameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        else if (keyword.equals("blue"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            blue = parameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    /* Colortbls don't understand any parameterless keywords */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    public boolean handleKeyword(String keyword) { return false; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    /* Groups are irrelevant. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    public void begingroup() {}
25193
187a455af8f8 8043549: Fix raw and unchecked lint warnings in javax.swing.text.*
darcy
parents: 24157
diff changeset
   812
    public void endgroup(Dictionary<Object, Object> oldState) {}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    /* Shouldn't see any binary blobs ... */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    public void handleBinaryBlob(byte[] data) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
/** Handles the stylesheet keyword. Styles are read and sorted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
 *  into the three style arrays in the RTFReader. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
class StylesheetDestination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    extends DiscardingDestination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    implements Destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
{
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   824
    Dictionary<Integer, StyleDefiningDestination> definedStyles;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    public StylesheetDestination()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   828
        definedStyles = new Hashtable<Integer, StyleDefiningDestination>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    public void begingroup()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        setRTFDestination(new StyleDefiningDestination());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    public void close()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   838
        Vector<Style> chrStyles = new Vector<Style>();
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   839
        Vector<Style> pgfStyles = new Vector<Style>();
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   840
        Vector<Style> secStyles = new Vector<Style>();
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   841
        Enumeration<StyleDefiningDestination> styles = definedStyles.elements();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        while(styles.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            StyleDefiningDestination style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            Style defined;
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   845
            style = styles.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            defined = style.realize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            warning("Style "+style.number+" ("+style.styleName+"): "+defined);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            String stype = (String)defined.getAttribute(Constants.StyleType);
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   849
            Vector<Style> toSet;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
            if (stype.equals(Constants.STSection)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                toSet = secStyles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            } else if (stype.equals(Constants.STCharacter)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                toSet = chrStyles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                toSet = pgfStyles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            if (toSet.size() <= style.number)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                toSet.setSize(style.number + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            toSet.setElementAt(defined, style.number);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        if (!(chrStyles.isEmpty())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            Style[] styleArray = new Style[chrStyles.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            chrStyles.copyInto(styleArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            characterStyles = styleArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        if (!(pgfStyles.isEmpty())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            Style[] styleArray = new Style[pgfStyles.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            pgfStyles.copyInto(styleArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            paragraphStyles = styleArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        if (!(secStyles.isEmpty())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            Style[] styleArray = new Style[secStyles.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
            secStyles.copyInto(styleArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            sectionStyles = styleArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
/* (old debugging code)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        int i, m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        if (characterStyles != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
          m = characterStyles.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
          for(i=0;i<m;i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            warnings.println("chrStyle["+i+"]="+characterStyles[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        } else warnings.println("No character styles.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        if (paragraphStyles != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
          m = paragraphStyles.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
          for(i=0;i<m;i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            warnings.println("pgfStyle["+i+"]="+paragraphStyles[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        } else warnings.println("No paragraph styles.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        if (sectionStyles != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
          m = characterStyles.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
          for(i=0;i<m;i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            warnings.println("secStyle["+i+"]="+sectionStyles[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        } else warnings.println("No section styles.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    /** This subclass handles an individual style */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    class StyleDefiningDestination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        extends AttributeTrackingDestination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        implements Destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        final int STYLENUMBER_NONE = 222;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        boolean additive;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        boolean characterStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        boolean sectionStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        public String styleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        public int number;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        int basedOn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        int nextStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        boolean hidden;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        Style realizedStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        public StyleDefiningDestination()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            additive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            characterStyle = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            sectionStyle = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            styleName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            number = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            basedOn = STYLENUMBER_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            nextStyle = STYLENUMBER_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            hidden = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        public void handleText(String text)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            if (styleName != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                styleName = styleName + text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                styleName = text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        public void close() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            int semicolon = (styleName == null) ? 0 : styleName.indexOf(';');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            if (semicolon > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                styleName = styleName.substring(0, semicolon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            definedStyles.put(Integer.valueOf(number), this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            super.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        public boolean handleKeyword(String keyword)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            if (keyword.equals("additive")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                additive = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            if (keyword.equals("shidden")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                hidden = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            return super.handleKeyword(keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        public boolean handleKeyword(String keyword, int parameter)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            if (keyword.equals("s")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                characterStyle = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                sectionStyle = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                number = parameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            } else if (keyword.equals("cs")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                characterStyle = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                sectionStyle = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                number = parameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            } else if (keyword.equals("ds")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                characterStyle = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                sectionStyle = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                number = parameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            } else if (keyword.equals("sbasedon")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                basedOn = parameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            } else if (keyword.equals("snext")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                nextStyle = parameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                return super.handleKeyword(keyword, parameter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        public Style realize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            Style basis = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            Style next = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            if (realizedStyle != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                return realizedStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            if (basedOn != STYLENUMBER_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                StyleDefiningDestination styleDest;
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   989
                styleDest = definedStyles.get(Integer.valueOf(basedOn));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                if (styleDest != null && styleDest != this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                    basis = styleDest.realize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            /* NB: Swing StyleContext doesn't allow distinct styles with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
               the same name; RTF apparently does. This may confuse the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
               user. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            realizedStyle = target.addStyle(styleName, basis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            if (characterStyle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                realizedStyle.addAttributes(currentTextAttributes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                realizedStyle.addAttribute(Constants.StyleType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                                           Constants.STCharacter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
            } else if (sectionStyle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                realizedStyle.addAttributes(currentSectionAttributes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                realizedStyle.addAttribute(Constants.StyleType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                                           Constants.STSection);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            } else { /* must be a paragraph style */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                realizedStyle.addAttributes(currentParagraphAttributes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                realizedStyle.addAttribute(Constants.StyleType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                                           Constants.STParagraph);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
            if (nextStyle != STYLENUMBER_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                StyleDefiningDestination styleDest;
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
  1016
                styleDest = definedStyles.get(Integer.valueOf(nextStyle));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                if (styleDest != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                    next = styleDest.realize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
            if (next != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                realizedStyle.addAttribute(Constants.StyleNext, next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            realizedStyle.addAttribute(Constants.StyleAdditive,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                                       Boolean.valueOf(additive));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            realizedStyle.addAttribute(Constants.StyleHidden,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                                       Boolean.valueOf(hidden));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            return realizedStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
/** Handles the info group. Currently no info keywords are recognized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
 *  so this is a subclass of DiscardingDestination. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
class InfoDestination
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    extends DiscardingDestination
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
    implements Destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
/** RTFReader.TextHandlingDestination is an abstract RTF destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
 *  which simply tracks the attributes specified by the RTF control words
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
 *  in internal form and can produce acceptable AttributeSets for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
 *  current character, paragraph, and section attributes. It is up
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
 *  to the subclasses to determine what is done with the actual text. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
abstract class AttributeTrackingDestination implements Destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
    /** This is the "chr" element of parserState, cached for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     *  more efficient use */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    MutableAttributeSet characterAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
    /** This is the "pgf" element of parserState, cached for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     *  more efficient use */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
    MutableAttributeSet paragraphAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
    /** This is the "sec" element of parserState, cached for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     *  more efficient use */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
    MutableAttributeSet sectionAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
    public AttributeTrackingDestination()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        characterAttributes = rootCharacterAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
        parserState.put("chr", characterAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        paragraphAttributes = rootParagraphAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
        parserState.put("pgf", paragraphAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        sectionAttributes = rootSectionAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        parserState.put("sec", sectionAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 32491
diff changeset
  1069
    public abstract void handleText(String text);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    public void handleBinaryBlob(byte[] data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        /* This should really be in TextHandlingDestination, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
         * since *nobody* does anything with binary blobs, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
         * is more convenient. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        warning("Unexpected binary data in RTF file.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
    public void begingroup()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        AttributeSet characterParent = currentTextAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        AttributeSet paragraphParent = currentParagraphAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        AttributeSet sectionParent = currentSectionAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        /* It would probably be more efficient to use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
         * resolver property of the attributes set for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
         * implementing rtf groups,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
         * but that's needed for styles. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        /* update the cached attribute dictionaries */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        characterAttributes = new SimpleAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        characterAttributes.addAttributes(characterParent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        parserState.put("chr", characterAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        paragraphAttributes = new SimpleAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        paragraphAttributes.addAttributes(paragraphParent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        parserState.put("pgf", paragraphAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        sectionAttributes = new SimpleAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        sectionAttributes.addAttributes(sectionParent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        parserState.put("sec", sectionAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
25193
187a455af8f8 8043549: Fix raw and unchecked lint warnings in javax.swing.text.*
darcy
parents: 24157
diff changeset
  1104
    public void endgroup(Dictionary<Object, Object> oldState)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        characterAttributes = (MutableAttributeSet)parserState.get("chr");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        paragraphAttributes = (MutableAttributeSet)parserState.get("pgf");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        sectionAttributes   = (MutableAttributeSet)parserState.get("sec");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    public void close()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
    public boolean handleKeyword(String keyword)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
        if (keyword.equals("ulnone")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
            return handleKeyword("ul", 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
  1122
            RTFAttribute attr = straightforwardAttributes.get(keyword);
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
  1123
            if (attr != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                boolean ok;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
                switch(attr.domain()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
                  case RTFAttribute.D_CHARACTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                    ok = attr.set(characterAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                  case RTFAttribute.D_PARAGRAPH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                    ok = attr.set(paragraphAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
                  case RTFAttribute.D_SECTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                    ok = attr.set(sectionAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
                  case RTFAttribute.D_META:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
                    mockery.backing = parserState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                    ok = attr.set(mockery);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
                    mockery.backing = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                  case RTFAttribute.D_DOCUMENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                    ok = attr.set(documentAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
                  default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                    /* should never happen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
                    ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                if (ok)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        if (keyword.equals("plain")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
            resetCharacterAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        if (keyword.equals("pard")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            resetParagraphAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        if (keyword.equals("sectd")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
            resetSectionAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
    public boolean handleKeyword(String keyword, int parameter)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        boolean booleanParameter = (parameter != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        if (keyword.equals("fc"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            keyword = "cf"; /* whatEVER, dude. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        if (keyword.equals("f")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
            parserState.put(keyword, Integer.valueOf(parameter));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        if (keyword.equals("cf")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
            parserState.put(keyword, Integer.valueOf(parameter));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
  1190
            RTFAttribute attr = straightforwardAttributes.get(keyword);
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
  1191
            if (attr != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
                boolean ok;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
                switch(attr.domain()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
                  case RTFAttribute.D_CHARACTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
                    ok = attr.set(characterAttributes, parameter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                  case RTFAttribute.D_PARAGRAPH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                    ok = attr.set(paragraphAttributes, parameter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                  case RTFAttribute.D_SECTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                    ok = attr.set(sectionAttributes, parameter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                  case RTFAttribute.D_META:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
                    mockery.backing = parserState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
                    ok = attr.set(mockery, parameter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                    mockery.backing = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
                  case RTFAttribute.D_DOCUMENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
                    ok = attr.set(documentAttributes, parameter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                  default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                    /* should never happen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                    ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                if (ok)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        if (keyword.equals("fs")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            StyleConstants.setFontSize(characterAttributes, (parameter / 2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        /* TODO: superscript/subscript */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        if (keyword.equals("sl")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
            if (parameter == 1000) {  /* magic value! */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                characterAttributes.removeAttribute(StyleConstants.LineSpacing);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                /* TODO: The RTF sl attribute has special meaning if it's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                   negative. Make sure that SwingText has the same special
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
                   meaning, or find a way to imitate that. When SwingText
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
                   handles this, also recognize the slmult keyword. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
                StyleConstants.setLineSpacing(characterAttributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
                                              parameter / 20f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
        /* TODO: Other kinds of underlining */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        if (keyword.equals("tx") || keyword.equals("tb")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
            float tabPosition = parameter / 20f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
            int tabAlignment, tabLeader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
            Number item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
            tabAlignment = TabStop.ALIGN_LEFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
            item = (Number)(parserState.get("tab_alignment"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
            if (item != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                tabAlignment = item.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            tabLeader = TabStop.LEAD_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
            item = (Number)(parserState.get("tab_leader"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
            if (item != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                tabLeader = item.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
            if (keyword.equals("tb"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                tabAlignment = TabStop.ALIGN_BAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
            parserState.remove("tab_alignment");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
            parserState.remove("tab_leader");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
            TabStop newStop = new TabStop(tabPosition, tabAlignment, tabLeader);
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
  1265
            Dictionary<Object, Object> tabs;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            Integer stopCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
25193
187a455af8f8 8043549: Fix raw and unchecked lint warnings in javax.swing.text.*
darcy
parents: 24157
diff changeset
  1268
            @SuppressWarnings("unchecked")
187a455af8f8 8043549: Fix raw and unchecked lint warnings in javax.swing.text.*
darcy
parents: 24157
diff changeset
  1269
            Dictionary<Object, Object>tmp = (Dictionary)parserState.get("_tabs");
187a455af8f8 8043549: Fix raw and unchecked lint warnings in javax.swing.text.*
darcy
parents: 24157
diff changeset
  1270
            tabs = tmp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            if (tabs == null) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
  1272
                tabs = new Hashtable<Object, Object>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
                parserState.put("_tabs", tabs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
                stopCount = Integer.valueOf(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                stopCount = (Integer)tabs.get("stop count");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
                stopCount = Integer.valueOf(1 + stopCount.intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
            tabs.put(stopCount, newStop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
            tabs.put("stop count", stopCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
            parserState.remove("_tabs_immutable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
        if (keyword.equals("s") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
            paragraphStyles != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
            parserState.put("paragraphStyle", paragraphStyles[parameter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
        if (keyword.equals("cs") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
            characterStyles != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
            parserState.put("characterStyle", characterStyles[parameter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
        if (keyword.equals("ds") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
            sectionStyles != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
            parserState.put("sectionStyle", sectionStyles[parameter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
    /** Returns a new MutableAttributeSet containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
     *  default character attributes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
    protected MutableAttributeSet rootCharacterAttributes()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
        MutableAttributeSet set = new SimpleAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
        /* TODO: default font */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
        StyleConstants.setItalic(set, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
        StyleConstants.setBold(set, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
        StyleConstants.setUnderline(set, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        StyleConstants.setForeground(set, defaultColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
        return set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
    /** Returns a new MutableAttributeSet containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
     *  default paragraph attributes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
    protected MutableAttributeSet rootParagraphAttributes()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        MutableAttributeSet set = new SimpleAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        StyleConstants.setLeftIndent(set, 0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        StyleConstants.setRightIndent(set, 0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        StyleConstants.setFirstLineIndent(set, 0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        /* TODO: what should this be, really? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        set.setResolveParent(target.getStyle(StyleContext.DEFAULT_STYLE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        return set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
    /** Returns a new MutableAttributeSet containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
     *  default section attributes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
    protected MutableAttributeSet rootSectionAttributes()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
        MutableAttributeSet set = new SimpleAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
        return set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
     * Calculates the current text (character) attributes in a form suitable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
     * for SwingText from the current parser state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
     *
32491
7b3783f9484d 8133807: java.desktop docs: replace some invalid "@returns" tags
avstepan
parents: 25859
diff changeset
  1352
     * @return a new MutableAttributeSet containing the text attributes.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
    MutableAttributeSet currentTextAttributes()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
        MutableAttributeSet attributes =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
            new SimpleAttributeSet(characterAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
        Integer fontnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
        Integer stateItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
        /* figure out the font name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
        /* TODO: catch exceptions for undefined attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
           bad font indices, etc.? (as it stands, it is the caller's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
           job to clean up after corrupt RTF) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
        fontnum = (Integer)parserState.get("f");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        /* note setFontFamily() can not handle a null font */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
        String fontFamily;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
        if (fontnum != null)
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
  1369
            fontFamily = fontTable.get(fontnum);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
            fontFamily = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
        if (fontFamily != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
            StyleConstants.setFontFamily(attributes, fontFamily);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
            attributes.removeAttribute(StyleConstants.FontFamily);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
        if (colorTable != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
            stateItem = (Integer)parserState.get("cf");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
            if (stateItem != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
                Color fg = colorTable[stateItem.intValue()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
                StyleConstants.setForeground(attributes, fg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                /* AttributeSet dies if you set a value to null */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                attributes.removeAttribute(StyleConstants.Foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        if (colorTable != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
            stateItem = (Integer)parserState.get("cb");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
            if (stateItem != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
                Color bg = colorTable[stateItem.intValue()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                attributes.addAttribute(StyleConstants.Background,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
                                        bg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
                /* AttributeSet dies if you set a value to null */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                attributes.removeAttribute(StyleConstants.Background);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
        Style characterStyle = (Style)parserState.get("characterStyle");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
        if (characterStyle != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
            attributes.setResolveParent(characterStyle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
        /* Other attributes are maintained directly in "attributes" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
        return attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
     * Calculates the current paragraph attributes (with keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     * as given in StyleConstants) from the current parser state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     *
32491
7b3783f9484d 8133807: java.desktop docs: replace some invalid "@returns" tags
avstepan
parents: 25859
diff changeset
  1413
     * @return a newly created MutableAttributeSet.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     * @see StyleConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
    MutableAttributeSet currentParagraphAttributes()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
        /* NB if there were a mutableCopy() method we should use it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
        MutableAttributeSet bld = new SimpleAttributeSet(paragraphAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
        Integer stateItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
        /*** Tab stops ***/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
        TabStop tabs[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
        tabs = (TabStop[])parserState.get("_tabs_immutable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
        if (tabs == null) {
25193
187a455af8f8 8043549: Fix raw and unchecked lint warnings in javax.swing.text.*
darcy
parents: 24157
diff changeset
  1428
            @SuppressWarnings("unchecked")
187a455af8f8 8043549: Fix raw and unchecked lint warnings in javax.swing.text.*
darcy
parents: 24157
diff changeset
  1429
            Dictionary<Object, Object> workingTabs = (Dictionary)parserState.get("_tabs");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
            if (workingTabs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
                int count = ((Integer)workingTabs.get("stop count")).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
                tabs = new TabStop[count];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
                for (int ix = 1; ix <= count; ix ++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
                    tabs[ix-1] = (TabStop)workingTabs.get(Integer.valueOf(ix));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
                parserState.put("_tabs_immutable", tabs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
        if (tabs != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
            bld.addAttribute(Constants.Tabs, tabs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
        Style paragraphStyle = (Style)parserState.get("paragraphStyle");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
        if (paragraphStyle != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
            bld.setResolveParent(paragraphStyle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
        return bld;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
     * Calculates the current section attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
     * from the current parser state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
     *
32491
7b3783f9484d 8133807: java.desktop docs: replace some invalid "@returns" tags
avstepan
parents: 25859
diff changeset
  1452
     * @return a newly created MutableAttributeSet.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
    public AttributeSet currentSectionAttributes()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
        MutableAttributeSet attributes = new SimpleAttributeSet(sectionAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
        Style sectionStyle = (Style)parserState.get("sectionStyle");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
        if (sectionStyle != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
            attributes.setResolveParent(sectionStyle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
        return attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
    /** Resets the filter's internal notion of the current character
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
     *  attributes to their default values. Invoked to handle the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
     *  \plain keyword. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
    protected void resetCharacterAttributes()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
        handleKeyword("f", 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        handleKeyword("cf", 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
        handleKeyword("fs", 24);  /* 12 pt. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
  1475
        Enumeration<RTFAttribute> attributes = straightforwardAttributes.elements();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
        while(attributes.hasMoreElements()) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
  1477
            RTFAttribute attr = attributes.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
            if (attr.domain() == RTFAttribute.D_CHARACTER)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
                attr.setDefault(characterAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
        handleKeyword("sl", 1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
        parserState.remove("characterStyle");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
    /** Resets the filter's internal notion of the current paragraph's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
     *  attributes to their default values. Invoked to handle the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
     *  \pard keyword. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
    protected void resetParagraphAttributes()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
        parserState.remove("_tabs");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
        parserState.remove("_tabs_immutable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
        parserState.remove("paragraphStyle");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
        StyleConstants.setAlignment(paragraphAttributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
                                    StyleConstants.ALIGN_LEFT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
  1499
        Enumeration<RTFAttribute> attributes = straightforwardAttributes.elements();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
        while(attributes.hasMoreElements()) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
  1501
            RTFAttribute attr = attributes.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
            if (attr.domain() == RTFAttribute.D_PARAGRAPH)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
                attr.setDefault(characterAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
    /** Resets the filter's internal notion of the current section's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
     *  attributes to their default values. Invoked to handle the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
     *  \sectd keyword. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
    protected void resetSectionAttributes()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
    {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
  1512
        Enumeration<RTFAttribute> attributes = straightforwardAttributes.elements();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
        while(attributes.hasMoreElements()) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
  1514
            RTFAttribute attr = attributes.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
            if (attr.domain() == RTFAttribute.D_SECTION)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
                attr.setDefault(characterAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
        parserState.remove("sectionStyle");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
/** RTFReader.TextHandlingDestination provides basic text handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
 *  functionality. Subclasses must implement: <dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
 *  <dt>deliverText()<dd>to handle a run of text with the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
 *                       attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
 *  <dt>finishParagraph()<dd>to end the current paragraph and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
 *                           set the paragraph's attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
 *  <dt>endSection()<dd>to end the current section
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
 *  </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
abstract class TextHandlingDestination
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
    extends AttributeTrackingDestination
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
    implements Destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
    /** <code>true</code> if the reader has not just finished
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
     *  a paragraph; false upon startup */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
    boolean inParagraph;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
    public TextHandlingDestination()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
        inParagraph = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
    public void handleText(String text)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
        if (! inParagraph)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
            beginParagraph();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
        deliverText(text, currentTextAttributes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
    abstract void deliverText(String text, AttributeSet characterAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
    public void close()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
        if (inParagraph)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
            endParagraph();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
        super.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
    public boolean handleKeyword(String keyword)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
        if (keyword.equals("\r") || keyword.equals("\n")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
            keyword = "par";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
        if (keyword.equals("par")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
//          warnings.println("Ending paragraph.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
            endParagraph();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
        if (keyword.equals("sect")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
//          warnings.println("Ending section.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
            endSection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
        return super.handleKeyword(keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
    protected void beginParagraph()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
        inParagraph = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
    protected void endParagraph()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
        AttributeSet pgfAttributes = currentParagraphAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
        AttributeSet chrAttributes = currentTextAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
        finishParagraph(pgfAttributes, chrAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
        inParagraph = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
    abstract void finishParagraph(AttributeSet pgfA, AttributeSet chrA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
    abstract void endSection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
/** RTFReader.DocumentDestination is a concrete subclass of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
 *  TextHandlingDestination which appends the text to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
 *  StyledDocument given by the <code>target</code> ivar of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
 *  containing RTFReader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
class DocumentDestination
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
    extends TextHandlingDestination
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
    implements Destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
    public void deliverText(String text, AttributeSet characterAttributes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
            target.insertString(target.getLength(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
                                text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
                                currentTextAttributes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
        } catch (BadLocationException ble) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
            /* This shouldn't be able to happen, of course */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
            /* TODO is InternalError the correct error to throw? */
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 5506
diff changeset
  1621
            throw new InternalError(ble.getMessage(), ble);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
    public void finishParagraph(AttributeSet pgfAttributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
                                AttributeSet chrAttributes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
        int pgfEndPosition = target.getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
            target.insertString(pgfEndPosition, "\n", chrAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
            target.setParagraphAttributes(pgfEndPosition, 1, pgfAttributes, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
        } catch (BadLocationException ble) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
            /* This shouldn't be able to happen, of course */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
            /* TODO is InternalError the correct error to throw? */
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 5506
diff changeset
  1635
            throw new InternalError(ble.getMessage(), ble);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
    public void endSection()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
        /* If we implemented sections, we'd end 'em here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
}