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
34 * Adapted for jalview use.
35 * @author Andrew Waterhouse
36 * Updated to Das 1.53e feature spec.
40 public class DAS_Feature_Handler
41 extends DefaultHandler
51 StringBuffer characterdata;
64 public DAS_Feature_Handler() {
67 features = new ArrayList();
70 characterdata = new StringBuffer();
82 /** get the id information specified int the SEGMENT field of the DAS response
84 * @return the segmentId or an emtpy string if not available
86 public String getSegmentId() {
90 /** get the version informationspecified in the SEGMENT field of the DAS response
92 * @return the version information of an empty string if not available
94 public String getVersion() {
98 public boolean isMD5Checksum(){
100 if ((version != null) && (version.length() == 32))
106 /** specifies a maximum number of features to be downloaded. if a
107 server returns more, they will be ignored. default is to load
109 @param max the maximium number of features to be downloaded
112 public void setMaxFeatures(int max)
117 public int getMaxFeatures()
122 public void setDASCommand(String cmd)
127 public String getDASCommand()
132 public List get_features()
137 public int getComBackLater()
139 return comeBackLater;
142 void start_feature(String uri, String name, String qName, Attributes atts)
145 if (( maxFeatures > 0 ) && ( features.size() > maxFeatures ) ) {
146 characterdata = new StringBuffer();
149 feature = new HashMap();
150 String id = atts.getValue("id");
151 feature.put("id", id);
152 feature.put("dassource", dasCommand);
153 characterdata = new StringBuffer();
156 void add_featuredata(String uri, String name, String qName)
158 //System.out.println("featurefield "+featurefield+ " data "+characterdata);
159 // NOTE can have multiple lines ..
161 if ( (maxFeatures > 0) && (features.size() > maxFeatures))
166 String data = (String) feature.get(featurefield);
167 String featureText = characterdata.toString();
169 featureText = data + " " + featureText;
172 if ( qName.equals("TYPE")){
173 if ( featureText.length() < 1)
174 featureText = type_id;
176 feature.put("TYPE_ID",type_id);
177 feature.put("TYPE_CATEGORY", type_category);
183 feature.put(featurefield,featureText);
185 characterdata = new StringBuffer();
188 private void addLink(String uri, String name, String qName, Attributes atts)
190 String href = atts.getValue("href");
191 feature.put("LINK", href);
192 characterdata= new StringBuffer();
193 featurefield = "LINK-TEXT";
197 private void addGroup(String uri, String name, String qName, Attributes atts) {
198 String id = atts.getValue("id");
199 feature.put("GROUP",id);
200 characterdata= new StringBuffer();
201 featurefield = "GROUP";
204 public void startElement (String uri, String name, String qName, Attributes atts){
205 //System.out.println("new element "+qName);
207 if (qName.equals("FEATURE"))
209 start_feature(uri, name, qName, atts);
211 else if (qName.equals("LINK"))
213 addLink(uri, name, qName, atts);
214 } else if ( qName.equals("GROUP"))
215 { addGroup(uri,name,qName, atts); }
216 else if (qName.equals("METHOD") ||
217 qName.equals("TYPE") ||
218 qName.equals("START") ||
219 qName.equals("END") ||
220 qName.equals("NOTE") ||
221 qName.equals("SCORE") ||
222 qName.equals("ORIENTATION")
224 characterdata = new StringBuffer();
225 featurefield = qName;
226 } else if (qName.equals("SEGMENT")){
227 String id = atts.getValue("id");
230 String v = atts.getValue("version");
236 if ( qName.equals("TYPE")){
237 type_id = atts.getValue("id");
238 type_category= atts.getValue("category");
243 public void startDocument()
247 public void endDocument()
251 public void endElement(String uri, String name, String qName)
254 if (qName.equals("METHOD") ||
255 qName.equals("TYPE") ||
256 qName.equals("START") ||
257 qName.equals("END") ||
258 qName.equals("NOTE") ||
259 qName.equals("LINK") ||
260 qName.equals("SCORE") ||
261 qName.equals("ORIENTATION") ||
262 qName.equals("GROUP")
264 add_featuredata(uri, name, qName);
266 else if (qName.equals("FEATURE"))
271 if (features.size() < maxFeatures)
273 features.add(feature);
279 features.add(feature);
284 public void characters (char ch[], int start, int length){
285 if ( maxFeatures > 0)
286 if ( features.size() > maxFeatures )
289 for (int i = start; i < start + length; i++) {
291 characterdata.append(ch[i]);