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.IOException;
  42: import java.io.Reader;
  43: import java.io.Serializable;
  44: 
  45: import javax.swing.text.BadLocationException;
  46: import javax.swing.text.Document;
  47: import javax.swing.text.MutableAttributeSet;
  48: import javax.swing.text.StyledEditorKit;
  49: import javax.swing.text.html.parser.ParserDelegator;
  50: 
  51: /**
  52:  * This class is NOT implemented. This file currently holds only
  53:  * declarations of the two enclosing classes, necessary for testing
  54:  * the implemented javax.swing.text.html.parser package.
  55:  *
  56:  * @author No authorship is taken, implement the class and be!
  57:  * TODO: replace this header after implementing the class.
  58:  */
  59: public class HTMLEditorKit
  60:   extends StyledEditorKit
  61:   implements Serializable, Cloneable
  62: {
  63:   /**
  64:    * The abstract HTML parser declaration.
  65:    */
  66:   public abstract static class Parser
  67:   {
  68:     /**
  69:      * Parse the HTML text, calling various methods of the provided callback
  70:      * in response to the occurence of the corresponding HTML constructions.
  71:      * @param reader The reader to read the source HTML from.
  72:      * @param callback The callback to receive information about the parsed
  73:      * HTML structures
  74:      * @param ignoreCharSet If true, the parser ignores all charset information
  75:      * that may be present in HTML documents.
  76:      * @throws IOException, normally if the reader throws one.
  77:      */
  78:     public abstract void parse(Reader reader, ParserCallback callback,
  79:                                boolean ignoreCharSet
  80:                               )
  81:                         throws IOException;
  82:   }
  83: 
  84:   /**
  85:    * The "hook" that receives all information about the HTML document
  86:    * structure while parsing it. The methods are invoked by parser
  87:    * and should be normally overridden.
  88:    */
  89:   public static class ParserCallback
  90:   {
  91:     /**
  92:      * If the tag does not occurs in the html stream directly, but
  93:      * is supposed by parser, the tag attribute set contains this additional
  94:      * attribute, having value Boolean.True.
  95:      */
  96:     public static final Object IMPLIED = "_implied_";
  97: 
  98:     /**
  99:      * The parser calls this method after it finishes parsing the document.
 100:      */
 101:     public void flush() throws BadLocationException
 102:     {
 103:       // TODO: What to do here, if anything?
 104:     }
 105: 
 106:     /**
 107:      * Handle HTML comment, present in the given position.
 108:      * @param comment the comment
 109:      * @position the position of the comment in the text being parsed.
 110:      */
 111:     public void handleComment(char[] comment, int position)
 112:     {
 113:       // TODO: What to do here, if anything?
 114:     }
 115: 
 116:     /**
 117:      * Notifies about the character sequences, used to separate lines in
 118:      * this document. The parser calls this method after it finishes
 119:      * parsing the document, but before flush().
 120:      * @param end_of_line The "end of line sequence", one of: \r or \n or \r\n.
 121:      */
 122:     public void handleEndOfLineString(String end_of_line)
 123:     {
 124:       // TODO: What to do here, if anything?
 125:     }
 126: 
 127:     /**
 128:      * The method is called when the HTML closing tag ((like </table>)
 129:      * is found or if the parser concludes that the one should be present
 130:      * in the current position.
 131:      * @param tag The tag being handled
 132:      * @param position the tag position in the text being parsed.
 133:      */
 134:     public void handleEndTag(HTML.Tag tag, int position)
 135:     {
 136:       // TODO: What to do here, if anything?
 137:     }
 138: 
 139:     /**
 140:      * Handle the error.
 141:      * @param message The message, explaining the error.
 142:      * @param position The starting position of the fragment that has caused
 143:      * the error in the html document being parsed.
 144:      */
 145:     public void handleError(String message, int position)
 146:     {
 147:       // TODO: What to do here, if anything?
 148:     }
 149: 
 150:     /**
 151:      * Handle the tag with no content, like <br>. The method is
 152:      * called for the elements that, in accordance with the current DTD,
 153:      * has an empty content.
 154:      * @param tag The tag being handled.
 155:      * @param position The tag position in the text being parsed.
 156:      */
 157:     public void handleSimpleTag(HTML.Tag tag, MutableAttributeSet attributes,
 158:                                 int position)
 159:     {
 160:       // TODO: What to do here, if anything?
 161:     }
 162: 
 163:     /**
 164:      * The method is called when the HTML opening tag ((like <table>)
 165:      * is found or if the parser concludes that the one should be present
 166:      * in the current position.
 167:      * @param tag The tag being handled
 168:      * @param position The tag position in the text being parsed
 169:      */
 170:     public void handleStartTag(HTML.Tag tag, MutableAttributeSet attributes,
 171:                                int position
 172:                               )
 173:     {
 174:       // TODO: What to do here, if anything?
 175:     }
 176: 
 177:     /**
 178:      * Handle the text section.
 179:      * @param text A section text.
 180:      * @param position The text position in the HTML document text being parsed.
 181:      */
 182:     public void handleText(char[] text, int position)
 183:     {
 184:       // TODO: What to do here, if anything?
 185:     }
 186:   }
 187: 
 188:   /**
 189:    * Use serialVersionUID (v1.4) for interoperability.
 190:    */
 191:   private static final long serialVersionUID = 8751997116710384592L;
 192: 
 193:   /**
 194:    * Default cascading stylesheed file ("default.css").
 195:    */
 196:   public static final String DEFAULT_CSS = "default.css";
 197: 
 198:   /**
 199:    * The <b>bold</b> action identifier.
 200:    */
 201:   public static final String BOLD_ACTION = "html-bold-action";
 202: 
 203:   /**
 204:    * The <i>italic</i> action identifier.
 205:    */
 206:   public static final String ITALIC_ACTION = "html-italic-action";
 207: 
 208:   /**
 209:    * The <font color="#FF0000">color</font> action indentifier
 210:    * (passing the color as an argument).
 211:    */
 212:   public static final String COLOR_ACTION = "html-color-action";
 213: 
 214:   /**
 215:    * The <font size="+1">increase</font> font action identifier.
 216:    */
 217:   public static final String FONT_CHANGE_BIGGER = "html-font-bigger";
 218: 
 219:   /**
 220:    * The <font size="-1">decrease</font> font action identifier.
 221:    */
 222:   public static final String FONT_CHANGE_SMALLER = "html-font-smaller";
 223: 
 224:   /**
 225:    * Align images at the bottom.
 226:    */
 227:   public static final String IMG_ALIGN_BOTTOM = "html-image-align-bottom";
 228: 
 229:   /**
 230:    * Align images at the middle.
 231:    */
 232:   public static final String IMG_ALIGN_MIDDLE = "html-image-align-middle";
 233: 
 234:   /**
 235:    * Align images at the top.
 236:    */
 237:   public static final String IMG_ALIGN_TOP = "html-image-align-top";
 238: 
 239:   /**
 240:    * Align images at the border.
 241:    */
 242:   public static final String IMG_BORDER = "html-image-border";
 243: 
 244:   /**
 245:    * The "logical style" action identifier, passing that style as parameter.
 246:    */
 247:   public static final String LOGICAL_STYLE_ACTION = "html-logical-style-action";
 248: 
 249:   /**
 250:    * The "ident paragraph left" action.
 251:    */
 252:   public static final String PARA_INDENT_LEFT = "html-para-indent-left";
 253: 
 254:   /**
 255:    * The "ident paragraph right" action.
 256:    */
 257:   public static final String PARA_INDENT_RIGHT = "html-para-indent-right";
 258: 
 259:   /**
 260:    * Create a text storage model for this type of editor.
 261:    *
 262:    * @return the model
 263:    */
 264:   public Document createDefaultDocument()
 265:   {
 266:     HTMLDocument document = new HTMLDocument();
 267:     return document;
 268:   }
 269: 
 270:   /**
 271:    * Get the parser that this editor kit uses for reading HTML streams. This
 272:    * method can be overridden to use the alternative parser.
 273:    *
 274:    * @return the HTML parser (by default, {@link ParserDelegator}).
 275:    */
 276:   protected Parser getParser()
 277:   {
 278:     return new ParserDelegator();
 279:   }