On Nov 4, 2008, at 7:36 AM, asiri (SVN) wrote:
Author: asiri
Date: 2008-11-04 07:36:17 +0100 (Tue, 04 Nov 2008)
New Revision: 13945
Added:
sandbox/xwiki-plugin-officeimporter/src/main/java/com/xpn/xwiki/
plugin/officeimporter/filter/StyleFixFilter.java
sandbox/xwiki-plugin-officeimporter/src/main/java/com/xpn/xwiki/
plugin/officeimporter/filter/TableFixFilter.java
Log:
JIRA :
http://jira.xwiki.org/jira/browse/XAOFFICE-1
Introduced two fix filters. These filters pre-process the xhtml
document so that rendering via xwiki 2.0 syntax renderer produces
acceptable results.
Copied: sandbox/xwiki-plugin-officeimporter/src/main/java/com/xpn/
xwiki/plugin/officeimporter/filter/StyleFixFilter.java (from rev
13943, sandbox/xwiki-plugin-officeimporter/src/main/java/com/xpn/
xwiki/plugin/officeimporter/filter/HtmlStylesFilter.java)
===================================================================
--- sandbox/xwiki-plugin-officeimporter/src/main/java/com/xpn/xwiki/
plugin/officeimporter/filter/
StyleFixFilter.java (rev 0)
+++ sandbox/xwiki-plugin-officeimporter/src/main/java/com/xpn/xwiki/
plugin/officeimporter/filter/StyleFixFilter.java 2008-11-04 06:36:17
UTC (rev 13945)
@@ -0,0 +1,56 @@
+package com.xpn.xwiki.plugin.officeimporter.filter;
+
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * This particular filter searches for {@code <span>} and {@code
<div>} tags containing style
+ * attributes and removes such attributes if present.
I don't think this is correct. You should filter style attributes for
ALL HTML elements.
I have no idea what your second filter does and whether it should be
done in the office importer or not.
Thanks
-Vincent
Also, if the resulting {@code <span>} or
+ * {@code <div>} tag has no other attributes, this filter will
completely rip off the tag itself and
+ * append the content of the tag into it's parent.
+ */
+public class StyleFixFilter implements HtmlFilter
+{
+ /**
+ * Tags that contain style information.
+ */
+ private static final String[] styleTags = new String[] {"span",
"div"};
+
+ /**
+ * {@inheritDoc}
+ */
+ public void filter(Document document)
+ {
+ Element root = document.getDocumentElement();
+ for (String tagName : styleTags) {
+ NodeList tagList = root.getElementsByTagName(tagName);
+ for (int i = 0; i < tagList.getLength(); i++) {
+ Node tag = tagList.item(i);
+ if (tag.hasAttributes()) {
+ try {
+ tag.getAttributes().removeNamedItem("style");
+ } catch (DOMException ex) {
+ // Not a problem.
+ }
+ }
+ // Check if the tag has no more attributes.
+ if (!tag.hasAttributes()) {
+ // Append the children into parent node.
+ Node parentNode = tag.getParentNode();
+ NodeList grandChildren = tag.getChildNodes();
+ for (int j = 0; j < grandChildren.getLength(); j
++) {
+
parentNode.appendChild(grandChildren.item(j));
+ }
+ // Get rid of it.
+ parentNode.removeChild(tag);
+ // Removing the tag causes the tag list to
collapse.
+ // To address this issue, we need to decrement
the counter.
+ i--;
+ }
+ }
+ }
+ }
+}
Property changes on: sandbox/xwiki-plugin-officeimporter/src/main/
java/com/xpn/xwiki/plugin/officeimporter/filter/StyleFixFilter.java
___________________________________________________________________
Name: svn:mergeinfo
+
Added: sandbox/xwiki-plugin-officeimporter/src/main/java/com/xpn/
xwiki/plugin/officeimporter/filter/TableFixFilter.java
===================================================================
--- sandbox/xwiki-plugin-officeimporter/src/main/java/com/xpn/xwiki/
plugin/officeimporter/filter/
TableFixFilter.java (rev 0)
+++ sandbox/xwiki-plugin-officeimporter/src/main/java/com/xpn/xwiki/
plugin/officeimporter/filter/TableFixFilter.java 2008-11-04 06:36:17
UTC (rev 13945)
@@ -0,0 +1,19 @@
+package com.xpn.xwiki.plugin.officeimporter.filter;
+
+import org.w3c.dom.Document;
+
+/**
+ * The purpose of this filter is to pre-adjust the html {@code
<table>} elements so that they are
+ * rendered properly in the xwiki 2.0 syntax renderer. This also
implies any formatting elements
+ * present in the html which are not compatible with xwiki 2.0
getting ripped off entirely.
+ */
+public class TableFixFilter implements HtmlFilter
+{
+ /**
+ * {@inheritDoc}
+ */
+ public void filter(Document document)
+ {
+
+ }
+}
_______________________________________________
notifications mailing list
notifications(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/notifications