blob: 8f1c6cf69253fbd95ed12d68ad536d9d08eaf764 [file] [log] [blame]
<HTML><HEAD><META CONTENT="text/html; charset=UTF-8" HTTP-EQUIV="Content-Type"/><TITLE>EMMA Coverage Report</TITLE><STYLE TYPE="text/css"> TABLE,TD,TH {border-style:solid; border-color:black;} TD,TH {background:white;margin:0;line-height:100%;padding-left:0.5em;padding-right:0.5em;} TD {border-width:0 1px 0 0;} TH {border-width:1px 1px 1px 0;} TR TD.h {color:red;} TABLE {border-spacing:0; border-collapse:collapse;border-width:0 0 1px 1px;} P,H1,H2,H3,TH {font-family:verdana,arial,sans-serif;font-size:10pt;} TD {font-family:courier,monospace;font-size:10pt;} TABLE.hdft {border-spacing:0;border-collapse:collapse;border-style:none;} TABLE.hdft TH,TABLE.hdft TD {border-style:none;line-height:normal;} TABLE.hdft TH.tl,TABLE.hdft TD.tl {background:#6699CC;color:white;} TABLE.hdft TD.nv {background:#6633DD;color:white;} .nv A:link {color:white;} .nv A:visited {color:white;} .nv A:active {color:yellow;} TABLE.hdft A:link {color:white;} TABLE.hdft A:visited {color:white;} TABLE.hdft A:active {color:yellow;} .in {color:#356085;} TABLE.s TD {padding-left:0.25em;padding-right:0.25em;} TABLE.s TD.l {padding-left:0.25em;padding-right:0.25em;text-align:right;background:#F0F0F0;} TABLE.s TR.z TD {background:#FF9999;} TABLE.s TR.p TD {background:#FFFF88;} TABLE.s TR.c TD {background:#CCFFCC;} A:link {color:#0000EE;text-decoration:none;} A:visited {color:#0000EE;text-decoration:none;} A:hover {color:#0000EE;text-decoration:underline;} TABLE.cn {border-width:0 0 1px 0;} TABLE.s {border-width:1px 0 1px 1px;} TD.h {color:red;border-width:0 1px 0 0;} TD.f {border-width:0 1px 0 1px;} TD.hf {color:red;border-width:0 1px 0 1px;} TH.f {border-width:1px 1px 1px 1px;} TR.cis TD {background:#F0F0F0;} TR.cis TD {border-width:1px 1px 1px 0;} TR.cis TD.h {color:red;border-width:1px 1px 1px 0;} TR.cis TD.f {border-width:1px 1px 1px 1px;} TR.cis TD.hf {color:red;border-width:1px 1px 1px 1px;} TD.b {border-style:none;background:transparent;line-height:50%;} TD.bt {border-width:1px 0 0 0;background:transparent;line-height:50%;} TR.o TD {background:#F0F0F0;}TABLE.it {border-style:none;}TABLE.it TD,TABLE.it TH {border-style:none;}</STYLE></HEAD><BODY><TABLE CLASS="hdft" CELLSPACING="0" WIDTH="100%"><TR><TH CLASS="tl"><A HREF="http://www.eclemma.org/">EMMA</A> Coverage Report (generated Fri Feb 20 18:44:54 GMT 2009)</TH></TR><TR><TD CLASS="nv">[<A HREF="../xslUnitTestCoverage.html">all classes</A>][<A HREF="a3.html">org.eclipse.wst.xml.core.internal.contenttype</A>]</TD></TR></TABLE><H2>COVERAGE SUMMARY FOR SOURCE FILE [<SPAN CLASS="in">AbstractResourceEncodingDetector.java</SPAN>]</H2><TABLE CELLSPACING="0" WIDTH="100%"><TR><TH>name</TH><TH>class, %</TH><TH>method, %</TH><TH>block, %</TH><TH>line, %</TH></TR><TR><TD>AbstractResourceEncodingDetector.java</TD><TD>100% (1/1)</TD><TD CLASS="h">46%  (6/13)</TD><TD CLASS="h">32%  (73/228)</TD><TD CLASS="h">34%  (25/74)</TD></TR></TABLE><H3>COVERAGE BREAKDOWN BY CLASS AND METHOD</H3><TABLE CLASS="cn" CELLSPACING="0" WIDTH="100%"><TR><TH CLASS="f">name</TH><TH>class, %</TH><TH>method, %</TH><TH>block, %</TH><TH>line, %</TH></TR><TR><TD CLASS="b"> </TD><TD CLASS="b"> </TD><TD CLASS="b"> </TD><TD CLASS="b"> </TD><TD CLASS="b"> </TD></TR><TR CLASS="cis"><TD CLASS="f">class <A HREF="#0">AbstractResourceEncodingDetector</A></TD><TD>100% (1/1)</TD><TD CLASS="h">46%  (6/13)</TD><TD CLASS="h">32%  (73/228)</TD><TD CLASS="h">34%  (25/74)</TD></TR><TR><TD CLASS="f"><A HREF="#1">ensureInputSet (): void</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/9)</TD><TD CLASS="h">0%   (0/3)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#2">getEncoding (): String</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/4)</TD><TD CLASS="h">0%   (0/1)</TD></TR><TR><TD CLASS="f"><A HREF="#3">getEncodingMemento (): EncodingMemento</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/26)</TD><TD CLASS="h">0%   (0/9)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#4">getSpecDefaultEncodingMemento (): EncodingMemento</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/22)</TD><TD CLASS="h">0%   (0/8)</TD></TR><TR><TD CLASS="f"><A HREF="#5">handleSpecDefault (): void</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/19)</TD><TD CLASS="h">0%   (0/6)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#6">set (IStorage): void</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/18)</TD><TD CLASS="h">0%   (0/6)</TD></TR><TR><TD CLASS="f"><A HREF="#7">set (Reader): void</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/28)</TD><TD CLASS="h">0%   (0/8)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#8">getAppropriateJavaCharset (String): String</A></TD><TD> </TD><TD>100% (1/1)</TD><TD CLASS="h">48%  (21/44)</TD><TD CLASS="h">57%  (8/14)</TD></TR><TR><TD CLASS="f"><A HREF="#9">set (InputStream): void</A></TD><TD> </TD><TD>100% (1/1)</TD><TD CLASS="h">70%  (14/20)</TD><TD CLASS="h">67%  (4/6)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#0">AbstractResourceEncodingDetector (): void</A></TD><TD> </TD><TD>100% (1/1)</TD><TD>100% (3/3)</TD><TD>100% (2/2)</TD></TR><TR><TD CLASS="f"><A HREF="#b">createEncodingMemento (String): void</A></TD><TD> </TD><TD>100% (1/1)</TD><TD>100% (21/21)</TD><TD>100% (5/5)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#c">createEncodingMemento (String, String): void</A></TD><TD> </TD><TD>100% (1/1)</TD><TD>100% (4/4)</TD><TD>100% (2/2)</TD></TR><TR><TD CLASS="f"><A HREF="#d">resetAll (): void</A></TD><TD> </TD><TD>100% (1/1)</TD><TD>100% (10/10)</TD><TD>100% (4/4)</TD></TR></TABLE><P></P><TABLE CLASS="s" CELLSPACING="0" WIDTH="100%"><TR><TD CLASS="l">1</TD><TD>/*******************************************************************************</TD></TR><TR><TD CLASS="l">2</TD><TD> * Copyright (c) 2001, 2005 IBM Corporation and others.</TD></TR><TR><TD CLASS="l">3</TD><TD> * All rights reserved. This program and the accompanying materials</TD></TR><TR><TD CLASS="l">4</TD><TD> * are made available under the terms of the Eclipse Public License v1.0</TD></TR><TR><TD CLASS="l">5</TD><TD> * which accompanies this distribution, and is available at</TD></TR><TR><TD CLASS="l">6</TD><TD> * http://www.eclipse.org/legal/epl-v10.html</TD></TR><TR><TD CLASS="l">7</TD><TD> *</TD></TR><TR><TD CLASS="l">8</TD><TD> * Contributors:</TD></TR><TR><TD CLASS="l">9</TD><TD> *     IBM Corporation - initial API and implementation</TD></TR><TR><TD CLASS="l">10</TD><TD> *     Jens Lukowski/Innoopract - initial renaming/restructuring</TD></TR><TR><TD CLASS="l">11</TD><TD> *     </TD></TR><TR><TD CLASS="l">12</TD><TD> *******************************************************************************/</TD></TR><TR><TD CLASS="l">13</TD><TD>package org.eclipse.wst.xml.core.internal.contenttype;</TD></TR><TR><TD CLASS="l">14</TD><TD> </TD></TR><TR><TD CLASS="l">15</TD><TD>import java.io.BufferedInputStream;</TD></TR><TR><TD CLASS="l">16</TD><TD>import java.io.BufferedReader;</TD></TR><TR><TD CLASS="l">17</TD><TD>import java.io.IOException;</TD></TR><TR><TD CLASS="l">18</TD><TD>import java.io.InputStream;</TD></TR><TR><TD CLASS="l">19</TD><TD>import java.io.Reader;</TD></TR><TR><TD CLASS="l">20</TD><TD>import java.nio.charset.Charset;</TD></TR><TR><TD CLASS="l">21</TD><TD>import java.nio.charset.IllegalCharsetNameException;</TD></TR><TR><TD CLASS="l">22</TD><TD>import java.nio.charset.UnsupportedCharsetException;</TD></TR><TR><TD CLASS="l">23</TD><TD> </TD></TR><TR><TD CLASS="l">24</TD><TD>import org.eclipse.core.resources.IStorage;</TD></TR><TR><TD CLASS="l">25</TD><TD>import org.eclipse.core.runtime.CoreException;</TD></TR><TR><TD CLASS="l">26</TD><TD> </TD></TR><TR><TD CLASS="l">27</TD><TD>import org.eclipse.wst.sse.core.internal.encoding.CodedIO;</TD></TR><TR><TD CLASS="l">28</TD><TD>import org.eclipse.wst.sse.core.internal.encoding.EncodingMemento;</TD></TR><TR><TD CLASS="l">29</TD><TD>import org.eclipse.wst.sse.core.internal.encoding.IResourceCharsetDetector;</TD></TR><TR><TD CLASS="l">30</TD><TD> </TD></TR><TR><TD CLASS="l">31</TD><TD> </TD></TR><TR><TD CLASS="l">32</TD><TD>public abstract class AbstractResourceEncodingDetector implements IResourceCharsetDetector {</TD></TR><TR><TD CLASS="l">33</TD><TD> </TD></TR><TR><TD CLASS="l">34</TD><TD>        protected EncodingMemento fEncodingMemento;</TD></TR><TR><TD CLASS="l">35</TD><TD> </TD></TR><TR><TD CLASS="l">36</TD><TD>        protected boolean fHeaderParsed;</TD></TR><TR><TD CLASS="l">37</TD><TD> </TD></TR><TR><TD CLASS="l">38</TD><TD>        protected Reader fReader;</TD></TR><TR><TD CLASS="l">39</TD><TD> </TD></TR><TR><TD CLASS="l"><A NAME="0">40</A></TD><TD>        /**</TD></TR><TR><TD CLASS="l">41</TD><TD>         *  </TD></TR><TR><TD CLASS="l">42</TD><TD>         */</TD></TR><TR><TD CLASS="l">43</TD><TD>        public AbstractResourceEncodingDetector() {</TD></TR><TR CLASS="c"><TD CLASS="l">44</TD><TD>                super();</TD></TR><TR CLASS="c"><TD CLASS="l">45</TD><TD>        }</TD></TR><TR><TD CLASS="l">46</TD><TD> </TD></TR><TR><TD CLASS="l">47</TD><TD>        /**</TD></TR><TR><TD CLASS="l"><A NAME="b">48</A></TD><TD>         * Note: once this instance is created, trace info still needs to be</TD></TR><TR><TD CLASS="l">49</TD><TD>         * appended by caller, depending on the context its created.</TD></TR><TR><TD CLASS="l">50</TD><TD>         */</TD></TR><TR><TD CLASS="l">51</TD><TD>        private void createEncodingMemento(String detectedCharsetName) {</TD></TR><TR CLASS="c"><TD CLASS="l">52</TD><TD>                fEncodingMemento = new EncodingMemento();</TD></TR><TR CLASS="c"><TD CLASS="l">53</TD><TD>                fEncodingMemento.setJavaCharsetName(getAppropriateJavaCharset(detectedCharsetName));</TD></TR><TR CLASS="c"><TD CLASS="l">54</TD><TD>                fEncodingMemento.setDetectedCharsetName(detectedCharsetName);</TD></TR><TR><TD CLASS="l">55</TD><TD>                // TODO: if detectedCharset and spec default is</TD></TR><TR><TD CLASS="l">56</TD><TD>                // null, need to use &#34;work</TD></TR><TR><TD CLASS="l">57</TD><TD>                // bench based&#34; defaults.</TD></TR><TR CLASS="c"><TD CLASS="l">58</TD><TD>                fEncodingMemento.setAppropriateDefault(getSpecDefaultEncoding());</TD></TR><TR CLASS="c"><TD CLASS="l">59</TD><TD>        }</TD></TR><TR><TD CLASS="l">60</TD><TD> </TD></TR><TR><TD CLASS="l">61</TD><TD>        /**</TD></TR><TR><TD CLASS="l">62</TD><TD>         * convience method all subclasses can use (but not override)</TD></TR><TR><TD CLASS="l">63</TD><TD>         * </TD></TR><TR><TD CLASS="l"><A NAME="c">64</A></TD><TD>         * @param detectedCharsetName</TD></TR><TR><TD CLASS="l">65</TD><TD>         * @param reason</TD></TR><TR><TD CLASS="l">66</TD><TD>         */</TD></TR><TR><TD CLASS="l">67</TD><TD>        final protected void createEncodingMemento(String detectedCharsetName, String reason) {</TD></TR><TR CLASS="c"><TD CLASS="l">68</TD><TD>                createEncodingMemento(detectedCharsetName);</TD></TR><TR CLASS="c"><TD CLASS="l">69</TD><TD>        }</TD></TR><TR><TD CLASS="l">70</TD><TD> </TD></TR><TR><TD CLASS="l"><A NAME="1">71</A></TD><TD>        /**</TD></TR><TR><TD CLASS="l">72</TD><TD>         * convience method all subclasses can use (but not override)</TD></TR><TR><TD CLASS="l">73</TD><TD>         */</TD></TR><TR><TD CLASS="l">74</TD><TD>        final protected void ensureInputSet() {</TD></TR><TR CLASS="z"><TD CLASS="l">75</TD><TD>                if (fReader == null) {</TD></TR><TR CLASS="z"><TD CLASS="l">76</TD><TD>                        throw new IllegalStateException(&#34;input must be set before use&#34;); //$NON-NLS-1$</TD></TR><TR><TD CLASS="l">77</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">78</TD><TD>        }</TD></TR><TR><TD CLASS="l">79</TD><TD> </TD></TR><TR><TD CLASS="l">80</TD><TD>        /**</TD></TR><TR><TD CLASS="l">81</TD><TD>         * This method can return null, if invalid charset name (in which case</TD></TR><TR><TD CLASS="l">82</TD><TD>         * &#34;appropriateDefault&#34; should be used, if a name is really need for some</TD></TR><TR><TD CLASS="l">83</TD><TD>         * &#34;save anyway&#34; cases).</TD></TR><TR><TD CLASS="l">84</TD><TD>         * </TD></TR><TR><TD CLASS="l"><A NAME="8">85</A></TD><TD>         * @param detectedCharsetName</TD></TR><TR><TD CLASS="l">86</TD><TD>         * @return</TD></TR><TR><TD CLASS="l">87</TD><TD>         */</TD></TR><TR><TD CLASS="l">88</TD><TD>        private String getAppropriateJavaCharset(String detectedCharsetName) {</TD></TR><TR CLASS="c"><TD CLASS="l">89</TD><TD>                String result = null;</TD></TR><TR><TD CLASS="l">90</TD><TD>                // 1. Check explicit mapping overrides from</TD></TR><TR><TD CLASS="l">91</TD><TD>                // property file -- its here we pick up &#34;rules&#34; for cases</TD></TR><TR><TD CLASS="l">92</TD><TD>                // that are not even in Java</TD></TR><TR CLASS="c"><TD CLASS="l">93</TD><TD>                result = CodedIO.checkMappingOverrides(detectedCharsetName);</TD></TR><TR><TD CLASS="l">94</TD><TD>                // 2. Use the &#34;canonical&#34; name from JRE mappings</TD></TR><TR><TD CLASS="l">95</TD><TD>                // Note: see Charset JavaDoc, the name you get one</TD></TR><TR><TD CLASS="l">96</TD><TD>                // with can be alias,</TD></TR><TR><TD CLASS="l">97</TD><TD>                // the name you get back is &#34;standard&#34; name.</TD></TR><TR CLASS="c"><TD CLASS="l">98</TD><TD>                Charset javaCharset = null;</TD></TR><TR><TD CLASS="l">99</TD><TD>                try {</TD></TR><TR CLASS="c"><TD CLASS="l">100</TD><TD>                        javaCharset = Charset.forName(detectedCharsetName);</TD></TR><TR CLASS="z"><TD CLASS="l">101</TD><TD>                } catch (UnsupportedCharsetException e) {</TD></TR><TR><TD CLASS="l">102</TD><TD>                        // only set invalid, if result is same as detected -- they won't</TD></TR><TR><TD CLASS="l">103</TD><TD>                        // be equal if</TD></TR><TR><TD CLASS="l">104</TD><TD>                        // overridden</TD></TR><TR CLASS="z"><TD CLASS="l">105</TD><TD>                        if (result != null &amp;&amp; result.equals(detectedCharsetName)) {</TD></TR><TR CLASS="z"><TD CLASS="l">106</TD><TD>                                fEncodingMemento.setInvalidEncoding(detectedCharsetName);</TD></TR><TR><TD CLASS="l">107</TD><TD>                        }</TD></TR><TR CLASS="z"><TD CLASS="l">108</TD><TD>                } catch (IllegalCharsetNameException e) {</TD></TR><TR><TD CLASS="l">109</TD><TD>                        // only set invalid, if result is same as detected -- they won't</TD></TR><TR><TD CLASS="l">110</TD><TD>                        // be equal if</TD></TR><TR><TD CLASS="l">111</TD><TD>                        // overridden</TD></TR><TR CLASS="z"><TD CLASS="l">112</TD><TD>                        if (result != null &amp;&amp; result.equals(detectedCharsetName)) {</TD></TR><TR CLASS="z"><TD CLASS="l">113</TD><TD>                                fEncodingMemento.setInvalidEncoding(detectedCharsetName);</TD></TR><TR><TD CLASS="l">114</TD><TD>                        }</TD></TR><TR><TD CLASS="l">115</TD><TD>                }</TD></TR><TR><TD CLASS="l">116</TD><TD>                // give priority to java cononical name, if present</TD></TR><TR CLASS="c"><TD CLASS="l">117</TD><TD>                if (javaCharset != null) {</TD></TR><TR CLASS="c"><TD CLASS="l">118</TD><TD>                        result = javaCharset.name();</TD></TR><TR><TD CLASS="l">119</TD><TD>                        // but still allow overrides</TD></TR><TR CLASS="c"><TD CLASS="l">120</TD><TD>                        result = CodedIO.checkMappingOverrides(result);</TD></TR><TR><TD CLASS="l">121</TD><TD>                }</TD></TR><TR CLASS="c"><TD CLASS="l"><A NAME="2">122</A></TD><TD>                return result;</TD></TR><TR><TD CLASS="l">123</TD><TD>        }</TD></TR><TR><TD CLASS="l">124</TD><TD> </TD></TR><TR><TD CLASS="l">125</TD><TD>        public String getEncoding() throws IOException {</TD></TR><TR CLASS="z"><TD CLASS="l">126</TD><TD>                return getEncodingMemento().getDetectedCharsetName();</TD></TR><TR><TD CLASS="l">127</TD><TD>        }</TD></TR><TR><TD CLASS="l">128</TD><TD> </TD></TR><TR><TD CLASS="l">129</TD><TD>        // to ensure consist overall rules used, we'll mark as</TD></TR><TR><TD CLASS="l">130</TD><TD>        // final,</TD></TR><TR><TD CLASS="l"><A NAME="3">131</A></TD><TD>        // and require subclasses to provide certain pieces of</TD></TR><TR><TD CLASS="l">132</TD><TD>        // the</TD></TR><TR><TD CLASS="l">133</TD><TD>        // implementation</TD></TR><TR><TD CLASS="l">134</TD><TD>        public EncodingMemento getEncodingMemento() throws IOException {</TD></TR><TR CLASS="z"><TD CLASS="l">135</TD><TD>                ensureInputSet();</TD></TR><TR CLASS="z"><TD CLASS="l">136</TD><TD>                if (!fHeaderParsed) {</TD></TR><TR CLASS="z"><TD CLASS="l">137</TD><TD>                        parseInput();</TD></TR><TR><TD CLASS="l">138</TD><TD>                        // we keep track of if header's already been</TD></TR><TR><TD CLASS="l">139</TD><TD>                        // parse, so can make</TD></TR><TR><TD CLASS="l">140</TD><TD>                        // multiple 'get' calls, without causing</TD></TR><TR><TD CLASS="l">141</TD><TD>                        // reparsing.</TD></TR><TR CLASS="z"><TD CLASS="l">142</TD><TD>                        fHeaderParsed = true;</TD></TR><TR><TD CLASS="l">143</TD><TD>                        // Note: there is a &#34;hidden assumption&#34; here</TD></TR><TR><TD CLASS="l">144</TD><TD>                        // that an empty</TD></TR><TR><TD CLASS="l">145</TD><TD>                        // string in content should be treated same as</TD></TR><TR><TD CLASS="l">146</TD><TD>                        // not present.</TD></TR><TR><TD CLASS="l">147</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">148</TD><TD>                if (fEncodingMemento == null) {</TD></TR><TR CLASS="z"><TD CLASS="l">149</TD><TD>                        handleSpecDefault();</TD></TR><TR><TD CLASS="l">150</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">151</TD><TD>                if (fEncodingMemento == null) {</TD></TR><TR><TD CLASS="l">152</TD><TD>                        // safty net</TD></TR><TR CLASS="z"><TD CLASS="l">153</TD><TD>                        fEncodingMemento = new NullMemento();</TD></TR><TR><TD CLASS="l">154</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">155</TD><TD>                return fEncodingMemento;</TD></TR><TR><TD CLASS="l">156</TD><TD>        }</TD></TR><TR><TD CLASS="l">157</TD><TD> </TD></TR><TR><TD CLASS="l">158</TD><TD>        /**</TD></TR><TR><TD CLASS="l">159</TD><TD>         * This is to return a default encoding -- as specified by an industry</TD></TR><TR><TD CLASS="l">160</TD><TD>         * content type spec -- when not present in the stream, for example, XML</TD></TR><TR><TD CLASS="l">161</TD><TD>         * specifies UTF-8, JSP specifies ISO-8859-1. This method should return</TD></TR><TR><TD CLASS="l">162</TD><TD>         * null if there is no such &#34;spec default&#34;.</TD></TR><TR><TD CLASS="l"><A NAME="4">163</A></TD><TD>         */</TD></TR><TR><TD CLASS="l">164</TD><TD>        abstract public String getSpecDefaultEncoding();</TD></TR><TR><TD CLASS="l">165</TD><TD> </TD></TR><TR><TD CLASS="l">166</TD><TD>        public EncodingMemento getSpecDefaultEncodingMemento() {</TD></TR><TR CLASS="z"><TD CLASS="l">167</TD><TD>                resetAll();</TD></TR><TR CLASS="z"><TD CLASS="l">168</TD><TD>                EncodingMemento result = null;</TD></TR><TR CLASS="z"><TD CLASS="l">169</TD><TD>                String enc = getSpecDefaultEncoding();</TD></TR><TR CLASS="z"><TD CLASS="l">170</TD><TD>                if (enc != null) {</TD></TR><TR CLASS="z"><TD CLASS="l">171</TD><TD>                        createEncodingMemento(enc, EncodingMemento.DEFAULTS_ASSUMED_FOR_EMPTY_INPUT);</TD></TR><TR CLASS="z"><TD CLASS="l">172</TD><TD>                        fEncodingMemento.setAppropriateDefault(enc);</TD></TR><TR CLASS="z"><TD CLASS="l">173</TD><TD>                        result = fEncodingMemento;</TD></TR><TR><TD CLASS="l">174</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">175</TD><TD>                return result;</TD></TR><TR><TD CLASS="l"><A NAME="5">176</A></TD><TD>        }</TD></TR><TR><TD CLASS="l">177</TD><TD> </TD></TR><TR><TD CLASS="l">178</TD><TD>        private void handleSpecDefault() {</TD></TR><TR><TD CLASS="l">179</TD><TD>                String encodingName;</TD></TR><TR CLASS="z"><TD CLASS="l">180</TD><TD>                encodingName = getSpecDefaultEncoding();</TD></TR><TR CLASS="z"><TD CLASS="l">181</TD><TD>                if (encodingName != null) {</TD></TR><TR><TD CLASS="l">182</TD><TD>                        //createEncodingMemento(encodingName,</TD></TR><TR><TD CLASS="l">183</TD><TD>                        // EncodingMemento.USED_CONTENT_TYPE_DEFAULT);</TD></TR><TR CLASS="z"><TD CLASS="l">184</TD><TD>                        fEncodingMemento = new EncodingMemento();</TD></TR><TR CLASS="z"><TD CLASS="l">185</TD><TD>                        fEncodingMemento.setJavaCharsetName(encodingName);</TD></TR><TR CLASS="z"><TD CLASS="l">186</TD><TD>                        fEncodingMemento.setAppropriateDefault(encodingName);</TD></TR><TR><TD CLASS="l">187</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">188</TD><TD>        }</TD></TR><TR><TD CLASS="l">189</TD><TD> </TD></TR><TR><TD CLASS="l">190</TD><TD>        /**</TD></TR><TR><TD CLASS="l">191</TD><TD>         * Every subclass must provide a way to parse the input. This method has</TD></TR><TR><TD CLASS="l">192</TD><TD>         * several critical responsibilities:</TD></TR><TR><TD CLASS="l">193</TD><TD>         * &lt;li&gt;set the fEncodingMemento field appropriately, according to the</TD></TR><TR><TD CLASS="l">194</TD><TD>         * results of the parse of fReader.&lt;/li&gt;</TD></TR><TR><TD CLASS="l">195</TD><TD>         * &lt;li&gt;set fHarderParsed to true, to avoid wasted re-parsing.&lt;/li&gt;</TD></TR><TR><TD CLASS="l">196</TD><TD>         */</TD></TR><TR><TD CLASS="l">197</TD><TD>        abstract protected void parseInput() throws IOException;</TD></TR><TR><TD CLASS="l">198</TD><TD> </TD></TR><TR><TD CLASS="l"><A NAME="d">199</A></TD><TD>        /**</TD></TR><TR><TD CLASS="l">200</TD><TD>         *  </TD></TR><TR><TD CLASS="l">201</TD><TD>         */</TD></TR><TR><TD CLASS="l">202</TD><TD>        protected void resetAll() {</TD></TR><TR CLASS="c"><TD CLASS="l">203</TD><TD>                fReader = null;</TD></TR><TR CLASS="c"><TD CLASS="l">204</TD><TD>                fHeaderParsed = false;</TD></TR><TR CLASS="c"><TD CLASS="l">205</TD><TD>                fEncodingMemento = null;</TD></TR><TR CLASS="c"><TD CLASS="l">206</TD><TD>        }</TD></TR><TR><TD CLASS="l">207</TD><TD> </TD></TR><TR><TD CLASS="l"><A NAME="9">208</A></TD><TD>        /**</TD></TR><TR><TD CLASS="l">209</TD><TD>         *  </TD></TR><TR><TD CLASS="l">210</TD><TD>         */</TD></TR><TR><TD CLASS="l">211</TD><TD>        public void set(InputStream inputStream) {</TD></TR><TR CLASS="c"><TD CLASS="l">212</TD><TD>                resetAll();</TD></TR><TR CLASS="c"><TD CLASS="l">213</TD><TD>                fReader = new ByteReader(inputStream);</TD></TR><TR><TD CLASS="l">214</TD><TD>                try {</TD></TR><TR CLASS="c"><TD CLASS="l">215</TD><TD>                        fReader.mark(CodedIO.MAX_MARK_SIZE);</TD></TR><TR CLASS="z"><TD CLASS="l">216</TD><TD>                } catch (IOException e) {</TD></TR><TR><TD CLASS="l">217</TD><TD>                        // impossible, since we know ByteReader</TD></TR><TR><TD CLASS="l">218</TD><TD>                        // supports marking</TD></TR><TR CLASS="z"><TD CLASS="l">219</TD><TD>                        throw new Error(e);</TD></TR><TR><TD CLASS="l">220</TD><TD>                }</TD></TR><TR CLASS="c"><TD CLASS="l">221</TD><TD>        }</TD></TR><TR><TD CLASS="l">222</TD><TD> </TD></TR><TR><TD CLASS="l"><A NAME="6">223</A></TD><TD>        /**</TD></TR><TR><TD CLASS="l">224</TD><TD>         *  </TD></TR><TR><TD CLASS="l">225</TD><TD>         */</TD></TR><TR><TD CLASS="l">226</TD><TD>        public void set(IStorage iStorage) throws CoreException {</TD></TR><TR CLASS="z"><TD CLASS="l">227</TD><TD>                resetAll();</TD></TR><TR CLASS="z"><TD CLASS="l">228</TD><TD>                InputStream inputStream = iStorage.getContents();</TD></TR><TR CLASS="z"><TD CLASS="l">229</TD><TD>                InputStream resettableStream = new BufferedInputStream(inputStream, CodedIO.MAX_BUF_SIZE);</TD></TR><TR CLASS="z"><TD CLASS="l">230</TD><TD>                resettableStream.mark(CodedIO.MAX_MARK_SIZE);</TD></TR><TR CLASS="z"><TD CLASS="l">231</TD><TD>                set(resettableStream);</TD></TR><TR><TD CLASS="l">232</TD><TD>                // TODO we'll need to &#34;remember&#34; IFile, or</TD></TR><TR><TD CLASS="l">233</TD><TD>                // get its (or its project's) settings, in case</TD></TR><TR><TD CLASS="l">234</TD><TD>                // those are needed to handle cases when the</TD></TR><TR><TD CLASS="l">235</TD><TD>                // encoding is not in the file stream.</TD></TR><TR CLASS="z"><TD CLASS="l">236</TD><TD>        }</TD></TR><TR><TD CLASS="l">237</TD><TD> </TD></TR><TR><TD CLASS="l">238</TD><TD>        /**</TD></TR><TR><TD CLASS="l">239</TD><TD>         * Note: this is not part of interface to help avoid confusion ... it</TD></TR><TR><TD CLASS="l">240</TD><TD>         * expected this Reader is a well formed character reader ... that is, its</TD></TR><TR><TD CLASS="l">241</TD><TD>         * all ready been determined to not be a unicode marked input stream. And,</TD></TR><TR><TD CLASS="l"><A NAME="7">242</A></TD><TD>         * its assumed to be in the correct position, at position zero, ready to</TD></TR><TR><TD CLASS="l">243</TD><TD>         * read first character.</TD></TR><TR><TD CLASS="l">244</TD><TD>         */</TD></TR><TR><TD CLASS="l">245</TD><TD>        public void set(Reader reader) {</TD></TR><TR CLASS="z"><TD CLASS="l">246</TD><TD>                resetAll();</TD></TR><TR CLASS="z"><TD CLASS="l">247</TD><TD>                fReader = reader;</TD></TR><TR CLASS="z"><TD CLASS="l">248</TD><TD>                if (!fReader.markSupported()) {</TD></TR><TR CLASS="z"><TD CLASS="l">249</TD><TD>                        fReader = new BufferedReader(fReader);</TD></TR><TR><TD CLASS="l">250</TD><TD>                }</TD></TR><TR><TD CLASS="l">251</TD><TD>                try {</TD></TR><TR CLASS="z"><TD CLASS="l">252</TD><TD>                        fReader.mark(CodedIO.MAX_MARK_SIZE);</TD></TR><TR CLASS="z"><TD CLASS="l">253</TD><TD>                } catch (IOException e) {</TD></TR><TR><TD CLASS="l">254</TD><TD>                        // impossble, since we just checked if markable</TD></TR><TR CLASS="z"><TD CLASS="l">255</TD><TD>                        throw new Error(e);</TD></TR><TR><TD CLASS="l">256</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">257</TD><TD>        }</TD></TR><TR><TD CLASS="l">258</TD><TD>}</TD></TR></TABLE><P></P><TABLE CLASS="hdft" CELLSPACING="0" WIDTH="100%"><TR><TD CLASS="nv">[<A HREF="../xslUnitTestCoverage.html">all classes</A>][<A HREF="a3.html">org.eclipse.wst.xml.core.internal.contenttype</A>]</TD></TR><TR><TD CLASS="tl"><A HREF="http://www.eclemma.org/support.html">EMMA 2.0.5312 EclEmma Fix 1</A> (C) Vladimir Roubtsov</TD></TR></TABLE></BODY></HTML>