jwo.utils.gui.html
Class ImprovedHTMLEditorKit

java.lang.Object
  extended by javax.swing.text.EditorKit
      extended by javax.swing.text.DefaultEditorKit
          extended by javax.swing.text.StyledEditorKit
              extended by javax.swing.text.html.HTMLEditorKit
                  extended by jwo.utils.gui.html.ImprovedHTMLEditorKit
All Implemented Interfaces:
Serializable, Cloneable, Accessible

public class ImprovedHTMLEditorKit
extends HTMLEditorKit

HTML editor kit to replace the default one used by JEditorPane. This kit can attempt to parse XHTML as well as HTML 3.2. It can report XHTML parsing errors to a log which can be retrieved using the getErrorLog() method. It also adopts a more sophisticated mechanism for looking for relative image links. Image searching based on the JavaWorld Tip 109.

Version:
2.3, 20th December, 2004.
Author:
Jo Wood with image searching code by Rob Kenworthy.
See Also:
Serialized Form

Nested Class Summary
static class ImprovedHTMLEditorKit.HTMLFactoryX
          A customised view factory that contains an image viewer that can cope with relative links.
 
Nested classes/interfaces inherited from class javax.swing.text.html.HTMLEditorKit
HTMLEditorKit.HTMLFactory, HTMLEditorKit.HTMLTextAction, HTMLEditorKit.InsertHTMLTextAction, HTMLEditorKit.LinkController, HTMLEditorKit.Parser, HTMLEditorKit.ParserCallback
 
Nested classes/interfaces inherited from class javax.swing.text.StyledEditorKit
StyledEditorKit.AlignmentAction, StyledEditorKit.BoldAction, StyledEditorKit.FontFamilyAction, StyledEditorKit.FontSizeAction, StyledEditorKit.ForegroundAction, StyledEditorKit.ItalicAction, StyledEditorKit.StyledTextAction, StyledEditorKit.UnderlineAction
 
Nested classes/interfaces inherited from class javax.swing.text.DefaultEditorKit
DefaultEditorKit.BeepAction, DefaultEditorKit.CopyAction, DefaultEditorKit.CutAction, DefaultEditorKit.DefaultKeyTypedAction, DefaultEditorKit.InsertBreakAction, DefaultEditorKit.InsertContentAction, DefaultEditorKit.InsertTabAction, DefaultEditorKit.PasteAction
 
Field Summary
 
Fields inherited from class javax.swing.text.html.HTMLEditorKit
BOLD_ACTION, COLOR_ACTION, DEFAULT_CSS, FONT_CHANGE_BIGGER, FONT_CHANGE_SMALLER, IMG_ALIGN_BOTTOM, IMG_ALIGN_MIDDLE, IMG_ALIGN_TOP, IMG_BORDER, ITALIC_ACTION, LOGICAL_STYLE_ACTION, PARA_INDENT_LEFT, PARA_INDENT_RIGHT
 
Fields inherited from class javax.swing.text.DefaultEditorKit
backwardAction, beepAction, beginAction, beginLineAction, beginParagraphAction, beginWordAction, copyAction, cutAction, defaultKeyTypedAction, deleteNextCharAction, deletePrevCharAction, downAction, endAction, endLineAction, EndOfLineStringProperty, endParagraphAction, endWordAction, forwardAction, insertBreakAction, insertContentAction, insertTabAction, nextWordAction, pageDownAction, pageUpAction, pasteAction, previousWordAction, readOnlyAction, selectAllAction, selectionBackwardAction, selectionBeginAction, selectionBeginLineAction, selectionBeginParagraphAction, selectionBeginWordAction, selectionDownAction, selectionEndAction, selectionEndLineAction, selectionEndParagraphAction, selectionEndWordAction, selectionForwardAction, selectionNextWordAction, selectionPreviousWordAction, selectionUpAction, selectLineAction, selectParagraphAction, selectWordAction, upAction, writableAction
 
Constructor Summary
ImprovedHTMLEditorKit()
          Creates an editor kit that will process HTML, but will not validate XHTML.
ImprovedHTMLEditorKit(boolean validateXHTML)
          Creates an editor kit that will process (X)HTML.
 
Method Summary
 String getErrorLog()
          Reports the error log that can contain any errors or warnings generated when attempting to parse some (X)HTML.
protected  HTMLEditorKit.Parser getParser()
          Returns the a parser used to process the (X)HTML.
 ViewFactory getViewFactory()
          Overrides the default view factory by returning a customised HTML view factory that looks for relative links.
 boolean isLastParseSuccessful()
          Reports whether the last parse of code was successful.
 boolean isValidation()
          Reports whether or not XHTML validation is set.
 boolean setNewStyleSheet(String css)
          Sets the style sheet of the editor kit to the given css file.
 void setValidation(boolean validateXHTML)
          Determines whether or not XHTML validation is to be applied.
 boolean validateXHTML(String xhtml)
          Validates the given XHTML content.
 
Methods inherited from class javax.swing.text.html.HTMLEditorKit
clone, createDefaultDocument, createInputAttributes, deinstall, getAccessibleContext, getActions, getContentType, getDefaultCursor, getInputAttributes, getLinkCursor, getStyleSheet, insertHTML, install, isAutoFormSubmission, read, setAutoFormSubmission, setDefaultCursor, setLinkCursor, setStyleSheet, write
 
Methods inherited from class javax.swing.text.StyledEditorKit
getCharacterAttributeRun
 
Methods inherited from class javax.swing.text.DefaultEditorKit
createCaret, read, write
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImprovedHTMLEditorKit

public ImprovedHTMLEditorKit()
Creates an editor kit that will process HTML, but will not validate XHTML.


ImprovedHTMLEditorKit

public ImprovedHTMLEditorKit(boolean validateXHTML)
Creates an editor kit that will process (X)HTML. Can validate XHTML if validateXHTML is true.

Parameters:
validateXHTML - Will validate for XHTML wellformedness if true.
Method Detail

getViewFactory

public ViewFactory getViewFactory()
Overrides the default view factory by returning a customised HTML view factory that looks for relative links.

Overrides:
getViewFactory in class HTMLEditorKit
Returns:
An HTML view factory.

getErrorLog

public String getErrorLog()
Reports the error log that can contain any errors or warnings generated when attempting to parse some (X)HTML.

Returns:
Text of error log. Will be empty, but not null if no errors.

isValidation

public boolean isValidation()
Reports whether or not XHTML validation is set.

Returns:
True if kit set to validate for well-formed XHTML.

setValidation

public void setValidation(boolean validateXHTML)
Determines whether or not XHTML validation is to be applied.

Parameters:
validateXHTML - If true kit set to validate for well-formed XHTML.

isLastParseSuccessful

public boolean isLastParseSuccessful()
Reports whether the last parse of code was successful. If the parser is not validating XHTML, this will always be true. Any errors or warnings of XHTML parsing will result in this method returning false.

Returns:
True if last parse of XHTML (or HTML) was caused no errors or warnings. If false, details of the error can be found from the getErrorLog() method.

setNewStyleSheet

public boolean setNewStyleSheet(String css)
Sets the style sheet of the editor kit to the given css file. This file should be relative to the directory identified by system.css.path.key or identified as an absolute URL.

Parameters:
css - CSS file to use for formatting output.
Returns:
True if CSS file found and used.

validateXHTML

public boolean validateXHTML(String xhtml)
Validates the given XHTML content. If validation is not set (via the constructor or setValidation()), this method will always return true. If validation is set and the given XHTML is not well-formed, the form of the error can be found from getErrorLog.

Parameters:
xhtml - Text to validate.
Returns:
True if the XHTML (or HTML) was caused no errors or warnings.

getParser

protected HTMLEditorKit.Parser getParser()
Returns the a parser used to process the (X)HTML. This will either validate XHTML or HTML depending on the constructor used.

Overrides:
getParser in class HTMLEditorKit
Returns:
XHTML parser.


Copyright Jo Wood, 1996-2009, last modified, 17th April, 2009