Package org.fife.rsta.ac.xml
Class XmlParser
- java.lang.Object
-
- org.fife.ui.rsyntaxtextarea.parser.AbstractParser
-
- org.fife.rsta.ac.xml.XmlParser
-
- All Implemented Interfaces:
org.fife.ui.rsyntaxtextarea.parser.Parser
public class XmlParser extends org.fife.ui.rsyntaxtextarea.parser.AbstractParserParses XML code in anRSyntaxTextArea.Like all RSTA
Parsers, anXmlParserinstance 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 typePROPERTY_ASTis fired. Listeners can check the new value of the property for anXmlTreeNodethat represents the root of a tree structure modeling the XML content in the text area. Note that theXmlTreeNodemay 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 classXmlParser.HandlerCallback for events when we're parsing the XML in the editor.
-
Field Summary
Fields Modifier and Type Field Description private XmlTreeNodecurElemprivate intelemCountprivate org.xml.sax.Locatorlocatorstatic java.lang.StringPROPERTY_ASTThe property change event that's fired when the document is re-parsed.private XmlTreeNoderootprivate javax.xml.parsers.SAXParserspprivate javax.xml.parsers.SAXParserFactoryspfprivate java.beans.PropertyChangeSupportsupportprivate ValidationConfigvalidationConfigprivate XmlLanguageSupportxls
-
Constructor Summary
Constructors Constructor Description XmlParser(XmlLanguageSupport xls)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPropertyChangeListener(java.lang.String prop, java.beans.PropertyChangeListener l)Adds a listener to this parser.XmlTreeNodegetAst()Returns the XML model from the last time it was parsed.private java.lang.StringgetMainAttribute(org.xml.sax.Attributes attributes)Returns a string representing the "main" attribute for an element.javax.xml.parsers.SAXParserFactorygetSaxParserFactory()org.fife.ui.rsyntaxtextarea.parser.ParseResultparse(org.fife.ui.rsyntaxtextarea.RSyntaxDocument doc, java.lang.String style)voidremovePropertyChangeListener(java.lang.String prop, java.beans.PropertyChangeListener l)Removes a listener on a specific property.voidsetValidationConfig(ValidationConfig config)Sets how validation will be done by this parser.
-
-
-
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 anXmlTreeNoderepresenting the root of a tree modeling the XML content. The "old value" is alwaysnull.- See Also:
- Constant Field Values
-
xls
private XmlLanguageSupport xls
-
support
private java.beans.PropertyChangeSupport support
-
curElem
private XmlTreeNode curElem
-
root
private XmlTreeNode root
-
locator
private org.xml.sax.Locator locator
-
spf
private javax.xml.parsers.SAXParserFactory spf
-
sp
private javax.xml.parsers.SAXParser sp
-
validationConfig
private ValidationConfig validationConfig
-
elemCount
private int elemCount
-
-
Constructor Detail
-
XmlParser
public XmlParser(XmlLanguageSupport xls)
-
-
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 thePROPERTY_ASTproperty.- 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
nullif 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 isnull, no validation will be done.
-
-