Re: [xwiki-devs] [xwiki-notifications] r15020 - in platform/core/trunk/xwiki-xml/src/main/java/org/xwiki/xml: html internal/html
Hi Asiri, You absolutely need a JIRA issue for this! Actually you would also normally need a vote since you're modifying a public API but it's probably ok.... See also the comments below. On Jan 2, 2009, at 5:07 PM, asiri (SVN) wrote:
Author: asiri Date: 2009-01-02 17:07:40 +0100 (Fri, 02 Jan 2009) New Revision: 15020
Modified: platform/core/trunk/xwiki-xml/src/main/java/org/xwiki/xml/html/ HTMLCleaner.java platform/core/trunk/xwiki-xml/src/main/java/org/xwiki/xml/internal/ html/DefaultHTMLCleaner.java Log: * Introduced a clean(Reader html, Map<String, String> params) method to the HTMLCleaner interface.
Modified: platform/core/trunk/xwiki-xml/src/main/java/org/xwiki/xml/ html/HTMLCleaner.java =================================================================== --- platform/core/trunk/xwiki-xml/src/main/java/org/xwiki/xml/html/ HTMLCleaner.java 2009-01-02 15:42:50 UTC (rev 15019) +++ platform/core/trunk/xwiki-xml/src/main/java/org/xwiki/xml/html/ HTMLCleaner.java 2009-01-02 16:07:40 UTC (rev 15020) @@ -20,12 +20,13 @@ package org.xwiki.xml.html;
import java.io.Reader; +import java.util.Map;
import org.w3c.dom.Document;
/** * Transforms any HTML content into valid XHTML that can be feed to the XHTML Parser for example. - * + * * @version $Id: $ * @since 1.6M1 */ @@ -43,4 +44,14 @@ * @return the cleaned HTML as a w3c DOM (this allows further transformations if needed) */ Document clean(Reader originalHtmlContent); + + /** + * Transforms any HTML content into valid XHTML. Additional parameters may be passed in to fine tune the cleaning + * process. + * + * @param originalHtmlContent The original html content to be cleaned. + * @param params Additional parameters (implementation dependent) for cleaning. + * @return The cleaned HTML as a w3c DOM
You should use "the" and not "The". See http://dev.xwiki.org/xwiki/bin/view/Community/CodeStyle which points to http://java.sun.com/j2se/javadoc/writingdoccomments/
+ */ + Document clean(Reader originalHtmlContent, Map<String, String> params);
Can you rename params to cleaningParameters since this is more explicit and this is what we discussed?
}
Modified: platform/core/trunk/xwiki-xml/src/main/java/org/xwiki/xml/ internal/html/DefaultHTMLCleaner.java =================================================================== --- platform/core/trunk/xwiki-xml/src/main/java/org/xwiki/xml/ internal/html/DefaultHTMLCleaner.java 2009-01-02 15:42:50 UTC (rev 15019) +++ platform/core/trunk/xwiki-xml/src/main/java/org/xwiki/xml/ internal/html/DefaultHTMLCleaner.java 2009-01-02 16:07:40 UTC (rev 15020) @@ -24,6 +24,7 @@ import java.io.StringReader; import java.util.ArrayList; import java.util.List; +import java.util.Map;
import org.htmlcleaner.CleanerProperties; import org.htmlcleaner.CleanerTransformations; @@ -64,20 +65,20 @@ this.filters = new ArrayList<CleaningFilter>(); this.filters.add(new ListCleaningFilter()); this.filters.add(new DocTypeCleaningFilter()); - + // 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)
Why did you remove the white space I had put to indent the stack trace? :)
// 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 + // http://osdir.com/ml/text.xml.xforms.chiba.devel/2006-09/msg00025.html
same here.
clean(new StringReader("")); }
@@ -90,25 +91,30 @@ { org.w3c.dom.Document result;
- // HtmlCleaner is not threadsafe. Thus we need to recreate an instance at each run since otherwise - // we would need to synchronize this clean() method which would slow down the whole system by + // HtmlCleaner is not threadsafe. Thus we need to recreate an instance at each run since + // otherwise
Why did you break at 100 chars when we are breaking at 120?
+ // we would need to synchronize this clean() method which would slow down the whole system + // by // queuing up cleaning requests. - // See http://sourceforge.net/tracker/index.php?func=detail&aid=2139927&group_id=18... + // See + // http://sourceforge.net/tracker/index.php?func=detail&aid=2139927&group_id=18... + // 903699
Same here.
HtmlCleaner cleaner = new HtmlCleaner(); cleaner.setTransformations(getCleaningTransformations()); CleanerProperties cleanerProperties = cleaner.getProperties(); cleanerProperties.setOmitUnknownTags(true);
- // By default HTMLCleaner treats style and script tags as CDATA. This is causing errors if we use + // By default HTMLCleaner treats style and script tags as CDATA. This is causing errors if + // we use // the best practice of using CDATA inside a script. For example: - // <script type="text/javascript"> - // //<![CDATA[ - // ... - // // ]]> - // </script> + // <script type="text/javascript"> + // //<![CDATA[ + // ... + // // ]]> + // </script> // Thus we need to turn off this feature. cleanerProperties.setUseCdataForScriptAndStyle(false); - + TagNode cleanedNode; try { cleanedNode = cleaner.clean(originalHtmlContent); @@ -120,7 +126,7 @@
// Fix cleaned node bug fixCleanedNodeBug(cleanedNode); - + Document document = new JDomSerializer(cleanerProperties, false).createJDom(cleanedNode);
// Perform other cleaning operation this time using the W3C Document interface. @@ -139,9 +145,20 @@ }
/** - * @return the cleaning transformations to perform on tags, in addition to the base transformations done by - * HTML Cleaner + * {@inheritDoc} + * <p> + * {@link DefaultHTMLCleaner} does not allow fine-tuning of html cleaning via parameters. + * </p> */ + public org.w3c.dom.Document clean(Reader originalHtmlContent, Map<String, String> params) + { + return clean(originalHtmlContent);
the params don't seem to be used?
+ } + + /** + * @return the cleaning transformations to perform on tags, in addition to the base transformations done by HTML + * Cleaner + */ private CleanerTransformations getCleaningTransformations() { CleanerTransformations transformations = new CleanerTransformations(); @@ -174,9 +191,9 @@ }
/** - * There's a known limitation (bug?) in HTML Cleaner where if there's a XML declaration specified - * it'll be copied as the first element of the body. Thus remove it if it's there. - * See https://sourceforge.net/forum/message.php?msg_id=4657800 + * There's a known limitation (bug?) in HTML Cleaner where if there's a XML declaration specified it'll be copied as + * the first element of the body. Thus remove it if it's there. See + * https://sourceforge.net/forum/message.php?msg_id=4657800 * * @param cleanedNode the cleaned node (ie after the HTML cleaning) */
Thanks -Vincent http://xwiki.com http://massol.net http://xwiki.org
Hi Vincent: On Sat, Jan 3, 2009 at 12:24 AM, Vincent Massol <[email protected]> wrote:
Hi Asiri,
You absolutely need a JIRA issue for this!
Actually you would also normally need a vote since you're modifying a public API but it's probably ok....
Issue created : http://jira.xwiki.org/jira/browse/XWIKI-3063
+ /** + * Transforms any HTML content into valid XHTML. Additional parameters may be passed in to fine tune the cleaning + * process. + * + * @param originalHtmlContent The original html content to be cleaned. + * @param params Additional parameters (implementation dependent) for cleaning. + * @return The cleaned HTML as a w3c DOM
You should use "the" and not "The". See http://dev.xwiki.org/xwiki/bin/view/Community/CodeStyle which points to http://java.sun.com/j2se/javadoc/writingdoccomments/
Ok, I think I have used "The" in several other places (if not all) also. I will fix them.
+ */ + Document clean(Reader originalHtmlContent, Map<String, String> params);
Can you rename params to cleaningParameters since this is more explicit and this is what we discussed?
Fixed
+ // at org.jdom.output.DOMOutputter.createDOMDocument(DOMOutputter.java:208) + // at org.jdom.output.DOMOutputter.output(DOMOutputter.java: 127)
Why did you remove the white space I had put to indent the stack trace? :)
Sorry. I have been using a wrong version of codestyle-eclipse.xml. I've fixed the changes accidentally made to HTMLCleaner but I think I have done the same thing in several other places (webdav & office importer). Will fix them. the params don't seem to be used? The DefaultHTMLCleaner doesn't use the parameters. It's the OpenOfficeHTMLCleaner that will use the params. We discussed this on the chat, if we have a different HTMLCleaner interface only for Office Importer module we don't need to change the xwiki-xml HTMLCleaner interface. But OpenOfficeHTMLCleaner implements HTMLCleaner interface from xwiki-xml This is why we decided to change HTMLCleaner interface. The cleaning parameters are dependant on the implementation classes. I mean, cleaning parameters for DefaultHTMLCleaner (if there going to be any) will not apply for OpenOfficeHTMLCleaner. I hope there has been no misunderstanding. Thanks. - Asiri
On Jan 3, 2009, at 7:58 PM, Asiri Rathnayake wrote: [snip]
the params don't seem to be used?
The DefaultHTMLCleaner doesn't use the parameters. It's the OpenOfficeHTMLCleaner that will use the params. We discussed this on the chat, if we have a different HTMLCleaner interface only for Office Importer module we don't need to change the xwiki-xml HTMLCleaner interface. But OpenOfficeHTMLCleaner implements HTMLCleaner interface from xwiki- xml This is why we decided to change HTMLCleaner interface. The cleaning parameters are dependant on the implementation classes. I mean, cleaning parameters for DefaultHTMLCleaner (if there going to be any) will not apply for OpenOfficeHTMLCleaner.
I hope there has been no misunderstanding.
This is fine but it needs to be documented in the method with the parameter signature to explain why the params are not used. Thanks -Vincent http://xwiki.com http://massol.net http://xwiki.org
Hi, This is fine but it needs to be documented in the method with the
parameter signature to explain why the params are not used.
In HTMLCleaner#clean(Reader, Map) method i have included a javadoc comment which includes : "@param cleaningParameters Additional parameters (implementation dependent) for cleaning." And in DefaultHTMLCleaner: "/** * {@inheritDoc} * <p> * {@link DefaultHTMLCleaner} does not allow fine-tuning of html cleaning via parameters. * </p> */" I thought this was enough because of {@inheritDoc} tag plus the additional comment. Sorry, may be I have misunderstood something. Thanks. - Asiri
My bad, didn't see it. On Jan 3, 2009, at 8:27 PM, Asiri Rathnayake wrote:
Hi,
This is fine but it needs to be documented in the method with the
parameter signature to explain why the params are not used.
In HTMLCleaner#clean(Reader, Map) method i have included a javadoc comment which includes :
"@param cleaningParameters Additional parameters (implementation dependent) for cleaning."
And in DefaultHTMLCleaner:
"/** * {@inheritDoc} * <p> * {@link DefaultHTMLCleaner} does not allow fine-tuning of html cleaning via parameters. * </p> */"
I thought this was enough because of {@inheritDoc} tag plus the additional comment.
Sorry, may be I have misunderstood something.
Thanks.
- Asiri _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
Thanks -Vincent http://xwiki.com http://massol.net http://xwiki.org
participants (2)
-
Asiri Rathnayake -
Vincent Massol