cziegeler 2003/10/30 04:38:26
Modified: src/java/org/apache/cocoon/environment
EnvironmentHelper.java EnvironmentInfo.java
src/java/org/apache/cocoon/components
CocoonComponentManager.java
src/java/org/apache/cocoon/environment/commandline
AbstractCommandLineEnvironment.java
Log:
Updating environment handling
Revision Changes Path
1.10 +16 -1
cocoon-2.2/src/java/org/apache/cocoon/environment/EnvironmentHelper.java
Index: EnvironmentHelper.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/environment/EnvironmentHelper.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- EnvironmentHelper.java 30 Oct 2003 12:31:05 -0000 1.9
+++ EnvironmentHelper.java 30 Oct 2003 12:38:26 -0000 1.10
@@ -449,6 +449,21 @@
}
/**
+ * Get the current sitemap component manager.
+ * This method return the current sitemap component manager. This
+ * is the manager that holds all the components of the currently
+ * processed (sub)sitemap.
+ */
+ static public ServiceManager getSitemapServiceManager() {
+ final EnvironmentStack stack =
(EnvironmentStack)environmentStack.get();
+ if ( stack != null && !stack.isEmpty()) {
+ final EnvironmentInfo info = stack.getCurrentInfo();
+ return info.manager;
+ }
+ return null;
+ }
+
+ /**
* Return the processor that is actually processing the request
*/
public static Processor getLastProcessor(Environment env) {
1.2 +3 -3
cocoon-2.2/src/java/org/apache/cocoon/environment/EnvironmentInfo.java
Index: EnvironmentInfo.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/environment/EnvironmentInfo.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EnvironmentInfo.java 29 Oct 2003 18:58:06 -0000 1.1
+++ EnvironmentInfo.java 30 Oct 2003 12:38:26 -0000 1.2
@@ -64,7 +64,7 @@
public final Processor processor;
public final int oldStackCount;
- //public final ServiceManager manager;
+ public final ServiceManager manager;
public final Environment environment;
public EnvironmentInfo(Processor processor,
@@ -73,7 +73,7 @@
Environment environment) {
this.processor = processor;
this.oldStackCount = oldStackCount;
-// this.manager = manager;
+ this.manager = manager;
this.environment = environment;
}
}
1.28 +3 -2
cocoon-2.2/src/java/org/apache/cocoon/components/CocoonComponentManager.java
Index: CocoonComponentManager.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/components/CocoonComponentManager.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- CocoonComponentManager.java 24 Oct 2003 07:29:56 -0000 1.27
+++ CocoonComponentManager.java 30 Oct 2003 12:38:26 -0000 1.28
@@ -53,6 +53,7 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.cocoon.environment.EnvironmentHelper;
import java.util.ArrayList;
import java.util.Iterator;
@@ -161,7 +162,7 @@
* processed (sub)sitemap.
*/
static public ServiceManager getSitemapComponentManager() {
- return RequestLifecycleHelper.getSitemapComponentManager();
+ return EnvironmentHelper.getSitemapServiceManager();
}
}
1.8 +55 -48
cocoon-2.2/src/java/org/apache/cocoon/environment/commandline/AbstractCommandLineEnvironment.java
Index: AbstractCommandLineEnvironment.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/environment/commandline/AbstractCommandLineEnvironment.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- AbstractCommandLineEnvironment.java 30 Oct 2003 12:20:45 -0000
1.7
+++ AbstractCommandLineEnvironment.java 30 Oct 2003 12:38:26 -0000
1.8
@@ -51,13 +51,17 @@
package org.apache.cocoon.environment.commandline;
import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
import org.apache.cocoon.CascadingIOException;
import org.apache.cocoon.Constants;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.components.source.SourceUtil;
import org.apache.cocoon.environment.AbstractEnvironment;
+import org.apache.cocoon.environment.EnvironmentHelper;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceException;
+import org.apache.excalibur.source.SourceResolver;
import org.xml.sax.SAXException;
import java.io.File;
@@ -78,7 +82,6 @@
protected String contentType;
protected int contentLength;
- protected boolean hasRedirected = false;
protected int statusCode;
public AbstractCommandLineEnvironment(String uri,
@@ -96,11 +99,9 @@
/**
* Redirect to the given URL
*/
- public void redirect(String newURL, boolean permanent)
+ public void redirect(String newURL, boolean global, boolean permanent)
throws IOException {
- this.hasRedirected = true;
-
// fix all urls created with request.getScheme()+... etc.
if (newURL.startsWith("cli:/")) {
int pos = newURL.indexOf('/', 6);
@@ -113,52 +114,58 @@
}
// FIXME: this is a hack for the links view
- if (newURL.startsWith("cocoon:")
- && this.getView() != null
- && this.getView().equals(Constants.LINK_VIEW)) {
-
- // 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.outputStream);
-
- Source redirectSource = null;
- try {
- redirectSource = this.sourceResolver.resolveURI(newURL);
- SourceUtil.parse( this.manager, redirectSource, ls);
- } catch (SourceException se) {
- throw new CascadingIOException("SourceException: " + se, se);
- } catch (SAXException se) {
- throw new CascadingIOException("SAXException: " + se, se);
- } catch (ProcessingException pe) {
- throw new CascadingIOException("ProcessingException: " + pe,
pe);
- } finally {
- this.sourceResolver.release( redirectSource );
- }
- } else {
- Source redirectSource = null;
- try {
- redirectSource = this.sourceResolver.resolveURI(newURL);
- InputStream is = redirectSource.getInputStream();
- byte[] buffer = new byte[8192];
- int length = -1;
-
- while ((length = is.read(buffer)) > -1) {
- this.outputStream.write(buffer, 0, length);
+ ServiceManager manager =
EnvironmentHelper.getSitemapServiceManager();
+ SourceResolver resolver = null;
+ try {
+ resolver = (SourceResolver)manager.lookup(SourceResolver.ROLE);
+ if (newURL.startsWith("cocoon:")
+ && this.getView() != null
+ && this.getView().equals(Constants.LINK_VIEW)) {
+
+ // 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.outputStream);
+
+ Source redirectSource = null;
+ try {
+ redirectSource = resolver.resolveURI(newURL);
+ SourceUtil.parse( manager, redirectSource, ls);
+ } catch (SourceException se) {
+ throw new CascadingIOException("SourceException: " + se,
se);
+ } catch (SAXException se) {
+ throw new CascadingIOException("SAXException: " + se,
se);
+ } catch (ProcessingException pe) {
+ throw new CascadingIOException("ProcessingException: " +
pe, pe);
+ } finally {
+ resolver.release( redirectSource );
+ }
+
+ } else {
+ Source redirectSource = null;
+ try {
+ redirectSource = resolver.resolveURI(newURL);
+ InputStream is = redirectSource.getInputStream();
+ byte[] buffer = new byte[8192];
+ int length = -1;
+
+ while ((length = is.read(buffer)) > -1) {
+ this.outputStream.write(buffer, 0, length);
+ }
+ } catch (SourceException se) {
+ throw new CascadingIOException("SourceException: " + se,
se);
+ } finally {
+ resolver.release( redirectSource);
}
- } catch (SourceException se) {
- throw new CascadingIOException("SourceException: " + se, se);
- } finally {
- this.sourceResolver.release( redirectSource);
}
+ } catch (ServiceException se) {
+ throw new CascadingIOException("Unable to get source resolver.",
se);
+ } finally {
+ manager.release(resolver);
}
- }
-
- public boolean hasRedirected() {
- return this.hasRedirected;
}
/**