You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2005/03/14 09:30:37 UTC
svn commit: r157405 -
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationTemplateFallbackModule.java
Author: andreas
Date: Mon Mar 14 00:30:35 2005
New Revision: 157405
URL: http://svn.apache.org/viewcvs?view=rev&rev=157405
Log:
allow to pass publication ID as parameter to fallback module
Modified:
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationTemplateFallbackModule.java
Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationTemplateFallbackModule.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationTemplateFallbackModule.java?view=diff&r1=157404&r2=157405
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationTemplateFallbackModule.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationTemplateFallbackModule.java Mon Mar 14 00:30:35 2005
@@ -20,13 +20,23 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.excalibur.source.SourceUtil;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.PublicationFactory;
import org.apache.lenya.cms.publication.templating.ExistingSourceResolver;
import org.apache.lenya.cms.publication.templating.PublicationTemplateManager;
/**
- * @version $Id$
+ * This module uses publication templating to resolve the real path for a
+ * resource. The current publication ID can be provided as a parameter:
+ * <code>{fallback:{pub-id}:foo/bar}</code>. This is especially useful for
+ * cocoon:// request which are triggered from non-environment components (e.g.
+ * the scheduler).
+ *
+ * @version $Id: PublicationTemplateFallbackModule.java 157115 2005-03-11
+ * 17:21:14Z andreas $
*/
public class PublicationTemplateFallbackModule extends AbstractPageEnvelopeModule {
@@ -39,22 +49,64 @@
/**
* @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String,
- * org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+ * org.apache.avalon.framework.configuration.Configuration,
+ * java.util.Map)
*/
- public Object getAttribute(String name, Configuration modeConf, Map objectModel)
+ public Object getAttribute(final String name, Configuration modeConf, Map objectModel)
throws ConfigurationException {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Resolving publication template for file [" + name + "]");
+ }
+
String resolvedUri = null;
try {
PublicationTemplateManager templateManager = (PublicationTemplateManager) this.manager
.lookup(PublicationTemplateManager.ROLE);
PublicationFactory factory = PublicationFactory.getInstance(getLogger());
- Publication publication = factory.getPublication(objectModel);
+ Publication publication;
+ String targetUri = null;
+
+ // check if publication ID is provided in attribute name
+ if (name.indexOf(":") > -1) {
+ String[] parts = name.split(":");
+ if (parts.length > 2) {
+ throw new RuntimeException("The attribute may not contain more than one colons!");
+ }
+ String publicationId = parts[0];
+ targetUri = parts[1];
+
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Publication ID provided explicitely: [" + publicationId + "]");
+ }
+
+ SourceResolver resolver = null;
+ Source source = null;
+ try {
+ resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+ source = resolver.resolveURI("context://");
+ String contextPath = SourceUtil.getFile(source).getAbsolutePath();
+ publication = factory.getPublication(publicationId, contextPath);
+ } finally {
+ if (resolver != null) {
+ if (source != null) {
+ resolver.release(source);
+ }
+ this.manager.release(resolver);
+ }
+ }
+ } else {
+ publication = factory.getPublication(objectModel);
+ targetUri = name;
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Publication resolved from request: [" + publication.getId() + "]");
+ }
+ }
templateManager.setup(publication);
ExistingSourceResolver resolver = new ExistingSourceResolver();
- templateManager.visit(name, resolver);
+ templateManager.visit(targetUri, resolver);
resolvedUri = resolver.getURI();
} catch (Exception e) {
@@ -77,7 +129,8 @@
}
/**
- * Returns the base URI for a certain publication including the prefix "lenya".
+ * Returns the base URI for a certain publication including the prefix
+ * "lenya".
* @param publication The publication.
* @return A string.
*/
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org