Hi Vincent,
On Mon, Mar 23, 2009 at 1:47 AM, Vincent Massol <vincent(a)massol.net> wrote:
Hi Asiri,
On Mar 22, 2009, at 8:16 AM, asiri (SVN) wrote:
Author: asiri
Date: 2009-03-22 08:16:13 +0100 (Sun, 22 Mar 2009)
New Revision: 17894
Modified:
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/
officeimporter/filter/AnchorFilter.java
platform/core/trunk/xwiki-officeimporter/src/test/java/org/xwiki/
officeimporter/internal/cleaner/LinkOpenOfficeCleaningTest.java
Log:
XWIKI-3415: Office Importer fails when importing documents with TOC
(Table Of Contents) structures
* Fixed.
* But there is still a problem (not a failure) with importing word
documents with TOC structures. That's a different issue.
Modified: platform/core/trunk/xwiki-officeimporter/src/main/java/org/
xwiki/officeimporter/filter/AnchorFilter.java
===================================================================
--- platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/
officeimporter/filter/AnchorFilter.java 2009-03-21 22:20:38 UTC
(rev
17893)
+++ platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/
officeimporter/filter/AnchorFilter.java 2009-03-22 07:16:13 UTC
(rev
17894)
@@ -61,7 +61,7 @@
Node heading = link.getParentNode();
Node paragraph = (heading != null) ?
heading.getPreviousSibling() : null;
Node originalAnchor =
- (paragraph != null) ? ((Element)
paragraph).getElementsByTagName(TAG_A).item(0) : null;
+ (paragraph instanceof Element) ? ((Element)
paragraph).getElementsByTagName(TAG_A).item(0) : null;
if (isSameAnchor(link, originalAnchor)) {
// Means this anchor was a result of close-
before-copy-inside operation of default html cleaner.
anchorsToRemove.add(link);
Modified: platform/core/trunk/xwiki-officeimporter/src/test/java/org/
xwiki/officeimporter/internal/cleaner/LinkOpenOfficeCleaningTest.java
===================================================================
--- platform/core/trunk/xwiki-officeimporter/src/test/java/org/xwiki/
officeimporter/internal/cleaner/LinkOpenOfficeCleaningTest.java
2009-03-21 22:20:38 UTC (rev 17893)
+++ platform/core/trunk/xwiki-officeimporter/src/test/java/org/xwiki/
officeimporter/internal/cleaner/LinkOpenOfficeCleaningTest.java
2009-03-22 07:16:13 UTC (rev 17894)
@@ -72,6 +72,21 @@
}
/**
+ * Test duplicate anchor filtering with TOC structures. see:
http://jira.xwiki.org/jira/browse/XWIKI-3415
+ */
+ public void testAnchorFilteringWithTOC()
+ {
+ String html = header + "<div>some text<h1><a name=
\"Topic1\"/>Topic1</h1></div>" + footer;
+ try {
+ Document doc = openOfficeHTMLCleaner.clean(new
StringReader(html));
+ NodeList nodes = doc.getElementsByTagName("a");
+ assertEquals(1, nodes.getLength());
+ } catch (ClassCastException ex) {
+ fail(ex.getMessage());
+ }
+ }
The best practice is never to catch an exception unless the test is
about testing for exeption use cases.
So you should instead have testAnchor*() throws Exception {...} and
don't put put the try/catch.
see
http://junit.sourceforge.net/doc/faq/faq.htm#tests_8 for example.