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.FeatureSettingsModelI;
26 import jalview.api.FeaturesDisplayedI;
27 import jalview.datamodel.ColumnSelection;
28 import jalview.datamodel.SequenceI;
30 import java.io.IOException;
31 import java.io.StringReader;
33 import org.jsoup.Jsoup;
34 import org.jsoup.nodes.Document;
35 import org.jsoup.nodes.Element;
37 public class HtmlFile extends AlignFile implements ComplexAlignFile
39 public static final String FILE_EXT = "html";
41 public static final String FILE_DESC = "HTML";
43 private String globalColourScheme;
45 private boolean showSeqFeatures;
47 private ColumnSelection columnSelection;
49 private SequenceI[] hiddenSequences;
51 private FeaturesDisplayedI displayedFeatures;
58 public HtmlFile(FileParse source) throws IOException
63 public HtmlFile(String inFile, String type) throws IOException
69 public void parse() throws IOException
71 Element content = null;
75 StringBuilder htmlData = new StringBuilder();
77 while ((currentLine = nextLine()) != null)
79 htmlData.append(currentLine);
81 doc = Jsoup.parse(htmlData.toString());
82 } catch (OutOfMemoryError oom)
84 errormessage = "Not enough memory to process HTML document";
85 throw new IOException(errormessage);
90 boolean contentFromDiv = true;
91 // search for BioJSON data in div element with id seqData
92 content = doc.select("div[id=seqData]").first();
95 contentFromDiv = false;
96 // search for BioJSON data in input element with id seqData
97 content = doc.getElementById("seqData");
102 errormessage = "The html document is not embedded with BioJSON data";
103 throw new IOException(errormessage);
105 JSONFile jsonFile = new JSONFile().parse(new StringReader(
106 contentFromDiv ? content.text() : content.val()));
107 this.seqs = jsonFile.getSeqs();
108 this.seqGroups = jsonFile.getSeqGroups();
109 this.annotations = jsonFile.getAnnotations();
110 this.showSeqFeatures = jsonFile.isShowSeqFeatures();
111 this.globalColourScheme = jsonFile.getGlobalColourScheme();
112 this.hiddenSequences = jsonFile.getHiddenSequences();
113 this.columnSelection = jsonFile.getColumnSelection();
114 this.displayedFeatures = jsonFile.getDisplayedFeatures();
115 } catch (Exception e)
122 public String print()
124 throw new UnsupportedOperationException(
125 "Print method of HtmlFile is not supported!");
129 public boolean isShowSeqFeatures()
131 return showSeqFeatures;
134 public void setShowSeqFeatures(boolean showSeqFeatures)
136 this.showSeqFeatures = showSeqFeatures;
140 public String getGlobalColourScheme()
142 return globalColourScheme;
145 public void setColourScheme(String globalColourScheme)
147 this.globalColourScheme = globalColourScheme;
151 public ColumnSelection getColumnSelection()
153 return columnSelection;
156 public void setColumnSelection(ColumnSelection columnSelection)
158 this.columnSelection = columnSelection;
162 public SequenceI[] getHiddenSequences()
164 return hiddenSequences;
167 public void setHiddenSequences(SequenceI[] hiddenSequences)
169 this.hiddenSequences = hiddenSequences;
173 public FeaturesDisplayedI getDisplayedFeatures()
175 return displayedFeatures;
179 * Returns a descriptor for suitable feature display settings with
181 * <li>ResNums or insertions features visible</li>
182 * <li>insertions features coloured red</li>
183 * <li>ResNum features coloured by label</li>
184 * <li>Insertions displayed above (on top of) ResNums</li>
188 public FeatureSettingsModelI getFeatureColourScheme()
190 return new PDBFeatureSettings();