JAL-1641 refactor
[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
26 import org.jsoup.Jsoup;
27 import org.jsoup.nodes.Document;
28 import org.jsoup.nodes.Element;
29
30 import jalview.api.ComplexAlignFile;
31 import jalview.datamodel.ColumnSelection;
32 import jalview.datamodel.SequenceI;
33 import jalview.schemes.ColourSchemeI;
34
35 public class HtmlFile extends AlignFile implements ComplexAlignFile
36 {
37   public static final String FILE_EXT = "html";
38
39   public static final String FILE_DESC = "HTML";
40
41   private ColourSchemeI colourScheme;
42
43   private boolean showSeqFeatures;
44
45   private ColumnSelection columnSelection;
46
47   private SequenceI[] hiddenSequences;
48
49   public HtmlFile()
50   {
51     super();
52   }
53
54   public HtmlFile(FileParse source) throws IOException
55   {
56     super(source);
57   }
58
59   public HtmlFile(String inFile, String type) throws IOException
60   {
61     super(inFile, type);
62   }
63
64   @Override
65   public void parse() throws IOException
66   {
67     try
68     {
69       StringBuilder htmlData = new StringBuilder();
70       String currentLine;
71       while ((currentLine = nextLine()) != null)
72       {
73         htmlData.append(currentLine);
74       }
75
76       Document doc = Jsoup.parse(htmlData.toString());
77       Element content = doc.getElementById("seqData");
78       String alignmentJsonString = content.val();
79
80       JSONFile jsonFile = new JSONFile().parse(alignmentJsonString);
81       this.seqs = jsonFile.getSeqs();
82       this.seqGroups = jsonFile.getSeqGroups();
83       this.annotations = jsonFile.getAnnotations();
84       this.showSeqFeatures = jsonFile.isShowSeqFeatures();
85       this.colourScheme = jsonFile.getColourScheme();
86       this.hiddenSequences = jsonFile.getHiddenSequences();
87       this.columnSelection = jsonFile.getColumnSelection();
88     } catch (Exception e)
89     {
90       e.printStackTrace();
91     }
92   }
93
94
95   @Override
96   public String print()
97   {
98     throw new UnsupportedOperationException(
99             "Print method of HtmlFile is not supported!");
100   }
101
102   public boolean isShowSeqFeatures()
103   {
104     return showSeqFeatures;
105   }
106
107   public void setShowSeqFeatures(boolean showSeqFeatures)
108   {
109     this.showSeqFeatures = showSeqFeatures;
110   }
111
112   public ColourSchemeI getColourScheme()
113   {
114     return colourScheme;
115   }
116
117   public void setColourScheme(ColourSchemeI colourScheme)
118   {
119     this.colourScheme = colourScheme;
120   }
121
122   public ColumnSelection getColumnSelection()
123   {
124     return columnSelection;
125   }
126
127   public void setColumnSelection(ColumnSelection columnSelection)
128   {
129     this.columnSelection = columnSelection;
130   }
131
132   public SequenceI[] getHiddenSequences()
133   {
134     return hiddenSequences;
135   }
136
137   public void setHiddenSequences(SequenceI[] hiddenSequences)
138   {
139     this.hiddenSequences = hiddenSequences;
140   }
141
142 }