cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: xml-cocoon2/src/org/apache/cocoon/environment/commandline AbstractCommandLineEnvironment.java
Date Tue, 16 Oct 2001 13:29:49 GMT
cziegeler    01/10/16 06:29:49

  Modified:    src/org/apache/cocoon/environment/commandline
                        AbstractCommandLineEnvironment.java
  Log:
  First version for redirects in cli; this includes a little hack for making the links-view
work
  
  Revision  Changes    Path
  1.9       +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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- AbstractCommandLineEnvironment.java	2001/10/11 07:28:20	1.8
  +++ AbstractCommandLineEnvironment.java	2001/10/16 13:29:49	1.9
  @@ -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:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.8 $ $Date: 2001/10/11 07:28:20 $
  + * @version CVS $Revision: 1.9 $ $Date: 2001/10/16 13:29:49 $
    */
   
   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:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message