cziegeler 01/10/16 06:30:05
Modified: src/org/apache/cocoon/environment/commandline Tag:
cocoon_20_branch
AbstractCommandLineEnvironment.java
Log:
First version for redirects in cli; this includes a little hack for making
the links-view work
Revision Changes Path
No revision
No revision
1.1.1.1.2.7 +57 -3
xml-cocoon2/src/org/apache/cocoon/environment/commandline/AbstractCommandLineEnvironment.java
Index: AbstractCommandLineEnvironment.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/environment/commandline/AbstractCommandLineEnvironment.java,v
retrieving revision 1.1.1.1.2.6
retrieving revision 1.1.1.1.2.7
diff -u -r1.1.1.1.2.6 -r1.1.1.1.2.7
--- AbstractCommandLineEnvironment.java 2001/10/11 08:56:10
1.1.1.1.2.6
+++ AbstractCommandLineEnvironment.java 2001/10/16 13:30:05
1.1.1.1.2.7
@@ -8,11 +8,17 @@
package org.apache.cocoon.environment.commandline;
+import org.apache.cocoon.Constants;
+import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.environment.AbstractEnvironment;
import org.apache.cocoon.environment.Redirector;
+import org.apache.cocoon.environment.Session;
+import org.apache.cocoon.environment.Source;
import org.apache.log.Logger;
+import org.xml.sax.SAXException;
import java.io.File;
+import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.MalformedURLException;
@@ -21,7 +27,7 @@
* This environment is used to save the requested file to disk.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
- * @version CVS $Revision: 1.1.1.1.2.6 $ $Date: 2001/10/11 08:56:10 $
+ * @version CVS $Revision: 1.1.1.1.2.7 $ $Date: 2001/10/16 13:30:05 $
*/
public abstract class AbstractCommandLineEnvironment
@@ -46,8 +52,56 @@
/**
* Redirect the client to a new URL
*/
- public void redirect(boolean sessionmode, String newURL) throws
IOException {
- throw new RuntimeException (this.getClass().getName() +
".redirect(String url) method not yet implemented!");
+ public void redirect(boolean sessionmode, String newURL)
+ throws IOException {
+ if (sessionmode == true) {
+ CommandLineSession.getSession(true);
+ }
+ // fix all urls created with request.getScheme()+... etc.
+ if (newURL.startsWith("cli:/") == true) {
+ int pos = newURL.indexOf('/', 6);
+ newURL = newURL.substring(pos+1);
+ }
+ // fix all relative urls to use to cocoon: protocol
+ if (newURL.indexOf(":") == -1) {
+ newURL = "cocoon:/" + newURL;
+ }
+ // FIXME: this is a hack for the links view
+ if (newURL.startsWith("cocoon:") == true
+ && this.getView() != null
+ && this.getView().equals(Constants.LINK_VIEW) == true) {
+
+ // as the internal cocoon protocol is used the last
+ // serializer is removed from it! And therefore
+ // the LinkSerializer is not used.
+ // so we create one without Avalon...
+ org.apache.cocoon.serialization.LinkSerializer ls =
+ new org.apache.cocoon.serialization.LinkSerializer();
+ ls.setOutputStream(this.stream);
+ try {
+ final Source redirectSource = this.resolve(newURL);
+ redirectSource.toSAX(ls);
+ } catch (SAXException se) {
+ throw new IOException("SAXException: " + se);
+ } catch (ProcessingException pe) {
+ throw new IOException("ProcessingException: " + pe);
+ }
+ } else {
+ try {
+ final Source redirectSource = this.resolve(newURL);
+ InputStream is = redirectSource.getInputStream();
+ byte[] buffer = new byte[8192];
+ int length = -1;
+
+ while ((length = is.read(buffer)) > -1) {
+ this.stream.write(buffer, 0, length);
+ }
+ } catch (SAXException se) {
+ throw new IOException("SAXException: " + se);
+ } catch (ProcessingException pe) {
+ throw new IOException("ProcessingException: " + pe);
+ }
+ }
}
/**
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]