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
34 * @author Andreas Prlic Adapted for jalview use.
35 * @author Andrew Waterhouse Updated to Das 1.53e feature spec.
39 public class DAS_Feature_Handler extends DefaultHandler
53 StringBuffer characterdata;
69 public DAS_Feature_Handler()
73 features = new ArrayList();
76 characterdata = new StringBuffer();
87 * get the id information specified int the SEGMENT field of the DAS response
89 * @return the segmentId or an emtpy string if not available
91 public String getSegmentId()
97 * get the version informationspecified in the SEGMENT field of the DAS
100 * @return the version information of an empty string if not available
102 public String getVersion()
107 public boolean isMD5Checksum()
110 if ((version != null) && (version.length() == 32))
116 * specifies a maximum number of features to be downloaded. if a server
117 * returns more, they will be ignored. default is to load all features
120 * the maximium number of features to be downloaded
123 public void setMaxFeatures(int max)
128 public int getMaxFeatures()
133 public void setDASCommand(String cmd)
138 public String getDASCommand()
143 public List get_features()
148 public int getComBackLater()
150 return comeBackLater;
153 void start_feature(String uri, String name, String qName, Attributes atts)
156 if ((maxFeatures > 0) && (features.size() > maxFeatures))
158 characterdata = new StringBuffer();
161 feature = new HashMap();
162 String id = atts.getValue("id");
163 feature.put("id", id);
164 feature.put("dassource", dasCommand);
165 characterdata = new StringBuffer();
168 void add_featuredata(String uri, String name, String qName)
170 // System.out.println("featurefield "+featurefield+ " data "+characterdata);
171 // NOTE can have multiple lines ..
173 if ((maxFeatures > 0) && (features.size() > maxFeatures))
178 String data = (String) feature.get(featurefield);
179 String featureText = characterdata.toString();
182 featureText = data + " " + featureText;
185 if (qName.equals("TYPE"))
187 if (featureText.length() < 1)
188 featureText = type_id;
190 feature.put("TYPE_ID", type_id);
191 feature.put("TYPE_CATEGORY", type_category);
196 feature.put(featurefield, featureText);
198 characterdata = new StringBuffer();
201 private void addLink(String uri, String name, String qName,
204 String href = atts.getValue("href");
205 feature.put("LINK", href);
206 characterdata = new StringBuffer();
207 featurefield = "LINK-TEXT";
211 private void addGroup(String uri, String name, String qName,
214 String id = atts.getValue("id");
215 feature.put("GROUP", id);
216 characterdata = new StringBuffer();
217 featurefield = "GROUP";
220 public void startElement(String uri, String name, String qName,
223 // System.out.println("new element "+qName);
225 if (qName.equals("FEATURE"))
227 start_feature(uri, name, qName, atts);
229 else if (qName.equals("LINK"))
231 addLink(uri, name, qName, atts);
233 else if (qName.equals("GROUP"))
235 addGroup(uri, name, qName, atts);
237 else if (qName.equals("METHOD") || qName.equals("TYPE")
238 || qName.equals("START") || qName.equals("END")
239 || qName.equals("NOTE") || qName.equals("SCORE")
240 || qName.equals("ORIENTATION"))
242 characterdata = new StringBuffer();
243 featurefield = qName;
245 else if (qName.equals("SEGMENT"))
247 String id = atts.getValue("id");
250 String v = atts.getValue("version");
255 if (qName.equals("TYPE"))
257 type_id = atts.getValue("id");
258 type_category = atts.getValue("category");
263 public void startDocument()
267 public void endDocument()
271 public void endElement(String uri, String name, String qName)
274 if (qName.equals("METHOD") || qName.equals("TYPE")
275 || qName.equals("START") || qName.equals("END")
276 || qName.equals("NOTE") || qName.equals("LINK")
277 || qName.equals("SCORE") || qName.equals("ORIENTATION")
278 || qName.equals("GROUP"))
280 add_featuredata(uri, name, qName);
282 else if (qName.equals("FEATURE"))
287 if (features.size() < maxFeatures)
289 features.add(feature);
295 features.add(feature);
300 public void characters(char ch[], int start, int length)
303 if (features.size() > maxFeatures)
306 for (int i = start; i < start + length; i++)
309 characterdata.append(ch[i]);