3 import jalview.datamodel.Sequence;
5 import java.io.IOException;
6 import java.util.Iterator;
8 import org.json.simple.JSONArray;
9 import org.json.simple.JSONObject;
10 import org.json.simple.parser.JSONParser;
11 import org.jsoup.Jsoup;
12 import org.jsoup.nodes.Document;
13 import org.jsoup.nodes.Element;
15 public class HtmlFile extends AlignFile {
16 public static final String FILE_EXT = "html";
18 public static final String FILE_DESC = "HTML";
24 public HtmlFile(FileParse source) throws IOException {
28 public HtmlFile(String inFile, String type) throws IOException {
32 @SuppressWarnings("unchecked")
34 public void parse() throws IOException {
36 StringBuilder htmlData = new StringBuilder();
38 while ((currentLine = nextLine()) != null) {
39 htmlData.append(currentLine);
42 Document doc = Jsoup.parse(htmlData.toString());
43 Element content = doc.getElementById("seqData");
45 String alignmentJsonString = "{\"seqs\":" + content.val() + "}";
46 JSONParser jsonParser = new JSONParser();
47 JSONObject alignmentJsonObj = (JSONObject) jsonParser.parse(alignmentJsonString);
48 JSONArray seqJsonArray = (JSONArray) alignmentJsonObj.get("seqs");
50 for (Iterator<JSONObject> sequenceIter = seqJsonArray.iterator(); sequenceIter.hasNext();) {
51 JSONObject sequence = sequenceIter.next();
52 System.out.println(sequence.get("id").toString() + " " + sequence.get("name"));
53 String sequcenceString = sequence.get("seq").toString();
54 Sequence seq = new Sequence(sequence.get("name").toString(), sequcenceString, 0, sequcenceString.length());
58 } catch (Exception e) {
64 public String print() {
65 throw new UnsupportedOperationException("Print method of HtmlFile not yet supported!");