Source for javax.swing.text.html.HTMLEditorKit

   1: /* HTMLEditorKit.java --
   2:    Copyright (C) 2005 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package javax.swing.text.html;
  40: 
  41: import java.io.Reader;
  42: import java.io.Serializable;
  43: 
  44: import javax.swing.text.BadLocationException;
  45: import javax.swing.text.MutableAttributeSet;
  46: import javax.swing.text.StyledEditorKit;
  47: 
  48: /**
  49:  * This class is NOT implemented. This file currently holds only
  50:  * declarations of the two enclosing classes, necessary for testing
  51:  * the implemented javax.swing.text.html.parser package.
  52:  *
  53:  * @author No authorship is taken, implement the class and be!
  54:  * TODO: replace this header after implementing the class.
  55:  */
  56: public class HTMLEditorKit
  57:   extends StyledEditorKit
  58:   implements Serializable, Cloneable
  59: {
  60:   /**
  61:    * The abstract HTML parser declaration.
  62:    */
  63:   public abstract static class Parser
  64:   {
  65:     /**
  66:      * Parse the HTML text, calling various methods of the provided callback
  67:      * in response to the occurence of the corresponding HTML constructions.
  68:      * @param reader The reader to read the source HTML from.
  69:      * @param callback The callback to receive information about the parsed
  70:      * HTML structures
  71:      * @param ignoreCharSet If true, the parser ignores all charset information
  72:      * that may be present in HTML documents.
  73:      * @throws IOException, normally if the reader throws one.
  74:      */
  75:     public abstract void parse(Reader reader, ParserCallback callback,
  76:                                boolean ignoreCharSet
  77:                               )
  78:                         throws java.io.IOException;
  79:   }
  80: 
  81:   /**
  82:    * The "hook" that receives all information about the HTML document
  83:    * structure while parsing it. The methods are invoked by parser
  84:    * and should be normally overridden.
  85:    */
  86:   public static class ParserCallback
  87:   {
  88:     /**
  89:      * If the tag does not occurs in the html stream directly, but
  90:      * is supposed by parser, the tag attribute set contains this additional
  91:      * attribute, having value Boolean.True.
  92:      */
  93:     public static final Object IMPLIED = "_implied_";
  94: 
  95:     /**
  96:      * The parser calls this method after it finishes parsing the document.
  97:      */
  98:     public void flush()
  99:                throws BadLocationException
 100:     {
 101:     }
 102: 
 103:     /**
 104:      * Handle HTML comment, present in the given position.
 105:      * @param comment the comment
 106:      * @position the position of the comment in the text being parsed.
 107:      */
 108:     public void handleComment(char[] comment, int position)
 109:     {
 110:     }
 111: 
 112:     /**
 113:      * Notifies about the character sequences, used to separate lines in
 114:      * this document. The parser calls this method after it finishes
 115:      * parsing the document, but before flush().
 116:      * @param end_of_line The "end of line sequence", one of: \r or \n or \r\n.
 117:      */
 118:     public void handleEndOfLineString(String end_of_line)
 119:     {
 120:     }
 121: 
 122:     /**
 123:      * The method is called when the HTML closing tag ((like </table>)
 124:      * is found or if the parser concludes that the one should be present
 125:      * in the current position.
 126:      * @param The tag being handled
 127:      * @position the tag position in the text being parsed.
 128:      */
 129:     public void handleEndTag(HTML.Tag tag, int position)
 130:     {
 131:     }
 132: 
 133:     /**
 134:      * Handle the error.
 135:      * @param message The message, explaining the error.
 136:      * @param position The starting position of the fragment that has caused
 137:      * the error in the html document being parsed.
 138:      */
 139:     public void handleError(String message, int position)
 140:     {
 141:     }
 142: 
 143:     /**
 144:      * Handle the tag with no content, like <br>. The method is
 145:      * called for the elements that, in accordance with the current DTD,
 146:      * has an empty content.
 147:      * @param tag The tag being handled.
 148:      * @param position The tag position in the text being parsed.
 149:      */
 150:     public void handleSimpleTag(HTML.Tag tag, MutableAttributeSet attributes,
 151:                                 int position
 152:                                )
 153:     {
 154:     }
 155: 
 156:     /**
 157:      * The method is called when the HTML opening tag ((like <table>)
 158:      * is found or if the parser concludes that the one should be present
 159:      * in the current position.
 160:      * @param tag The tag being handled
 161:      * @param position The tag position in the text being parsed
 162:      */
 163:     public void handleStartTag(HTML.Tag tag, MutableAttributeSet attributes,
 164:                                int position
 165:                               )
 166:     {
 167:     }
 168: 
 169:     /**
 170:      * Handle the text section.
 171:      * @param text A section text.
 172:      * @param position The text position in the HTML document text being parsed.
 173:      */
 174:     public void handleText(char[] text, int position)
 175:     {
 176:     }
 177:   }
 178: 
 179:   /**
 180:    * Use serialVersionUID (v1.4) for interoperability.
 181:    */
 182:   private static final long serialVersionUID = 8751997116710384592L;
 183: 
 184:   /**
 185:    * Default cascading stylesheed file ("default.css").
 186:    */
 187:   public static final String DEFAULT_CSS = "default.css";
 188: 
 189:   /**
 190:    * The <b>bold</b> action identifier.
 191:    */
 192:   public static final String BOLD_ACTION = "html-bold-action";
 193: 
 194:   /**
 195:    * The <i>italic</i> action identifier.
 196:    */
 197:   public static final String ITALIC_ACTION = "html-italic-action";
 198: 
 199:   /**
 200:    * The <font color="#FF0000">color</font> action indentifier
 201:    * (passing the color as an argument).
 202:    */
 203:   public static final String COLOR_ACTION = "html-color-action";
 204: 
 205:   /**
 206:    * The <font size="+1">increase</font> font action identifier.
 207:    */
 208:   public static final String FONT_CHANGE_BIGGER = "html-font-bigger";
 209: 
 210:   /**
 211:    * The <font size="-1">decrease</font> font action identifier.
 212:    */
 213:   public static final String FONT_CHANGE_SMALLER = "html-font-smaller";
 214: 
 215:   /**
 216:    * Align images at the bottom.
 217:    */
 218:   public static final String IMG_ALIGN_BOTTOM = "html-image-align-bottom";
 219: 
 220:   /**
 221:    * Align images at the middle.
 222:    */
 223:   public static final String IMG_ALIGN_MIDDLE = "html-image-align-middle";
 224: 
 225:   /**
 226:    * Align images at the top.
 227:    */
 228:   public static final String IMG_ALIGN_TOP = "html-image-align-top";
 229: 
 230:   /**
 231:    * Align images at the border.
 232:    */
 233:   public static final String IMG_BORDER = "html-image-border";
 234: 
 235:   /**
 236:    * The "logical style" action identifier, passing that style as parameter.
 237:    */
 238:   public static final String LOGICAL_STYLE_ACTION = "html-logical-style-action";
 239: 
 240:   /**
 241:    * The "ident paragraph left" action.
 242:    */
 243:   public static final String PARA_INDENT_LEFT = "html-para-indent-left";
 244: 
 245:   /**
 246:    * The "ident paragraph right" action.
 247:    */
 248:   public static final String PARA_INDENT_RIGHT = "html-para-indent-right";