2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
24 import jalview.api.ComplexAlignFile;
25 import jalview.api.FeaturesDisplayedI;
26 import jalview.datamodel.ColumnSelection;
27 import jalview.datamodel.SequenceI;
29 import java.io.IOException;
30 import java.io.StringReader;
32 import org.jsoup.Jsoup;
33 import org.jsoup.nodes.Document;
34 import org.jsoup.nodes.Element;
36 public class HtmlFile extends AlignFile implements ComplexAlignFile
38 public static final String FILE_EXT = "html";
40 public static final String FILE_DESC = "HTML";
42 private String globalColourScheme;
44 private boolean showSeqFeatures;
46 private ColumnSelection columnSelection;
48 private SequenceI[] hiddenSequences;
50 private FeaturesDisplayedI displayedFeatures;
57 public HtmlFile(FileParse source) throws IOException
62 public HtmlFile(String inFile, String type) throws IOException
68 public void parse() throws IOException
70 Element content = null;
74 StringBuilder htmlData = new StringBuilder();
76 while ((currentLine = nextLine()) != null)
78 htmlData.append(currentLine);
80 doc = Jsoup.parse(htmlData.toString());
81 } catch (OutOfMemoryError oom)
83 errormessage = "Not enough memory to process HTML document";
84 throw new IOException(errormessage);
89 boolean contentFromDiv = true;
90 // search for BioJSON data in div element with id seqData
91 content = doc.select("div[id=seqData]").first();
94 contentFromDiv = false;
95 // search for BioJSON data in input element with id seqData
96 content = doc.getElementById("seqData");
101 errormessage = "The html document is not embedded with BioJSON data";
102 throw new IOException(errormessage);
104 JSONFile jsonFile = new JSONFile().parse(new StringReader(
105 contentFromDiv ? content.text() : content.val()));
106 this.seqs = jsonFile.getSeqs();
107 this.seqGroups = jsonFile.getSeqGroups();
108 this.annotations = jsonFile.getAnnotations();
109 this.showSeqFeatures = jsonFile.isShowSeqFeatures();
110 this.globalColourScheme = jsonFile.getGlobalColourScheme();
111 this.hiddenSequences = jsonFile.getHiddenSequences();
112 this.columnSelection = jsonFile.getColumnSelection();
113 this.displayedFeatures = jsonFile.getDisplayedFeatures();
114 } catch (Exception e)
121 public String print()
123 throw new UnsupportedOperationException(
124 "Print method of HtmlFile is not supported!");
127 public boolean isShowSeqFeatures()
129 return showSeqFeatures;
132 public void setShowSeqFeatures(boolean showSeqFeatures)
134 this.showSeqFeatures = showSeqFeatures;
137 public String getGlobalColourScheme()
139 return globalColourScheme;
142 public void setColourScheme(String globalColourScheme)
144 this.globalColourScheme = globalColourScheme;
147 public ColumnSelection getColumnSelection()
149 return columnSelection;
152 public void setColumnSelection(ColumnSelection columnSelection)
154 this.columnSelection = columnSelection;
157 public SequenceI[] getHiddenSequences()
159 return hiddenSequences;
162 public void setHiddenSequences(SequenceI[] hiddenSequences)
164 this.hiddenSequences = hiddenSequences;
168 public FeaturesDisplayedI getDisplayedFeatures()
170 return displayedFeatures;