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.HiddenColumns;
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 HiddenColumns hiddenColumns;
49 private SequenceI[] hiddenSequences;
51 private FeaturesDisplayedI displayedFeatures;
58 public HtmlFile(FileParse source) throws IOException
63 public HtmlFile(String inFile, DataSourceType sourceType)
66 super(inFile, sourceType);
70 public void parse() throws IOException
72 Element content = null;
76 StringBuilder htmlData = new StringBuilder();
78 while ((currentLine = nextLine()) != null)
80 htmlData.append(currentLine);
82 doc = Jsoup.parse(htmlData.toString());
83 } catch (OutOfMemoryError oom)
85 errormessage = "Not enough memory to process HTML document";
86 throw new IOException(errormessage);
91 boolean contentFromDiv = true;
92 // search for BioJSON data in div element with id seqData
93 content = doc.select("div[id=seqData]").first();
96 contentFromDiv = false;
97 // search for BioJSON data in input element with id seqData
98 content = doc.getElementById("seqData");
103 errormessage = "The html document is not embedded with BioJSON data";
104 throw new IOException(errormessage);
106 JSONFile jsonFile = new JSONFile().parse(new StringReader(
107 contentFromDiv ? content.text() : content.val()));
108 this.seqs = jsonFile.getSeqs();
109 this.seqGroups = jsonFile.getSeqGroups();
110 this.annotations = jsonFile.getAnnotations();
111 this.showSeqFeatures = jsonFile.isShowSeqFeatures();
112 this.globalColourScheme = jsonFile.getGlobalColourScheme();
113 this.hiddenSequences = jsonFile.getHiddenSequences();
114 this.hiddenColumns = jsonFile.getHiddenColumns();
115 this.displayedFeatures = jsonFile.getDisplayedFeatures();
116 } catch (Exception e)
123 public String print(SequenceI[] sqs, boolean jvsuffix)
125 throw new UnsupportedOperationException(
126 "Print method of HtmlFile is not supported!");
130 public boolean isShowSeqFeatures()
132 return showSeqFeatures;
135 public void setShowSeqFeatures(boolean showSeqFeatures)
137 this.showSeqFeatures = showSeqFeatures;
141 public String getGlobalColourScheme()
143 return globalColourScheme;
146 public void setColourScheme(String globalColourScheme)
148 this.globalColourScheme = globalColourScheme;
152 public HiddenColumns getHiddenColumns()
154 return hiddenColumns;
157 public void setHiddenColumns(HiddenColumns hidden)
159 this.hiddenColumns = hidden;
163 public SequenceI[] getHiddenSequences()
165 return hiddenSequences;
168 public void setHiddenSequences(SequenceI[] hiddenSequences)
170 this.hiddenSequences = hiddenSequences;
174 public FeaturesDisplayedI getDisplayedFeatures()
176 return displayedFeatures;
180 * Returns a descriptor for suitable feature display settings with
182 * <li>ResNums or insertions features visible</li>
183 * <li>insertions features coloured red</li>
184 * <li>ResNum features coloured by label</li>
185 * <li>Insertions displayed above (on top of) ResNums</li>
189 public FeatureSettingsModelI getFeatureColourScheme()
191 return new PDBFeatureSettings();