Merge branch 'develop' of https://source.jalview.org/git/jalview.git into develop
[jalview.git] / src / jalview / io / HtmlFile.java
1 package jalview.io;
2
3 import jalview.gui.AlignFrame;
4 import jalview.schemes.ColourSchemeI;
5
6 import java.io.IOException;
7
8 import org.jsoup.Jsoup;
9 import org.jsoup.nodes.Document;
10 import org.jsoup.nodes.Element;
11
12 public class HtmlFile extends AlignFile
13 {
14   // public static final String FILE_EXT = "html";
15   //
16   // public static final String FILE_DESC = "HTML";
17
18   private ColourSchemeI cs;
19
20   public HtmlFile()
21   {
22     super();
23   }
24
25   public HtmlFile(FileParse source) throws IOException
26   {
27     super(source);
28   }
29
30   public HtmlFile(String inFile, String type) throws IOException
31   {
32     super(inFile, type);
33   }
34
35   @SuppressWarnings("unchecked")
36   @Override
37   public void parse() throws IOException
38   {
39     try
40     {
41       StringBuilder htmlData = new StringBuilder();
42       String currentLine;
43       while ((currentLine = nextLine()) != null)
44       {
45         htmlData.append(currentLine);
46       }
47
48       Document doc = Jsoup.parse(htmlData.toString());
49       Element content = doc.getElementById("seqData");
50
51       String alignmentJsonString = content.val();
52
53       new JSONFile().parse(alignmentJsonString);
54
55       // JSONParser jsonParser = new JSONParser();
56       // JSONObject alignmentJsonObj = (JSONObject) jsonParser
57       // .parse(alignmentJsonString);
58       // JSONArray seqJsonArray = (JSONArray) alignmentJsonObj.get("seqs");
59       // String bioJsColourScheme = (String) alignmentJsonObj
60       // .get("globalColorScheme");
61       // cs = getJalviewColorScheme(bioJsColourScheme);
62       //
63       // for (Iterator<JSONObject> sequenceIter = seqJsonArray.iterator();
64       // sequenceIter
65       // .hasNext();)
66       // {
67       // JSONObject sequence = sequenceIter.next();
68       // String sequcenceString = sequence.get("seq").toString();
69       // Sequence seq = new Sequence(sequence.get("name").toString(),
70       // sequcenceString, Integer.valueOf(sequence.get("start")
71       // .toString()), Integer.valueOf(sequence.get("end")
72       // .toString()));
73       //
74       // JSONArray jsonSeqArray = (JSONArray) sequence.get("features");
75       // SequenceFeature[] retrievedSeqFeatures = getJalviewSequenceFeatures(
76       // jsonSeqArray, seq);
77       // if (retrievedSeqFeatures != null)
78       // {
79       // seq.setSequenceFeatures(retrievedSeqFeatures);
80       // }
81       // seqs.add(seq);
82       //
83       // }
84     } catch (Exception e)
85     {
86       e.printStackTrace();
87     }
88   }
89
90   // public SequenceFeature[] getJalviewSequenceFeatures(
91   // JSONArray jsonSeqFeatures, Sequence seq)
92   // {
93   // SequenceFeature[] seqFeatures = null;
94   // int count = 0;
95   // if (jsonSeqFeatures != null)
96   // {
97   // seqFeatures = new SequenceFeature[jsonSeqFeatures.size()];
98   // for (@SuppressWarnings("unchecked")
99   // Iterator<JSONObject> seqFeatureItr = jsonSeqFeatures.iterator();
100   // seqFeatureItr
101   // .hasNext();)
102   // {
103   //
104   // SequenceFeature sequenceFeature = new SequenceFeature();
105   // JSONObject jsonFeature = seqFeatureItr.next();
106   // Long begin = (Long) jsonFeature.get("xStart");
107   // Long end = (Long) jsonFeature.get("xEnd");
108   // String type = (String) jsonFeature.get("text");
109   // // String color = (String) jsonFeature.get("fillColor");
110   //
111   // sequenceFeature.setBegin(seq.findPosition(begin.intValue()));
112   // sequenceFeature.setEnd(seq.findPosition(end.intValue()) - 1);
113   // sequenceFeature.setType(type);
114   // seqFeatures[count++] = sequenceFeature;
115   // }
116   // }
117   // return seqFeatures;
118   // }
119
120   public void LoadAlignmentFeatures(AlignFrame af)
121   {
122
123     af.setShowSeqFeatures(true);
124     af.changeColour(cs);
125     af.setMenusForViewport();
126   }
127
128   // private ColourSchemeI getJalviewColorScheme(String bioJsColourSchemeName)
129   // {
130   // ColourSchemeI jalviewColor = null;
131   // for (JalviewBioJsColorSchemeMapper cs : JalviewBioJsColorSchemeMapper
132   // .values())
133   // {
134   // if (cs.getBioJsName().equals(bioJsColourSchemeName))
135   // {
136   // jalviewColor = cs.getJvColourScheme();
137   // break;
138   // }
139   // }
140   // return jalviewColor;
141   // }
142
143   @Override
144   public String print()
145   {
146     throw new UnsupportedOperationException(
147             "Print method of HtmlFile not yet supported!");
148   }
149
150 }