blob: 3c890259bcdc32257578012a79ca4404365b7a7b [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">ContentDescriberForXML.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>ContentDescriberForXML.java</TD><TD>100% (1/1)</TD><TD CLASS="h">43%  (6/14)</TD><TD CLASS="h">25%  (74/301)</TD><TD CLASS="h">21%  (18/87)</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">ContentDescriberForXML</A></TD><TD>100% (1/1)</TD><TD CLASS="h">43%  (6/14)</TD><TD CLASS="h">25%  (74/301)</TD><TD CLASS="h">21%  (18/87)</TD></TR><TR><TD CLASS="f"><A HREF="#1">calculateSupportedOptions (int, InputStream, IContentDescription): int</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/22)</TD><TD CLASS="h">0%   (0/7)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#2">calculateSupportedOptions (int, Reader, IContentDescription): int</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/20)</TD><TD CLASS="h">0%   (0/6)</TD></TR><TR><TD CLASS="f"><A HREF="#3">describe (Reader, IContentDescription): int</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/18)</TD><TD CLASS="h">0%   (0/5)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#4">determineValidity (int, Reader): int</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/17)</TD><TD CLASS="h">0%   (0/6)</TD></TR><TR><TD CLASS="f"><A HREF="#5">getSupportedOptions (): QualifiedName []</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/2)</TD><TD CLASS="h">0%   (0/1)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#6">handleCalculations (int, IContentDescription, IResourceCharsetDetector): int</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/90)</TD><TD CLASS="h">0%   (0/25)</TD></TR><TR><TD CLASS="f"><A HREF="#7">handleDetectedSpecialCase (IContentDescription, Object, Object): void</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/7)</TD><TD CLASS="h">0%   (0/3)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#8">isRelevent (IContentDescription): boolean</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/43)</TD><TD CLASS="h">0%   (0/14)</TD></TR><TR><TD CLASS="f"><A HREF="#9">describe (InputStream, IContentDescription): int</A></TD><TD> </TD><TD>100% (1/1)</TD><TD CLASS="h">67%  (12/18)</TD><TD>80%  (4/5)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#a">determineValidity (IResourceCharsetDetector, int): int</A></TD><TD> </TD><TD>100% (1/1)</TD><TD>88%  (14/16)</TD><TD>83%  (5/6)</TD></TR><TR><TD CLASS="f"><A HREF="#b">&lt;static initializer&gt;</A></TD><TD> </TD><TD>100% (1/1)</TD><TD>100% (24/24)</TD><TD>100% (2/2)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#0">ContentDescriberForXML (): void</A></TD><TD> </TD><TD>100% (1/1)</TD><TD>100% (3/3)</TD><TD>100% (1/1)</TD></TR><TR><TD CLASS="f"><A HREF="#d">determineValidity (int, InputStream): int</A></TD><TD> </TD><TD>100% (1/1)</TD><TD>100% (17/17)</TD><TD>100% (6/6)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#e">getDetector (): IResourceCharsetDetector</A></TD><TD> </TD><TD>100% (1/1)</TD><TD>100% (4/4)</TD><TD>100% (1/1)</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, 2006 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.IOException;</TD></TR><TR><TD CLASS="l">16</TD><TD>import java.io.InputStream;</TD></TR><TR><TD CLASS="l">17</TD><TD>import java.io.Reader;</TD></TR><TR><TD CLASS="l">18</TD><TD> </TD></TR><TR><TD CLASS="l">19</TD><TD>import org.eclipse.core.runtime.QualifiedName;</TD></TR><TR><TD CLASS="l">20</TD><TD>import org.eclipse.core.runtime.content.IContentDescriber;</TD></TR><TR><TD CLASS="l">21</TD><TD>import org.eclipse.core.runtime.content.IContentDescription;</TD></TR><TR><TD CLASS="l">22</TD><TD>import org.eclipse.core.runtime.content.ITextContentDescriber;</TD></TR><TR><TD CLASS="l">23</TD><TD>import org.eclipse.wst.sse.core.internal.encoding.EncodingMemento;</TD></TR><TR><TD CLASS="l"><A NAME="0">24</A></TD><TD>import org.eclipse.wst.sse.core.internal.encoding.IContentDescriptionExtended;</TD></TR><TR><TD CLASS="l"><A NAME="b">25</A></TD><TD>import org.eclipse.wst.sse.core.internal.encoding.IResourceCharsetDetector;</TD></TR><TR><TD CLASS="l">26</TD><TD> </TD></TR><TR><TD CLASS="l">27</TD><TD> </TD></TR><TR CLASS="c"><TD CLASS="l">28</TD><TD>public final class ContentDescriberForXML implements ITextContentDescriber {</TD></TR><TR CLASS="c"><TD CLASS="l">29</TD><TD>        private final static QualifiedName[] SUPPORTED_OPTIONS = {IContentDescription.CHARSET, IContentDescription.BYTE_ORDER_MARK, IContentDescriptionExtended.DETECTED_CHARSET, IContentDescriptionExtended.UNSUPPORTED_CHARSET, IContentDescriptionExtended.APPROPRIATE_DEFAULT};</TD></TR><TR><TD CLASS="l">30</TD><TD>        /**</TD></TR><TR><TD CLASS="l">31</TD><TD>         * &lt;code&gt;restrictedMode&lt;/code&gt; is used just for testing/experiments.</TD></TR><TR><TD CLASS="l">32</TD><TD>         * </TD></TR><TR><TD CLASS="l">33</TD><TD>         * If in restrictedMode, our &#34;custom&#34; contentType is seen as valid only in</TD></TR><TR><TD CLASS="l"><A NAME="e">34</A></TD><TD>         * cases that the platform's standard one does not cover.</TD></TR><TR><TD CLASS="l">35</TD><TD>         */</TD></TR><TR><TD CLASS="l">36</TD><TD>        private final static boolean restrictedMode = true;</TD></TR><TR><TD CLASS="l">37</TD><TD>        private IResourceCharsetDetector getDetector() {</TD></TR><TR CLASS="c"><TD CLASS="l">38</TD><TD>                        return new XMLResourceEncodingDetector();</TD></TR><TR><TD CLASS="l">39</TD><TD>        }</TD></TR><TR><TD CLASS="l">40</TD><TD> </TD></TR><TR><TD CLASS="l">41</TD><TD>        /*</TD></TR><TR><TD CLASS="l">42</TD><TD>         * (non-Javadoc)</TD></TR><TR><TD CLASS="l">43</TD><TD>         * </TD></TR><TR><TD CLASS="l">44</TD><TD>         * @see org.eclipse.core.runtime.content.IContentDescriber#describe(java.io.InputStream,</TD></TR><TR><TD CLASS="l">45</TD><TD>         *      org.eclipse.core.runtime.content.IContentDescription)</TD></TR><TR><TD CLASS="l"><A NAME="9">46</A></TD><TD>         */</TD></TR><TR><TD CLASS="l">47</TD><TD>        public int describe(InputStream contents, IContentDescription description) throws IOException {</TD></TR><TR><TD CLASS="l">48</TD><TD>                // for this special case, always assume invalid, unless</TD></TR><TR><TD CLASS="l">49</TD><TD>                // our special circumstances are met.</TD></TR><TR CLASS="c"><TD CLASS="l">50</TD><TD>                int result = IContentDescriber.INVALID;</TD></TR><TR><TD CLASS="l">51</TD><TD> </TD></TR><TR CLASS="c"><TD CLASS="l">52</TD><TD>                if (description == null) {</TD></TR><TR><TD CLASS="l">53</TD><TD>                        // purely request for validty</TD></TR><TR CLASS="c"><TD CLASS="l">54</TD><TD>                        result = determineValidity(result, contents);</TD></TR><TR><TD CLASS="l">55</TD><TD>                }</TD></TR><TR><TD CLASS="l">56</TD><TD>                else {</TD></TR><TR CLASS="z"><TD CLASS="l">57</TD><TD>                        result = calculateSupportedOptions(result, contents, description);</TD></TR><TR><TD CLASS="l">58</TD><TD>                }</TD></TR><TR CLASS="c"><TD CLASS="l">59</TD><TD>                return result;</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>        /*</TD></TR><TR><TD CLASS="l">63</TD><TD>         * (non-Javadoc)</TD></TR><TR><TD CLASS="l">64</TD><TD>         * </TD></TR><TR><TD CLASS="l">65</TD><TD>         * @see org.eclipse.core.runtime.content.ITextContentDescriber#describe(java.io.Reader,</TD></TR><TR><TD CLASS="l">66</TD><TD>         *      org.eclipse.core.runtime.content.IContentDescription)</TD></TR><TR><TD CLASS="l"><A NAME="3">67</A></TD><TD>         */</TD></TR><TR><TD CLASS="l">68</TD><TD>        public int describe(Reader contents, IContentDescription description) throws IOException {</TD></TR><TR><TD CLASS="l">69</TD><TD>                // for this special case, always assume invalid, unless</TD></TR><TR><TD CLASS="l">70</TD><TD>                // our special circumstances are met.</TD></TR><TR CLASS="z"><TD CLASS="l">71</TD><TD>                int result = IContentDescriber.INVALID;</TD></TR><TR><TD CLASS="l">72</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">73</TD><TD>                if (description == null) {</TD></TR><TR><TD CLASS="l">74</TD><TD>                        // purely request for validty</TD></TR><TR CLASS="z"><TD CLASS="l">75</TD><TD>                        result = determineValidity(result, contents);</TD></TR><TR><TD CLASS="l">76</TD><TD>                }</TD></TR><TR><TD CLASS="l">77</TD><TD>                else {</TD></TR><TR CLASS="z"><TD CLASS="l">78</TD><TD>                        result = calculateSupportedOptions(result, contents, description);</TD></TR><TR><TD CLASS="l">79</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">80</TD><TD>                return result;</TD></TR><TR><TD CLASS="l">81</TD><TD>        }</TD></TR><TR><TD CLASS="l">82</TD><TD> </TD></TR><TR><TD CLASS="l">83</TD><TD>        /*</TD></TR><TR><TD CLASS="l">84</TD><TD>         * (non-Javadoc)</TD></TR><TR><TD CLASS="l">85</TD><TD>         * </TD></TR><TR><TD CLASS="l"><A NAME="5">86</A></TD><TD>         * @see org.eclipse.core.runtime.content.IContentDescriber#getSupportedOptions()</TD></TR><TR><TD CLASS="l">87</TD><TD>         */</TD></TR><TR><TD CLASS="l">88</TD><TD>        public QualifiedName[] getSupportedOptions() {</TD></TR><TR><TD CLASS="l">89</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l"><A NAME="1">90</A></TD><TD>                return SUPPORTED_OPTIONS;</TD></TR><TR><TD CLASS="l">91</TD><TD>        }</TD></TR><TR><TD CLASS="l">92</TD><TD> </TD></TR><TR><TD CLASS="l">93</TD><TD>        private int calculateSupportedOptions(int result, InputStream contents, IContentDescription description) throws IOException {</TD></TR><TR CLASS="z"><TD CLASS="l">94</TD><TD>                int returnResult = result;</TD></TR><TR CLASS="z"><TD CLASS="l">95</TD><TD>                if (isRelevent(description)) {</TD></TR><TR CLASS="z"><TD CLASS="l">96</TD><TD>                        IResourceCharsetDetector detector = getDetector();</TD></TR><TR CLASS="z"><TD CLASS="l">97</TD><TD>                        contents.reset();</TD></TR><TR CLASS="z"><TD CLASS="l">98</TD><TD>                        detector.set(contents);</TD></TR><TR CLASS="z"><TD CLASS="l">99</TD><TD>                        returnResult = handleCalculations(result, description, detector);</TD></TR><TR><TD CLASS="l">100</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l"><A NAME="d">101</A></TD><TD>                return returnResult;</TD></TR><TR><TD CLASS="l">102</TD><TD>        }</TD></TR><TR><TD CLASS="l">103</TD><TD> </TD></TR><TR><TD CLASS="l">104</TD><TD>        private int determineValidity(int result, InputStream contents) throws IOException {</TD></TR><TR CLASS="c"><TD CLASS="l">105</TD><TD>                int returnResult = result;</TD></TR><TR CLASS="c"><TD CLASS="l">106</TD><TD>                IResourceCharsetDetector detector = getDetector();</TD></TR><TR CLASS="c"><TD CLASS="l">107</TD><TD>                contents.reset();</TD></TR><TR CLASS="c"><TD CLASS="l">108</TD><TD>                detector.set(contents);</TD></TR><TR CLASS="c"><TD CLASS="l"><A NAME="4">109</A></TD><TD>                returnResult = determineValidity(detector, returnResult);</TD></TR><TR CLASS="c"><TD CLASS="l">110</TD><TD>                return returnResult;</TD></TR><TR><TD CLASS="l">111</TD><TD>        }</TD></TR><TR><TD CLASS="l">112</TD><TD>        private int determineValidity(int result, Reader contents) throws IOException {</TD></TR><TR CLASS="z"><TD CLASS="l">113</TD><TD>                int returnResult = result;</TD></TR><TR CLASS="z"><TD CLASS="l">114</TD><TD>                IResourceCharsetDetector detector = getDetector();</TD></TR><TR CLASS="z"><TD CLASS="l">115</TD><TD>                contents.reset();</TD></TR><TR CLASS="z"><TD CLASS="l">116</TD><TD>                detector.set(contents);</TD></TR><TR CLASS="z"><TD CLASS="l">117</TD><TD>                returnResult = determineValidity(detector, returnResult);</TD></TR><TR CLASS="z"><TD CLASS="l">118</TD><TD>                return returnResult;</TD></TR><TR><TD CLASS="l">119</TD><TD>        }</TD></TR><TR><TD CLASS="l">120</TD><TD>        /**</TD></TR><TR><TD CLASS="l">121</TD><TD>         * @param contents</TD></TR><TR><TD CLASS="l"><A NAME="2">122</A></TD><TD>         * @param description</TD></TR><TR><TD CLASS="l">123</TD><TD>         * @throws IOException</TD></TR><TR><TD CLASS="l">124</TD><TD>         */</TD></TR><TR><TD CLASS="l">125</TD><TD>        private int calculateSupportedOptions(int result, Reader contents, IContentDescription description) throws IOException {</TD></TR><TR CLASS="z"><TD CLASS="l">126</TD><TD>                int returnResult = result;</TD></TR><TR CLASS="z"><TD CLASS="l">127</TD><TD>                if (isRelevent(description)) {</TD></TR><TR CLASS="z"><TD CLASS="l">128</TD><TD>                        IResourceCharsetDetector detector = getDetector();</TD></TR><TR CLASS="z"><TD CLASS="l">129</TD><TD>                        detector.set(contents);</TD></TR><TR CLASS="z"><TD CLASS="l">130</TD><TD>                        returnResult = handleCalculations(result, description, detector);</TD></TR><TR><TD CLASS="l">131</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">132</TD><TD>                return returnResult;</TD></TR><TR><TD CLASS="l">133</TD><TD>        }</TD></TR><TR><TD CLASS="l">134</TD><TD> </TD></TR><TR><TD CLASS="l">135</TD><TD>        private void handleDetectedSpecialCase(IContentDescription description, Object detectedCharset, Object javaCharset) {</TD></TR><TR><TD CLASS="l">136</TD><TD>                // since equal, we don't need to add, but if our detected version is</TD></TR><TR><TD CLASS="l"><A NAME="7">137</A></TD><TD>                // different than</TD></TR><TR><TD CLASS="l">138</TD><TD>                // javaCharset, then we should add it. This will happen, for example,</TD></TR><TR><TD CLASS="l">139</TD><TD>                // if there's</TD></TR><TR><TD CLASS="l">140</TD><TD>                // differences in case, or differences due to override properties</TD></TR><TR CLASS="z"><TD CLASS="l">141</TD><TD>                if (detectedCharset != null) {</TD></TR><TR><TD CLASS="l">142</TD><TD>                        // if (!detectedCharset.equals(javaCharset)) {</TD></TR><TR><TD CLASS="l">143</TD><TD>                        // description.setProperty(IContentDescriptionExtended.DETECTED_CHARSET,</TD></TR><TR><TD CLASS="l">144</TD><TD>                        // detectedCharset);</TD></TR><TR><TD CLASS="l">145</TD><TD>                        // }</TD></TR><TR><TD CLASS="l">146</TD><TD> </TD></TR><TR><TD CLASS="l">147</TD><TD>                        // Once we detected a charset, we should set the property even</TD></TR><TR><TD CLASS="l">148</TD><TD>                        // though it's the same as javaCharset</TD></TR><TR><TD CLASS="l">149</TD><TD>                        // because there are clients that rely on this property to</TD></TR><TR><TD CLASS="l">150</TD><TD>                        // determine if the charset is actually detected in file or not.</TD></TR><TR CLASS="z"><TD CLASS="l">151</TD><TD>                        description.setProperty(IContentDescriptionExtended.DETECTED_CHARSET, detectedCharset);</TD></TR><TR><TD CLASS="l">152</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">153</TD><TD>        }</TD></TR><TR><TD CLASS="l">154</TD><TD> </TD></TR><TR><TD CLASS="l">155</TD><TD>        /**</TD></TR><TR><TD CLASS="l"><A NAME="8">156</A></TD><TD>         * @param description</TD></TR><TR><TD CLASS="l">157</TD><TD>         * @return</TD></TR><TR><TD CLASS="l">158</TD><TD>         */</TD></TR><TR><TD CLASS="l">159</TD><TD>        private boolean isRelevent(IContentDescription description) {</TD></TR><TR CLASS="z"><TD CLASS="l">160</TD><TD>                boolean result = false;</TD></TR><TR CLASS="z"><TD CLASS="l">161</TD><TD>                if (description == null)</TD></TR><TR CLASS="z"><TD CLASS="l">162</TD><TD>                        result = false;</TD></TR><TR CLASS="z"><TD CLASS="l">163</TD><TD>                else if (description.isRequested(IContentDescription.BYTE_ORDER_MARK))</TD></TR><TR CLASS="z"><TD CLASS="l">164</TD><TD>                        result = true;</TD></TR><TR CLASS="z"><TD CLASS="l">165</TD><TD>                else if (description.isRequested(IContentDescription.CHARSET))</TD></TR><TR CLASS="z"><TD CLASS="l">166</TD><TD>                        result = true;</TD></TR><TR CLASS="z"><TD CLASS="l">167</TD><TD>                else if (description.isRequested(IContentDescriptionExtended.APPROPRIATE_DEFAULT))</TD></TR><TR CLASS="z"><TD CLASS="l">168</TD><TD>                        result = true;</TD></TR><TR CLASS="z"><TD CLASS="l">169</TD><TD>                else if (description.isRequested(IContentDescriptionExtended.DETECTED_CHARSET))</TD></TR><TR CLASS="z"><TD CLASS="l">170</TD><TD>                        result = true;</TD></TR><TR CLASS="z"><TD CLASS="l">171</TD><TD>                else if (description.isRequested(IContentDescriptionExtended.UNSUPPORTED_CHARSET))</TD></TR><TR CLASS="z"><TD CLASS="l">172</TD><TD>                        result = true;</TD></TR><TR CLASS="z"><TD CLASS="l">173</TD><TD>                return result;</TD></TR><TR><TD CLASS="l">174</TD><TD>        }</TD></TR><TR><TD CLASS="l">175</TD><TD> </TD></TR><TR><TD CLASS="l">176</TD><TD>        /**</TD></TR><TR><TD CLASS="l">177</TD><TD>         * @param description</TD></TR><TR><TD CLASS="l"><A NAME="6">178</A></TD><TD>         * @param detector</TD></TR><TR><TD CLASS="l">179</TD><TD>         * @throws IOException</TD></TR><TR><TD CLASS="l">180</TD><TD>         */</TD></TR><TR><TD CLASS="l">181</TD><TD>        private int handleCalculations(int result, IContentDescription description, IResourceCharsetDetector detector) throws IOException {</TD></TR><TR CLASS="z"><TD CLASS="l">182</TD><TD>                int returnResult = result;</TD></TR><TR CLASS="z"><TD CLASS="l">183</TD><TD>                EncodingMemento encodingMemento = ((XMLResourceEncodingDetector) detector).getEncodingMemento();</TD></TR><TR CLASS="z"><TD CLASS="l">184</TD><TD>                if (description != null) {</TD></TR><TR><TD CLASS="l">185</TD><TD>                        // TODO: I need to verify to see if this BOM work is always done</TD></TR><TR><TD CLASS="l">186</TD><TD>                        // by text type.</TD></TR><TR CLASS="z"><TD CLASS="l">187</TD><TD>                        Object detectedByteOrderMark = encodingMemento.getUnicodeBOM();</TD></TR><TR CLASS="z"><TD CLASS="l">188</TD><TD>                        if (detectedByteOrderMark != null) {</TD></TR><TR CLASS="z"><TD CLASS="l">189</TD><TD>                                Object existingByteOrderMark = description.getProperty(IContentDescription.BYTE_ORDER_MARK);</TD></TR><TR><TD CLASS="l">190</TD><TD>                                // not sure why would ever be different, so if is different,</TD></TR><TR><TD CLASS="l">191</TD><TD>                                // may</TD></TR><TR><TD CLASS="l">192</TD><TD>                                // need to &#34;push&#34; up into base.</TD></TR><TR CLASS="z"><TD CLASS="l">193</TD><TD>                                if (!detectedByteOrderMark.equals(existingByteOrderMark))</TD></TR><TR CLASS="z"><TD CLASS="l">194</TD><TD>                                        description.setProperty(IContentDescription.BYTE_ORDER_MARK, detectedByteOrderMark);</TD></TR><TR><TD CLASS="l">195</TD><TD>                        }</TD></TR><TR><TD CLASS="l">196</TD><TD> </TD></TR><TR><TD CLASS="l">197</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">198</TD><TD>                        if (!encodingMemento.isValid()) {</TD></TR><TR><TD CLASS="l">199</TD><TD>                                // note: after setting here, its the mere presence of</TD></TR><TR><TD CLASS="l">200</TD><TD>                                // IContentDescriptionExtended.UNSUPPORTED_CHARSET</TD></TR><TR><TD CLASS="l">201</TD><TD>                                // in the resource's description that can be used to determine</TD></TR><TR><TD CLASS="l">202</TD><TD>                                // if invalid in those cases, the &#34;detected&#34; property contains</TD></TR><TR><TD CLASS="l">203</TD><TD>                                // an &#34;appropriate default&#34; to use.</TD></TR><TR CLASS="z"><TD CLASS="l">204</TD><TD>                                description.setProperty(IContentDescriptionExtended.UNSUPPORTED_CHARSET, encodingMemento.getInvalidEncoding());</TD></TR><TR CLASS="z"><TD CLASS="l">205</TD><TD>                                description.setProperty(IContentDescriptionExtended.APPROPRIATE_DEFAULT, encodingMemento.getAppropriateDefault());</TD></TR><TR><TD CLASS="l">206</TD><TD>                        }</TD></TR><TR><TD CLASS="l">207</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">208</TD><TD>                        Object detectedCharset = encodingMemento.getDetectedCharsetName();</TD></TR><TR CLASS="z"><TD CLASS="l">209</TD><TD>                        Object javaCharset = encodingMemento.getJavaCharsetName();</TD></TR><TR><TD CLASS="l">210</TD><TD> </TD></TR><TR><TD CLASS="l">211</TD><TD>                        // we always include detected, if its different than java</TD></TR><TR CLASS="z"><TD CLASS="l">212</TD><TD>                        handleDetectedSpecialCase(description, detectedCharset, javaCharset);</TD></TR><TR><TD CLASS="l">213</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">214</TD><TD>                        if (javaCharset != null) {</TD></TR><TR CLASS="z"><TD CLASS="l">215</TD><TD>                                Object existingCharset = description.getProperty(IContentDescription.CHARSET);</TD></TR><TR CLASS="z"><TD CLASS="l">216</TD><TD>                                if (javaCharset.equals(existingCharset)) {</TD></TR><TR CLASS="z"><TD CLASS="l">217</TD><TD>                                        handleDetectedSpecialCase(description, detectedCharset, javaCharset);</TD></TR><TR><TD CLASS="l">218</TD><TD>                                }</TD></TR><TR><TD CLASS="l">219</TD><TD>                                else {</TD></TR><TR><TD CLASS="l">220</TD><TD>                                        // we may need to add what we found, but only need to add</TD></TR><TR><TD CLASS="l">221</TD><TD>                                        // if different from the default</TD></TR><TR CLASS="z"><TD CLASS="l">222</TD><TD>                                        Object defaultCharset = detector.getSpecDefaultEncoding();</TD></TR><TR CLASS="z"><TD CLASS="l">223</TD><TD>                                        if (defaultCharset != null) {</TD></TR><TR CLASS="z"><TD CLASS="l">224</TD><TD>                                                if (!defaultCharset.equals(javaCharset)) {</TD></TR><TR CLASS="z"><TD CLASS="l">225</TD><TD>                                                        description.setProperty(IContentDescription.CHARSET, javaCharset);</TD></TR><TR><TD CLASS="l">226</TD><TD>                                                }</TD></TR><TR><TD CLASS="l">227</TD><TD>                                        }</TD></TR><TR><TD CLASS="l">228</TD><TD>                                        else {</TD></TR><TR><TD CLASS="l">229</TD><TD>                                                // assuming if there is no spec default, we always</TD></TR><TR><TD CLASS="l">230</TD><TD>                                                // need to add.</TD></TR><TR><TD CLASS="l">231</TD><TD>                                                // TODO: this is probably a dead branch in current</TD></TR><TR><TD CLASS="l">232</TD><TD>                                                // code, should re-examine for removal.</TD></TR><TR CLASS="z"><TD CLASS="l">233</TD><TD>                                                description.setProperty(IContentDescription.CHARSET, javaCharset);</TD></TR><TR><TD CLASS="l">234</TD><TD>                                        }</TD></TR><TR><TD CLASS="l">235</TD><TD>                                }</TD></TR><TR><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 CLASS="z"><TD CLASS="l">239</TD><TD>                returnResult = determineValidity(detector, returnResult);</TD></TR><TR CLASS="z"><TD CLASS="l">240</TD><TD>                return returnResult;</TD></TR><TR><TD CLASS="l">241</TD><TD>        }</TD></TR><TR><TD CLASS="l"><A NAME="a">242</A></TD><TD> </TD></TR><TR><TD CLASS="l">243</TD><TD>        private int determineValidity(IResourceCharsetDetector detector, int returnResult) {</TD></TR><TR><TD CLASS="l">244</TD><TD>                // we always expect XMLResourceEncodingDetector, but just to make safe</TD></TR><TR><TD CLASS="l">245</TD><TD>                // cast.</TD></TR><TR CLASS="c"><TD CLASS="l">246</TD><TD>                if (detector instanceof XMLResourceEncodingDetector) {</TD></TR><TR CLASS="c"><TD CLASS="l">247</TD><TD>                        XMLResourceEncodingDetector xmlResourceDetector = (XMLResourceEncodingDetector) detector;</TD></TR><TR CLASS="c"><TD CLASS="l">248</TD><TD>                        if (xmlResourceDetector.isDeclDetected()) {</TD></TR><TR><TD CLASS="l">249</TD><TD>                                if (restrictedMode) {</TD></TR><TR><TD CLASS="l">250</TD><TD>                                        // if there is no initial whitespace, then platform's</TD></TR><TR><TD CLASS="l">251</TD><TD>                                        // default one will do.</TD></TR><TR CLASS="c"><TD CLASS="l">252</TD><TD>                                        if (xmlResourceDetector.hasInitialWhiteSpace()) {</TD></TR><TR CLASS="z"><TD CLASS="l">253</TD><TD>                                                returnResult = IContentDescriber.VALID;</TD></TR><TR><TD CLASS="l">254</TD><TD>                                        }</TD></TR><TR><TD CLASS="l">255</TD><TD>                                }</TD></TR><TR><TD CLASS="l">256</TD><TD>                                else {</TD></TR><TR><TD CLASS="l">257</TD><TD>                                        returnResult = IContentDescriber.VALID;</TD></TR><TR><TD CLASS="l">258</TD><TD>                                }</TD></TR><TR><TD CLASS="l">259</TD><TD>                        }</TD></TR><TR><TD CLASS="l">260</TD><TD>                }</TD></TR><TR CLASS="c"><TD CLASS="l">261</TD><TD>                return returnResult;</TD></TR><TR><TD CLASS="l">262</TD><TD>        }</TD></TR><TR><TD CLASS="l">263</TD><TD> </TD></TR><TR><TD CLASS="l">264</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>