Index: src/main/java/org/xwiki/xml/internal/html/XWikiDOMSerializer.java
===================================================================
--- src/main/java/org/xwiki/xml/internal/html/XWikiDOMSerializer.java	(revision 34598)
+++ src/main/java/org/xwiki/xml/internal/html/XWikiDOMSerializer.java	(working copy)
@@ -30,8 +30,8 @@
 
 import org.apache.commons.lang.StringEscapeUtils;
 import org.htmlcleaner.CleanerProperties;
-import org.htmlcleaner.CommentToken;
-import org.htmlcleaner.ContentToken;
+import org.htmlcleaner.CommentNode;
+import org.htmlcleaner.ContentNode;
 import org.htmlcleaner.TagNode;
 import org.htmlcleaner.Utils;
 import org.w3c.dom.Comment;
@@ -39,14 +39,11 @@
 import org.w3c.dom.Element;
 
 /**
- * Generate a W3C Document from a SF's HTML Cleaner TagNode.
- * Original implementation by Vladimir Nikic, under the BSD license
- * (see http://htmlcleaner.sourceforge.net/license.php).
- * 
- * Modified to bypass following bugs:
+ * Generate a W3C Document from a SF's HTML Cleaner TagNode. Original implementation by Vladimir Nikic, under the BSD
+ * license (see http://htmlcleaner.sourceforge.net/license.php). Modified to bypass following bugs:
  * <ul>
- *   <li>https://sourceforge.net/tracker/?func=detail&aid=2691888&group_id=183053&atid=903696</li>
- *   <li>https://sourceforge.net/tracker/?func=detail&aid=2761963&group_id=183053&atid=903696</li>
+ * <li>https://sourceforge.net/tracker/?func=detail&aid=2691888&group_id=183053&atid=903696</li>
+ * <li>https://sourceforge.net/tracker/?func=detail&aid=2761963&group_id=183053&atid=903696</li>
  * </ul>
  * 
  * @version $Id$
@@ -57,8 +54,8 @@
     /**
      * The Regex Pattern to recognize a CDATA block.
      */
-    private static final Pattern CDATA_PATTERN =
-        Pattern.compile("<!\\[CDATA\\[.*(\\]\\]>|<!\\[CDATA\\[)", Pattern.DOTALL);
+    private static final Pattern CDATA_PATTERN = Pattern.compile("<!\\[CDATA\\[.*(\\]\\]>|<!\\[CDATA\\[)",
+        Pattern.DOTALL);
 
     /**
      * The HTML Cleaner properties set by the user to control the HTML cleaning.
@@ -108,11 +105,12 @@
      */
     private void flushContent(Document document, Element element, StringBuffer bufferedContent, Object item)
     {
-        if (bufferedContent.length() > 0 && !(item instanceof ContentToken)) {
+        if (bufferedContent.length() > 0 && !(item instanceof ContentNode)) {
             // Flush the buffered content
             String nodeName = element.getNodeName();
-            boolean specialCase = this.props.isUseCdataForScriptAndStyle()
-                && ("script".equalsIgnoreCase(nodeName) || "style".equalsIgnoreCase(nodeName));
+            boolean specialCase =
+                this.props.isUseCdataForScriptAndStyle()
+                    && ("script".equalsIgnoreCase(nodeName) || "style".equalsIgnoreCase(nodeName));
             String content = bufferedContent.toString();
 
             if (this.escapeXml && !specialCase) {
@@ -193,18 +191,17 @@
                 // Flush content tokens
                 flushContent(document, element, bufferedContent, item);
 
-                if (item instanceof CommentToken) {
-                    CommentToken commentToken = (CommentToken) item;
-                    Comment comment = document.createComment(commentToken.getContent());
+                if (item instanceof CommentNode) {
+                    CommentNode commentToken = (CommentNode) item;
+                    Comment comment = document.createComment(commentToken.getContent().toString());
                     element.appendChild(comment);
-                } else if (item instanceof ContentToken) {
-                    ContentToken contentToken = (ContentToken) item;
-                    String content = contentToken.getContent();
+                } else if (item instanceof ContentNode) {
+                    ContentNode contentToken = (ContentNode) item;
+                    CharSequence content = contentToken.getContent();
                     bufferedContent.append(content);
                 } else if (item instanceof TagNode) {
                     TagNode subTagNode = (TagNode) item;
                     Element subelement = document.createElement(subTagNode.getName());
-                    @SuppressWarnings("unchecked")
                     Map<String, String> attributes = subTagNode.getAttributes();
                     for (Map.Entry<String, String> entry : attributes.entrySet()) {
                         String attrName = entry.getKey();
Index: src/main/java/org/xwiki/xml/internal/html/DefaultHTMLCleaner.java
===================================================================
--- src/main/java/org/xwiki/xml/internal/html/DefaultHTMLCleaner.java	(revision 34598)
+++ src/main/java/org/xwiki/xml/internal/html/DefaultHTMLCleaner.java	(working copy)
@@ -29,7 +29,7 @@
 
 import org.htmlcleaner.CleanerProperties;
 import org.htmlcleaner.CleanerTransformations;
-import org.htmlcleaner.ContentToken;
+import org.htmlcleaner.ContentNode;
 import org.htmlcleaner.HtmlCleaner;
 import org.htmlcleaner.TagNode;
 import org.htmlcleaner.TagTransformation;
@@ -85,12 +85,12 @@
     {
         // The clean method below is thread safe. However it seems that DOMOutputter.output() is not fully thread safe
         // since it causes the following exception on the first time it's called from different threads:
-        //  Caused by: org.jdom.JDOMException: Reflection failed while creating new JAXP document:
-        //  duplicate class definition: org/apache/xerces/jaxp/DocumentBuilderFactoryImpl
-        //  at org.jdom.adapters.JAXPDOMAdapter.createDocument(JAXPDOMAdapter.java:191)
-        //  at org.jdom.adapters.AbstractDOMAdapter.createDocument(AbstractDOMAdapter.java:133)
-        //  at org.jdom.output.DOMOutputter.createDOMDocument(DOMOutputter.java:208)
-        //  at org.jdom.output.DOMOutputter.output(DOMOutputter.java:127)
+        // Caused by: org.jdom.JDOMException: Reflection failed while creating new JAXP document:
+        // duplicate class definition: org/apache/xerces/jaxp/DocumentBuilderFactoryImpl
+        // at org.jdom.adapters.JAXPDOMAdapter.createDocument(JAXPDOMAdapter.java:191)
+        // at org.jdom.adapters.AbstractDOMAdapter.createDocument(AbstractDOMAdapter.java:133)
+        // at org.jdom.output.DOMOutputter.createDOMDocument(DOMOutputter.java:208)
+        // at org.jdom.output.DOMOutputter.output(DOMOutputter.java:127)
         // Since this only happens once, we call it first here at initialization time (since there's no thread
         // contention at that time). Note: This email thread seems to say it's thread safe but that's not what we see
         // here: http:osdir.com/ml/text.xml.xforms.chiba.devel/2006-09/msg00025.html
@@ -253,8 +253,8 @@
         TagNode body = cleanedNode.getElementsByName("body", false)[0];
         if (body.getChildren().size() > 0) {
             Object firstBodyChild = body.getChildren().get(0);
-            if (firstBodyChild instanceof ContentToken
-                && ((ContentToken) firstBodyChild).getContent().startsWith("<?xml")) {
+            if (firstBodyChild instanceof ContentNode
+                && ((ContentNode) firstBodyChild).getContent().toString().startsWith("<?xml")) {
                 body.removeChild(firstBodyChild);
             }
         }
Index: src/test/java/org/xwiki/xml/internal/html/DefaultHTMLCleanerTest.java
===================================================================
--- src/test/java/org/xwiki/xml/internal/html/DefaultHTMLCleanerTest.java	(revision 34598)
+++ src/test/java/org/xwiki/xml/internal/html/DefaultHTMLCleanerTest.java	(working copy)
@@ -165,7 +165,7 @@
         assertHTML("<script>//<![CDATA[\n<>\n//]]></script>", "<script>&lt;&gt;</script>");
         assertHTML("<script>//<![CDATA[\n<>\n//]]></script>", "<script><></script>");
 
-        assertHTML("<p><![CDATA[&]]></p>", "<p><![CDATA[&]]></p>");
+        assertHTML("<p><![CDATA[aa]]></p>", "<p><![CDATA[aa]]></p>");
 
         assertHTML("<p>&amp;<![CDATA[&]]>&amp;</p>", "<p>&<![CDATA[&]]>&</p>");
     }
Index: pom.xml
===================================================================
--- pom.xml	(revision 34598)
+++ pom.xml	(working copy)
@@ -49,28 +49,14 @@
       <artifactId>commons-lang</artifactId>
     </dependency>
     <dependency>
-      <groupId>net.sourceforge.htmlcleaner</groupId>
-      <artifactId>htmlcleaner</artifactId>
-      <version>2.1</version>
-      <!-- HTML Cleaner uses JDOM 1.0 but we want to use JDOM 1.1 so we need to exclude it -->
-      <exclusions>
-        <exclusion>
-          <groupId>jdom</groupId>
-          <artifactId>jdom</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    <dependency>
       <groupId>jdom</groupId>
       <artifactId>jdom</artifactId>
       <version>1.1</version>
-    </dependency>    
-    <!-- Testing dependencies -->
+    </dependency>
     <dependency>
-      <groupId>org.xwiki.platform</groupId>
-      <artifactId>xwiki-core-shared-tests</artifactId>
-      <version>${project.version}</version>
-      <scope>test</scope>
+      <groupId>net.sourceforge.htmlcleaner</groupId>
+      <artifactId>htmlcleaner</artifactId>
+      <version>2.2</version>
     </dependency>
     <dependency>
       <groupId>commons-logging</groupId>
@@ -81,6 +67,14 @@
       <artifactId>xercesImpl</artifactId>
       <version>2.8.1</version>
     </dependency>
+
+    <!-- Testing dependencies -->
+    <dependency>
+      <groupId>org.xwiki.platform</groupId>
+      <artifactId>xwiki-core-shared-tests</artifactId>
+      <version>${project.version}</version>
+      <scope>test</scope>
+    </dependency>
     <dependency>
       <groupId>org.xwiki.platform</groupId>
       <artifactId>xwiki-core-component-default</artifactId>
