2 * BioJava development code
4 * This code may be freely distributed and modified under the
5 * terms of the GNU Lesser General Public Licence. This should
6 * be distributed with the code. If you do not have a copy,
9 * http://www.gnu.org/copyleft/lesser.html
11 * Copyright for this code is held jointly by the individual
12 * authors. These should be listed in @author doc comments.
14 * For more information on the BioJava project and its aims,
15 * or to join the biojava-l mailing list, visit the home page
18 * http://www.biojava.org/
20 * Created on 19.03.2004
21 * @author Andreas Prlic
24 package jalview.biojava.dasobert.das;
26 import org.xml.sax.helpers.DefaultHandler;
27 import org.xml.sax.Attributes;
29 import java.util.ArrayList ;
30 import java.util.HashMap ;
31 import java.util.List;
34 * a class to parse the response of a DAS - Feature request
35 * @author Andreas Prlic
38 public class DAS_Feature_Handler extends DefaultHandler{
47 String characterdata ;
54 public DAS_Feature_Handler() {
57 features= new ArrayList() ;
66 /** specifies a maximum number of features to be downloaded. if a
67 server returns more, they will be ignored. default is to load
69 @param max the maximium number of features to be downloaded
72 public void setMaxFeatures(int max) {
76 public int getMaxFeatures() {
80 public void setDASCommand(String cmd) { dasCommand = cmd ;}
81 public String getDASCommand() { return dasCommand; }
83 public List get_features() {
87 public int getComBackLater(){
91 void start_feature(String uri, String name, String qName, Attributes atts) {
93 if (( maxFeatures > 0 ) && ( features.size() > maxFeatures ) ) {
97 feature = new HashMap() ;
98 String id = atts.getValue("id");
100 feature.put("dassource",dasCommand);
104 void add_featuredata(String uri, String name, String qName) {
105 //System.out.println("featurefield "+featurefield+ " data "+characterdata);
106 // NOTE can have multiple lines ..
108 if (( maxFeatures > 0 ) && ( features.size() > maxFeatures ) ) {
113 String data = (String)feature.get(featurefield);
115 characterdata = data + " " + characterdata;
118 feature.put(featurefield,characterdata);
123 private void addLink(String uri, String name, String qName, Attributes atts) {
124 String href = atts.getValue("href");
125 feature.put("LINK",href);
127 featurefield = "LINK-TEXT";
131 public void startElement (String uri, String name, String qName, Attributes atts){
132 //System.out.println("new element "+qName);
134 if (qName.equals("FEATURE"))
135 start_feature(uri, name, qName, atts);
136 else if ( qName.equals("LINK"))
137 addLink(uri,name,qName, atts);
138 else if ( qName.equals("METHOD") ||
139 qName.equals("TYPE") ||
140 qName.equals("START") ||
141 qName.equals("END") ||
142 qName.equals("NOTE") ||
143 qName.equals("SCORE")
146 featurefield = qName ;
151 public void startDocument() {
154 public void endDocument () {
156 public void endElement(String uri, String name, String qName) {
158 if ( qName.equals("METHOD") ||
159 qName.equals("TYPE") ||
160 qName.equals("START") ||
161 qName.equals("END") ||
162 qName.equals("NOTE") ||
163 qName.equals("LINK") ||
164 qName.equals("SCORE")
166 add_featuredata(uri,name,qName);
168 else if ( qName.equals("FEATURE")) {
170 if ( maxFeatures > 0 ) {
171 if ( features.size() < maxFeatures ) {
172 features.add(feature);
176 features.add(feature);
181 public void characters (char ch[], int start, int length){
183 for (int i = start; i < start + length; i++) {
185 characterdata += ch[i];