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/30 13:57:36 UTC
svn commit: r159477 - in lenya/trunk/src:
java/org/apache/lenya/cms/cocoon/components/modules/input/
java/org/apache/lenya/cms/cocoon/source/
java/org/apache/lenya/cms/publication/
java/org/apache/lenya/cms/publication/templating/
java/org/apache/lenya/cms/usecase/ webapp/lenya/pubs/default/
Author: andreas
Date: Wed Mar 30 03:57:32 2005
New Revision: 159477
URL: http://svn.apache.org/viewcvs?view=rev&rev=159477
Log:
added getSelectableHint() to PublicationTemplateManager, added new getPageEnvelope() method to PageEnvelopeFactory
Modified:
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/AbstractPageEnvelopeModule.java
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DublinCoreModule.java
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/FallbackModule.java
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PageEnvelopeModule.java
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationFallbackModule.java
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationTemplateFallbackModule.java
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/SitetreeModule.java
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/UsecaseFallbackModule.java
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/WorkflowModule.java
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/FallbackSourceFactory.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/PageEnvelope.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/PageEnvelopeFactory.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/templating/PublicationTemplateManager.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/templating/PublicationTemplateManagerImpl.java
lenya/trunk/src/java/org/apache/lenya/cms/usecase/UsecaseResolverImpl.java
lenya/trunk/src/webapp/lenya/pubs/default/parameter-doctype.xmap
Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/AbstractPageEnvelopeModule.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/AbstractPageEnvelopeModule.java?view=diff&r1=159476&r2=159477
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/AbstractPageEnvelopeModule.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/AbstractPageEnvelopeModule.java Wed Mar 30 03:57:32 2005
@@ -19,43 +19,73 @@
package org.apache.lenya.cms.cocoon.components.modules.input;
+import java.io.File;
import java.util.Map;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.cocoon.environment.Context;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.lenya.cms.publication.DocumentIdentityMap;
import org.apache.lenya.cms.publication.PageEnvelope;
import org.apache.lenya.cms.publication.PageEnvelopeFactory;
+import org.apache.lenya.util.ServletHelper;
/**
* Abstract superclass for classes which need access to the page envelope.
+ *
+ * The web application URL can be provided in the attribute name, separated by a colon (":").
*/
public abstract class AbstractPageEnvelopeModule extends OperationModule {
-
+
/**
* Get the the page envelope for the given objectModel.
* @param objectModel the objectModel for which the page enevelope is requested.
+ * @param name The attribute name.
* @return a <code>PageEnvelope</code>
* @throws ConfigurationException if the page envelope could not be instantiated.
*/
- protected PageEnvelope getEnvelope(Map objectModel) throws ConfigurationException {
+ protected PageEnvelope getEnvelope(Map objectModel, String name) throws ConfigurationException {
PageEnvelope envelope = null;
+ String webappUrl = null;
+ Request request = ObjectModelHelper.getRequest(objectModel);
+
+ String[] snippets = name.split(":");
+ if (snippets.length > 1) {
+ webappUrl = snippets[1];
+ } else {
+ webappUrl = ServletHelper.getWebappURI(request);
+ }
if (getLogger().isDebugEnabled()) {
- Request request = ObjectModelHelper.getRequest(objectModel);
- getLogger().debug("Resolving page envelope for URL [" + request.getRequestURI() + "]");
+ getLogger().debug("Resolving page envelope for URL [" + webappUrl + "]");
}
+ String contextPath = request.getContextPath();
+ Context context = ObjectModelHelper.getContext(objectModel);
+ String servletContextPath = context.getRealPath("");
+
try {
DocumentIdentityMap map = getUnitOfWork().getIdentityMap();
- envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(map, objectModel);
+ envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(map,
+ contextPath,
+ webappUrl,
+ new File(servletContextPath));
} catch (Exception e) {
throw new ConfigurationException("Resolving page envelope failed: ", e);
}
return envelope;
+ }
+
+ /**
+ * @param name The original attribute name.
+ * @return The attribute name without URL attachment.
+ */
+ protected String getAttributeName(String name) {
+ final String[] snippets = name.split(":");
+ return snippets[0];
}
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DublinCoreModule.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DublinCoreModule.java?view=diff&r1=159476&r2=159477
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DublinCoreModule.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DublinCoreModule.java Wed Mar 30 03:57:32 2005
@@ -47,7 +47,7 @@
throw new ConfigurationException("The attribute [" + name + "] is not supported!");
}
- Document document = getEnvelope(objectModel).getDocument();
+ Document document = getEnvelope(objectModel, name).getDocument();
if (document == null) {
throw new ConfigurationException("There is no document for this page envelope!");
Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/FallbackModule.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/FallbackModule.java?view=diff&r1=159476&r2=159477
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/FallbackModule.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/FallbackModule.java Wed Mar 30 03:57:32 2005
@@ -124,7 +124,7 @@
* @return A string.
* @throws ConfigurationException if an error occurs.
*/
- protected String resolveURI(String path, Map objectModel) throws ConfigurationException {
+ protected String resolveURI(final String path, Map objectModel) throws ConfigurationException {
String resolvedUri = null;
String checkedUris = "\n";
@@ -132,7 +132,7 @@
try {
resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
- String[] _baseUris = getBaseURIs(objectModel);
+ String[] _baseUris = getBaseURIs(objectModel, path);
Source source = null;
int i = 0;
while (resolvedUri == null && i < _baseUris.length) {
@@ -193,10 +193,11 @@
/**
* Returns the base directory URIs in the order they should be traversed.
* @param objectModel The object model.
+ * @param attributeName The name of the module attribute.
* @return An array of strings.
* @throws ConfigurationException if an error occurs.
*/
- protected String[] getBaseURIs(Map objectModel) throws ConfigurationException {
+ protected String[] getBaseURIs(Map objectModel, String attributeName) throws ConfigurationException {
return this.baseUris;
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PageEnvelopeModule.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PageEnvelopeModule.java?view=diff&r1=159476&r2=159477
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PageEnvelopeModule.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PageEnvelopeModule.java Wed Mar 30 03:57:32 2005
@@ -50,14 +50,16 @@
* org.apache.avalon.framework.configuration.Configuration,
* java.util.Map)
*/
- public Object getAttribute(String name, Configuration modeConf, Map objectModel)
+ public Object getAttribute(final String attributeName, Configuration modeConf, Map objectModel)
throws ConfigurationException {
+
+ final String name = getAttributeName(attributeName);
if (!Arrays.asList(PageEnvelope.PARAMETER_NAMES).contains(name)) {
throw new ConfigurationException("The attribute [" + name + "] is not supported!");
}
- PageEnvelope envelope = getEnvelope(objectModel);
+ PageEnvelope envelope = getEnvelope(objectModel, attributeName);
Object value = null;
try {
Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationFallbackModule.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationFallbackModule.java?view=diff&r1=159476&r2=159477
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationFallbackModule.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationFallbackModule.java Wed Mar 30 03:57:32 2005
@@ -36,14 +36,14 @@
}
/**
- * @throws ConfigurationException
- * @see org.apache.lenya.cms.cocoon.components.modules.input.FallbackModule#getBaseURIs(java.util.Map)
+ * @see org.apache.lenya.cms.cocoon.components.modules.input.FallbackModule#getBaseURIs(java.util.Map,
+ * java.lang.String)
*/
- protected String[] getBaseURIs(Map objectModel) throws ConfigurationException {
- String[] superUris = super.getBaseURIs(objectModel);
+ protected String[] getBaseURIs(Map objectModel, String name) throws ConfigurationException {
+ String[] superUris = super.getBaseURIs(objectModel, name);
String[] uris = new String[superUris.length + 1];
- PageEnvelope envelope = getEnvelope(objectModel);
+ PageEnvelope envelope = getEnvelope(objectModel, name);
String publicationId = envelope.getPublication().getId();
String publicationUri = "context://" + Publication.PUBLICATION_PREFIX_URI + "/"
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=159476&r2=159477
==============================================================================
--- 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 Wed Mar 30 03:57:32 2005
@@ -29,14 +29,12 @@
import org.apache.lenya.cms.publication.templating.PublicationTemplateManager;
/**
- * 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).
+ * 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 $
+ * @version $Id$
*/
public class PublicationTemplateFallbackModule extends AbstractPageEnvelopeModule {
@@ -49,8 +47,7 @@
/**
* @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(final String name, Configuration modeConf, Map objectModel)
throws ConfigurationException {
@@ -60,9 +57,10 @@
}
String resolvedUri = null;
+ PublicationTemplateManager templateManager = null;
try {
- PublicationTemplateManager templateManager = (PublicationTemplateManager) this.manager
+ templateManager = (PublicationTemplateManager) this.manager
.lookup(PublicationTemplateManager.ROLE);
PublicationFactory factory = PublicationFactory.getInstance(getLogger());
Publication publication;
@@ -72,15 +70,17 @@
if (name.indexOf(":") > -1) {
String[] parts = name.split(":");
if (parts.length > 2) {
- throw new RuntimeException("The attribute may not contain more than one colons!");
+ 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 + "]");
+ getLogger().debug("Publication ID provided explicitely: [" + publicationId
+ + "]");
}
-
+
SourceResolver resolver = null;
Source source = null;
try {
@@ -100,19 +100,22 @@
publication = factory.getPublication(objectModel);
targetUri = name;
if (getLogger().isDebugEnabled()) {
- getLogger().debug("Publication resolved from request: [" + publication.getId() + "]");
+ getLogger().debug("Publication resolved from request: [" + publication.getId()
+ + "]");
}
}
- templateManager.setup(publication);
-
ExistingSourceResolver resolver = new ExistingSourceResolver();
- templateManager.visit(targetUri, resolver);
+ templateManager.visit(publication, targetUri, resolver);
resolvedUri = resolver.getURI();
} catch (Exception e) {
String message = "Resolving path [" + name + "] failed: ";
getLogger().error(message, e);
throw new ConfigurationException(message, e);
+ } finally {
+ if (templateManager != null) {
+ this.manager.release(templateManager);
+ }
}
return resolvedUri;
}
@@ -129,8 +132,7 @@
}
/**
- * 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.
*/
Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/SitetreeModule.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/SitetreeModule.java?view=diff&r1=159476&r2=159477
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/SitetreeModule.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/SitetreeModule.java Wed Mar 30 03:57:32 2005
@@ -67,7 +67,7 @@
Object value = null;
try {
- PageEnvelope envelope = getEnvelope(objectModel);
+ PageEnvelope envelope = getEnvelope(objectModel, name);
Publication publication = envelope.getPublication();
DocumentIdentityMap map = new DocumentIdentityMap();
TreeSiteManager _manager = (TreeSiteManager) publication.getSiteManager();
Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/UsecaseFallbackModule.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/UsecaseFallbackModule.java?view=diff&r1=159476&r2=159477
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/UsecaseFallbackModule.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/UsecaseFallbackModule.java Wed Mar 30 03:57:32 2005
@@ -58,11 +58,10 @@
try {
PublicationTemplateManager templateManager = (PublicationTemplateManager) this._manager
.lookup(PublicationTemplateManager.ROLE);
- PageEnvelope envelope = getEnvelope(objectModel);
- templateManager.setup(envelope.getPublication());
+ PageEnvelope envelope = getEnvelope(objectModel, name);
ExistingUsecaseResolver resolver = new ExistingUsecaseResolver(name);
- templateManager.visit(resolver);
+ templateManager.visit(envelope.getPublication(), resolver);
Publication publication = resolver.getPublication();
if (publication != null) {
Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/WorkflowModule.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/WorkflowModule.java?view=diff&r1=159476&r2=159477
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/WorkflowModule.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/WorkflowModule.java Wed Mar 30 03:57:32 2005
@@ -63,7 +63,7 @@
WorkflowResolver resolver = null;
try {
- PageEnvelope envelope = getEnvelope(objectModel);
+ PageEnvelope envelope = getEnvelope(objectModel, name);
Document document = envelope.getDocument();
if (document != null) {
resolver = (WorkflowResolver) this.manager.lookup(WorkflowResolver.ROLE);
Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/FallbackSourceFactory.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/FallbackSourceFactory.java?view=diff&r1=159476&r2=159477
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/FallbackSourceFactory.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/FallbackSourceFactory.java Wed Mar 30 03:57:32 2005
@@ -109,9 +109,8 @@
Publication pub = factory.getPublication(publicationId, contextPath);
if (pub.exists()) {
- templateManager.setup(pub);
ExistingSourceResolver resolver = new ExistingSourceResolver();
- templateManager.visit(path, resolver);
+ templateManager.visit(pub, path, resolver);
resolvedUri = resolver.getURI();
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java?view=diff&r1=159476&r2=159477
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java Wed Mar 30 03:57:32 2005
@@ -97,9 +97,6 @@
if (!document.exists()) {
throw new PublicationException("Document [" + document + "] does not exist!");
}
- Publication publication = document.getPublication();
- publication.getSiteManager().delete(document);
- deleteDocumentSource(document);
ResourcesManager resourcesManager = document.getResourcesManager();
resourcesManager.deleteResources();
@@ -115,6 +112,10 @@
this.manager.release(workflowManager);
}
}
+
+ Publication publication = document.getPublication();
+ publication.getSiteManager().delete(document);
+ deleteDocumentSource(document);
}
/**
@@ -124,7 +125,6 @@
public void move(Document sourceDocument, Document destinationDocument)
throws PublicationException {
copy(sourceDocument, destinationDocument);
- delete(sourceDocument);
ResourcesManager resourcesManager = sourceDocument.getResourcesManager();
WorkflowManager workflowManager = null;
@@ -141,6 +141,8 @@
this.manager.release(workflowManager);
}
}
+
+ delete(sourceDocument);
}
/**
@@ -451,7 +453,6 @@
DocumentIdentityMap identityMap = document.getIdentityMap();
String[] languages = document.getLanguages();
for (int i = 0; i < languages.length; i++) {
-
Document version = identityMap.getFactory().getLanguageVersion(document, languages[i]);
delete(version);
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/PageEnvelope.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/PageEnvelope.java?view=diff&r1=159476&r2=159477
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/PageEnvelope.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/PageEnvelope.java Wed Mar 30 03:57:32 2005
@@ -19,13 +19,11 @@
package org.apache.lenya.cms.publication;
-import java.util.Map;
+import java.io.File;
import org.apache.avalon.framework.logger.ConsoleLogger;
-import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.lenya.cms.rc.RCEnvironment;
-import org.apache.lenya.util.ServletHelper;
/**
* A page envelope carries a set of information that are needed during the presentation of a
@@ -160,15 +158,21 @@
/**
* Creates a page envelope from an object model.
* @param map The identity map to use.
- * @param objectModel The object model.
+ * @param contextPath The servlet context prefix.
+ * @param webappUrl The web application URL.
+ * @param servletContext The servlet context directory.
* @throws PageEnvelopeException when something went wrong.
*/
- public PageEnvelope(DocumentIdentityMap map, Map objectModel) throws PageEnvelopeException {
+ public PageEnvelope(DocumentIdentityMap map, String contextPath, String webappUrl,
+ File servletContext) throws PageEnvelopeException {
this.identityMap = map;
- this.objectModel = objectModel;
+ this.context = contextPath;
+ this.webappUrl = webappUrl;
+ this.servletContext = servletContext;
}
- private Map objectModel;
+ private String webappUrl;
+ private File servletContext;
private DocumentIdentityMap identityMap;
@@ -198,16 +202,14 @@
*/
public Publication getPublication() {
if (this.publication == null) {
- Request request = ObjectModelHelper.getRequest(this.objectModel);
- String webappURI = ServletHelper.getWebappURI(request);
try {
Publication pub = PublicationFactory.getInstance(new ConsoleLogger())
- .getPublication(this.objectModel);
+ .getPublication(this.webappUrl, this.servletContext);
if (pub.exists()) {
this.publication = pub;
- if (getIdentityMap().getFactory().isDocument(publication, webappURI)) {
+ if (getIdentityMap().getFactory().isDocument(publication, this.webappUrl)) {
Document _document = getIdentityMap().getFactory().getFromURL(publication,
- webappURI);
+ this.webappUrl);
setDocument(_document);
}
}
@@ -223,9 +225,7 @@
*/
public String getArea() {
if (this.area == null) {
- Request request = ObjectModelHelper.getRequest(this.objectModel);
- String webappURI = ServletHelper.getWebappURI(request);
- URLInformation info = new URLInformation(webappURI);
+ URLInformation info = new URLInformation(this.webappUrl);
this.area = info.getArea();
}
return this.area;
@@ -246,13 +246,6 @@
* @return a <code>String</code> value
*/
public String getContext() {
- if (this.context == null) {
- Request request = ObjectModelHelper.getRequest(this.objectModel);
- this.context = request.getContextPath();
- if (this.context == null) {
- this.context = "";
- }
- }
return this.context;
}
@@ -280,13 +273,10 @@
*/
public Document getDocument() {
if (this.document == null) {
- Request request = ObjectModelHelper.getRequest(this.objectModel);
- String webappUrl = ServletHelper.getWebappURI(request);
-
DocumentFactory factory = getIdentityMap().getFactory();
try {
- if (factory.isDocument(getPublication(), webappUrl)) {
- this.document = getIdentityMap().getFromURL(getPublication(), webappUrl);
+ if (factory.isDocument(getPublication(), this.webappUrl)) {
+ this.document = getIdentityMap().getFromURL(getPublication(), this.webappUrl);
}
} catch (final DocumentBuildException e) {
throw new RuntimeException(e);
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/PageEnvelopeFactory.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/PageEnvelopeFactory.java?view=diff&r1=159476&r2=159477
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/PageEnvelopeFactory.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/PageEnvelopeFactory.java Wed Mar 30 03:57:32 2005
@@ -19,8 +19,14 @@
package org.apache.lenya.cms.publication;
+import java.io.File;
import java.util.Map;
+import org.apache.cocoon.environment.Context;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.lenya.util.ServletHelper;
+
/**
* Common entry point for creating page envelopes.
*/
@@ -29,7 +35,7 @@
* Creates a new PageEnvelopeFactory.
*/
protected PageEnvelopeFactory() {
- // do nothing
+ // do nothing
}
private static PageEnvelopeFactory instance;
@@ -54,7 +60,26 @@
*/
public PageEnvelope getPageEnvelope(DocumentIdentityMap map, Map objectModel)
throws PageEnvelopeException {
- PageEnvelope envelope = new PageEnvelope(map, objectModel);
+ Request request = ObjectModelHelper.getRequest(objectModel);
+ String contextPath = request.getContextPath();
+ Context context = ObjectModelHelper.getContext(objectModel);
+ String webappUrl = ServletHelper.getWebappURI(request);
+ String servletContextPath = context.getRealPath("");
+ return getPageEnvelope(map, contextPath, webappUrl, new File(servletContextPath));
+ }
+
+ /**
+ * Creates a page envelope.
+ * @param map The document identity map to use.
+ * @param contextPath The servlet context prefix.
+ * @param webappUrl The web application URL.
+ * @param servletContext The servlet context directory.
+ * @return A page envelope.
+ * @throws PageEnvelopeException if something went wrong.
+ */
+ public PageEnvelope getPageEnvelope(DocumentIdentityMap map, String contextPath,
+ String webappUrl, File servletContext) throws PageEnvelopeException {
+ PageEnvelope envelope = new PageEnvelope(map, contextPath, webappUrl, servletContext);
return envelope;
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/templating/PublicationTemplateManager.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/templating/PublicationTemplateManager.java?view=diff&r1=159476&r2=159477
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/templating/PublicationTemplateManager.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/templating/PublicationTemplateManager.java Wed Mar 30 03:57:32 2005
@@ -16,7 +16,8 @@
*/
package org.apache.lenya.cms.publication.templating;
-import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceSelector;
import org.apache.lenya.cms.publication.Publication;
/**
@@ -41,27 +42,32 @@
String ROLE = PublicationTemplateManager.class.getName();
/**
- * Hands to publication to the template manager.
- * @param publication A publication.
- * @throws ConfigurationException if setting up fails.
- */
- void setup(Publication publication) throws ConfigurationException;
-
- /**
* <p>
- * Visits the versions of a source in traversing order.
- * The source doesn't have to exist to be visited.
+ * Visits the versions of a source in traversing order. The source doesn't have to exist to be
+ * visited.
* </p>
+ * @param publication The original publication.
* @param path The path of the source, relatively to the publication directory.
* @param visitor The visitor.
*/
- void visit(String path, SourceVisitor visitor);
-
+ void visit(Publication publication, String path, SourceVisitor visitor);
+
/**
- * Visits the publications in traversing order.
- * The core is not visited.
+ * Visits the publications in traversing order. The core is not visited.
+ * @param publication The original publication.
* @param visitor The visitor.
*/
- void visit(PublicationVisitor visitor);
-
+ void visit(Publication publication, PublicationVisitor visitor);
+
+ /**
+ * Returns the hint for the publiation which declares a service.
+ * @param publication The original publication.
+ * @param selector The service selector.
+ * @param originalHint The original hint.
+ * @return An object.
+ * @throws ServiceException if an error occurs.
+ */
+ Object getSelectableHint(Publication publication, ServiceSelector selector, String originalHint)
+ throws ServiceException;
+
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/templating/PublicationTemplateManagerImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/templating/PublicationTemplateManagerImpl.java?view=diff&r1=159476&r2=159477
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/templating/PublicationTemplateManagerImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/templating/PublicationTemplateManagerImpl.java Wed Mar 30 03:57:32 2005
@@ -20,10 +20,11 @@
import java.util.ArrayList;
import java.util.List;
-import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.ServiceSelector;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceResolver;
@@ -32,15 +33,11 @@
/**
* Manager for publication templates.
*
- * @version $Id: PublicationTemplateManagerImpl.java 123348 2004-12-25 22:49:57Z
- * gregor $
+ * @version $Id$
*/
public class PublicationTemplateManagerImpl extends AbstractLogEnabled implements
PublicationTemplateManager, Serviceable {
- private Publication publication;
-
-
/**
* Ctor.
*/
@@ -48,23 +45,16 @@
}
/**
- * @see org.apache.lenya.cms.publication.templating.PublicationTemplateManager#setup(org.apache.lenya.cms.publication.Publication)
+ * @see org.apache.lenya.cms.publication.templating.PublicationTemplateManager#visit(org.apache.lenya.cms.publication.Publication,
+ * java.lang.String, org.apache.lenya.cms.publication.templating.SourceVisitor)
*/
- public void setup(Publication _publication) throws ConfigurationException {
- this.publication = _publication;
- }
-
- /**
- * @see org.apache.lenya.cms.publication.templating.PublicationTemplateManager#visit(java.lang.String,
- * org.apache.lenya.cms.publication.templating.SourceVisitor)
- */
- public void visit(String path, SourceVisitor visitor) {
+ public void visit(Publication publication, String path, SourceVisitor visitor) {
SourceResolver resolver = null;
try {
resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
- String[] baseUris = getBaseURIs();
+ String[] baseUris = getBaseURIs(publication);
for (int i = 0; i < baseUris.length; i++) {
String uri = baseUris[i] + "/" + path;
@@ -107,21 +97,19 @@
/**
* Returns the publication.
- * @return A publication.
+ * @return A publication. protected Publication getPublication1() { return this.publication; }
*/
- protected Publication getPublication() {
- return this.publication;
- }
/**
* Returns the base URIs in traversing order.
+ * @param publication The original publication.
* @return An array of strings.
*/
- protected String[] getBaseURIs() {
+ protected String[] getBaseURIs(Publication publication) {
List uris = new ArrayList();
- Publication[] publications = getPublications();
+ Publication[] publications = getPublications(publication);
for (int i = 0; i < publications.length; i++) {
uris.add(getBaseURI(publications[i]));
}
@@ -144,14 +132,15 @@
}
/**
- * @see org.apache.lenya.cms.publication.templating.PublicationTemplateManager#visit(org.apache.lenya.cms.publication.templating.PublicationVisitor)
+ * @see org.apache.lenya.cms.publication.templating.PublicationTemplateManager#visit(org.apache.lenya.cms.publication.Publication,
+ * org.apache.lenya.cms.publication.templating.PublicationVisitor)
*/
- public void visit(PublicationVisitor visitor) {
+ public void visit(Publication publication, PublicationVisitor visitor) {
SourceResolver resolver = null;
try {
resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
- Publication[] publications = getPublications();
+ Publication[] publications = getPublications(publication);
for (int i = 0; i < publications.length; i++) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Visiting publication [" + publications[i] + "]");
@@ -171,20 +160,98 @@
/**
* Returns the publications in traversing order.
+ * @param publication The original publication.
* @return An array of strings.
*/
- protected Publication[] getPublications() {
+ protected Publication[] getPublications(Publication publication) {
List publications = new ArrayList();
- publications.add(getPublication());
+ publications.add(publication);
- Publication[] templates = getPublication().getTemplates();
+ Publication[] templates = publication.getTemplates();
for (int i = 0; i < templates.length; i++) {
publications.add(templates[i]);
}
return (Publication[]) publications.toArray(new Publication[publications.size()]);
}
-
+
+ /**
+ * @see org.apache.lenya.cms.publication.templating.PublicationTemplateManager#getSelectableHint(org.apache.lenya.cms.publication.Publication,
+ * org.apache.avalon.framework.service.ServiceSelector, java.lang.String)
+ */
+ public Object getSelectableHint(Publication publication, ServiceSelector selector,
+ final String originalHint) throws ServiceException {
+ PublicationTemplateManager templateManager = null;
+ Object selectableHint = null;
+
+ try {
+ ExistingServiceVisitor resolver = new ExistingServiceVisitor(selector, originalHint,
+ getLogger());
+ visit(publication, resolver);
+ selectableHint = resolver.getSelectableHint();
+ if (selectableHint == null) {
+ selectableHint = originalHint;
+ }
+
+ } catch (Exception e) {
+ String message = "Resolving hint [" + originalHint + "] failed: ";
+ getLogger().error(message, e);
+ throw new RuntimeException(message, e);
+ } finally {
+ if (templateManager != null) {
+ this.manager.release(templateManager);
+ }
+ }
+ return selectableHint;
+ }
+
+ /**
+ * Searches for a declared service of the form "publicationId/service".
+ */
+ public class ExistingServiceVisitor implements PublicationVisitor {
+
+ /**
+ * Ctor.
+ * @param selector The service selector to use.
+ * @param hint The hint to check.
+ * @param logger The logger.
+ */
+ public ExistingServiceVisitor(ServiceSelector selector, Object hint, Logger logger) {
+ this.selector = selector;
+ this.hint = hint;
+ this.logger = logger;
+ }
+
+ private ServiceSelector selector;
+ private Object hint;
+ private Object selectableHint = null;
+ private Logger logger;
+
+ /**
+ * @see org.apache.lenya.cms.publication.templating.PublicationVisitor#visit(org.apache.lenya.cms.publication.Publication)
+ */
+ public void visit(Publication publication) {
+ String publicationHint = publication.getId() + "/" + this.hint;
+ boolean success = false;
+ if (this.selector.isSelectable(publicationHint)) {
+ this.selectableHint = publicationHint;
+ success = true;
+ }
+ if (this.logger.isDebugEnabled()) {
+ this.logger.debug("Checking hint [" + publicationHint + "]: " + success);
+ }
+ }
+
+ /**
+ * @return The publication hint that could be selected or <code>null</code> if no hint
+ * could be selected.
+ */
+ public Object getSelectableHint() {
+ return this.selectableHint;
+ }
+
+ }
+
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/usecase/UsecaseResolverImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/usecase/UsecaseResolverImpl.java?view=diff&r1=159476&r2=159477
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/usecase/UsecaseResolverImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/usecase/UsecaseResolverImpl.java Wed Mar 30 03:57:32 2005
@@ -30,6 +30,7 @@
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.PublicationFactory;
import org.apache.lenya.cms.publication.URLInformation;
+import org.apache.lenya.cms.publication.templating.PublicationTemplateManager;
/**
* Usecase resolver implementation.
@@ -104,13 +105,30 @@
* @param webappUrl The web application URL.
* @param name The plain usecase name.
* @return A string.
+ * @throws ServiceException if an error occurs.
*/
- protected String getPublicationUsecaseName(String webappUrl, final String name) {
+ protected String getUsecaseName(String webappUrl, final String name) throws ServiceException {
String newName = null;
+
Publication publication = getPublication(webappUrl);
if (publication != null) {
- newName = publication.getId() + "/" + name;
+ PublicationTemplateManager templateManager = null;
+ try {
+ templateManager = (PublicationTemplateManager) this.manager
+ .lookup(PublicationTemplateManager.ROLE);
+ newName = (String) templateManager.getSelectableHint(publication,
+ this.selector,
+ name);
+ } finally {
+ if (templateManager != null) {
+ this.manager.release(templateManager);
+ }
+ }
+ }
+ else {
+ newName = name;
}
+
return newName;
}
@@ -159,15 +177,8 @@
* @see org.apache.lenya.cms.usecase.UsecaseResolver#resolve(java.lang.String, java.lang.String)
*/
public Usecase resolve(String webappUrl, String name) throws ServiceException {
- Usecase usecase = null;
- String publicationUsecaseName = getPublicationUsecaseName(webappUrl, name);
- if (publicationUsecaseName != null && this.selector.isSelectable(publicationUsecaseName)) {
- usecase = (Usecase) this.selector.select(publicationUsecaseName);
- } else {
- usecase = (Usecase) this.selector.select(name);
-
- }
- return usecase;
+ Object usecaseName = getUsecaseName(webappUrl, name);
+ return (Usecase) this.selector.select(usecaseName);
}
/**
@@ -175,9 +186,8 @@
* java.lang.String)
*/
public boolean isRegistered(String webappUrl, String name) throws ServiceException {
- String pubName = getPublicationUsecaseName(webappUrl, name);
- return (pubName != null && this.selector.isSelectable(pubName))
- || this.selector.isSelectable(name);
+ String usecaseName = getUsecaseName(webappUrl, name);
+ return this.selector.isSelectable(usecaseName);
}
}
Modified: lenya/trunk/src/webapp/lenya/pubs/default/parameter-doctype.xmap
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/default/parameter-doctype.xmap?view=diff&r1=159476&r2=159477
==============================================================================
--- lenya/trunk/src/webapp/lenya/pubs/default/parameter-doctype.xmap (original)
+++ lenya/trunk/src/webapp/lenya/pubs/default/parameter-doctype.xmap Wed Mar 30 03:57:32 2005
@@ -47,7 +47,7 @@
<map:pipeline>
<!-- {area}/{uri} -->
<map:match pattern="*/**.html">
- <map:act type="sourcetype" src="fallback://content/{1}/{page-envelope:document-path}">
+ <map:act type="sourcetype" src="fallback://content/{1}/{page-envelope:document-path:/{page-envelope:publication-id}/{1}/{2}.html}">
<map:generate type="serverpages" src="../../config/parameters/default.xsp">
<map:parameter name="value" value="{sourcetype}"/>
</map:generate>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org