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 java.io.IOException;
25 import java.io.StringReader;
27 import org.jsoup.Jsoup;
28 import org.jsoup.nodes.Document;
29 import org.jsoup.nodes.Element;
31 import jalview.api.ComplexAlignFile;
32 import jalview.datamodel.ColumnSelection;
33 import jalview.datamodel.SequenceI;
34 import jalview.schemes.ColourSchemeI;
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 ColourSchemeI colourScheme;
44 private boolean showSeqFeatures;
46 private ColumnSelection columnSelection;
48 private SequenceI[] hiddenSequences;
55 public HtmlFile(FileParse source) throws IOException
60 public HtmlFile(String inFile, String type) throws IOException
66 public void parse() throws IOException
70 Element content = null;
73 StringBuilder htmlData = new StringBuilder();
75 while ((currentLine = nextLine()) != null)
77 htmlData.append(currentLine);
80 doc = Jsoup.parse(htmlData.toString());
81 } catch (OutOfMemoryError oom) {
82 errormessage = "Not enough memory to process HTML document";
83 throw new IOException(errormessage);
85 content = doc.getElementById("seqData");
87 JSONFile jsonFile = new JSONFile().parse(new StringReader(content.val()));
88 this.seqs = jsonFile.getSeqs();
89 this.seqGroups = jsonFile.getSeqGroups();
90 this.annotations = jsonFile.getAnnotations();
91 this.showSeqFeatures = jsonFile.isShowSeqFeatures();
92 this.colourScheme = jsonFile.getColourScheme();
93 this.hiddenSequences = jsonFile.getHiddenSequences();
94 this.columnSelection = jsonFile.getColumnSelection();
97 errormessage = "Failed to extract data from HTML document.";
98 throw new IOException("Unexpected exception whilst extracting JSon from HTML.",e);
104 public String print()
106 throw new UnsupportedOperationException(
107 "Print method of HtmlFile is not supported!");
110 public boolean isShowSeqFeatures()
112 return showSeqFeatures;
115 public void setShowSeqFeatures(boolean showSeqFeatures)
117 this.showSeqFeatures = showSeqFeatures;
120 public ColourSchemeI getColourScheme()
125 public void setColourScheme(ColourSchemeI colourScheme)
127 this.colourScheme = colourScheme;
130 public ColumnSelection getColumnSelection()
132 return columnSelection;
135 public void setColumnSelection(ColumnSelection columnSelection)
137 this.columnSelection = columnSelection;
140 public SequenceI[] getHiddenSequences()
142 return hiddenSequences;
145 public void setHiddenSequences(SequenceI[] hiddenSequences)
147 this.hiddenSequences = hiddenSequences;