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/17 10:57:23 UTC
svn commit: r157930 - in lenya/trunk/src:
java/org/apache/lenya/cms/publication/
java/org/apache/lenya/cms/publication/templating/
java/org/apache/lenya/cms/publication/usecases/
webapp/lenya/pubs/default/config/
Author: andreas
Date: Thu Mar 17 01:57:19 2005
New Revision: 157930
URL: http://svn.apache.org/viewcvs?view=rev&rev=157930
Log:
template managment moved to Publication, lazy loading for PageEnvelope fields
Modified:
lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocumentBuilder.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentFactory.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeResolverImpl.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/PageEnvelope.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationImpl.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/publication/usecases/CreatePublicationFromTemplate.java
lenya/trunk/src/webapp/lenya/pubs/default/config/publication.xconf
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocumentBuilder.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocumentBuilder.java?view=diff&r1=157929&r2=157930
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocumentBuilder.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocumentBuilder.java Thu Mar 17 01:57:19 2005
@@ -76,8 +76,8 @@
}
/**
- * Creates a new document object. Override this method to create specific
- * document objects, e.g., for different document IDs.
+ * Creates a new document object. Override this method to create specific document objects,
+ * e.g., for different document IDs.
* @param map The identity map.
* @param publication The publication.
* @param area The area.
@@ -93,8 +93,8 @@
}
/**
- * Removes all "."-separated extensions from a URL (e.g.,
- * <code>/foo.print.html</code> is transformed to <code>/foo</code>).
+ * Removes all "."-separated extensions from a URL (e.g., <code>/foo.print.html</code> is
+ * transformed to <code>/foo</code>).
* @param url The URL to trim.
* @return A URL string.
*/
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentFactory.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentFactory.java?view=diff&r1=157929&r2=157930
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentFactory.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentFactory.java Thu Mar 17 01:57:19 2005
@@ -48,7 +48,12 @@
*/
public boolean isDocument(Publication publication, String webappUrl)
throws DocumentBuildException {
- return publication.getDocumentBuilder().isDocument(publication, webappUrl);
+ if (publication.exists()) {
+ return publication.getDocumentBuilder().isDocument(publication, webappUrl);
+ }
+ else {
+ return false;
+ }
}
/**
@@ -133,8 +138,7 @@
/**
* Returns the parent of a document.
* @param document A document.
- * @param defaultDocumentId The document ID to use if the document has no
- * parent.
+ * @param defaultDocumentId The document ID to use if the document has no parent.
* @return A document.
* @throws DocumentBuildException if an error occurs.
*/
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeResolverImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeResolverImpl.java?view=diff&r1=157929&r2=157930
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeResolverImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeResolverImpl.java Thu Mar 17 01:57:19 2005
@@ -27,7 +27,6 @@
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.cocoon.components.ContextHelper;
-import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.lenya.cms.cocoon.uriparameterizer.URIParameterizer;
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=157929&r2=157930
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/PageEnvelope.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/PageEnvelope.java Thu Mar 17 01:57:19 2005
@@ -28,8 +28,8 @@
import org.apache.lenya.util.ServletHelper;
/**
- * A page envelope carries a set of information that are needed during the
- * presentation of a document.
+ * A page envelope carries a set of information that are needed during the presentation of a
+ * document.
*/
public class PageEnvelope {
/**
@@ -54,8 +54,8 @@
*/
public static final String PUBLICATION = "publication";
/**
- * <code>PUBLICATION_LANGUAGES_CSV</code> A list of the publication's
- * languages, comma-seperated
+ * <code>PUBLICATION_LANGUAGES_CSV</code> A list of the publication's languages,
+ * comma-seperated
*/
public static final String PUBLICATION_LANGUAGES_CSV = "publication-languages-csv";
/**
@@ -95,8 +95,8 @@
*/
public static final String DOCUMENT_URL = "document-url";
/**
- * <code>DOCUMENT_URL_WITHOUT_LANGUAGE</code> The URL of the current
- * document without a language extension.
+ * <code>DOCUMENT_URL_WITHOUT_LANGUAGE</code> The URL of the current document without a
+ * language extension.
*/
public static final String DOCUMENT_URL_WITHOUT_LANGUAGE = "document-url-without-language";
/**
@@ -116,23 +116,21 @@
*/
public static final String DOCUMENT_LANGUAGE = "document-language";
/**
- * <code>DOCUMENT_LANGUAGES</code> The languages the current document is
- * available in
+ * <code>DOCUMENT_LANGUAGES</code> The languages the current document is available in
*/
public static final String DOCUMENT_LANGUAGES = "document-languages";
/**
- * <code>DOCUMENT_LANGUAGES_CSV</code> The languages the current document
- * is available in, comma-seperated
+ * <code>DOCUMENT_LANGUAGES_CSV</code> The languages the current document is available in,
+ * comma-seperated
*/
public static final String DOCUMENT_LANGUAGES_CSV = "document-languages-csv";
/**
- * <code>DOCUMENT_LASTMODIFIED</code> The last modified date of the
- * current document
+ * <code>DOCUMENT_LASTMODIFIED</code> The last modified date of the current document
*/
public static final String DOCUMENT_LASTMODIFIED = "document-lastmodified";
/**
- * <code>BREADCRUMB_PREFIX</code> The breadcrumb prefix of the
- * publication, used for navigation
+ * <code>BREADCRUMB_PREFIX</code> The breadcrumb prefix of the publication, used for
+ * navigation
*/
public static final String BREADCRUMB_PREFIX = "breadcrumb-prefix";
/**
@@ -151,7 +149,7 @@
private String context;
private String area;
private Publication publication;
-
+
/**
* Constructor.
*/
@@ -167,33 +165,11 @@
*/
public PageEnvelope(DocumentIdentityMap map, Map objectModel) throws PageEnvelopeException {
this.identityMap = map;
- Request request = ObjectModelHelper.getRequest(objectModel);
- String webappURI;
- try {
-
- this.context = request.getContextPath();
- if (this.context == null) {
- this.context = "";
- }
-
- webappURI = ServletHelper.getWebappURI(request);
-
- URLInformation info = new URLInformation(webappURI);
- this.area = info.getArea();
-
- this.publication = PublicationFactory.getInstance(new ConsoleLogger())
- .getPublication(objectModel);
-
- if (map.getFactory().isDocument(publication, webappURI)) {
- Document _document = map.getFactory().getFromURL(publication, webappURI);
- setDocument(_document);
- }
-
- } catch (Exception e) {
- throw new PageEnvelopeException(e);
- }
+ this.objectModel = objectModel;
}
+ private Map objectModel;
+
private DocumentIdentityMap identityMap;
/**
@@ -221,6 +197,24 @@
* @return a <code>Publication</code> value
*/
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);
+ if (pub.exists()) {
+ this.publication = pub;
+ if (getIdentityMap().getFactory().isDocument(publication, webappURI)) {
+ Document _document = getIdentityMap().getFactory().getFromURL(publication,
+ webappURI);
+ setDocument(_document);
+ }
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
return this.publication;
}
@@ -228,6 +222,12 @@
* @return The current area.
*/
public String getArea() {
+ if (this.area == null) {
+ Request request = ObjectModelHelper.getRequest(this.objectModel);
+ String webappURI = ServletHelper.getWebappURI(request);
+ URLInformation info = new URLInformation(webappURI);
+ this.area = info.getArea();
+ }
return this.area;
}
@@ -246,6 +246,13 @@
* @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;
}
@@ -268,11 +275,23 @@
private Document document;
/**
- * Returns the document or <code>null</code> if the current URL does not
- * represent a document.
+ * Returns the document or <code>null</code> if the current URL does not represent a document.
* @return A document
*/
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);
+ }
+ } catch (final DocumentBuildException e) {
+ throw new RuntimeException(e);
+ }
+ }
return this.document;
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java?view=diff&r1=157929&r2=157930
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java Thu Mar 17 01:57:19 2005
@@ -184,4 +184,14 @@
*/
Proxy getProxy(Document document, boolean isSslProtected);
+ /**
+ * @return The templates of the publication.
+ */
+ Publication[] getTemplates();
+
+ /**
+ * @return if the publication can be used as a template.
+ */
+ boolean supportsTemplating();
+
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationImpl.java?view=diff&r1=157929&r2=157930
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationImpl.java Thu Mar 17 01:57:19 2005
@@ -23,6 +23,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.apache.avalon.framework.configuration.Configuration;
@@ -63,50 +64,17 @@
public static final String CONFIGURATION_FILE = CONFIGURATION_PATH + File.separator
+ "publication.xconf";
- /**
- * <code>ELEMENT_PATH_MAPPER</code> The path mapper element
- */
- String ELEMENT_PATH_MAPPER = "path-mapper";
- /**
- * <code>ELEMENT_DOCUMENT_BUILDER</code> The document buider element
- */
- String ELEMENT_DOCUMENT_BUILDER = "document-builder";
- /**
- * <code>ELEMENT_SITE_STRUCTURE</code> The site structure element
- */
- String ELEMENT_SITE_STRUCTURE = "site-structure";
- /**
- * <code>ATTRIBUTE_TYPE</code> The type attribute
- */
- String ATTRIBUTE_TYPE = "type";
- /**
- * <code>ATTRIBUTE_SRC</code> The src attribute
- */
- String ATTRIBUTE_SRC = "type";
- /**
- * <code>LANGUAGES</code> The languages
- */
- String LANGUAGES = "languages";
- /**
- * <code>LANGUAGE</code> The language
- */
- String LANGUAGE = "language";
- /**
- * <code>DEFAULT_LANGUAGE_ATTR</code> The default language attribute
- */
- String DEFAULT_LANGUAGE_ATTR = "default";
- /**
- * <code>BREADCRUMB_PREFIX</code> The breadcrumb prefix
- */
- String BREADCRUMB_PREFIX = "breadcrumb-prefix";
- /**
- * <code>SSL_PREFIX</code> The SSL prefix
- */
- String SSL_PREFIX = "ssl-prefix";
- /**
- * <code>LIVE_MOUNT_POINT</code> The live mount point
- */
- String LIVE_MOUNT_POINT = "live-mount-point";
+ private static final String ELEMENT_TEMPLATES = "templates";
+ private static final String ELEMENT_TEMPLATE = "template";
+ private static final String ATTRIBUTE_ID = "id";
+ private static final String ELEMENT_PATH_MAPPER = "path-mapper";
+ private static final String ELEMENT_DOCUMENT_BUILDER = "document-builder";
+ private static final String ELEMENT_SITE_STRUCTURE = "site-structure";
+ private static final String ATTRIBUTE_TYPE = "type";
+ private static final String ATTRIBUTE_SUPPORTS_TEMPLATING = "supports-templating";
+ private static final String LANGUAGES = "languages";
+ private static final String DEFAULT_LANGUAGE_ATTR = "default";
+ private static final String BREADCRUMB_PREFIX = "breadcrumb-prefix";
/**
* Creates a new instance of Publication
@@ -135,8 +103,13 @@
File configFile = getConfigurationFile();
if (!configFile.exists()) {
+ getLogger()
+ .error("Config file [" + configFile.getAbsolutePath() + "] does not exist: ",
+ new RuntimeException());
throw new RuntimeException("The configuration file [" + configFile
+ "] does not exist!");
+ } else {
+ getLogger().debug("Configuration file [" + configFile + "] exists.");
}
DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
@@ -206,6 +179,23 @@
+ ssl + "]");
}
}
+
+ Configuration templatesConfig = config.getChild(ELEMENT_TEMPLATES);
+ if (templatesConfig != null) {
+ PublicationFactory factory = PublicationFactory.getInstance(getLogger());
+ Configuration[] templateConfigs = templatesConfig.getChildren(ELEMENT_TEMPLATE);
+ this.templates = new Publication[templateConfigs.length];
+ for (int i = 0; i < templateConfigs.length; i++) {
+ String templateId = templateConfigs[i].getAttribute(ATTRIBUTE_ID);
+ Publication template = factory.getPublication(templateId, getServletContext()
+ .getAbsolutePath());
+ this.templates[i] = template;
+ }
+ }
+
+ this.supportsTemplating = config
+ .getAttributeAsBoolean(PublicationImpl.ATTRIBUTE_SUPPORTS_TEMPLATING, false);
+
} catch (final Exception e) {
throw new RuntimeException("Problem with config file: " + configFile.getAbsolutePath(),
e);
@@ -432,5 +422,26 @@
*/
public boolean exists() {
return getConfigurationFile().exists();
+ }
+
+ private Publication[] templates;
+
+ /**
+ * @see org.apache.lenya.cms.publication.Publication#getTemplates()
+ */
+ public Publication[] getTemplates() {
+ loadConfiguration();
+ List list = Arrays.asList(this.templates);
+ return (Publication[]) list.toArray(new Publication[list.size()]);
+ }
+
+ private boolean supportsTemplating = false;
+
+ /**
+ * @see org.apache.lenya.cms.publication.Publication#supportsTemplating()
+ */
+ public boolean supportsTemplating() {
+ loadConfiguration();
+ return this.supportsTemplating;
}
}
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=157929&r2=157930
==============================================================================
--- 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 Thu Mar 17 01:57:19 2005
@@ -48,12 +48,6 @@
void setup(Publication publication) throws ConfigurationException;
/**
- * Returns the template publications of a publication in order of their priority.
- * @return An array of publications.
- */
- Publication[] getTemplates();
-
- /**
* <p>
* Visits the versions of a source in traversing order.
* The source doesn't have to exist to be visited.
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=157929&r2=157930
==============================================================================
--- 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 Thu Mar 17 01:57:19 2005
@@ -17,13 +17,10 @@
package org.apache.lenya.cms.publication.templating;
-import java.io.File;
import java.util.ArrayList;
import java.util.List;
-import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
@@ -31,8 +28,6 @@
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceResolver;
import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.PublicationFactory;
-import org.apache.lenya.cms.publication.PublicationImpl;
/**
* Manager for publication templates.
@@ -45,54 +40,18 @@
private Publication publication;
- private static final String ELEMENT_TEMPLATES = "templates";
- private static final String ELEMENT_TEMPLATE = "template";
- private static final String ATTRIBUTE_ID = "id";
/**
* Ctor.
*/
public PublicationTemplateManagerImpl() {
- // do nothing
}
- private Publication[] templatePublications;
-
/**
* @see org.apache.lenya.cms.publication.templating.PublicationTemplateManager#setup(org.apache.lenya.cms.publication.Publication)
*/
public void setup(Publication _publication) throws ConfigurationException {
this.publication = _publication;
-
- File configFile = new File(_publication.getDirectory(), PublicationImpl.CONFIGURATION_FILE);
- DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
-
- try {
- Configuration config = builder.buildFromFile(configFile);
- Configuration templatesConfig = config.getChild(ELEMENT_TEMPLATES);
- if (templatesConfig != null) {
- List templates = new ArrayList();
- Configuration[] templateConfigs = templatesConfig.getChildren(ELEMENT_TEMPLATE);
- for (int i = 0; i < templateConfigs.length; i++) {
- String templateId = templateConfigs[i].getAttribute(ATTRIBUTE_ID);
- PublicationFactory factory = PublicationFactory.getInstance(getLogger());
- Publication template = factory.getPublication(templateId, _publication
- .getServletContext().getAbsolutePath());
- templates.add(template);
- }
- this.templatePublications = (Publication[]) templates
- .toArray(new Publication[templates.size()]);
- }
- } catch (Exception e) {
- throw new ConfigurationException("Setting up templates failed: ", e);
- }
- }
-
- /**
- * @see org.apache.lenya.cms.publication.templating.PublicationTemplateManager#getTemplates()
- */
- public Publication[] getTemplates() {
- return this.templatePublications;
}
/**
@@ -220,7 +179,7 @@
publications.add(getPublication());
- Publication[] templates = getTemplates();
+ Publication[] templates = getPublication().getTemplates();
for (int i = 0; i < templates.length; i++) {
publications.add(templates[i]);
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/usecases/CreatePublicationFromTemplate.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/usecases/CreatePublicationFromTemplate.java?view=diff&r1=157929&r2=157930
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/usecases/CreatePublicationFromTemplate.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/usecases/CreatePublicationFromTemplate.java Thu Mar 17 01:57:19 2005
@@ -66,7 +66,9 @@
Publication[] pubs = factory.getPublications(this.manager);
List templates = new ArrayList();
for (int i = 0; i < pubs.length; i++) {
- templates.add(pubs[i].getId());
+ if (pubs[i].supportsTemplating()) {
+ templates.add(pubs[i].getId());
+ }
}
setParameter(AVAILABLE_TEMPLATES, templates);
Modified: lenya/trunk/src/webapp/lenya/pubs/default/config/publication.xconf
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/default/config/publication.xconf?view=diff&r1=157929&r2=157930
==============================================================================
--- lenya/trunk/src/webapp/lenya/pubs/default/config/publication.xconf (original)
+++ lenya/trunk/src/webapp/lenya/pubs/default/config/publication.xconf Thu Mar 17 01:57:19 2005
@@ -17,7 +17,7 @@
<!-- $Id$ -->
-<publication>
+<publication supports-templating="true">
<languages>
<language default="true">en</language>
<language>de</language>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org