Das client files
[jalview.git] / src / org / biojava / dasobert / das / DAS_Sequence_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 import java.util.logging.*                ;
30
31 /**
32  * a class that parses the XML response of a DAS - sequence command.
33  * @author Andreas Prlic
34  *
35  */
36 public class DAS_Sequence_Handler extends DefaultHandler {
37
38         String sequence ;
39         int length ;
40         boolean dna_flag; 
41         /**
42          * 
43          */
44         public DAS_Sequence_Handler() {
45                 super();
46                 // TODO Auto-generated constructor stub
47                 sequence = "" ;
48                 length = 0;
49                 dna_flag = false ;
50         }
51
52         public void startElement (String uri, String name, String qName, Attributes atts){
53
54             if ( qName.equals("SEQUENCE")){
55                 //System.out.println("new element >" + name + "< >" + qName+"<");
56                 // was : length
57                 String lenstr   = atts.getValue("stop");
58                 length = Integer.parseInt(lenstr);
59                 dna_flag = true ;
60             }
61                 
62         }
63         
64         public void characters (char ch[], int start, int length){
65             //System.out.print("Characters:    \"");
66                 if (dna_flag) 
67                  for (int i = start; i < start + length; i++) {
68                         switch (ch[i]) {
69                         case '\\':
70                                 //System.out.print("\\\\");
71                                 break;
72                         case '"':
73                                 //System.out.print("\\\"");
74                                 break;
75                         case '\n':
76                                 //System.out.print("\\n");
77                                 break;
78                         case '\r':
79                                 //System.out.print("\\r");
80                                 break;
81                         case '\t':
82                                 //System.out.print("\\t");
83                                 break;
84                         case ' ':
85                                 break;
86                         default:
87                                 sequence = sequence + ch[i];
88                                 //System.out.print(ch[i]);
89                  break;
90                  }
91                  }
92                  //System.out.print("\"\n");
93                  
94         }
95         
96         public String get_sequence() {
97                 if ( length != sequence.length()) {     
98                     Logger logger  = Logger.getLogger("org.biojava.spice");
99                     logger.warning("Sequence does not match specified length!");
100                         
101                 }
102                 
103                 return sequence;
104         }
105                 
106         
107         
108 }