vgritsenko 2003/03/11 06:42:54
Modified: src/java/org/apache/cocoon/components/xscript
XScriptObject.java XScriptObjectFromURL.java
XScriptObjectInlineXML.java
Log:
Move from deprecated Cocoon source interface to Excalibur source interface
Revision Changes Path
1.2 +29 -13
cocoon-2.1/src/java/org/apache/cocoon/components/xscript/XScriptObject.java
Index: XScriptObject.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/xscript/XScriptObject.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XScriptObject.java 9 Mar 2003 00:09:27 -0000 1.1
+++ XScriptObject.java 11 Mar 2003 14:42:54 -0000 1.2
@@ -51,18 +51,19 @@
package org.apache.cocoon.components.xscript;
import org.apache.avalon.framework.component.Component;
-import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.Composable;
+import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.excalibur.xml.xslt.XSLTProcessor;
import org.apache.excalibur.xml.xslt.XSLTProcessorException;
import org.apache.cocoon.ProcessingException;
-import org.apache.cocoon.environment.Source;
import org.apache.cocoon.xml.EmbeddedXMLPipe;
import org.apache.excalibur.xml.sax.SAXParser;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceValidity;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
@@ -83,6 +84,7 @@
* @since August 4, 2001
*/
public abstract class XScriptObject implements Source, Composable {
+
/**
* The creation date of this <code>XScriptObject</code>.
*/
@@ -106,8 +108,7 @@
((XScriptManagerImpl) this.xscriptManager).register(this);
}
- public void compose(ComponentManager manager)
- throws ComponentException {
+ public void compose(ComponentManager manager) throws ComponentException {
this.componentManager = manager;
}
@@ -134,10 +135,7 @@
= (XSLTProcessor) componentManager.lookup(XSLTProcessor.ROLE);
try {
- transformer.transform(new
org.apache.cocoon.components.source.impl.CocoonToAvalonSource(this.getSystemId(),
this),
- new
org.apache.cocoon.components.source.impl.CocoonToAvalonSource(stylesheet.getSystemId(),
stylesheet),
- params,
- result);
+ transformer.transform(this, stylesheet, params, result);
} finally {
componentManager.release(transformer);
}
@@ -145,7 +143,7 @@
return new XScriptObjectResult(xscriptManager, writer.toString());
} catch (XSLTProcessorException ex) {
throw new ProcessingException(ex);
- } catch (ComponentException ex) {
+ } catch (Exception ex) {
throw new ProcessingException(ex);
}
}
@@ -180,13 +178,31 @@
public abstract long getContentLength();
- public InputSource getInputSource()
- throws ProcessingException, IOException {
+ public InputSource getInputSource() throws ProcessingException, IOException {
InputSource is = new InputSource(getInputStream());
- is.setSystemId(getSystemId());
+ is.setSystemId(getURI());
return is;
}
public void recycle() {
+ }
+
+ public String getScheme() {
+ return "xscript";
+ }
+
+ public void refresh() {
+ }
+
+ public String getMimeType() {
+ return "text/xml";
+ }
+
+ public SourceValidity getValidity() {
+ return null;
+ }
+
+ public boolean exists() {
+ return true;
}
}
1.2 +11 -26
cocoon-2.1/src/java/org/apache/cocoon/components/xscript/XScriptObjectFromURL.java
Index: XScriptObjectFromURL.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/xscript/XScriptObjectFromURL.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XScriptObjectFromURL.java 9 Mar 2003 00:09:27 -0000 1.1
+++ XScriptObjectFromURL.java 11 Mar 2003 14:42:54 -0000 1.2
@@ -50,14 +50,10 @@
*/
package org.apache.cocoon.components.xscript;
-import org.apache.avalon.framework.component.ComponentException;
-
-import org.apache.cocoon.ProcessingException;
-import org.apache.cocoon.components.source.SourceUtil;
-
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceException;
import org.apache.excalibur.source.SourceResolver;
+import org.apache.excalibur.source.SourceNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@@ -70,6 +66,7 @@
* @since August 30, 2001
*/
public class XScriptObjectFromURL extends XScriptObject {
+
/**
* The content obtained from this URL becomes the content of this
* instance.
@@ -77,11 +74,6 @@
String systemId;
/**
- * The content length.
- */
- int contentLength;
-
- /**
* When was the content of the URL last modified.
*/
long lastModified;
@@ -92,19 +84,15 @@
this.systemId = systemId;
}
- public InputStream getInputStream()
- throws ProcessingException, IOException {
+ public InputStream getInputStream() throws IOException, SourceNotFoundException
{
SourceResolver resolver = null;
Source source = null;
try {
resolver = (SourceResolver)
componentManager.lookup(SourceResolver.ROLE);
source = resolver.resolveURI(this.systemId);
-
return source.getInputStream();
- } catch (SourceException ex) {
- throw SourceUtil.handle(ex);
- } catch (ComponentException ex) {
- throw new ProcessingException(ex);
+ } catch (Exception e) {
+ throw new SourceException("Exception during processing of " +
this.systemId, e);
} finally {
if (resolver != null) {
resolver.release(source);
@@ -121,15 +109,12 @@
return 0;
}
- public String getSystemId() {
- // FIXME: generate a real system id to represent this object
- return "xscript:url:" + systemId;
- }
-
- public void recycle() {
- }
-
public String toString() {
return new StringBuffer("XScriptObjectFromURL(systemId =
").append(systemId).append(")").toString();
+ }
+
+ public String getURI() {
+ // FIXME: generate a real system id to represent this object
+ return "xscript:url:" + systemId;
}
}
1.2 +6 -9
cocoon-2.1/src/java/org/apache/cocoon/components/xscript/XScriptObjectInlineXML.java
Index: XScriptObjectInlineXML.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/xscript/XScriptObjectInlineXML.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XScriptObjectInlineXML.java 9 Mar 2003 00:09:27 -0000 1.1
+++ XScriptObjectInlineXML.java 11 Mar 2003 14:42:54 -0000 1.2
@@ -50,8 +50,6 @@
*/
package org.apache.cocoon.components.xscript;
-import org.apache.cocoon.ProcessingException;
-
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
@@ -69,6 +67,7 @@
* @since July 7, 2001
*/
public class XScriptObjectInlineXML extends XScriptObject {
+
StringBuffer stringBuffer;
StringBufferContentHandler streamHandler;
@@ -92,17 +91,15 @@
streamHandler = new StringBufferContentHandler(stringBuffer);
}
- public InputStream getInputStream()
- throws ProcessingException, IOException {
+ public InputStream getInputStream() throws IOException {
// FIXME(VG): This method should never be used because it
// incorrectly converts characters into bytes.
return new StringBufferInputStream(stringBuffer.toString());
}
- public InputSource getInputSource()
- throws ProcessingException, IOException {
+ public InputSource getInputSource() throws IOException {
InputSource is = new InputSource(new StringReader(stringBuffer.toString()));
- is.setSystemId(getSystemId());
+ is.setSystemId(getURI());
return is;
}
@@ -122,7 +119,7 @@
return stringBuffer.toString();
}
- public String getSystemId() {
+ public String getURI() {
// FIXME: Implement a URI scheme to be able to refer to XScript
// variables by URI
return "xscript:inline:" + System.identityHashCode(this);