diff options
Diffstat (limited to 'tests/org.eclipse.wst.xml.xpath2.processor.tests/coverageReport/_files/1643.html')
-rw-r--r-- | tests/org.eclipse.wst.xml.xpath2.processor.tests/coverageReport/_files/1643.html | 1 |
1 files changed, 0 insertions, 1 deletions
diff --git a/tests/org.eclipse.wst.xml.xpath2.processor.tests/coverageReport/_files/1643.html b/tests/org.eclipse.wst.xml.xpath2.processor.tests/coverageReport/_files/1643.html deleted file mode 100644 index a5ec77e6..00000000 --- a/tests/org.eclipse.wst.xml.xpath2.processor.tests/coverageReport/_files/1643.html +++ /dev/null @@ -1 +0,0 @@ -<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 Tue Jun 09 19:59:05 GMT 2009)</TH></TR><TR><TD CLASS="nv">[<A HREF="../xslUnitTestCoverage.html">all classes</A>][<A HREF="208.html">org.eclipse.wst.xml.core.internal.cleanup</A>]</TD></TR></TABLE><H2>COVERAGE SUMMARY FOR SOURCE FILE [<SPAN CLASS="in">ElementNodeCleanupHandler.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>ElementNodeCleanupHandler.java</TD><TD CLASS="h">0% (0/1)</TD><TD CLASS="h">0% (0/19)</TD><TD CLASS="h">0% (0/970)</TD><TD CLASS="h">0% (0/253)</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">ElementNodeCleanupHandler</A></TD><TD CLASS="h">0% (0/1)</TD><TD CLASS="h">0% (0/19)</TD><TD CLASS="h">0% (0/970)</TD><TD CLASS="h">0% (0/253)</TD></TR><TR><TD CLASS="f"><A HREF="#0">ElementNodeCleanupHandler (): void</A></TD><TD> </TD><TD CLASS="h">0% (0/1)</TD><TD CLASS="h">0% (0/3)</TD><TD CLASS="h">0% (0/1)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#2">cleanup (Node): Node</A></TD><TD> </TD><TD CLASS="h">0% (0/1)</TD><TD CLASS="h">0% (0/69)</TD><TD CLASS="h">0% (0/17)</TD></TR><TR><TD CLASS="f"><A HREF="#3">cleanupChildren (Node): Node</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">compressEmptyElementTag (IDOMNode): IDOMNode</A></TD><TD> </TD><TD CLASS="h">0% (0/1)</TD><TD CLASS="h">0% (0/105)</TD><TD CLASS="h">0% (0/21)</TD></TR><TR><TD CLASS="f"><A HREF="#5">getCleanupHandler (Node): IStructuredCleanupHandler</A></TD><TD> </TD><TD CLASS="h">0% (0/1)</TD><TD CLASS="h">0% (0/27)</TD><TD CLASS="h">0% (0/10)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#6">getModelQuery (Node): ModelQuery</A></TD><TD> </TD><TD CLASS="h">0% (0/1)</TD><TD CLASS="h">0% (0/12)</TD><TD CLASS="h">0% (0/3)</TD></TR><TR><TD CLASS="f"><A HREF="#7">getRequiredAttrs (Node): List</A></TD><TD> </TD><TD CLASS="h">0% (0/1)</TD><TD CLASS="h">0% (0/43)</TD><TD CLASS="h">0% (0/13)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#8">insertEndTag (IDOMNode): IDOMNode</A></TD><TD> </TD><TD CLASS="h">0% (0/1)</TD><TD CLASS="h">0% (0/115)</TD><TD CLASS="h">0% (0/27)</TD></TR><TR><TD CLASS="f"><A HREF="#9">insertMissingTags (IDOMNode): IDOMNode</A></TD><TD> </TD><TD CLASS="h">0% (0/1)</TD><TD CLASS="h">0% (0/62)</TD><TD CLASS="h">0% (0/17)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#a">insertRequiredAttrs (IDOMNode): IDOMNode</A></TD><TD> </TD><TD CLASS="h">0% (0/1)</TD><TD CLASS="h">0% (0/183)</TD><TD CLASS="h">0% (0/45)</TD></TR><TR><TD CLASS="f"><A HREF="#b">insertStartTag (IDOMNode): IDOMNode</A></TD><TD> </TD><TD CLASS="h">0% (0/1)</TD><TD CLASS="h">0% (0/40)</TD><TD CLASS="h">0% (0/11)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#c">insertTagClose (IDOMModel, IStructuredDocumentRegion): void</A></TD><TD> </TD><TD CLASS="h">0% (0/1)</TD><TD CLASS="h">0% (0/38)</TD><TD CLASS="h">0% (0/10)</TD></TR><TR><TD CLASS="f"><A HREF="#d">isCommentTag (Node): boolean</A></TD><TD> </TD><TD CLASS="h">0% (0/1)</TD><TD CLASS="h">0% (0/13)</TD><TD CLASS="h">0% (0/5)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#e">isEmptyElement (IDOMElement): boolean</A></TD><TD> </TD><TD CLASS="h">0% (0/1)</TD><TD CLASS="h">0% (0/30)</TD><TD CLASS="h">0% (0/10)</TD></TR><TR><TD CLASS="f"><A HREF="#f">isEndTagRequired (IDOMNode): boolean</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="#10">isImplicitTag (IDOMNode): boolean</A></TD><TD> </TD><TD CLASS="h">0% (0/1)</TD><TD CLASS="h">0% (0/7)</TD><TD CLASS="h">0% (0/1)</TD></TR><TR><TD CLASS="f"><A HREF="#11">isStartTagRequired (IDOMNode): boolean</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="#12">isXMLType (IDOMModel): boolean</A></TD><TD> </TD><TD CLASS="h">0% (0/1)</TD><TD CLASS="h">0% (0/16)</TD><TD CLASS="h">0% (0/6)</TD></TR><TR><TD CLASS="f"><A HREF="#13">quoteAttrValue (IDOMNode): IDOMNode</A></TD><TD> </TD><TD CLASS="h">0% (0/1)</TD><TD CLASS="h">0% (0/167)</TD><TD CLASS="h">0% (0/41)</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.cleanup;</TD></TR><TR><TD CLASS="l">14</TD><TD> </TD></TR><TR><TD CLASS="l">15</TD><TD>import java.util.ArrayList;</TD></TR><TR><TD CLASS="l">16</TD><TD>import java.util.Iterator;</TD></TR><TR><TD CLASS="l">17</TD><TD>import java.util.List;</TD></TR><TR><TD CLASS="l">18</TD><TD> </TD></TR><TR><TD CLASS="l">19</TD><TD>import org.eclipse.jface.text.BadLocationException;</TD></TR><TR><TD CLASS="l">20</TD><TD>import org.eclipse.text.edits.InsertEdit;</TD></TR><TR><TD CLASS="l">21</TD><TD>import org.eclipse.text.edits.MultiTextEdit;</TD></TR><TR><TD CLASS="l">22</TD><TD>import org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupHandler;</TD></TR><TR><TD CLASS="l">23</TD><TD>import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;</TD></TR><TR><TD CLASS="l">24</TD><TD>import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;</TD></TR><TR><TD CLASS="l">25</TD><TD>import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;</TD></TR><TR><TD CLASS="l">26</TD><TD>import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;</TD></TR><TR><TD CLASS="l">27</TD><TD>import org.eclipse.wst.sse.core.utils.StringUtils;</TD></TR><TR><TD CLASS="l">28</TD><TD>import org.eclipse.wst.xml.core.internal.Logger;</TD></TR><TR><TD CLASS="l">29</TD><TD>import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;</TD></TR><TR><TD CLASS="l">30</TD><TD>import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;</TD></TR><TR><TD CLASS="l">31</TD><TD>import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap;</TD></TR><TR><TD CLASS="l">32</TD><TD>import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;</TD></TR><TR><TD CLASS="l">33</TD><TD>import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil;</TD></TR><TR><TD CLASS="l">34</TD><TD>import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;</TD></TR><TR><TD CLASS="l">35</TD><TD>import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;</TD></TR><TR><TD CLASS="l">36</TD><TD>import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;</TD></TR><TR><TD CLASS="l">37</TD><TD>import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;</TD></TR><TR><TD CLASS="l">38</TD><TD>import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;</TD></TR><TR><TD CLASS="l">39</TD><TD>import org.eclipse.wst.xml.core.internal.provisional.document.ISourceGenerator;</TD></TR><TR><TD CLASS="l">40</TD><TD>import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;</TD></TR><TR><TD CLASS="l">41</TD><TD>import org.w3c.dom.Document;</TD></TR><TR><TD CLASS="l">42</TD><TD>import org.w3c.dom.Element;</TD></TR><TR><TD CLASS="l">43</TD><TD>import org.w3c.dom.NamedNodeMap;</TD></TR><TR><TD CLASS="l"><A NAME="0">44</A></TD><TD>import org.w3c.dom.Node;</TD></TR><TR><TD CLASS="l">45</TD><TD>import org.w3c.dom.NodeList;</TD></TR><TR><TD CLASS="l">46</TD><TD> </TD></TR><TR><TD CLASS="l">47</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">48</TD><TD>public class ElementNodeCleanupHandler extends NodeCleanupHandler {</TD></TR><TR><TD CLASS="l">49</TD><TD> protected static final char DOUBLE_QUOTE = '\"'; //$NON-NLS-1$</TD></TR><TR><TD CLASS="l">50</TD><TD> protected static final String DOUBLE_QUOTES = "\"\""; //$NON-NLS-1$</TD></TR><TR><TD CLASS="l">51</TD><TD> protected static final String EMPTY_TAG_CLOSE = "/>"; //$NON-NLS-1$</TD></TR><TR><TD CLASS="l">52</TD><TD> protected static final String END_TAG_OPEN = "</"; //$NON-NLS-1$</TD></TR><TR><TD CLASS="l">53</TD><TD> protected static final char SINGLE_QUOTE = '\''; //$NON-NLS-1$</TD></TR><TR><TD CLASS="l">54</TD><TD> protected static final String SINGLE_QUOTES = "''"; //$NON-NLS-1$</TD></TR><TR><TD CLASS="l">55</TD><TD> </TD></TR><TR><TD CLASS="l">56</TD><TD> /** Non-NLS strings */</TD></TR><TR><TD CLASS="l"><A NAME="2">57</A></TD><TD> protected static final String START_TAG_OPEN = "<"; //$NON-NLS-1$</TD></TR><TR><TD CLASS="l">58</TD><TD> protected static final String TAG_CLOSE = ">"; //$NON-NLS-1$</TD></TR><TR><TD CLASS="l">59</TD><TD> </TD></TR><TR><TD CLASS="l">60</TD><TD> public Node cleanup(Node node) {</TD></TR><TR CLASS="z"><TD CLASS="l">61</TD><TD> Node newNode = cleanupChildren(node);</TD></TR><TR CLASS="z"><TD CLASS="l">62</TD><TD> IDOMNode renamedNode = newNode instanceof IDOMNode ? (IDOMNode) newNode : null;</TD></TR><TR><TD CLASS="l">63</TD><TD> </TD></TR><TR><TD CLASS="l">64</TD><TD> // call quoteAttrValue() first so it will close any unclosed attr</TD></TR><TR><TD CLASS="l">65</TD><TD> // quoteAttrValue() will return the new start tag if there is a</TD></TR><TR><TD CLASS="l">66</TD><TD> // structure change</TD></TR><TR CLASS="z"><TD CLASS="l">67</TD><TD> renamedNode = quoteAttrValue(renamedNode);</TD></TR><TR><TD CLASS="l">68</TD><TD> </TD></TR><TR><TD CLASS="l">69</TD><TD> // insert tag close if missing</TD></TR><TR><TD CLASS="l">70</TD><TD> // if node is not comment tag</TD></TR><TR><TD CLASS="l">71</TD><TD> // and not implicit tag</TD></TR><TR CLASS="z"><TD CLASS="l">72</TD><TD> if (!isCommentTag(renamedNode) && !isImplicitTag(renamedNode)) {</TD></TR><TR CLASS="z"><TD CLASS="l">73</TD><TD> IDOMModel structuredModel = renamedNode.getModel();</TD></TR><TR><TD CLASS="l">74</TD><TD> </TD></TR><TR><TD CLASS="l">75</TD><TD> // save start offset before insertTagClose()</TD></TR><TR><TD CLASS="l">76</TD><TD> // or else renamedNode.getStartOffset() will be zero if</TD></TR><TR><TD CLASS="l">77</TD><TD> // renamedNode replaced by insertTagClose()</TD></TR><TR CLASS="z"><TD CLASS="l">78</TD><TD> int startTagStartOffset = renamedNode.getStartOffset();</TD></TR><TR><TD CLASS="l">79</TD><TD> </TD></TR><TR><TD CLASS="l">80</TD><TD> // for start tag</TD></TR><TR CLASS="z"><TD CLASS="l">81</TD><TD> IStructuredDocumentRegion startTagStructuredDocumentRegion = renamedNode.getStartStructuredDocumentRegion();</TD></TR><TR CLASS="z"><TD CLASS="l">82</TD><TD> insertTagClose(structuredModel, startTagStructuredDocumentRegion);</TD></TR><TR><TD CLASS="l">83</TD><TD> </TD></TR><TR><TD CLASS="l">84</TD><TD> // update renamedNode and startTagStructuredDocumentRegion after</TD></TR><TR><TD CLASS="l">85</TD><TD> // insertTagClose()</TD></TR><TR CLASS="z"><TD CLASS="l">86</TD><TD> renamedNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset);</TD></TR><TR CLASS="z"><TD CLASS="l">87</TD><TD> startTagStructuredDocumentRegion = renamedNode.getStartStructuredDocumentRegion();</TD></TR><TR><TD CLASS="l">88</TD><TD> </TD></TR><TR><TD CLASS="l">89</TD><TD> // for end tag</TD></TR><TR CLASS="z"><TD CLASS="l">90</TD><TD> IStructuredDocumentRegion endTagStructuredDocumentRegion = renamedNode.getEndStructuredDocumentRegion();</TD></TR><TR CLASS="z"><TD CLASS="l">91</TD><TD> if (endTagStructuredDocumentRegion != startTagStructuredDocumentRegion)</TD></TR><TR CLASS="z"><TD CLASS="l">92</TD><TD> insertTagClose(structuredModel, endTagStructuredDocumentRegion);</TD></TR><TR><TD CLASS="l">93</TD><TD> }</TD></TR><TR><TD CLASS="l">94</TD><TD> </TD></TR><TR><TD CLASS="l">95</TD><TD> // call insertMissingTags() next, it will generate implicit tags if</TD></TR><TR><TD CLASS="l">96</TD><TD> // there are any</TD></TR><TR><TD CLASS="l">97</TD><TD> // insertMissingTags() will return the new missing start tag if one is</TD></TR><TR><TD CLASS="l">98</TD><TD> // missing</TD></TR><TR CLASS="z"><TD CLASS="l">99</TD><TD> renamedNode = insertMissingTags(renamedNode);</TD></TR><TR><TD CLASS="l">100</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">101</TD><TD> renamedNode = compressEmptyElementTag(renamedNode);</TD></TR><TR><TD CLASS="l">102</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">103</TD><TD> renamedNode = insertRequiredAttrs(renamedNode);</TD></TR><TR><TD CLASS="l">104</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l"><A NAME="3">105</A></TD><TD> return renamedNode;</TD></TR><TR><TD CLASS="l">106</TD><TD> }</TD></TR><TR><TD CLASS="l">107</TD><TD> </TD></TR><TR><TD CLASS="l">108</TD><TD> protected Node cleanupChildren(Node node) {</TD></TR><TR CLASS="z"><TD CLASS="l">109</TD><TD> Node parentNode = node;</TD></TR><TR><TD CLASS="l">110</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">111</TD><TD> if (node != null) {</TD></TR><TR CLASS="z"><TD CLASS="l">112</TD><TD> Node childNode = node.getFirstChild();</TD></TR><TR CLASS="z"><TD CLASS="l">113</TD><TD> while (childNode != null) {</TD></TR><TR><TD CLASS="l">114</TD><TD> // get cleanup handler</TD></TR><TR CLASS="z"><TD CLASS="l">115</TD><TD> IStructuredCleanupHandler cleanupHandler = getCleanupHandler(childNode);</TD></TR><TR><TD CLASS="l">116</TD><TD> </TD></TR><TR><TD CLASS="l">117</TD><TD> // cleanup each child</TD></TR><TR CLASS="z"><TD CLASS="l">118</TD><TD> childNode = cleanupHandler.cleanup(childNode);</TD></TR><TR><TD CLASS="l">119</TD><TD> </TD></TR><TR><TD CLASS="l">120</TD><TD> // get new parent node</TD></TR><TR CLASS="z"><TD CLASS="l">121</TD><TD> parentNode = childNode.getParentNode();</TD></TR><TR><TD CLASS="l">122</TD><TD> </TD></TR><TR><TD CLASS="l">123</TD><TD> // get next child node</TD></TR><TR CLASS="z"><TD CLASS="l">124</TD><TD> childNode = childNode.getNextSibling();</TD></TR><TR><TD CLASS="l">125</TD><TD> }</TD></TR><TR><TD CLASS="l">126</TD><TD> }</TD></TR><TR><TD CLASS="l">127</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l"><A NAME="4">128</A></TD><TD> return parentNode;</TD></TR><TR><TD CLASS="l">129</TD><TD> }</TD></TR><TR><TD CLASS="l">130</TD><TD> </TD></TR><TR><TD CLASS="l">131</TD><TD> private IDOMNode compressEmptyElementTag(IDOMNode node) {</TD></TR><TR CLASS="z"><TD CLASS="l">132</TD><TD> boolean compressEmptyElementTags = getCleanupPreferences().getCompressEmptyElementTags();</TD></TR><TR CLASS="z"><TD CLASS="l">133</TD><TD> IDOMNode newNode = node;</TD></TR><TR><TD CLASS="l">134</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">135</TD><TD> IStructuredDocumentRegion startTagStructuredDocumentRegion = newNode.getFirstStructuredDocumentRegion();</TD></TR><TR CLASS="z"><TD CLASS="l">136</TD><TD> IStructuredDocumentRegion endTagStructuredDocumentRegion = newNode.getLastStructuredDocumentRegion();</TD></TR><TR><TD CLASS="l">137</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">138</TD><TD> if (compressEmptyElementTags && startTagStructuredDocumentRegion != endTagStructuredDocumentRegion && startTagStructuredDocumentRegion != null) {</TD></TR><TR CLASS="z"><TD CLASS="l">139</TD><TD> ITextRegionList regions = startTagStructuredDocumentRegion.getRegions();</TD></TR><TR CLASS="z"><TD CLASS="l">140</TD><TD> ITextRegion lastRegion = regions.get(regions.size() - 1);</TD></TR><TR><TD CLASS="l">141</TD><TD> // format children and end tag if not empty element tag</TD></TR><TR CLASS="z"><TD CLASS="l">142</TD><TD> if (lastRegion.getType() != DOMRegionContext.XML_EMPTY_TAG_CLOSE) {</TD></TR><TR CLASS="z"><TD CLASS="l">143</TD><TD> NodeList childNodes = newNode.getChildNodes();</TD></TR><TR CLASS="z"><TD CLASS="l">144</TD><TD> if (childNodes == null || childNodes.getLength() == 0 || (childNodes.getLength() == 1 && (childNodes.item(0)).getNodeType() == Node.TEXT_NODE && ((childNodes.item(0)).getNodeValue().trim().length() == 0))) {</TD></TR><TR CLASS="z"><TD CLASS="l">145</TD><TD> IDOMModel structuredModel = newNode.getModel();</TD></TR><TR CLASS="z"><TD CLASS="l">146</TD><TD> IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();</TD></TR><TR><TD CLASS="l">147</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">148</TD><TD> int startTagStartOffset = newNode.getStartOffset();</TD></TR><TR CLASS="z"><TD CLASS="l">149</TD><TD> int offset = endTagStructuredDocumentRegion.getStart();</TD></TR><TR CLASS="z"><TD CLASS="l">150</TD><TD> int length = endTagStructuredDocumentRegion.getLength();</TD></TR><TR CLASS="z"><TD CLASS="l">151</TD><TD> structuredDocument.replaceText(structuredDocument, offset, length, ""); //$NON-NLS-1$</TD></TR><TR CLASS="z"><TD CLASS="l">152</TD><TD> newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset); // save</TD></TR><TR><TD CLASS="l">153</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">154</TD><TD> offset = startTagStructuredDocumentRegion.getStart() + lastRegion.getStart();</TD></TR><TR CLASS="z"><TD CLASS="l">155</TD><TD> structuredDocument.replaceText(structuredDocument, offset, 0, "/"); //$NON-NLS-1$</TD></TR><TR CLASS="z"><TD CLASS="l">156</TD><TD> newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset); // save</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> }</TD></TR><TR><TD CLASS="l">160</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l"><A NAME="5">161</A></TD><TD> return newNode;</TD></TR><TR><TD CLASS="l">162</TD><TD> }</TD></TR><TR><TD CLASS="l">163</TD><TD> </TD></TR><TR><TD CLASS="l">164</TD><TD> protected IStructuredCleanupHandler getCleanupHandler(Node node) {</TD></TR><TR CLASS="z"><TD CLASS="l">165</TD><TD> short nodeType = node.getNodeType();</TD></TR><TR CLASS="z"><TD CLASS="l">166</TD><TD> IStructuredCleanupHandler cleanupHandler = null;</TD></TR><TR CLASS="z"><TD CLASS="l">167</TD><TD> switch (nodeType) {</TD></TR><TR><TD CLASS="l">168</TD><TD> case org.w3c.dom.Node.ELEMENT_NODE : {</TD></TR><TR CLASS="z"><TD CLASS="l">169</TD><TD> cleanupHandler = new ElementNodeCleanupHandler();</TD></TR><TR CLASS="z"><TD CLASS="l">170</TD><TD> break;</TD></TR><TR><TD CLASS="l">171</TD><TD> }</TD></TR><TR><TD CLASS="l">172</TD><TD> case org.w3c.dom.Node.TEXT_NODE : {</TD></TR><TR CLASS="z"><TD CLASS="l">173</TD><TD> cleanupHandler = new NodeCleanupHandler();</TD></TR><TR CLASS="z"><TD CLASS="l">174</TD><TD> break;</TD></TR><TR><TD CLASS="l">175</TD><TD> }</TD></TR><TR><TD CLASS="l">176</TD><TD> default : {</TD></TR><TR CLASS="z"><TD CLASS="l">177</TD><TD> cleanupHandler = new NodeCleanupHandler();</TD></TR><TR><TD CLASS="l">178</TD><TD> }</TD></TR><TR><TD CLASS="l">179</TD><TD> }</TD></TR><TR><TD CLASS="l">180</TD><TD> </TD></TR><TR><TD CLASS="l">181</TD><TD> // init CleanupPreferences</TD></TR><TR CLASS="z"><TD CLASS="l">182</TD><TD> cleanupHandler.setCleanupPreferences(getCleanupPreferences());</TD></TR><TR><TD CLASS="l">183</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">184</TD><TD> return cleanupHandler;</TD></TR><TR><TD CLASS="l"><A NAME="6">185</A></TD><TD> }</TD></TR><TR><TD CLASS="l">186</TD><TD> </TD></TR><TR><TD CLASS="l">187</TD><TD> </TD></TR><TR><TD CLASS="l">188</TD><TD> protected ModelQuery getModelQuery(Node node) {</TD></TR><TR CLASS="z"><TD CLASS="l">189</TD><TD> if (node.getNodeType() == Node.DOCUMENT_NODE) {</TD></TR><TR CLASS="z"><TD CLASS="l">190</TD><TD> return ModelQueryUtil.getModelQuery((Document) node);</TD></TR><TR><TD CLASS="l">191</TD><TD> } else {</TD></TR><TR CLASS="z"><TD CLASS="l">192</TD><TD> return ModelQueryUtil.getModelQuery(node.getOwnerDocument());</TD></TR><TR><TD CLASS="l"><A NAME="7">193</A></TD><TD> }</TD></TR><TR><TD CLASS="l">194</TD><TD> }</TD></TR><TR><TD CLASS="l">195</TD><TD> </TD></TR><TR><TD CLASS="l">196</TD><TD> protected List getRequiredAttrs(Node node) {</TD></TR><TR CLASS="z"><TD CLASS="l">197</TD><TD> List result = new ArrayList();</TD></TR><TR><TD CLASS="l">198</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">199</TD><TD> ModelQuery modelQuery = getModelQuery(node);</TD></TR><TR CLASS="z"><TD CLASS="l">200</TD><TD> if (modelQuery != null) {</TD></TR><TR CLASS="z"><TD CLASS="l">201</TD><TD> CMElementDeclaration elementDecl = modelQuery.getCMElementDeclaration((Element) node);</TD></TR><TR CLASS="z"><TD CLASS="l">202</TD><TD> if (elementDecl != null) {</TD></TR><TR CLASS="z"><TD CLASS="l">203</TD><TD> CMNamedNodeMap attrMap = elementDecl.getAttributes();</TD></TR><TR CLASS="z"><TD CLASS="l">204</TD><TD> Iterator it = attrMap.iterator();</TD></TR><TR CLASS="z"><TD CLASS="l">205</TD><TD> CMAttributeDeclaration attr = null;</TD></TR><TR CLASS="z"><TD CLASS="l">206</TD><TD> while (it.hasNext()) {</TD></TR><TR CLASS="z"><TD CLASS="l">207</TD><TD> attr = (CMAttributeDeclaration) it.next();</TD></TR><TR CLASS="z"><TD CLASS="l">208</TD><TD> if (attr.getUsage() == CMAttributeDeclaration.REQUIRED) {</TD></TR><TR CLASS="z"><TD CLASS="l">209</TD><TD> result.add(attr);</TD></TR><TR><TD CLASS="l">210</TD><TD> }</TD></TR><TR><TD CLASS="l">211</TD><TD> }</TD></TR><TR><TD CLASS="l">212</TD><TD> }</TD></TR><TR><TD CLASS="l">213</TD><TD> }</TD></TR><TR><TD CLASS="l">214</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l"><A NAME="8">215</A></TD><TD> return result;</TD></TR><TR><TD CLASS="l">216</TD><TD> }</TD></TR><TR><TD CLASS="l">217</TD><TD> </TD></TR><TR><TD CLASS="l">218</TD><TD> private IDOMNode insertEndTag(IDOMNode node) {</TD></TR><TR CLASS="z"><TD CLASS="l">219</TD><TD> IDOMNode newNode = node;</TD></TR><TR CLASS="z"><TD CLASS="l">220</TD><TD> IDOMElement element = (IDOMElement) node;</TD></TR><TR CLASS="z"><TD CLASS="l">221</TD><TD> if (element.isCommentTag())</TD></TR><TR CLASS="z"><TD CLASS="l">222</TD><TD> return node; // do nothing</TD></TR><TR><TD CLASS="l">223</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">224</TD><TD> int startTagStartOffset = node.getStartOffset();</TD></TR><TR CLASS="z"><TD CLASS="l">225</TD><TD> IDOMModel structuredModel = node.getModel();</TD></TR><TR><TD CLASS="l">226</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">227</TD><TD> if (isEmptyElement(element)) {</TD></TR><TR CLASS="z"><TD CLASS="l">228</TD><TD> IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();</TD></TR><TR CLASS="z"><TD CLASS="l">229</TD><TD> IStructuredDocumentRegion startStructuredDocumentRegion = node.getStartStructuredDocumentRegion();</TD></TR><TR CLASS="z"><TD CLASS="l">230</TD><TD> ITextRegionList regions = startStructuredDocumentRegion.getRegions();</TD></TR><TR CLASS="z"><TD CLASS="l">231</TD><TD> ITextRegion lastRegion = regions.get(regions.size() - 1);</TD></TR><TR CLASS="z"><TD CLASS="l">232</TD><TD> structuredDocument.replaceText(structuredDocument, startStructuredDocumentRegion.getStartOffset(lastRegion), lastRegion.getLength(), EMPTY_TAG_CLOSE);</TD></TR><TR><TD CLASS="l">233</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">234</TD><TD> if (regions.size() > 1) {</TD></TR><TR CLASS="z"><TD CLASS="l">235</TD><TD> ITextRegion regionBeforeTagClose = regions.get(regions.size() - 1 - 1);</TD></TR><TR><TD CLASS="l">236</TD><TD> </TD></TR><TR><TD CLASS="l">237</TD><TD> // insert a space separator before tag close if the previous</TD></TR><TR><TD CLASS="l">238</TD><TD> // region does not have extra spaces</TD></TR><TR CLASS="z"><TD CLASS="l">239</TD><TD> if (regionBeforeTagClose.getTextLength() == regionBeforeTagClose.getLength())</TD></TR><TR CLASS="z"><TD CLASS="l">240</TD><TD> structuredDocument.replaceText(structuredDocument, startStructuredDocumentRegion.getStartOffset(lastRegion), 0, " "); //$NON-NLS-1$</TD></TR><TR><TD CLASS="l">241</TD><TD> }</TD></TR><TR><TD CLASS="l">242</TD><TD> } else {</TD></TR><TR CLASS="z"><TD CLASS="l">243</TD><TD> String tagName = node.getNodeName();</TD></TR><TR CLASS="z"><TD CLASS="l">244</TD><TD> String endTag = END_TAG_OPEN.concat(tagName).concat(TAG_CLOSE);</TD></TR><TR><TD CLASS="l">245</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">246</TD><TD> IDOMNode lastChild = (IDOMNode) node.getLastChild();</TD></TR><TR CLASS="z"><TD CLASS="l">247</TD><TD> int endTagStartOffset = 0;</TD></TR><TR CLASS="z"><TD CLASS="l">248</TD><TD> if (lastChild != null)</TD></TR><TR><TD CLASS="l">249</TD><TD> // if this node has children, insert the end tag after the</TD></TR><TR><TD CLASS="l">250</TD><TD> // last child</TD></TR><TR CLASS="z"><TD CLASS="l">251</TD><TD> endTagStartOffset = lastChild.getEndOffset();</TD></TR><TR><TD CLASS="l">252</TD><TD> else</TD></TR><TR><TD CLASS="l">253</TD><TD> // if this node does not has children, insert the end tag</TD></TR><TR><TD CLASS="l">254</TD><TD> // after the start tag</TD></TR><TR CLASS="z"><TD CLASS="l">255</TD><TD> endTagStartOffset = node.getEndOffset();</TD></TR><TR><TD CLASS="l">256</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">257</TD><TD> IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();</TD></TR><TR CLASS="z"><TD CLASS="l">258</TD><TD> structuredDocument.replaceText(structuredDocument, endTagStartOffset, 0, endTag);</TD></TR><TR><TD CLASS="l">259</TD><TD> }</TD></TR><TR><TD CLASS="l">260</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">261</TD><TD> newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset); // save</TD></TR><TR><TD CLASS="l">262</TD><TD> // new</TD></TR><TR><TD CLASS="l">263</TD><TD> // node</TD></TR><TR><TD CLASS="l">264</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l"><A NAME="9">265</A></TD><TD> return newNode;</TD></TR><TR><TD CLASS="l">266</TD><TD> }</TD></TR><TR><TD CLASS="l">267</TD><TD> </TD></TR><TR><TD CLASS="l">268</TD><TD> private IDOMNode insertMissingTags(IDOMNode node) {</TD></TR><TR CLASS="z"><TD CLASS="l">269</TD><TD> boolean insertMissingTags = getCleanupPreferences().getInsertMissingTags();</TD></TR><TR CLASS="z"><TD CLASS="l">270</TD><TD> IDOMNode newNode = node;</TD></TR><TR><TD CLASS="l">271</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">272</TD><TD> if (insertMissingTags) {</TD></TR><TR CLASS="z"><TD CLASS="l">273</TD><TD> IStructuredDocumentRegion startTagStructuredDocumentRegion = node.getStartStructuredDocumentRegion();</TD></TR><TR CLASS="z"><TD CLASS="l">274</TD><TD> if (startTagStructuredDocumentRegion == null) {</TD></TR><TR><TD CLASS="l">275</TD><TD> // implicit start tag; generate tag for it</TD></TR><TR CLASS="z"><TD CLASS="l">276</TD><TD> newNode = insertStartTag(node);</TD></TR><TR CLASS="z"><TD CLASS="l">277</TD><TD> startTagStructuredDocumentRegion = newNode.getStartStructuredDocumentRegion();</TD></TR><TR><TD CLASS="l">278</TD><TD> }</TD></TR><TR><TD CLASS="l">279</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">280</TD><TD> IStructuredDocumentRegion endTagStructuredDocumentRegion = newNode.getEndStructuredDocumentRegion();</TD></TR><TR CLASS="z"><TD CLASS="l">281</TD><TD> ITextRegionList startStructuredDocumentRegionRegions = startTagStructuredDocumentRegion.getRegions();</TD></TR><TR CLASS="z"><TD CLASS="l">282</TD><TD> if (startTagStructuredDocumentRegion != null && startStructuredDocumentRegionRegions != null && (startStructuredDocumentRegionRegions.get(startStructuredDocumentRegionRegions.size() - 1)).getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {</TD></TR><TR><TD CLASS="l">283</TD><TD> </TD></TR><TR><TD CLASS="l">284</TD><TD> } else {</TD></TR><TR CLASS="z"><TD CLASS="l">285</TD><TD> if (startTagStructuredDocumentRegion == null) {</TD></TR><TR><TD CLASS="l">286</TD><TD> // start tag missing</TD></TR><TR CLASS="z"><TD CLASS="l">287</TD><TD> if (isStartTagRequired(newNode))</TD></TR><TR CLASS="z"><TD CLASS="l">288</TD><TD> newNode = insertStartTag(newNode);</TD></TR><TR CLASS="z"><TD CLASS="l">289</TD><TD> } else if (endTagStructuredDocumentRegion == null) {</TD></TR><TR><TD CLASS="l">290</TD><TD> // end tag missing</TD></TR><TR CLASS="z"><TD CLASS="l">291</TD><TD> if (isEndTagRequired(newNode))</TD></TR><TR CLASS="z"><TD CLASS="l">292</TD><TD> newNode = insertEndTag(newNode);</TD></TR><TR><TD CLASS="l">293</TD><TD> }</TD></TR><TR><TD CLASS="l">294</TD><TD> }</TD></TR><TR><TD CLASS="l">295</TD><TD> }</TD></TR><TR><TD CLASS="l">296</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l"><A NAME="a">297</A></TD><TD> return newNode;</TD></TR><TR><TD CLASS="l">298</TD><TD> }</TD></TR><TR><TD CLASS="l">299</TD><TD> </TD></TR><TR><TD CLASS="l">300</TD><TD> private IDOMNode insertRequiredAttrs(IDOMNode node) {</TD></TR><TR CLASS="z"><TD CLASS="l">301</TD><TD> boolean insertRequiredAttrs = getCleanupPreferences().getInsertRequiredAttrs();</TD></TR><TR CLASS="z"><TD CLASS="l">302</TD><TD> IDOMNode newNode = node;</TD></TR><TR><TD CLASS="l">303</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">304</TD><TD> if (insertRequiredAttrs) {</TD></TR><TR CLASS="z"><TD CLASS="l">305</TD><TD> List requiredAttrs = getRequiredAttrs(newNode);</TD></TR><TR CLASS="z"><TD CLASS="l">306</TD><TD> if (requiredAttrs.size() > 0) {</TD></TR><TR CLASS="z"><TD CLASS="l">307</TD><TD> NamedNodeMap currentAttrs = node.getAttributes();</TD></TR><TR CLASS="z"><TD CLASS="l">308</TD><TD> List insertAttrs = new ArrayList();</TD></TR><TR CLASS="z"><TD CLASS="l">309</TD><TD> if (currentAttrs.getLength() == 0)</TD></TR><TR CLASS="z"><TD CLASS="l">310</TD><TD> insertAttrs.addAll(requiredAttrs);</TD></TR><TR><TD CLASS="l">311</TD><TD> else {</TD></TR><TR CLASS="z"><TD CLASS="l">312</TD><TD> for (int i = 0; i < requiredAttrs.size(); i++) {</TD></TR><TR CLASS="z"><TD CLASS="l">313</TD><TD> String requiredAttrName = ((CMAttributeDeclaration) requiredAttrs.get(i)).getAttrName();</TD></TR><TR CLASS="z"><TD CLASS="l">314</TD><TD> boolean found = false;</TD></TR><TR CLASS="z"><TD CLASS="l">315</TD><TD> for (int j = 0; j < currentAttrs.getLength(); j++) {</TD></TR><TR CLASS="z"><TD CLASS="l">316</TD><TD> String currentAttrName = currentAttrs.item(j).getNodeName();</TD></TR><TR CLASS="z"><TD CLASS="l">317</TD><TD> if (requiredAttrName.compareToIgnoreCase(currentAttrName) == 0) {</TD></TR><TR CLASS="z"><TD CLASS="l">318</TD><TD> found = true;</TD></TR><TR CLASS="z"><TD CLASS="l">319</TD><TD> break;</TD></TR><TR><TD CLASS="l">320</TD><TD> }</TD></TR><TR><TD CLASS="l">321</TD><TD> }</TD></TR><TR CLASS="z"><TD CLASS="l">322</TD><TD> if (!found)</TD></TR><TR CLASS="z"><TD CLASS="l">323</TD><TD> insertAttrs.add(requiredAttrs.get(i));</TD></TR><TR><TD CLASS="l">324</TD><TD> }</TD></TR><TR><TD CLASS="l">325</TD><TD> }</TD></TR><TR CLASS="z"><TD CLASS="l">326</TD><TD> if (insertAttrs.size() > 0) {</TD></TR><TR CLASS="z"><TD CLASS="l">327</TD><TD> IStructuredDocumentRegion startStructuredDocumentRegion = newNode.getStartStructuredDocumentRegion();</TD></TR><TR CLASS="z"><TD CLASS="l">328</TD><TD> int index = startStructuredDocumentRegion.getEndOffset();</TD></TR><TR CLASS="z"><TD CLASS="l">329</TD><TD> ITextRegion lastRegion = startStructuredDocumentRegion.getLastRegion();</TD></TR><TR CLASS="z"><TD CLASS="l">330</TD><TD> if (lastRegion.getType() == DOMRegionContext.XML_TAG_CLOSE) {</TD></TR><TR CLASS="z"><TD CLASS="l">331</TD><TD> index--;</TD></TR><TR CLASS="z"><TD CLASS="l">332</TD><TD> lastRegion = startStructuredDocumentRegion.getRegionAtCharacterOffset(index - 1);</TD></TR><TR CLASS="z"><TD CLASS="l">333</TD><TD> } else if (lastRegion.getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {</TD></TR><TR CLASS="z"><TD CLASS="l">334</TD><TD> index = index - 2;</TD></TR><TR CLASS="z"><TD CLASS="l">335</TD><TD> lastRegion = startStructuredDocumentRegion.getRegionAtCharacterOffset(index - 1);</TD></TR><TR><TD CLASS="l">336</TD><TD> }</TD></TR><TR CLASS="z"><TD CLASS="l">337</TD><TD> MultiTextEdit multiTextEdit = new MultiTextEdit();</TD></TR><TR><TD CLASS="l">338</TD><TD> try {</TD></TR><TR CLASS="z"><TD CLASS="l">339</TD><TD> for (int i = insertAttrs.size() - 1; i >= 0; i--) {</TD></TR><TR CLASS="z"><TD CLASS="l">340</TD><TD> CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) insertAttrs.get(i);</TD></TR><TR CLASS="z"><TD CLASS="l">341</TD><TD> String requiredAttributeName = attrDecl.getAttrName();</TD></TR><TR CLASS="z"><TD CLASS="l">342</TD><TD> String defaultValue = attrDecl.getDefaultValue();</TD></TR><TR CLASS="z"><TD CLASS="l">343</TD><TD> if (defaultValue == null)</TD></TR><TR CLASS="z"><TD CLASS="l">344</TD><TD> defaultValue = ""; //$NON-NLS-1$</TD></TR><TR CLASS="z"><TD CLASS="l">345</TD><TD> String nameAndDefaultValue = " "; //$NON-NLS-1$</TD></TR><TR CLASS="z"><TD CLASS="l">346</TD><TD> if (i == 0 && lastRegion.getLength() > lastRegion.getTextLength())</TD></TR><TR CLASS="z"><TD CLASS="l">347</TD><TD> nameAndDefaultValue = ""; //$NON-NLS-1$</TD></TR><TR CLASS="z"><TD CLASS="l">348</TD><TD> nameAndDefaultValue += requiredAttributeName + "=\"" + defaultValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$</TD></TR><TR CLASS="z"><TD CLASS="l">349</TD><TD> multiTextEdit.addChild(new InsertEdit(index, nameAndDefaultValue));</TD></TR><TR><TD CLASS="l">350</TD><TD> // BUG3381: MultiTextEdit applies all child</TD></TR><TR><TD CLASS="l">351</TD><TD> // TextEdit's basing on offsets</TD></TR><TR><TD CLASS="l">352</TD><TD> // in the document before the first TextEdit, not</TD></TR><TR><TD CLASS="l">353</TD><TD> // after each</TD></TR><TR><TD CLASS="l">354</TD><TD> // child TextEdit. Therefore, do not need to</TD></TR><TR><TD CLASS="l">355</TD><TD> // advance the index.</TD></TR><TR><TD CLASS="l">356</TD><TD> //index += nameAndDefaultValue.length();</TD></TR><TR><TD CLASS="l">357</TD><TD> }</TD></TR><TR CLASS="z"><TD CLASS="l">358</TD><TD> multiTextEdit.apply(newNode.getStructuredDocument());</TD></TR><TR CLASS="z"><TD CLASS="l">359</TD><TD> } catch (BadLocationException e) {</TD></TR><TR><TD CLASS="l">360</TD><TD> // log for now, unless we find reason not to</TD></TR><TR CLASS="z"><TD CLASS="l">361</TD><TD> Logger.log(Logger.INFO, e.getMessage());</TD></TR><TR><TD CLASS="l">362</TD><TD> }</TD></TR><TR><TD CLASS="l">363</TD><TD> }</TD></TR><TR><TD CLASS="l">364</TD><TD> }</TD></TR><TR><TD CLASS="l">365</TD><TD> }</TD></TR><TR><TD CLASS="l">366</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l"><A NAME="b">367</A></TD><TD> return newNode;</TD></TR><TR><TD CLASS="l">368</TD><TD> }</TD></TR><TR><TD CLASS="l">369</TD><TD> </TD></TR><TR><TD CLASS="l">370</TD><TD> private IDOMNode insertStartTag(IDOMNode node) {</TD></TR><TR CLASS="z"><TD CLASS="l">371</TD><TD> IDOMNode newNode = node;</TD></TR><TR><TD CLASS="l">372</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">373</TD><TD> if (isCommentTag(node))</TD></TR><TR CLASS="z"><TD CLASS="l">374</TD><TD> return node; // do nothing</TD></TR><TR><TD CLASS="l">375</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">376</TD><TD> String tagName = node.getNodeName();</TD></TR><TR CLASS="z"><TD CLASS="l">377</TD><TD> String startTag = START_TAG_OPEN.concat(tagName).concat(TAG_CLOSE);</TD></TR><TR CLASS="z"><TD CLASS="l">378</TD><TD> int startTagStartOffset = node.getStartOffset();</TD></TR><TR><TD CLASS="l">379</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">380</TD><TD> IDOMModel structuredModel = node.getModel();</TD></TR><TR CLASS="z"><TD CLASS="l">381</TD><TD> IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();</TD></TR><TR CLASS="z"><TD CLASS="l">382</TD><TD> structuredDocument.replaceText(structuredDocument, startTagStartOffset, 0, startTag);</TD></TR><TR CLASS="z"><TD CLASS="l">383</TD><TD> newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset); // save</TD></TR><TR><TD CLASS="l">384</TD><TD> // new</TD></TR><TR><TD CLASS="l">385</TD><TD> // node</TD></TR><TR><TD CLASS="l">386</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l"><A NAME="c">387</A></TD><TD> return newNode;</TD></TR><TR><TD CLASS="l">388</TD><TD> }</TD></TR><TR><TD CLASS="l">389</TD><TD> </TD></TR><TR><TD CLASS="l">390</TD><TD> private void insertTagClose(IDOMModel structuredModel, IStructuredDocumentRegion flatNode) {</TD></TR><TR CLASS="z"><TD CLASS="l">391</TD><TD> if (flatNode != null) {</TD></TR><TR CLASS="z"><TD CLASS="l">392</TD><TD> ITextRegionList flatnodeRegions = flatNode.getRegions();</TD></TR><TR CLASS="z"><TD CLASS="l">393</TD><TD> if (flatnodeRegions != null) {</TD></TR><TR CLASS="z"><TD CLASS="l">394</TD><TD> ITextRegion lastRegion = flatnodeRegions.get(flatnodeRegions.size() - 1);</TD></TR><TR CLASS="z"><TD CLASS="l">395</TD><TD> if (lastRegion != null) {</TD></TR><TR CLASS="z"><TD CLASS="l">396</TD><TD> String regionType = lastRegion.getType();</TD></TR><TR CLASS="z"><TD CLASS="l">397</TD><TD> if ((regionType != DOMRegionContext.XML_EMPTY_TAG_CLOSE) && (regionType != DOMRegionContext.XML_TAG_CLOSE)) {</TD></TR><TR CLASS="z"><TD CLASS="l">398</TD><TD> IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();</TD></TR><TR><TD CLASS="l">399</TD><TD> </TD></TR><TR><TD CLASS="l">400</TD><TD> // insert ">" after lastRegion of flatNode</TD></TR><TR><TD CLASS="l">401</TD><TD> // as in "<a</a>" if flatNode is for start tag, or in</TD></TR><TR><TD CLASS="l">402</TD><TD> // "<a></a" if flatNode is for end tag</TD></TR><TR CLASS="z"><TD CLASS="l">403</TD><TD> structuredDocument.replaceText(structuredDocument, flatNode.getTextEndOffset(lastRegion), 0, ">"); //$NON-NLS-1$</TD></TR><TR><TD CLASS="l">404</TD><TD> }</TD></TR><TR><TD CLASS="l">405</TD><TD> }</TD></TR><TR><TD CLASS="l">406</TD><TD> }</TD></TR><TR><TD CLASS="l">407</TD><TD> }</TD></TR><TR CLASS="z"><TD CLASS="l">408</TD><TD> }</TD></TR><TR><TD CLASS="l">409</TD><TD> </TD></TR><TR><TD CLASS="l">410</TD><TD> /**</TD></TR><TR><TD CLASS="l"><A NAME="d">411</A></TD><TD> * @param renamedNode</TD></TR><TR><TD CLASS="l">412</TD><TD> * @return</TD></TR><TR><TD CLASS="l">413</TD><TD> */</TD></TR><TR><TD CLASS="l">414</TD><TD> private boolean isCommentTag(Node renamedNode) {</TD></TR><TR CLASS="z"><TD CLASS="l">415</TD><TD> boolean result = false;</TD></TR><TR CLASS="z"><TD CLASS="l">416</TD><TD> if (renamedNode instanceof IDOMElement) {</TD></TR><TR CLASS="z"><TD CLASS="l">417</TD><TD> IDOMElement element = (IDOMElement) renamedNode;</TD></TR><TR CLASS="z"><TD CLASS="l">418</TD><TD> result = element.isCommentTag();</TD></TR><TR><TD CLASS="l">419</TD><TD> }</TD></TR><TR CLASS="z"><TD CLASS="l"><A NAME="e">420</A></TD><TD> return result;</TD></TR><TR><TD CLASS="l">421</TD><TD> }</TD></TR><TR><TD CLASS="l">422</TD><TD> </TD></TR><TR><TD CLASS="l">423</TD><TD> private boolean isEmptyElement(IDOMElement element) {</TD></TR><TR CLASS="z"><TD CLASS="l">424</TD><TD> Document document = element.getOwnerDocument();</TD></TR><TR CLASS="z"><TD CLASS="l">425</TD><TD> if (document == null)</TD></TR><TR><TD CLASS="l">426</TD><TD> // undefined tag, return default</TD></TR><TR CLASS="z"><TD CLASS="l">427</TD><TD> return false;</TD></TR><TR><TD CLASS="l">428</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">429</TD><TD> ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);</TD></TR><TR CLASS="z"><TD CLASS="l">430</TD><TD> if (modelQuery == null)</TD></TR><TR><TD CLASS="l">431</TD><TD> // undefined tag, return default</TD></TR><TR CLASS="z"><TD CLASS="l">432</TD><TD> return false;</TD></TR><TR><TD CLASS="l">433</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">434</TD><TD> CMElementDeclaration decl = modelQuery.getCMElementDeclaration(element);</TD></TR><TR CLASS="z"><TD CLASS="l">435</TD><TD> if (decl == null)</TD></TR><TR><TD CLASS="l">436</TD><TD> // undefined tag, return default</TD></TR><TR CLASS="z"><TD CLASS="l">437</TD><TD> return false;</TD></TR><TR><TD CLASS="l">438</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l"><A NAME="f">439</A></TD><TD> return (decl.getContentType() == CMElementDeclaration.EMPTY);</TD></TR><TR><TD CLASS="l">440</TD><TD> }</TD></TR><TR><TD CLASS="l">441</TD><TD> </TD></TR><TR><TD CLASS="l">442</TD><TD> private boolean isEndTagRequired(IDOMNode node) {</TD></TR><TR CLASS="z"><TD CLASS="l">443</TD><TD> if (node == null)</TD></TR><TR CLASS="z"><TD CLASS="l">444</TD><TD> return false;</TD></TR><TR CLASS="z"><TD CLASS="l">445</TD><TD> return node.isContainer();</TD></TR><TR><TD CLASS="l">446</TD><TD> }</TD></TR><TR><TD CLASS="l">447</TD><TD> </TD></TR><TR><TD CLASS="l">448</TD><TD> /**</TD></TR><TR><TD CLASS="l">449</TD><TD> * A tag is implicit if it has not corresponding region in document.</TD></TR><TR><TD CLASS="l">450</TD><TD> * </TD></TR><TR><TD CLASS="l"><A NAME="10">451</A></TD><TD> * @param renamedNode</TD></TR><TR><TD CLASS="l">452</TD><TD> * @return</TD></TR><TR><TD CLASS="l">453</TD><TD> */</TD></TR><TR><TD CLASS="l">454</TD><TD> private boolean isImplicitTag(IDOMNode renamedNode) {</TD></TR><TR CLASS="z"><TD CLASS="l">455</TD><TD> return renamedNode.getStartStructuredDocumentRegion() == null;</TD></TR><TR><TD CLASS="l">456</TD><TD> }</TD></TR><TR><TD CLASS="l">457</TD><TD> </TD></TR><TR><TD CLASS="l">458</TD><TD> /**</TD></TR><TR><TD CLASS="l">459</TD><TD> * The end tags of HTML EMPTY content type, such as IMG, and HTML</TD></TR><TR><TD CLASS="l"><A NAME="11">460</A></TD><TD> * undefined tags are parsed separately from the start tags. So inserting</TD></TR><TR><TD CLASS="l">461</TD><TD> * the missing start tag is useless and even harmful.</TD></TR><TR><TD CLASS="l">462</TD><TD> */</TD></TR><TR><TD CLASS="l">463</TD><TD> private boolean isStartTagRequired(IDOMNode node) {</TD></TR><TR CLASS="z"><TD CLASS="l">464</TD><TD> if (node == null)</TD></TR><TR CLASS="z"><TD CLASS="l">465</TD><TD> return false;</TD></TR><TR CLASS="z"><TD CLASS="l"><A NAME="12">466</A></TD><TD> return node.isContainer();</TD></TR><TR><TD CLASS="l">467</TD><TD> }</TD></TR><TR><TD CLASS="l">468</TD><TD> </TD></TR><TR><TD CLASS="l">469</TD><TD> private boolean isXMLType(IDOMModel structuredModel) {</TD></TR><TR CLASS="z"><TD CLASS="l">470</TD><TD> boolean result = false;</TD></TR><TR><TD CLASS="l">471</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">472</TD><TD> if (structuredModel != null && structuredModel != null) {</TD></TR><TR CLASS="z"><TD CLASS="l">473</TD><TD> IDOMDocument document = structuredModel.getDocument();</TD></TR><TR><TD CLASS="l">474</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">475</TD><TD> if (document != null)</TD></TR><TR CLASS="z"><TD CLASS="l">476</TD><TD> result = document.isXMLType();</TD></TR><TR><TD CLASS="l">477</TD><TD> }</TD></TR><TR><TD CLASS="l">478</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l"><A NAME="13">479</A></TD><TD> return result;</TD></TR><TR><TD CLASS="l">480</TD><TD> }</TD></TR><TR><TD CLASS="l">481</TD><TD> </TD></TR><TR><TD CLASS="l">482</TD><TD> private IDOMNode quoteAttrValue(IDOMNode node) {</TD></TR><TR CLASS="z"><TD CLASS="l">483</TD><TD> IDOMNode newNode = node;</TD></TR><TR><TD CLASS="l">484</TD><TD> //XMLElement element = (XMLElement) node;</TD></TR><TR CLASS="z"><TD CLASS="l">485</TD><TD> if (isCommentTag(node))</TD></TR><TR CLASS="z"><TD CLASS="l">486</TD><TD> return node; // do nothing</TD></TR><TR><TD CLASS="l">487</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">488</TD><TD> boolean quoteAttrValues = getCleanupPreferences().getQuoteAttrValues();</TD></TR><TR><TD CLASS="l">489</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">490</TD><TD> if (quoteAttrValues) {</TD></TR><TR CLASS="z"><TD CLASS="l">491</TD><TD> NamedNodeMap attributes = newNode.getAttributes();</TD></TR><TR CLASS="z"><TD CLASS="l">492</TD><TD> if (attributes != null) {</TD></TR><TR CLASS="z"><TD CLASS="l">493</TD><TD> int attributesLength = attributes.getLength();</TD></TR><TR CLASS="z"><TD CLASS="l">494</TD><TD> ISourceGenerator generator = node.getModel().getGenerator();</TD></TR><TR><TD CLASS="l">495</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">496</TD><TD> for (int i = 0; i < attributesLength; i++) {</TD></TR><TR CLASS="z"><TD CLASS="l">497</TD><TD> attributes = newNode.getAttributes();</TD></TR><TR CLASS="z"><TD CLASS="l">498</TD><TD> attributesLength = attributes.getLength();</TD></TR><TR CLASS="z"><TD CLASS="l">499</TD><TD> IDOMAttr eachAttr = (IDOMAttr) attributes.item(i);</TD></TR><TR><TD CLASS="l">500</TD><TD> //ITextRegion oldAttrValueRegion =</TD></TR><TR><TD CLASS="l">501</TD><TD> // eachAttr.getValueRegion();</TD></TR><TR CLASS="z"><TD CLASS="l">502</TD><TD> String oldAttrValue = eachAttr.getValueRegionText();</TD></TR><TR CLASS="z"><TD CLASS="l">503</TD><TD> if (oldAttrValue == null) {</TD></TR><TR CLASS="z"><TD CLASS="l">504</TD><TD> IDOMModel structuredModel = node.getModel();</TD></TR><TR CLASS="z"><TD CLASS="l">505</TD><TD> if (isXMLType(structuredModel)) {</TD></TR><TR CLASS="z"><TD CLASS="l">506</TD><TD> String newAttrValue = "\"" + eachAttr.getNameRegionText() + "\""; //$NON-NLS-1$ //$NON-NLS-2$</TD></TR><TR><TD CLASS="l">507</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">508</TD><TD> IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();</TD></TR><TR CLASS="z"><TD CLASS="l">509</TD><TD> if (eachAttr.getEqualRegion() != null)</TD></TR><TR><TD CLASS="l">510</TD><TD> // equal region exists</TD></TR><TR CLASS="z"><TD CLASS="l">511</TD><TD> structuredDocument.replaceText(structuredDocument, eachAttr.getEndOffset(), 0, newAttrValue);</TD></TR><TR><TD CLASS="l">512</TD><TD> else</TD></TR><TR><TD CLASS="l">513</TD><TD> // no equal region</TD></TR><TR CLASS="z"><TD CLASS="l">514</TD><TD> structuredDocument.replaceText(structuredDocument, eachAttr.getNameRegionTextEndOffset(), 0, "=".concat(newAttrValue)); //$NON-NLS-1$</TD></TR><TR CLASS="z"><TD CLASS="l">515</TD><TD> newNode = (IDOMNode) structuredModel.getIndexedRegion(node.getStartOffset()); // save</TD></TR><TR><TD CLASS="l">516</TD><TD> // new</TD></TR><TR><TD CLASS="l">517</TD><TD> // node</TD></TR><TR><TD CLASS="l">518</TD><TD> }</TD></TR><TR><TD CLASS="l">519</TD><TD> } else {</TD></TR><TR><TD CLASS="l">520</TD><TD> //String oldAttrValue = oldAttrValueRegion.getText();</TD></TR><TR CLASS="z"><TD CLASS="l">521</TD><TD> char quote = StringUtils.isQuoted(oldAttrValue) ? oldAttrValue.charAt(0) : DOUBLE_QUOTE;</TD></TR><TR CLASS="z"><TD CLASS="l">522</TD><TD> String newAttrValue = generator.generateAttrValue(eachAttr, quote);</TD></TR><TR><TD CLASS="l">523</TD><TD> </TD></TR><TR><TD CLASS="l">524</TD><TD> // There is a problem in</TD></TR><TR><TD CLASS="l">525</TD><TD> // StructuredDocumentRegionUtil.getAttrValue(ITextRegion)</TD></TR><TR><TD CLASS="l">526</TD><TD> // when the region is instanceof ContextRegion.</TD></TR><TR><TD CLASS="l">527</TD><TD> // Workaround for now...</TD></TR><TR CLASS="z"><TD CLASS="l">528</TD><TD> if (oldAttrValue.length() == 1) {</TD></TR><TR CLASS="z"><TD CLASS="l">529</TD><TD> char firstChar = oldAttrValue.charAt(0);</TD></TR><TR CLASS="z"><TD CLASS="l">530</TD><TD> if (firstChar == SINGLE_QUOTE)</TD></TR><TR CLASS="z"><TD CLASS="l">531</TD><TD> newAttrValue = SINGLE_QUOTES;</TD></TR><TR CLASS="z"><TD CLASS="l">532</TD><TD> else if (firstChar == DOUBLE_QUOTE)</TD></TR><TR CLASS="z"><TD CLASS="l">533</TD><TD> newAttrValue = DOUBLE_QUOTES;</TD></TR><TR><TD CLASS="l">534</TD><TD> }</TD></TR><TR><TD CLASS="l">535</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">536</TD><TD> if (newAttrValue != null) {</TD></TR><TR CLASS="z"><TD CLASS="l">537</TD><TD> if (newAttrValue.compareTo(oldAttrValue) != 0) {</TD></TR><TR CLASS="z"><TD CLASS="l">538</TD><TD> int attrValueStartOffset = eachAttr.getValueRegionStartOffset();</TD></TR><TR CLASS="z"><TD CLASS="l">539</TD><TD> int attrValueLength = oldAttrValue.length();</TD></TR><TR CLASS="z"><TD CLASS="l">540</TD><TD> int startTagStartOffset = node.getStartOffset();</TD></TR><TR><TD CLASS="l">541</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">542</TD><TD> IDOMModel structuredModel = node.getModel();</TD></TR><TR CLASS="z"><TD CLASS="l">543</TD><TD> IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();</TD></TR><TR CLASS="z"><TD CLASS="l">544</TD><TD> structuredDocument.replaceText(structuredDocument, attrValueStartOffset, attrValueLength, newAttrValue);</TD></TR><TR CLASS="z"><TD CLASS="l">545</TD><TD> newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset); // save</TD></TR><TR><TD CLASS="l">546</TD><TD> // new</TD></TR><TR><TD CLASS="l">547</TD><TD> // node</TD></TR><TR><TD CLASS="l">548</TD><TD> }</TD></TR><TR><TD CLASS="l">549</TD><TD> }</TD></TR><TR><TD CLASS="l">550</TD><TD> }</TD></TR><TR><TD CLASS="l">551</TD><TD> }</TD></TR><TR><TD CLASS="l">552</TD><TD> }</TD></TR><TR><TD CLASS="l">553</TD><TD> }</TD></TR><TR><TD CLASS="l">554</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">555</TD><TD> return newNode;</TD></TR><TR><TD CLASS="l">556</TD><TD> }</TD></TR><TR><TD CLASS="l">557</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="208.html">org.eclipse.wst.xml.core.internal.cleanup</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>
\ No newline at end of file |