From: <ad...@us...> - 2010-11-07 14:59:39
|
Revision: 1180 http://jtidy.svn.sourceforge.net/jtidy/?rev=1180&view=rev Author: aditsu Date: 2010-11-07 14:59:33 +0000 (Sun, 07 Nov 2010) Log Message: ----------- fixed test 655338 - updated insertMisc to insert xml declarations at the top Modified Paths: -------------- branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java Modified: branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java =================================================================== --- branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java 2010-11-07 14:48:06 UTC (rev 1179) +++ branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java 2010-11-07 14:59:33 UTC (rev 1180) @@ -1055,21 +1055,28 @@ * @param node will be inserted at the end of element * @return <code>true</code> if the node has been inserted */ - public static boolean insertMisc(Node element, Node node) - { + public static boolean insertMisc(Node element, Node node) { if (node.type == NodeType.CommentTag - || node.type == NodeType.ProcInsTag - || node.type == NodeType.CDATATag - || node.type == NodeType.SectionTag - || node.type == NodeType.AspTag - || node.type == NodeType.JsteTag - || node.type == NodeType.PhpTag - || node.type == NodeType.XmlDecl) - { + || node.type == NodeType.ProcInsTag + || node.type == NodeType.CDATATag + || node.type == NodeType.SectionTag + || node.type == NodeType.AspTag + || node.type == NodeType.JsteTag + || node.type == NodeType.PhpTag) { element.insertNodeAtEnd(node); return true; } - + + if (node.type == NodeType.XmlDecl) { + Node root = element; + while (root != null && root.parent != null) { + root = root.parent; + } + if (root != null && !(root.content != null && root.content.type == NodeType.XmlDecl)) { + root.insertNodeAtStart(node); + return true; + } + } return false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ad...@us...> - 2010-11-07 17:03:18
|
Revision: 1181 http://jtidy.svn.sourceforge.net/jtidy/?rev=1181&view=rev Author: aditsu Date: 2010-11-07 17:03:12 +0000 (Sun, 07 Nov 2010) Log Message: ----------- fixed test 640473 - updated insertMisc to insert empty tags Modified Paths: -------------- branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java Modified: branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java =================================================================== --- branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java 2010-11-07 14:59:33 UTC (rev 1180) +++ branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java 2010-11-07 17:03:12 UTC (rev 1181) @@ -1077,6 +1077,17 @@ return true; } } + + /* Declared empty tags seem to be slipping through + ** the cracks. This is an experiment to figure out + ** a decent place to pick them up. + */ + if (node.tag != null && node.isElement() && node.hasCM(Dict.CM_EMPTY) && node.is(TagId.UNKNOWN) + && (node.tag.versions & Versions.VERS_PROPRIETARY) != 0) { + element.insertNodeAtEnd(node); + return true; + } + return false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ad...@us...> - 2010-11-18 01:15:38
|
Revision: 1210 http://jtidy.svn.sourceforge.net/jtidy/?rev=1210&view=rev Author: aditsu Date: 2010-11-18 01:15:32 +0000 (Thu, 18 Nov 2010) Log Message: ----------- fixed test 586562 - added check for existing doctype in insertDocType Modified Paths: -------------- branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java Modified: branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java =================================================================== --- branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java 2010-11-18 00:58:15 UTC (rev 1209) +++ branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java 2010-11-18 01:15:32 UTC (rev 1210) @@ -857,16 +857,18 @@ * @param element document * @param doctype doctype node to insert at the beginning of element */ - public static void insertDocType(Lexer lexer, Node element, Node doctype) - { - lexer.report.warning(lexer, element, doctype, ErrorCode.DOCTYPE_AFTER_TAGS); - - while (!element.is(TagId.HTML)) - { - element = element.parent; - } - - insertNodeBeforeElement(element, doctype); + public static void insertDocType(final Lexer lexer, Node element, final Node doctype) { + Node existing = lexer.root.findDocType(); + if (existing != null) { + lexer.report.warning(lexer, element, doctype, ErrorCode.DISCARDING_UNEXPECTED); + } + else { + lexer.report.warning(lexer, element, doctype, ErrorCode.DOCTYPE_AFTER_TAGS); + while (!element.is(TagId.HTML)) { + element = element.parent; + } + insertNodeBeforeElement(element, doctype); + } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ad...@us...> - 2010-11-20 21:26:33
|
Revision: 1216 http://jtidy.svn.sourceforge.net/jtidy/?rev=1216&view=rev Author: aditsu Date: 2010-11-20 21:26:27 +0000 (Sat, 20 Nov 2010) Log Message: ----------- fixed test 1055398 - swapped "first" and "second" when joining styles in repairDuplicateAttributes Modified Paths: -------------- branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java Modified: branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java =================================================================== --- branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java 2010-11-20 21:12:16 UTC (rev 1215) +++ branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java 2010-11-20 21:26:27 UTC (rev 1216) @@ -320,40 +320,28 @@ // this doesn't handle CSS comments and leading/trailing white-space very well see // http://www.w3.org/TR/css-style-attr - int end = second.value.length() - 1; + int end = first.value.length() - 1; - if (second.value.charAt(end) == ';') + if (first.value.charAt(end) == ';') { // attribute ends with declaration seperator - second.value = second.value + " " + first.value; + first.value = first.value + " " + second.value; } - else if (second.value.charAt(end) == '}') + else if (first.value.charAt(end) == '}') { // attribute ends with rule set - second.value = second.value + " { " + first.value + " }"; + first.value = first.value + " { " + second.value + " }"; } else { // attribute ends with property value - second.value = second.value + "; " + first.value; + first.value = first.value + "; " + second.value; } - temp = first.next; - - if (temp.next == null) - { - second = null; - } - else - { - second = second.next; - } - - lexer.report.attrError(lexer, this, first, ErrorCode.JOINING_ATTRIBUTE); - - removeAttribute(first); - first = temp; - + temp = second.next; + lexer.report.attrError(lexer, this, second, ErrorCode.JOINING_ATTRIBUTE); + removeAttribute(second); + second = temp; } else if (lexer.configuration.getDuplicateAttrs() == DupAttrModes.KeepLast) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ad...@us...> - 2010-11-20 23:57:19
|
Revision: 1219 http://jtidy.svn.sourceforge.net/jtidy/?rev=1219&view=rev Author: aditsu Date: 2010-11-20 23:57:13 +0000 (Sat, 20 Nov 2010) Log Message: ----------- improved toString Modified Paths: -------------- branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java Modified: branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java =================================================================== --- branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java 2010-11-20 23:02:29 UTC (rev 1218) +++ branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java 2010-11-20 23:57:13 UTC (rev 1219) @@ -1202,59 +1202,48 @@ } } + protected String toString(final String indent) { + final StringBuilder sb = new StringBuilder(); + sb.append(type); + if (element != null) { + sb.append(':').append(element); + } + if (type == NodeType.TextNode || type == NodeType.CommentTag || type == NodeType.ProcInsTag) { + if (textarray != null && start <= end) { + sb.append(" \""); + sb.append(TidyUtils.getString(textarray, start, end - start)); + sb.append('"'); + } + else { + sb.append(" null"); + } + } + for (AttVal av = attributes; av != null; av = av.next) { + sb.append(' ').append(av.attribute).append('='); + if (av.value == null) { + sb.append("null"); + } + else { + sb.append('"').append(av.value).append('"'); + } + } + if (content != null) { + sb.append("\n ").append(indent); + sb.append(content.toString(indent + ' ')); + } + if (next != null) { + sb.append('\n').append(indent); + sb.append(next.toString(indent)); + } + return sb.toString(); + } + /** * @see java.lang.Object#toString() */ @Override - public String toString() - { - String s = ""; - Node n = this; - - while (n != null) - { - s += "[Node type="; - s += n.type; - s += ",element="; - if (n.element != null) - { - s += n.element; - } - else - { - s += "null"; - } - if (n.type == NodeType.TextNode || n.type == NodeType.CommentTag || n.type == NodeType.ProcInsTag) - { - s += ",text="; - if (n.textarray != null && n.start <= n.end) - { - s += "\""; - s += TidyUtils.getString(n.textarray, n.start, n.end - n.start); - s += "\""; - } - else - { - s += "null"; - } - } - s += ",content="; - if (n.content != null) - { - s += n.content.toString(); - } - else - { - s += "null"; - } - s += "]"; - if (n.next != null) - { - s += ","; - } - n = n.next; - } - return s; + public String toString() { + return toString(""); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ad...@us...> - 2010-11-26 00:21:30
|
Revision: 1236 http://jtidy.svn.sourceforge.net/jtidy/?rev=1236&view=rev Author: aditsu Date: 2010-11-26 00:21:24 +0000 (Fri, 26 Nov 2010) Log Message: ----------- added setParent and setNext, with integrity checks Modified Paths: -------------- branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java Modified: branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java =================================================================== --- branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java 2010-11-25 04:54:42 UTC (rev 1235) +++ branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java 2010-11-26 00:21:24 UTC (rev 1236) @@ -485,43 +485,35 @@ * Insert a node into markup tree. * @param node to insert */ - public void insertNodeAtStart(Node node) - { - node.parent = this; + public void insertNodeAtStart(final Node node) { + node.setParent(this); - if (this.content == null) - { - this.last = node; + if (content == null) { + last = node; } - else - { - this.content.prev = node; // AQ added 13 Apr 2000 + else { + content.prev = node; // AQ added 13 Apr 2000 } - - node.next = this.content; + node.setNext(content); node.prev = null; - this.content = node; + content = node; } /** * Insert node into markup tree. * @param node Node to insert */ - public void insertNodeAtEnd(Node node) - { - node.parent = this; - node.prev = this.last; - - if (this.last != null) - { - this.last.next = node; + public void insertNodeAtEnd(final Node node) { + node.setParent(this); + node.prev = last; + + if (last != null) { + last.setNext(node); } - else - { - this.content = node; + else { + content = node; } - - this.last = node; + last = node; } /** @@ -529,62 +521,48 @@ * @param element child node. Will be inserted as a child of element * @param node parent node */ - public static void insertNodeAsParent(Node element, Node node) - { + public static void insertNodeAsParent(final Node element, final Node node) { node.content = element; node.last = element; - node.parent = element.parent; - element.parent = node; + node.setParent(element.parent); + element.setParent(node); - if (node.parent.content == element) - { + if (node.parent.content == element) { node.parent.content = node; } - - if (node.parent.last == element) - { + if (node.parent.last == element) { node.parent.last = node; } - node.prev = element.prev; element.prev = null; - if (node.prev != null) - { - node.prev.next = node; + if (node.prev != null) { + node.prev.setNext(node); } - - node.next = element.next; + node.setNext(element.next); element.next = null; - if (node.next != null) - { + if (node.next != null) { node.next.prev = node; } } /** * Insert node into markup tree before element. - * @param element child node. Will be insertedbefore element + * @param element child node. Will be inserted before element * @param node following node */ - public static void insertNodeBeforeElement(Node element, Node node) - { - Node parent; - - parent = element.parent; - node.parent = parent; - node.next = element; + public static void insertNodeBeforeElement(Node element, Node node) { + Node parent = element.parent; + node.setParent(parent); + node.setNext(element); node.prev = element.prev; element.prev = node; - if (node.prev != null) - { - node.prev.next = node; + if (node.prev != null) { + node.prev.setNext(node); } - - if (parent != null && parent.content == element) - { + if (parent != null && parent.content == element) { parent.content = node; } } @@ -593,29 +571,21 @@ * Insert node into markup tree after element. * @param node new node to insert */ - public void insertNodeAfterElement(Node node) - { - Node parent; + public void insertNodeAfterElement(final Node node) { + node.setParent(parent); - parent = this.parent; - node.parent = parent; - // AQ - 13Jan2000 fix for parent == null - if (parent != null && parent.last == this) - { + if (parent != null && parent.last == this) { parent.last = node; } - else - { - node.next = this.next; + else { + node.setNext(next); // AQ - 13Jan2000 fix for node.next == null - if (node.next != null) - { + if (node.next != null) { node.next.prev = node; } } - - this.next = node; + setNext(node); node.prev = this; } @@ -918,30 +888,21 @@ * @param row Row node * @param node Node which should be moved before the table */ - public static void moveBeforeTable(Node row, Node node) - { - Node table; - + public static void moveBeforeTable(Node row, Node node) { /* first find the table element */ - for (table = row.parent; table != null; table = table.parent) - { - if (table.is(TagId.TABLE)) - { - if (table.parent.content == table) - { + for (Node table = row.parent; table != null; table = table.parent) { + if (table.is(TagId.TABLE)) { + if (table.parent.content == table) { table.parent.content = node; } - node.prev = table.prev; - node.next = table; + node.setNext(table); table.prev = node; - node.parent = table.parent; + node.setParent(table.parent); - if (node.prev != null) - { - node.prev.next = node; + if (node.prev != null) { + node.prev.setNext(node); } - break; } } @@ -992,34 +953,24 @@ /** * Extract this node and its children from a markup tree. */ - public void removeNode() - { - if (this.prev != null) - { - this.prev.next = this.next; + public void removeNode() { + if (prev != null) { + prev.setNext(next); } - - if (this.next != null) - { - this.next.prev = this.prev; + if (next != null) { + next.prev = prev; } - - if (this.parent != null) - { - if (this.parent.content == this) - { - this.parent.content = this.next; + if (parent != null) { + if (parent.content == this) { + parent.content = next; } - - if (this.parent.last == this) - { - this.parent.last = this.prev; + if (parent.last == this) { + parent.last = prev; } } - - this.parent = null; - this.prev = null; - this.next = null; + parent = null; + prev = null; + next = null; } /** @@ -1490,4 +1441,18 @@ } return 0; } + + protected void setParent(final Node node) { + if (node == this) { + throw new IllegalArgumentException("Attempt to insert a node into itself"); + } + parent = node; + } + + protected void setNext(final Node node) { + if (node == this) { + throw new IllegalArgumentException("Attempt to insert a node as its own sibling"); + } + next = node; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |