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;
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 ;
52 public DAS_Feature_Handler() {
55 features= new ArrayList() ;
63 public void setDASCommand(String cmd) { dasCommand = cmd ;}
64 public String getDASCommand() { return dasCommand; }
66 public List get_features() {
70 public int getComBackLater(){
74 void start_feature(String uri, String name, String qName, Attributes atts) {
75 feature = new HashMap() ;
76 String id = atts.getValue("id");
78 feature.put("dassource",dasCommand);
82 void add_featuredata(String uri, String name, String qName) {
83 //System.out.println("featurefield "+featurefield+ " data "+characterdata);
84 // NOTE can have multiple lines ..
86 String data = (String)feature.get(featurefield);
88 characterdata = data + " " + characterdata;
91 feature.put(featurefield,characterdata);
96 private void addLink(String uri, String name, String qName, Attributes atts) {
97 String href = atts.getValue("href");
98 feature.put("LINK",href);
100 featurefield = "LINK-TEXT";
104 public void startElement (String uri, String name, String qName, Attributes atts){
105 //System.out.println("new element "+qName);
107 if (qName.equals("FEATURE"))
108 start_feature(uri, name, qName, atts);
109 else if ( qName.equals("LINK"))
110 addLink(uri,name,qName, atts);
111 else if ( qName.equals("METHOD") ||
112 qName.equals("TYPE") ||
113 qName.equals("START") ||
114 qName.equals("END") ||
115 qName.equals("NOTE") ||
116 qName.equals("SCORE")
119 featurefield = qName ;
124 public void startDocument() {
125 //System.out.println("start document");
128 public void endDocument () {
129 //System.out.println("adding feature " + feature);
130 //features.add(feature);
133 public void endElement(String uri, String name, String qName) {
134 //System.out.println("end "+name);
135 if ( qName.equals("METHOD") ||
136 qName.equals("TYPE") ||
137 qName.equals("START") ||
138 qName.equals("END") ||
139 qName.equals("NOTE") ||
140 qName.equals("LINK") ||
141 qName.equals("SCORE")
143 add_featuredata(uri,name,qName);
145 else if ( qName.equals("FEATURE")) {
146 //System.out.println("adding ffeature " + feature);
147 features.add(feature);
151 public void characters (char ch[], int start, int length){
152 //System.out.println("characters");
153 for (int i = start; i < start + length; i++) {
155 characterdata += ch[i];