JAL-1784 refactor parse method to directly parse FileParser input reader stream.
[jalview.git] / src / jalview / io / HtmlFile.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21
22 package jalview.io;
23
24 import java.io.IOException;
25 import java.io.StringReader;
26
27 import org.jsoup.Jsoup;
28 import org.jsoup.nodes.Document;
29 import org.jsoup.nodes.Element;
30
31 import jalview.api.ComplexAlignFile;
32 import jalview.datamodel.ColumnSelection;
33 import jalview.datamodel.SequenceI;
34 import jalview.schemes.ColourSchemeI;
35
36 public class HtmlFile extends AlignFile implements ComplexAlignFile
37 {
38   public static final String FILE_EXT = "html";
39
40   public static final String FILE_DESC = "HTML";
41
42   private ColourSchemeI colourScheme;
43
44   private boolean showSeqFeatures;
45
46   private ColumnSelection columnSelection;
47
48   private SequenceI[] hiddenSequences;
49
50   public HtmlFile()
51   {
52     super();
53   }
54
55   public HtmlFile(FileParse source) throws IOException
56   {
57     super(source);
58   }
59
60   public HtmlFile(String inFile, String type) throws IOException
61   {
62     super(inFile, type);
63   }
64
65   @Override
66   public void parse() throws IOException
67   {
68     try
69     {
70       StringBuilder htmlData = new StringBuilder();
71       String currentLine;
72       while ((currentLine = nextLine()) != null)
73       {
74         htmlData.append(currentLine);
75       }
76
77       Document doc = Jsoup.parse(htmlData.toString());
78       Element content = doc.getElementById("seqData");
79       JSONFile jsonFile = new JSONFile().parse(new StringReader(content.val()));
80       this.seqs = jsonFile.getSeqs();
81       this.seqGroups = jsonFile.getSeqGroups();
82       this.annotations = jsonFile.getAnnotations();
83       this.showSeqFeatures = jsonFile.isShowSeqFeatures();
84       this.colourScheme = jsonFile.getColourScheme();
85       this.hiddenSequences = jsonFile.getHiddenSequences();
86       this.columnSelection = jsonFile.getColumnSelection();
87     } catch (Exception e)
88     {
89       e.printStackTrace();
90     }
91   }
92
93
94   @Override
95   public String print()
96   {
97     throw new UnsupportedOperationException(
98             "Print method of HtmlFile is not supported!");
99   }
100
101   public boolean isShowSeqFeatures()
102   {
103     return showSeqFeatures;
104   }
105
106   public void setShowSeqFeatures(boolean showSeqFeatures)
107   {
108     this.showSeqFeatures = showSeqFeatures;
109   }
110
111   public ColourSchemeI getColourScheme()
112   {
113     return colourScheme;
114   }
115
116   public void setColourScheme(ColourSchemeI colourScheme)
117   {
118     this.colourScheme = colourScheme;
119   }
120
121   public ColumnSelection getColumnSelection()
122   {
123     return columnSelection;
124   }
125
126   public void setColumnSelection(ColumnSelection columnSelection)
127   {
128     this.columnSelection = columnSelection;
129   }
130
131   public SequenceI[] getHiddenSequences()
132   {
133     return hiddenSequences;
134   }
135
136   public void setHiddenSequences(SequenceI[] hiddenSequences)
137   {
138     this.hiddenSequences = hiddenSequences;
139   }
140
141 }