sgala 01/05/04 08:52:14
Modified: src/java/org/apache/jetspeed/util SimpleTransform.java
src/java/org/apache/jetspeed/util/servlet
EcsStylesheetElement.java
src/java/org/apache/jetspeed/daemon/impl FeedDaemon.java
Added: lib xalan-2.0.1.jar
Removed: lib xalan.jar
Log:
Changing to xalan2.0.1 (Changes in SimpleTransform.java, EcsStylesheetElement.java
and FeedDaemon.java)
Revision Changes Path
1.15 +234 -60
jakarta-jetspeed/src/java/org/apache/jetspeed/util/SimpleTransform.java
Index: SimpleTransform.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/util/SimpleTransform.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- SimpleTransform.java 2001/03/07 06:50:02 1.14
+++ SimpleTransform.java 2001/05/04 15:51:10 1.15
@@ -59,21 +59,49 @@
import java.util.*;
//Xalan support
-import org.apache.xalan.xpath.xdom.XercesLiaison;
-import org.apache.xalan.xslt.XSLTProcessorFactory;
-import org.apache.xalan.xslt.XSLTInputSource;
-import org.apache.xalan.xslt.XSLTResultTarget;
-import org.apache.xalan.xslt.XSLTProcessor;
+//import org.apache.xalan.xpath.xdom.XercesLiaison;
+//import org.apache.xalan.xslt.XSLTProcessorFactory;
+//import org.apache.xalan.xslt.XSLTInputSource;
+//import org.apache.xalan.xslt.XSLTResultTarget;
+//import org.apache.xalan.xslt.XSLTProcessor;
+
+//Trax support
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.Templates;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.Result;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.sax.SAXTransformerFactory;
+import javax.xml.transform.sax.TemplatesHandler;
+import javax.xml.transform.sax.TransformerHandler;
+
+//xpath objects
+import org.apache.xpath.objects.XString;
+
+//SAX Suport
+import org.xml.sax.XMLReader;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.ext.LexicalHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.XMLReaderFactory;
+import org.xml.sax.InputSource;
+//DOM Support
+import org.w3c.dom.*;
+
//turbine support
import org.apache.turbine.util.*;
//Jetspeed stuff
import org.apache.jetspeed.cache.disk.*;
-//XML/SAX support
-import org.xml.sax.*;
-import org.w3c.dom.*;
@@ -85,7 +113,7 @@
* runtime failure.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Kevin A. Burton</a>
- * @version $Id: SimpleTransform.java,v 1.14 2001/03/07 06:50:02 taylor Exp $
+ * @version $Id: SimpleTransform.java,v 1.15 2001/05/04 15:51:10 sgala Exp $
*/
public class SimpleTransform {
@@ -94,8 +122,9 @@
* Given a a DOM and a URL to a stylesheet, transform the original document.
*/
public static String transform( Document doc,
- String stylesheet_url) throws SAXException {
- return transform(doc, stylesheet_url, null);
+ String stylesheet_url)
+ throws SAXException {
+ return transform( doc, stylesheet_url, null );
}
@@ -105,20 +134,84 @@
*/
public static String transform( Document doc,
String stylesheet_url,
- Map params) throws SAXException {
+ Map params)
+ throws SAXException {
- XSLTInputSource style;
+ // Instantiate a TransformerFactory.
+ TransformerFactory tFactory = TransformerFactory.newInstance();
+ // Determine whether the TransformerFactory supports the use of SAXSource
+ // and SAXResult
+ if (!tFactory.getFeature(SAXTransformerFactory.FEATURE) )
+ {
+ Log.error( "SimpleTransform: nobody told you that we need a SAX
Transformer?" );
+ throw new SAXException( "Invalid SAX Tranformer" );
+ }
+ try {
+ // Cast the TransformerFactory.
+ SAXTransformerFactory saxTFactory = ((SAXTransformerFactory) tFactory);
+ // Create a ContentHandler to handle parsing of the stylesheet.
+ TemplatesHandler templatesHandler = saxTFactory.newTemplatesHandler();
+
+ // Create an XMLReader and set its ContentHandler.
+ XMLReader reader = XMLReaderFactory.createXMLReader();
+ reader.setContentHandler(templatesHandler);
+
+ // Parse the stylesheet.
+ final InputSource xstyle = new InputSource( JetspeedDiskCache.getInstance()
+ .getEntry( stylesheet_url
).getReader() );
+ reader.parse( xstyle );
+
+ //Get the Templates object from the ContentHandler.
+ Templates templates = templatesHandler.getTemplates();
+ // Create a ContentHandler to handle parsing of the XML source.
+ TransformerHandler handler
+ = saxTFactory.newTransformerHandler(templates);
+
+ // Reset the XMLReader's ContentHandler.
+ reader.setContentHandler(handler);
+
+ // Set the ContentHandler to also function as a LexicalHandler, which
+ // includes "lexical" events (e.g., comments and CDATA).
+ try {
+ reader.setProperty("http://xml.org/sax/properties/lexical-handler",
handler);
+ } catch( org.xml.sax.SAXNotRecognizedException e ) {}
+
+ final Transformer processor = handler.getTransformer();
+
+ if( params != null )
+ {
+ Iterator keys = params.keySet().iterator();
+ while( keys.hasNext() )
+ {
+ String name = (String) keys.next();
+ String value = (String) params.get(name);
+ processor.setParameter(name,
+ value ); //FIXME: maybe we need to
quote again...
+ // was processor.createXString(
value)
+ }
+ }
+
+ StringWriter pw = new StringWriter();
+
+ // Have the XSLTProcessor processor object transform "foo.xml" to
+ // System.out, using the XSLT instructions found in "foo.xsl".
+ processor.transform( new DOMSource( doc ),
+ new StreamResult( pw ) );
+
try {
- style = new XSLTInputSource( JetspeedDiskCache.getInstance().getEntry(
stylesheet_url ).getReader() );
+
+ pw.flush();
+ pw.close();
+
} catch (IOException e) {
+ //should never really happen
Log.error( e );
- //at this point we can just use the original url and stylesheet_url so
this shouldn't be a problem
- style = new XSLTInputSource( stylesheet_url );
}
-
- return transform( new XSLTInputSource( doc ),
- style,
- params );
+ return pw.toString();
+ } catch (Exception e) {
+ Log.error( "Invalid SAX Transformer: " + e.toString() );
+ throw new SAXException( "problem in SAX transform: " + e.toString() );
+ }
}
/**
@@ -126,7 +219,8 @@
* original document.
*/
public static String transform( String url,
- String stylesheet_url ) throws SAXException {
+ String stylesheet_url )
+ throws SAXException {
return transform( url, stylesheet_url, null );
@@ -138,23 +232,24 @@
*/
public static String transform( String url,
String stylesheet_url,
- Map params ) throws SAXException {
+ Map params )
+ throws SAXException {
//bring these URLs local if they happen to be remote
- XSLTInputSource in;
- XSLTInputSource style;
+ InputSource in;
+ InputSource style;
try {
- in = new XSLTInputSource( JetspeedDiskCache.getInstance().getEntry( url
).getReader() );
- style = new XSLTInputSource( JetspeedDiskCache.getInstance().getEntry(
stylesheet_url ).getReader() );
+ in = new InputSource( JetspeedDiskCache.getInstance().getEntry( url
).getReader() );
+ style = new InputSource( JetspeedDiskCache.getInstance().getEntry(
stylesheet_url ).getReader() );
} catch (IOException e) {
Log.error( e );
//at this point we can just use the original url and stylesheet_url so
this shouldn't be a problem
- in = new XSLTInputSource( url );
- style = new XSLTInputSource( stylesheet_url );
+ in = new InputSource( url );
+ style = new InputSource( stylesheet_url );
}
- Log.note( "SimpleTransform: transforming url: " +
+ Log.info( "SimpleTransform: transforming url: " +
url +
" with stylesheet: " +
stylesheet_url );
@@ -168,17 +263,51 @@
/**
* Used internally to handle doing Xalan transfers directly.
*/
- public static String transform( XSLTInputSource content,
- XSLTInputSource stylesheet,
- Map params) throws SAXException {
+ public static String transform( InputSource content,
+ InputSource stylesheet,
+ Map params)
+ throws SAXException {
+
+ // Instantiate a TransformerFactory.
+ TransformerFactory tFactory = TransformerFactory.newInstance();
+ // Determine whether the TransformerFactory supports the use of SAXSource
+ // and SAXResult
+ if (!tFactory.getFeature(SAXTransformerFactory.FEATURE) )
+ {
+ Log.error( "SimpleTransform: nobody told you that we need a SAX
Transformer?" );
+ throw new SAXException( "Invalid SAX Tranformer" );
+ }
+ try {
+ // Cast the TransformerFactory.
+ SAXTransformerFactory saxTFactory = ((SAXTransformerFactory) tFactory);
+ // Create a ContentHandler to handle parsing of the stylesheet.
+ TemplatesHandler templatesHandler = saxTFactory.newTemplatesHandler();
+
+ // Create an XMLReader and set its ContentHandler.
+ XMLReader reader = XMLReaderFactory.createXMLReader();
+ reader.setContentHandler(templatesHandler);
+
+ // Parse the stylesheet.
+ reader.parse( stylesheet );
+ //Get the Templates object from the ContentHandler.
+ Templates templates = templatesHandler.getTemplates();
+ // Create a ContentHandler to handle parsing of the XML source.
+ TransformerHandler handler
+ = saxTFactory.newTransformerHandler(templates);
- // Have the XSLTProcessorFactory obtain a interface to a
- // new XSLTProcessor object.
- //XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
- XSLTProcessor processor = XSLTProcessorFactory.getProcessor( new
- XercesLiaison() );
+ // Reset the XMLReader's ContentHandler.
+ reader.setContentHandler(handler);
+
+ // Set the ContentHandler to also function as a LexicalHandler, which
+ // includes "lexical" events (e.g., comments and CDATA).
+ try {
+ reader.setProperty("http://xml.org/sax/properties/lexical-handler",
handler);
+ } catch( org.xml.sax.SAXNotRecognizedException e ) {}
+
+ final Transformer processor = handler.getTransformer();
+
if( params != null )
{
Iterator keys = params.keySet().iterator();
@@ -186,8 +315,9 @@
{
String name = (String) keys.next();
String value = (String) params.get(name);
- processor.setStylesheetParam(name,
- processor.createXString(
value) );
+ processor.setParameter(name,
+ new XString( value )
+/*FIXME: was processor.createXString( value) */ );
}
}
@@ -195,9 +325,8 @@
// Have the XSLTProcessor processor object transform "foo.xml" to
// System.out, using the XSLT instructions found in "foo.xsl".
- processor.process( content,
- stylesheet,
- new XSLTResultTarget( pw ) );
+ processor.transform( new SAXSource( content ),
+ new StreamResult( pw ) );
try {
@@ -209,6 +338,10 @@
Log.error( e );
}
return pw.toString();
+ } catch (Exception e) {
+ Log.error( "Invalid SAX Transformer: " + e.toString() );
+ throw new SAXException( "problem in SAX transform: " + e.toString() );
+ }
}
@@ -216,21 +349,57 @@
String stylesheet,
Map params) throws IOException {
+ // Instantiate a TransformerFactory.
+ TransformerFactory tFactory = TransformerFactory.newInstance();
+ // Determine whether the TransformerFactory supports the use of SAXSource
+ // and SAXResult
+ if (!tFactory.getFeature(SAXTransformerFactory.FEATURE) )
+ {
+ Log.error( "SimpleTransform: nobody told you that we need a SAX
Transformer?" );
+ throw new IOException( "Invalid SAX Tranformer" );
+ }
+ try {
+ // Cast the TransformerFactory.
+ SAXTransformerFactory saxTFactory = ((SAXTransformerFactory) tFactory);
+ // Create a ContentHandler to handle parsing of the stylesheet.
+ TemplatesHandler templatesHandler = saxTFactory.newTemplatesHandler();
+
+ // Create an XMLReader and set its ContentHandler.
+ XMLReader reader = XMLReaderFactory.createXMLReader();
+ reader.setContentHandler(templatesHandler);
+
+ // Parse the stylesheet.
+ final InputSource xstyle = new InputSource( JetspeedDiskCache.getInstance()
+ .getEntry( stylesheet
).getReader() );
+ reader.parse( xstyle );
+
+ //Get the Templates object from the ContentHandler.
+ Templates templates = templatesHandler.getTemplates();
+ // Create a ContentHandler to handle parsing of the XML source.
+ TransformerHandler handler
+ = saxTFactory.newTransformerHandler(templates);
- // Have the XSLTProcessorFactory obtain a interface to a
- // new XSLTProcessor object.
- final XSLTProcessor processor = XSLTProcessorFactory.getProcessor( new
- XercesLiaison() );
+ // Reset the XMLReader's ContentHandler.
+ reader.setContentHandler(handler);
- if( params != null )
+ // Set the ContentHandler to also function as a LexicalHandler, which
+ // includes "lexical" events (e.g., comments and CDATA).
+ try {
+ reader.setProperty("http://xml.org/sax/properties/lexical-handler",
handler);
+ } catch( org.xml.sax.SAXNotRecognizedException e ) {}
+
+ final Transformer processor = handler.getTransformer();
+
+ if( params != null )
{
Iterator keys = params.keySet().iterator();
while( keys.hasNext() )
{
String name = (String) keys.next();
String value = (String) params.get(name);
- processor.setStylesheetParam(name,
- processor.createXString(
value) );
+ processor.setParameter(name,
+ value ); //FIXME: maybe we need to
quote again...
+ // was processor.createXString(
value)
}
}
@@ -242,29 +411,34 @@
- final XSLTInputSource xinput = new XSLTInputSource(
JetspeedDiskCache.getInstance().getEntry( content ).getReader() );
- final XSLTInputSource xstyle = new XSLTInputSource(
JetspeedDiskCache.getInstance().getEntry( stylesheet ).getReader() );
+ final SAXSource xinput = new SAXSource( new InputSource(
JetspeedDiskCache.getInstance().getEntry( content ).getReader() ) );
Thread t = new Thread( new Runnable() {
public void run() {
- // Have the XSLTProcessor processor object transform
+ // Have the processor object transform
// "foo.xml" to
// System.out, using the XSLT instructions
//found in "foo.xsl".
- Log.note("Starting SAX thread...");
+ Log.debug("Starting SAX thread...");
try {
- processor.process( xinput,
- xstyle,
- new XSLTResultTarget( pw ) );
+ processor.transform( xinput,
+ new StreamResult( pw ) );
pw.close();
- Log.note("...ending SAX thread.");
+ Log.debug("...ending SAX thread.");
} catch( Exception se) {
- se.printStackTrace();
+ Log.debug("Error in SAXTransform");
+ Log.debug( se.toString() );
}
}
} );
- t.start();
- } catch (java.io.UnsupportedEncodingException uee) {}
+ t.start();
+ } catch (java.io.UnsupportedEncodingException uee) {
+ Log.debug("Need utf-8 encoding to SAXTransform");
+ }
return new InputStreamReader ( pis, "utf-8" );
+ } catch (Exception e) {
+ Log.error( "Invalid SAX Transformer:" + e.toString() );
+ throw new IOException( "problem in SAX transform: " + e.toString() );
+ }
}
}
1.3 +22 -11
jakarta-jetspeed/src/java/org/apache/jetspeed/util/servlet/EcsStylesheetElement.java
Index: EcsStylesheetElement.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/util/servlet/EcsStylesheetElement.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- EcsStylesheetElement.java 2001/03/07 06:50:29 1.2
+++ EcsStylesheetElement.java 2001/05/04 15:51:24 1.3
@@ -56,14 +56,17 @@
import java.io.OutputStream;
import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.IOException;
import org.apache.turbine.util.Log;
import org.apache.ecs.ConcreteElement;
import java.util.*;
-import org.apache.xalan.xslt.*;
+//import org.apache.xalan.xslt.*;
import org.xml.sax.*;
+import org.apache.jetspeed.util.SimpleTransform;
/**
* NOTE: The use of Ecs for aggregating portlet content is deprecated!
@@ -101,7 +104,15 @@
public void output(PrintWriter out)
{
try {
- // Get a new XSLT Processor
+
+ StringReader rdr = new StringReader (SimpleTransform.transform( content_,
stylesheet_, params_ ) );
+ int count = 0;
+ char buff[] = new char[1024];
+ while( (count = rdr.read( buff, 0, buff.length ) ) > 0 ) {
+ out.write( buff, 0, count );
+ }
+
+ /* // Get a new XSLT Processor
XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
// set the parameters for the stylesheet
@@ -116,9 +127,9 @@
}
// process the stylesheet
- processor.process( content_, stylesheet_, new XSLTResultTarget(out) );
+ processor.process( content_, stylesheet_, new XSLTResultTarget(out) ); */
- } catch (SAXException e)
+ } catch (Exception e)
{
String message = "ECSStylesheetElement.output(PrintWriter): error
processing stylesheet" + e.getMessage();
Log.error(message, e);
@@ -129,13 +140,13 @@
/** XML content to be processed. */
-private XSLTInputSource content_;
+private InputSource content_;
/** Parameters to be used by the stylesheet. */
-private Dictionary params_;
+private Map params_;
/** XSLT stylesheet to be used for rendering the content. */
-private XSLTInputSource stylesheet_;
+private InputSource stylesheet_;
/**
* Construct an ECS element that will render a given XML dicument using a given
@@ -145,9 +156,9 @@
* @param stylesheet XSLT stylesheet to be used for processing the content
* @param params parameters for the stylesheet
*/
-public EcsStylesheetElement( XSLTInputSource content,
- XSLTInputSource stylesheet,
- Dictionary params )
+public EcsStylesheetElement( InputSource content,
+ InputSource stylesheet,
+ Map params )
{
content_ = content;
stylesheet_ = stylesheet;
@@ -155,4 +166,4 @@
}
-}
\ No newline at end of file
+}
1.32 +5 -48
jakarta-jetspeed/src/java/org/apache/jetspeed/daemon/impl/FeedDaemon.java
Index: FeedDaemon.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/daemon/impl/FeedDaemon.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- FeedDaemon.java 2001/05/02 10:45:38 1.31
+++ FeedDaemon.java 2001/05/04 15:51:33 1.32
@@ -100,7 +100,7 @@
</p>
@author <A HREF="mailto:[EMAIL PROTECTED]">Kevin A. Burton</A>
-@version $Id: FeedDaemon.java,v 1.31 2001/05/02 10:45:38 raphael Exp $
+@version $Id: FeedDaemon.java,v 1.32 2001/05/04 15:51:33 sgala Exp $
*/
public class FeedDaemon implements Daemon, Initable {
@@ -189,7 +189,7 @@
String name = "feed_"+feeds[i].getName();
- String transformed = "";
+ Reader transformed;
try {
@@ -204,49 +204,15 @@
FileRegistry registry =
(FileRegistry)TurbineServices.getInstance()
.getService(
RegistryService.SERVICE_NAME );
- registry.createFragment( name, new StringReader( transformed ),
true );
+ registry.createFragment( name, transformed , true );
Log.note( "END FEED -> " + url + " -> SUCCESS");
this.setResult( Daemon.RESULT_SUCCESS );
} catch ( Exception e ) {
-
error( e, "FeedDaemon: Couldn't process URL: " + url );
- try {
-
- if ( ! new File( TEMP_DIRECTORY ).exists() ) {
- throw new IOException( TEMP_DIRECTORY + " -> does not
exist" );
- }
-
-
- //determine the temporary filename to use:
- String dest = "";
- int j = 0;
- while(true) {
- dest = TEMP_DIRECTORY +
- System.getProperty("file.separator") +
- TEMP_FILE_KEY +
- Integer.toString( j );
-
- if( ! new File( dest ).exists() ) {
- break;
- }
-
- ++j;
- }
-
-
- error( "FeedDaemon: Dumping URL to disk for further
observation -> " + dest );
-
- new FileOutputStream( dest ).write( transformed.getBytes()
);
-
- } catch (IOException ioe) {
- error( ioe, "Caught Exception while trying to write log:" );
- }
-
-
} catch ( Throwable t ) {
error( t, "FeedDaemon: Couldn't process URL: " + url );
}
@@ -279,7 +245,7 @@
/**
Get the PML for the given URL
*/
- public static final String getEntries( String url ) throws Exception {
+ public static final Reader getEntries( String url ) throws Exception {
//this should be the URL to the original document. Transform
@@ -287,21 +253,12 @@
String stylesheet = JetspeedResources.getString(
JetspeedResources.CONTENTFEEDS_STYLESHEET_URL_KEY );
- DiskCacheEntry ocsEntry =
- JetspeedDiskCache.getInstance().getEntry( stylesheet,
- false );
-
- stylesheet = ocsEntry.getURL();
-
- url = JetspeedDiskCache.getInstance().getEntry( url,
- false ).getURL();
-
Log.note( "FeedDaemon: transforming url: " +
url +
" with stylesheet: " +
stylesheet );
- return SimpleTransform.transform( url, stylesheet );
+ return SimpleTransform.SAXTransform( url, stylesheet, null );
}
1.1 jakarta-jetspeed/lib/xalan-2.0.1.jar
<<Binary file>>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]