001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021package org.biojava.bio.seq.io.agave;
022import org.xml.sax.Attributes;
023
024/**
025 * This class is copied to agave package
026 *
027 * Simple interface for filtering SAX/StAX startElement events
028 *
029 */
030public interface ElementRecognizer {
031    public static final ElementRecognizer ALL = new AllElementRecognizer();
032
033    public static class AllElementRecognizer implements ElementRecognizer {
034        public boolean filterStartElement(String nsURI,
035                                              String localName,
036                                              String qName,
037                                              Attributes attrs)
038        {
039            return true;
040        }
041    }
042
043    /**
044     * Filter elements on the existence of a specified attribute.
045     */
046
047    public static class HasAttribute implements ElementRecognizer {
048        private String attributeName;
049
050        public HasAttribute(String name) {
051            attributeName = name;
052        }
053
054        public boolean filterStartElement(String nsURI,
055                                          String localName,
056                                          String qName,
057                                          Attributes attrs)
058        {
059            return (attrs.getValue(attributeName) != null);
060        }
061    }
062
063    /**
064     * Filter elements by name and namespace.
065     */
066
067    public static class ByNSName implements ElementRecognizer {
068        private String nsURI;
069        private String localName;
070
071        public ByNSName(String nsURI, String localName) {
072            this.nsURI = nsURI;
073            this.localName = localName;
074        }
075
076        public boolean filterStartElement(String nsURI,
077                                          String localName,
078                                          String qName,
079                                          Attributes attrs)
080        {
081            return (localName.equals(this.localName) && nsURI.equals(this.nsURI));
082        }
083    }
084
085    /**
086     * Filter elements by local name (not recommended).
087     */
088
089    public static class ByLocalName implements ElementRecognizer {
090        private String localName;
091
092        public ByLocalName(String localName) {
093            this.localName = localName;
094        }
095
096        public boolean filterStartElement(String nsURI,
097                                          String localName,
098                                          String qName,
099                                          Attributes attrs)
100        {
101            return (localName.equals(this.localName));
102        }
103    }
104
105    public boolean filterStartElement(String nsURI, String localName, String qName, Attributes attrs);
106}