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;
27 import org.xml.sax.helpers.DefaultHandler;
28 import org.xml.sax.Attributes ;
29 import java.util.logging.* ;
32 * a class that parses the XML response of a DAS - sequence command.
33 * @author Andreas Prlic
36 public class DAS_Sequence_Handler extends DefaultHandler {
38 StringBuffer sequence ;
48 public DAS_Sequence_Handler() {
51 sequence = new StringBuffer() ;
60 /** set a maximum length of sequence that should be loaded
61 * default: -1. if -1 no length restriction is being supplied
62 * @return the maximum length or -1 if no restriction
64 public int getMaxLength() {
70 /** set a maximum length of sequence that should be loaded
71 * default: -1. if -1 no length restriction is being supplied
72 * @param maxLength the maximum length or -1 if unrestricted
74 public void setMaxLength(int maxLength) {
75 this.maxLength = maxLength;
81 public void startElement (String uri, String name, String qName, Attributes atts){
83 if ( qName.equals("SEQUENCE")){
84 version = atts.getValue("version");
85 String lenstr = atts.getValue("stop");
86 length = Integer.parseInt(lenstr);
92 public void characters (char ch[], int start, int length){
95 if ( sequence.length() > maxLength)
99 for (int i = start; i < start + length; i++) {
101 // all sorts of characters can be found in "seqeunces" ... ignore them...
104 //System.out.print("\\\\");
107 //System.out.print("\\\"");
110 //System.out.print("\\n");
113 //System.out.print("\\r");
116 //System.out.print("\\t");
121 sequence = sequence.append(ch[i]);
129 public String get_sequence() {
131 if ( maxLength < 0) {
132 if ( length != sequence.length()) {
133 Logger logger = Logger.getLogger("org.biojava.spice");
134 logger.warning("Sequence does not match specified length!");
138 return sequence.toString();
141 public String getVersion() {