1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  package org.utgenome.format.legacy;
26  
27  import java.io.BufferedReader;
28  import java.io.IOException;
29  import java.io.InputStreamReader;
30  import java.io.Reader;
31  import java.net.URL;
32  import java.util.List;
33  
34  import org.utgenome.gwt.utgb.client.track.bean.LegacyTrackInformation;
35  import org.xerial.core.XerialException;
36  import org.xerial.db.DBException;
37  import org.xerial.db.sql.sqlite.SQLiteAccess;
38  import org.xerial.lens.XMLLens;
39  
40  public class OldDescriptionXMLReader {
41  	public static void main(String[] args) {
42  		try {
43  			SQLiteAccess sqlite = new SQLiteAccess("resource/legacy-track.db");
44  
45  			List<LegacyTrackInformation> trackInfoList = sqlite.query("select * from tracks", LegacyTrackInformation.class);
46  			for (LegacyTrackInformation lt : trackInfoList) {
47  				boolean isValid = validate(lt);
48  				if (!isValid) {
49  					System.out.println(lt.getName() + ": " + lt.getDescriptionXML() + " is not valid");
50  				}
51  				else {
52  					System.out.println(lt.getName() + ": " + lt.getDescriptionXML() + " is valid");
53  
54  				}
55  			}
56  		}
57  		catch (DBException e) {
58  			
59  			e.printStackTrace();
60  		}
61  
62  	}
63  
64  	public static boolean speciesIsValid(String species, LegacyTrackInformation lt) {
65  		if (species.equals("any"))
66  			return true;
67  		else
68  			return species.equals(lt.getSpecies());
69  	}
70  
71  	public static boolean revisioIsValid(String revision, LegacyTrackInformation lt) {
72  		if (revision.equals("any"))
73  			return true;
74  		else
75  			return revision.equals(lt.getRevision());
76  	}
77  
78  	public static boolean validate(LegacyTrackInformation lt) {
79  
80  		try {
81  			
82  
83  			URL descriptionXMLURL = new URL(lt.getDescriptionXML().trim());
84  			Reader xmlReader = new BufferedReader(new InputStreamReader(descriptionXMLURL.openStream()));
85  			OldDescriptionXML descriptionXMLData = XMLLens.createXMLBean(OldDescriptionXML.class, xmlReader);
86  
87  			for (SpeciesEntry se : descriptionXMLData.getAccept_species().getEntry()) {
88  				if (speciesIsValid(se.getSpecies(), lt) && revisioIsValid(se.getRevision(), lt))
89  					return true;
90  			}
91  		}
92  		catch (XerialException e) {
93  			
94  			e.printStackTrace();
95  		}
96  		catch (IOException e) {
97  			
98  			e.printStackTrace();
99  		}
100 		return false;
101 	}
102 }