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 org.biojava.dasobert.das;
29 import org.xml.sax.helpers.*;
32 * a class to parse the response of a DAS - Feature request
33 * @author Andreas Prlic
36 public class DAS_Feature_Handler
37 extends DefaultHandler
54 public DAS_Feature_Handler()
58 features = new ArrayList();
67 /** specifies a maximum number of features to be downloaded. if a
68 server returns more, they will be ignored. default is to load
70 @param max the maximium number of features to be downloaded
73 public void setMaxFeatures(int max)
78 public int getMaxFeatures()
83 public void setDASCommand(String cmd)
88 public String getDASCommand()
93 public List get_features()
98 public int getComBackLater()
100 return comeBackLater;
103 void start_feature(String uri, String name, String qName, Attributes atts)
106 if ( (maxFeatures > 0) && (features.size() > maxFeatures))
111 feature = new HashMap();
112 String id = atts.getValue("id");
113 feature.put("id", id);
114 feature.put("dassource", dasCommand);
118 void add_featuredata(String uri, String name, String qName)
120 //System.out.println("featurefield "+featurefield+ " data "+characterdata);
121 // NOTE can have multiple lines ..
123 if ( (maxFeatures > 0) && (features.size() > maxFeatures))
128 String data = (String) feature.get(featurefield);
131 characterdata = data + " " + characterdata;
134 feature.put(featurefield, characterdata);
139 private void addLink(String uri, String name, String qName, Attributes atts)
141 String href = atts.getValue("href");
142 feature.put("LINK", href);
144 featurefield = "LINK-TEXT";
148 public void startElement(String uri, String name, String qName,
151 //System.out.println("new element "+qName);
153 if (qName.equals("FEATURE"))
155 start_feature(uri, name, qName, atts);
157 else if (qName.equals("LINK"))
159 addLink(uri, name, qName, atts);
161 else if (qName.equals("METHOD") ||
162 qName.equals("TYPE") ||
163 qName.equals("START") ||
164 qName.equals("END") ||
165 qName.equals("NOTE") ||
166 qName.equals("SCORE")
170 featurefield = qName;
175 public void startDocument()
179 public void endDocument()
183 public void endElement(String uri, String name, String qName)
186 if (qName.equals("METHOD") ||
187 qName.equals("TYPE") ||
188 qName.equals("START") ||
189 qName.equals("END") ||
190 qName.equals("NOTE") ||
191 qName.equals("LINK") ||
192 qName.equals("SCORE")
195 add_featuredata(uri, name, qName);
197 else if (qName.equals("FEATURE"))
202 if (features.size() < maxFeatures)
204 features.add(feature);
210 features.add(feature);
215 public void characters(char ch[], int start, int length)
218 for (int i = start; i < start + length; i++)
221 characterdata += ch[i];