Das client files
[jalview.git] / src / org / biojava / dasobert / das / DAS_DNA_Handler.java
1 /*
2  *                    BioJava development code
3  *
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,
7  * see:
8  *
9  *      http://www.gnu.org/copyleft/lesser.html
10  *
11  * Copyright for this code is held jointly by the individual
12  * authors.  These should be listed in @author doc comments.
13  *
14  * For more information on the BioJava project and its aims,
15  * or to join the biojava-l mailing list, visit the home page
16  * at:
17  *
18  *      http://www.biojava.org/
19  *
20  * Created on 19.03.2004
21  * @author Andreas Prlic
22  *
23  */
24 package org.biojava.dasobert.das;
25
26
27 import org.xml.sax.helpers.DefaultHandler;
28 import org.xml.sax.Attributes;
29
30 /**
31  * a class to parse the XML response of a DAS-DNA request.
32  * @author andreas
33  */
34 public class DAS_DNA_Handler extends DefaultHandler {
35
36         String sequence ;
37         int length ;
38         boolean dna_flag; 
39         /**
40          * 
41          */
42         public DAS_DNA_Handler() {
43                 super();
44                 // TODO Auto-generated constructor stub
45                 sequence = "" ;
46                 length = 0;
47                 dna_flag = false ;
48         }
49
50         public void startElement (String uri, String name, String qName, Attributes atts){
51
52             if ( qName.equals("DNA")){
53                 //System.out.println("new element >" + name + "< >" + qName+"<");
54                 // was : length
55                 String lenstr   = atts.getValue("length");
56                 length = Integer.parseInt(lenstr);
57                 dna_flag = true ;
58             }
59                 
60         }
61         
62         public void characters (char ch[], int start, int length){
63             //System.out.print("Characters:    \"");
64                 if (dna_flag) 
65                  for (int i = start; i < start + length; i++) {
66                         switch (ch[i]) {
67                         case '\\':
68                                 //System.out.print("\\\\");
69                                 break;
70                         case '"':
71                                 //System.out.print("\\\"");
72                                 break;
73                         case '\n':
74                                 //System.out.print("\\n");
75                                 break;
76                         case '\r':
77                                 //System.out.print("\\r");
78                                 break;
79                         case '\t':
80                                 //System.out.print("\\t");
81                                 break;
82                         case ' ':
83                                 break;
84                         default:
85                                 sequence = sequence + ch[i];
86                                 //System.out.print(ch[i]);
87                  break;
88                  }
89                  }
90                  //System.out.print("\"\n");
91                  
92         }
93         
94         public String get_sequence() {
95                 if ( length != sequence.length()) {             
96                         System.err.println("Sequence does not match specified length!");
97                 }
98                 
99                 return sequence;
100         }
101                 
102         
103         
104 }