cziegeler 02/02/11 02:12:35
Modified: src/java/org/apache/cocoon/components/source URLSource.java
Log:
Optional compilation works again
Revision Changes Path
1.6 +16 -13
xml-cocoon2/src/java/org/apache/cocoon/components/source/URLSource.java
Index: URLSource.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/source/URLSource.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- URLSource.java 11 Feb 2002 09:51:19 -0000 1.5
+++ URLSource.java 11 Feb 2002 10:12:35 -0000 1.6
@@ -64,12 +64,11 @@
import org.apache.cocoon.environment.ModifiableSource;
import org.apache.cocoon.util.ClassUtils;
import org.apache.cocoon.xml.XMLConsumer;
-import org.w3c.tidy.Tidy;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.ext.LexicalHandler;
-
+import org.w3c.dom.Document;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -90,13 +89,13 @@
* Description of a source which is described by an URL.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Id: URLSource.java,v 1.5 2002/02/11 09:51:19 cziegeler Exp $
+ * @version CVS $Id: URLSource.java,v 1.6 2002/02/11 10:12:35 cziegeler Exp $
*/
public class URLSource implements ModifiableSource {
/** Is JTidy available? */
- private static boolean jtidyAvailable;
+ private static Class jtidyClass;
/** Properties used for converting HTML to XML */
private static Properties xmlProperties;
@@ -108,10 +107,9 @@
* Test if JTidy is available
*/
static {
- jtidyAvailable = false;
+ jtidyClass = null;
try {
- Class jtidy = ClassUtils.loadClass("org.w3c.tidy.Tidy");
- if ( null != jtidy ) jtidyAvailable = true;
+ jtidyClass = ClassUtils.loadClass("org.w3c.tidy.Tidy");
} catch (ClassNotFoundException cnfe) {
// ignore
}
@@ -373,13 +371,18 @@
public InputSource getInputSource()
throws IOException, ProcessingException {
InputStream stream = this.getInputStream();
- if ( this.isHTMLContent && jtidyAvailable ) {
+ if ( this.isHTMLContent && null != jtidyClass ) {
try {
- final Tidy xhtmlconvert = new Tidy();
- xhtmlconvert.setXmlOut(true);
- xhtmlconvert.setXHTML(true);
- xhtmlconvert.setShowWarnings(false);
- final org.w3c.dom.Document doc = xhtmlconvert.parseDOM(stream,
null);
+ // FIXME (CZ) we need to speed up this!
+ final Object xhtmlconvert = jtidyClass.newInstance();
+ Method m = jtidyClass.getMethod("setXmlOut", new Class[] {
Class.forName("java.lang.Boolean")});
+ m.invoke(xhtmlconvert, new Object[] { new Boolean(true) });
+ m = jtidyClass.getMethod("setXHTML", new Class[]
{Class.forName("java.lang.Boolean")});
+ m.invoke(xhtmlconvert, new Object[] { new Boolean(true) });
+ m = jtidyClass.getMethod("setShowWarnings", new Class[] {
Class.forName("java.lang.Boolean")});
+ m.invoke(xhtmlconvert, new Object[] { new Boolean(false) });
+ m = jtidyClass.getMethod("parseDOM", new Class[] {
Class.forName("java.io.InputStream"), Class.forName("java.io.OutputStream")});
+ final Document doc = (Document)m.invoke(xhtmlconvert, new Object[]
{ stream, null });
final StringWriter writer = new StringWriter();
final Transformer transformer;
transformer = transformerFactory.newTransformer();
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]