Class XmlParser

  • All Implemented Interfaces:
    org.fife.ui.rsyntaxtextarea.parser.Parser

    public class XmlParser
    extends org.fife.ui.rsyntaxtextarea.parser.AbstractParser
    Parses XML code in an RSyntaxTextArea.

    Like all RSTA Parsers, an XmlParser instance is notified when the RSTA's text content changes. After a small delay, it will parse the content as XML, building an AST and looking for any errors. When parsing is complete, a property change event of type PROPERTY_AST is fired. Listeners can check the new value of the property for an XmlTreeNode that represents the root of a tree structure modeling the XML content in the text area. Note that the XmlTreeNode may be incomplete if there were parsing/syntax errors (it will usually be complete "up to" the error in the content).

    This parser cannot be shared amongst multiple instances of RSyntaxTextArea.

    Version:
    1.0
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  XmlParser.Handler
      Callback for events when we're parsing the XML in the editor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addPropertyChangeListener​(java.lang.String prop, java.beans.PropertyChangeListener l)
      Adds a listener to this parser.
      XmlTreeNode getAst()
      Returns the XML model from the last time it was parsed.
      private java.lang.String getMainAttribute​(org.xml.sax.Attributes attributes)
      Returns a string representing the "main" attribute for an element.
      javax.xml.parsers.SAXParserFactory getSaxParserFactory()  
      org.fife.ui.rsyntaxtextarea.parser.ParseResult parse​(org.fife.ui.rsyntaxtextarea.RSyntaxDocument doc, java.lang.String style)
      void removePropertyChangeListener​(java.lang.String prop, java.beans.PropertyChangeListener l)
      Removes a listener on a specific property.
      void setValidationConfig​(ValidationConfig config)
      Sets how validation will be done by this parser.
      • Methods inherited from class org.fife.ui.rsyntaxtextarea.parser.AbstractParser

        getHyperlinkListener, getImageBase, isEnabled, setEnabled, setHyperlinkListener
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PROPERTY_AST

        public static final java.lang.String PROPERTY_AST
        The property change event that's fired when the document is re-parsed. Applications can listen for this property change and update themselves accordingly. The property's "new value" will be an XmlTreeNode representing the root of a tree modeling the XML content. The "old value" is always null.
        See Also:
        Constant Field Values
      • support

        private java.beans.PropertyChangeSupport support
      • locator

        private org.xml.sax.Locator locator
      • spf

        private javax.xml.parsers.SAXParserFactory spf
      • sp

        private javax.xml.parsers.SAXParser sp
      • elemCount

        private int elemCount
    • Method Detail

      • addPropertyChangeListener

        public void addPropertyChangeListener​(java.lang.String prop,
                                              java.beans.PropertyChangeListener l)
        Adds a listener to this parser. Typically you'd want to register a listener on the PROPERTY_AST property.
        Parameters:
        prop - The property to listen for changes on.
        l - The listener itself.
        See Also:
        removePropertyChangeListener(String, PropertyChangeListener)
      • getAst

        public XmlTreeNode getAst()
        Returns the XML model from the last time it was parsed.
        Returns:
        The root node of the XML model, or null if it has not yet been parsed or an error occurred while parsing.
      • getMainAttribute

        private java.lang.String getMainAttribute​(org.xml.sax.Attributes attributes)
        Returns a string representing the "main" attribute for an element.
        Parameters:
        attributes - The attributes of an element. Calling code should have already verified this has length > 0.
        Returns:
        The "main" attribute.
      • getSaxParserFactory

        public javax.xml.parsers.SAXParserFactory getSaxParserFactory()
      • parse

        public org.fife.ui.rsyntaxtextarea.parser.ParseResult parse​(org.fife.ui.rsyntaxtextarea.RSyntaxDocument doc,
                                                                    java.lang.String style)
      • removePropertyChangeListener

        public void removePropertyChangeListener​(java.lang.String prop,
                                                 java.beans.PropertyChangeListener l)
        Removes a listener on a specific property.
        Parameters:
        prop - The property being listened to.
        l - The listener to remove.
        See Also:
        addPropertyChangeListener(String, PropertyChangeListener)
      • setValidationConfig

        public void setValidationConfig​(ValidationConfig config)
        Sets how validation will be done by this parser. This can be used to set up either DTD or Schema validation.
        Parameters:
        config - Configuration information for validation. If this is null, no validation will be done.