Class ValidatorPlugin

  • All Implemented Interfaces:
    IXMLValidator

    public class ValidatorPlugin
    extends java.lang.Object
    implements IXMLValidator
    ValidatorPlugin allows the application to insert additional validators into NanoXML.
    Author:
    Marc De Scheemaecker
    • Constructor Summary

      Constructors 
      Constructor Description
      ValidatorPlugin()
      Initializes the plugin.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void attributeAdded​(java.lang.String key, java.lang.String value, java.lang.String systemId, int lineNr)
      This method is called when the attributes of an XML element have been processed.
      void elementAttributesProcessed​(java.lang.String name, java.util.Properties extraAttributes, java.lang.String systemId, int lineNr)
      Indicates that an attribute has been added to the current element.
      void elementEnded​(java.lang.String name, java.lang.String systemId, int lineNr)
      Indicates that the current element has ended.
      void elementStarted​(java.lang.String name, java.lang.String systemId, int lineNr)
      Indicates that an element has been started.
      protected void finalize()
      Cleans up the object when it's destroyed.
      IXMLValidator getDelegate()
      Returns the delegate.
      IXMLEntityResolver getParameterEntityResolver()
      Returns the parameter entity resolver.
      void invalidAttributeValue​(java.lang.String systemID, int lineNr, java.lang.String elementName, java.lang.String attributeName, java.lang.String attributeValue)
      Throws an XMLValidationException to indicate that an attribute has an invalid value.
      void missingAttribute​(java.lang.String systemID, int lineNr, java.lang.String elementName, java.lang.String attributeName)
      Throws an XMLValidationException to indicate that an attribute is missing.
      void missingElement​(java.lang.String systemID, int lineNr, java.lang.String parentElementName, java.lang.String missingElementName)
      Throws an XMLValidationException to indicate that an element is missing.
      void missingPCData​(java.lang.String systemID, int lineNr, java.lang.String parentElementName)
      Throws an XMLValidationException to indicate that a #PCDATA element was missing.
      void parseDTD​(java.lang.String publicID, IXMLReader reader, IXMLEntityResolver entityResolver, boolean external)
      Parses the DTD.
      void PCDataAdded​(java.lang.String systemId, int lineNr)
      Indicates that a new #PCDATA element has been encountered.
      void setDelegate​(IXMLValidator delegate)
      Sets the delegate.
      void setParameterEntityResolver​(IXMLEntityResolver resolver)
      Sets the parameter entity resolver.
      void unexpectedAttribute​(java.lang.String systemID, int lineNr, java.lang.String elementName, java.lang.String attributeName)
      Throws an XMLValidationException to indicate that an attribute is unexpected.
      void unexpectedElement​(java.lang.String systemID, int lineNr, java.lang.String parentElementName, java.lang.String unexpectedElementName)
      Throws an XMLValidationException to indicate that an element is unexpected.
      void unexpectedPCData​(java.lang.String systemID, int lineNr, java.lang.String parentElementName)
      Throws an XMLValidationException to indicate that a #PCDATA element was unexpected.
      void validationError​(java.lang.String systemID, int lineNr, java.lang.String message, java.lang.String elementName, java.lang.String attributeName, java.lang.String attributeValue)
      Throws an XMLValidationException.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ValidatorPlugin

        public ValidatorPlugin()
        Initializes the plugin.
    • Method Detail

      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Cleans up the object when it's destroyed.
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • getDelegate

        public IXMLValidator getDelegate()
        Returns the delegate.
      • setDelegate

        public void setDelegate​(IXMLValidator delegate)
        Sets the delegate.
        Parameters:
        delegate - the delegate
      • parseDTD

        public void parseDTD​(java.lang.String publicID,
                             IXMLReader reader,
                             IXMLEntityResolver entityResolver,
                             boolean external)
                      throws java.lang.Exception
        Parses the DTD. The validator object is responsible for reading the full DTD.
        Specified by:
        parseDTD in interface IXMLValidator
        Parameters:
        publicID - the public ID, which may be null.
        reader - the reader to read the DTD from.
        entityResolver - the entity resolver.
        external - true if the DTD is external.
        Throws:
        java.lang.Exception - if something went wrong.
      • elementStarted

        public void elementStarted​(java.lang.String name,
                                   java.lang.String systemId,
                                   int lineNr)
                            throws java.lang.Exception
        Indicates that an element has been started.
        Specified by:
        elementStarted in interface IXMLValidator
        Parameters:
        name - the name of the element.
        systemId - the system ID of the XML data of the element.
        lineNr - the line number in the XML data of the element.
        Throws:
        java.lang.Exception - if the element could not be validated.
      • elementEnded

        public void elementEnded​(java.lang.String name,
                                 java.lang.String systemId,
                                 int lineNr)
                          throws java.lang.Exception
        Indicates that the current element has ended.
        Specified by:
        elementEnded in interface IXMLValidator
        Parameters:
        name - the name of the element.
        systemId - the system ID of the XML data of the element.
        lineNr - the line number in the XML data of the element.
        Throws:
        java.lang.Exception - if the element could not be validated.
      • elementAttributesProcessed

        public void elementAttributesProcessed​(java.lang.String name,
                                               java.util.Properties extraAttributes,
                                               java.lang.String systemId,
                                               int lineNr)
                                        throws java.lang.Exception
        Indicates that an attribute has been added to the current element.
        Specified by:
        elementAttributesProcessed in interface IXMLValidator
        Parameters:
        key - the name of the attribute.
        value - the value of the attribute.
        systemId - the system ID of the XML data of the element.
        lineNr - the line number in the XML data of the element.
        Throws:
        java.lang.Exception - if the attribute could not be validated.
      • attributeAdded

        public void attributeAdded​(java.lang.String key,
                                   java.lang.String value,
                                   java.lang.String systemId,
                                   int lineNr)
                            throws java.lang.Exception
        This method is called when the attributes of an XML element have been processed. If there are attributes with a default value which have not been specified yet, they have to be put into extraAttributes.
        Specified by:
        attributeAdded in interface IXMLValidator
        Parameters:
        name - the name of the element.
        extraAttributes - where to put extra attributes.
        systemId - the system ID of the XML data of the element.
        lineNr - the line number in the XML data of the element.
        Throws:
        java.lang.Exception - if the element could not be validated.
      • PCDataAdded

        public void PCDataAdded​(java.lang.String systemId,
                                int lineNr)
                         throws java.lang.Exception
        Indicates that a new #PCDATA element has been encountered.
        Specified by:
        PCDataAdded in interface IXMLValidator
        Parameters:
        systemId - the system ID of the XML data of the element.
        lineNr - the line number in the XML data of the element.
        Throws:
        java.lang.Exception - if the element could not be validated.
      • missingElement

        public void missingElement​(java.lang.String systemID,
                                   int lineNr,
                                   java.lang.String parentElementName,
                                   java.lang.String missingElementName)
                            throws XMLValidationException
        Throws an XMLValidationException to indicate that an element is missing.
        Parameters:
        systemID - the system ID of the XML data of the element
        lineNr - the line number in the XML data of the element
        parentElementName - the name of the parent element
        missingElementName - the name of the missing element
        Throws:
        XMLValidationException - of course :-)
      • unexpectedElement

        public void unexpectedElement​(java.lang.String systemID,
                                      int lineNr,
                                      java.lang.String parentElementName,
                                      java.lang.String unexpectedElementName)
                               throws XMLValidationException
        Throws an XMLValidationException to indicate that an element is unexpected.
        Parameters:
        systemID - the system ID of the XML data of the element
        lineNr - the line number in the XML data of the element
        parentElementName - the name of the parent element
        unexpectedElementName - the name of the missing element
        Throws:
        XMLValidationException - of course :-)
      • missingAttribute

        public void missingAttribute​(java.lang.String systemID,
                                     int lineNr,
                                     java.lang.String elementName,
                                     java.lang.String attributeName)
                              throws XMLValidationException
        Throws an XMLValidationException to indicate that an attribute is missing.
        Parameters:
        systemID - the system ID of the XML data of the element
        lineNr - the line number in the XML data of the element
        elementName - the name of the element
        attributeName - the name of the missing attribute
        Throws:
        XMLValidationException - of course :-)
      • unexpectedAttribute

        public void unexpectedAttribute​(java.lang.String systemID,
                                        int lineNr,
                                        java.lang.String elementName,
                                        java.lang.String attributeName)
                                 throws XMLValidationException
        Throws an XMLValidationException to indicate that an attribute is unexpected.
        Parameters:
        systemID - the system ID of the XML data of the element
        lineNr - the line number in the XML data of the element
        elementName - the name of the element
        attributeName - the name of the unexpected attribute
        Throws:
        XMLValidationException - of course :-)
      • invalidAttributeValue

        public void invalidAttributeValue​(java.lang.String systemID,
                                          int lineNr,
                                          java.lang.String elementName,
                                          java.lang.String attributeName,
                                          java.lang.String attributeValue)
                                   throws XMLValidationException
        Throws an XMLValidationException to indicate that an attribute has an invalid value.
        Parameters:
        systemID - the system ID of the XML data of the element
        lineNr - the line number in the XML data of the element
        elementName - the name of the element
        attributeName - the name of the attribute
        attributeValue - the value of the attribute
        Throws:
        XMLValidationException - of course :-)
      • missingPCData

        public void missingPCData​(java.lang.String systemID,
                                  int lineNr,
                                  java.lang.String parentElementName)
                           throws XMLValidationException
        Throws an XMLValidationException to indicate that a #PCDATA element was missing.
        Parameters:
        systemID - the system ID of the XML data of the element
        lineNr - the line number in the XML data of the element
        parentElementName - the name of the parent element
        Throws:
        XMLValidationException - of course :-)
      • unexpectedPCData

        public void unexpectedPCData​(java.lang.String systemID,
                                     int lineNr,
                                     java.lang.String parentElementName)
                              throws XMLValidationException
        Throws an XMLValidationException to indicate that a #PCDATA element was unexpected.
        Parameters:
        systemID - the system ID of the XML data of the element
        lineNr - the line number in the XML data of the element
        parentElementName - the name of the parent element
        Throws:
        XMLValidationException - of course :-)
      • validationError

        public void validationError​(java.lang.String systemID,
                                    int lineNr,
                                    java.lang.String message,
                                    java.lang.String elementName,
                                    java.lang.String attributeName,
                                    java.lang.String attributeValue)
                             throws XMLValidationException
        Throws an XMLValidationException.
        Parameters:
        systemID - the system ID of the XML data of the element
        lineNr - the line number in the XML data of the element
        message - the error message
        elementName - the name of the element (may be null)
        attributeName - the name of the attribute (may be null)
        attributeValue - the value of the attribute (may be null)
        Throws:
        XMLValidationException - of course :-)