lenya/src/java/org/apache/lenya/cms/publication PublicationFactory.java,NONE,1.1 PageEnvelope.java,1.12,1.13 Publication.java,1.3,1.4
Andreas Hartmann <[email protected]> Fri, 16 May 2003 17:17:01 +0200
| Newsgroups | gmane.comp.cms.wyona.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /repository/lenya/src/java/org/apache/lenya/cms/publication
In directory erbium:/tmp/cvs-serv29519/src/java/org/apache/lenya/cms/publication
Modified Files:
PageEnvelope.java Publication.java
Added Files:
PublicationFactory.java
Log Message:
- added PageEnvelopeModule
- PublicationFactory for creating Publication objects
--- NEW FILE: PublicationFactory.java ---
/*
* PublicationFactory.java
*
* Created on 15. Mai 2003, 17:49
*/
package org.apache.lenya.cms.publication;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Map;
import org.apache.avalon.framework.parameters.ParameterException;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.environment.Context;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.excalibur.source.Source;
import org.apache.log4j.Category;
/**
*
* @author andreas
*/
public class PublicationFactory {
static Category log = Category.getInstance(PublicationFactory.class);
/**
* Creates a new publication.
* The publication ID is resolved from the request URI.
* The servlet context path is resolved from the context object.
* @param objectModel The object model of the Cocoon component.
*/
public static Publication getPublication(Map objectModel) {
Request request = ObjectModelHelper.getRequest(objectModel);
String uri = request.getRequestURI();
String contextPath = request.getContextPath();
String webappUri = uri.substring(contextPath.length() + 1);
String publicationId;
int slashIndex = webappUri.indexOf("/");
if (slashIndex > -1) {
publicationId = webappUri.substring(0, slashIndex);
}
else {
publicationId = webappUri;
}
Context context = ObjectModelHelper.getContext(objectModel);
String servletContextPath = context.getRealPath("");
return new Publication(publicationId, servletContextPath);
}
}
Index: PageEnvelope.java
===================================================================
RCS file: /repository/lenya/src/java/org/apache/lenya/cms/publication/PageEnvelope.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** PageEnvelope.java 14 May 2003 08:35:46 -0000 1.12
--- PageEnvelope.java 16 May 2003 15:16:59 -0000 1.13
***************
*** 34,37 ****
--- 34,38 ----
public static final String AREA = "area";
public static final String DOCUMENT_ID = "document-id";
+ public static final String DOCUMENT_URL = "document-url";
public static final int AREA_POS = 3;
***************
*** 43,46 ****
--- 44,75 ----
private String area;
private String documentId;
+ private String documentUrl;
+
+ /**
+ * Creates a new instance of PageEnvelope from a sitemap inside a publication.
+ * @param publication The publication the page belongs to.
+ * @param request The request that calls the page.
+ * @exception PageEnvelopeException if an error occurs
+ * @exception ProcessingException if an error occurs
+ * @exception SAXException if an error occurs
+ * @exception IOException if an error occurs
+ */
+ public PageEnvelope(Publication publication, Request request)
+ throws PageEnvelopeException, ProcessingException, SAXException, IOException {
+
+ // compute area
+ String requestURI = request.getRequestURI();
+ log.debug("requestURI: " + requestURI);
+ String[] directories = requestURI.split("/");
+ area = directories[AREA_POS];
+
+ String urlPrefix = request.getContextPath() + "/" + publication.getId() + "/" + area;
+ documentUrl = requestURI.substring(urlPrefix.length());
+
+ documentId = computeDocumentId(requestURI);
+ this.publication = publication;
+ rcEnvironment = new RCEnvironment(publication.getServletContext().getCanonicalPath());
+ context = request.getContextPath();
+ }
/**
***************
*** 166,168 ****
--- 195,217 ----
return documentId;
}
+
+ /**
+ * Returns the document URL (without prefix and area).
+ * @return a <code>String</code> value
+ */
+ public String getDocumentURL() {
+ return documentUrl;
+ }
+
+ /**
+ * The names of the page envelope parameters.
+ */
+ public static String[] PARAMETER_NAMES = {
+ PageEnvelope.AREA,
+ PageEnvelope.CONTEXT,
+ PageEnvelope.PUBLICATION_ID,
+ PageEnvelope.DOCUMENT_ID,
+ PageEnvelope.DOCUMENT_URL
+ };
+
}
Index: Publication.java
===================================================================
RCS file: /repository/lenya/src/java/org/apache/lenya/cms/publication/Publication.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Publication.java 24 Apr 2003 13:52:38 -0000 1.3
--- Publication.java 16 May 2003 15:16:59 -0000 1.4
***************
*** 7,10 ****
--- 7,11 ----
package org.apache.lenya.cms.publication;
+ import java.io.File;
import org.apache.lenya.cms.publishing.PublishingEnvironment;
***************
*** 16,26 ****
*/
public class Publication {
- Category log = Category.getInstance(Publication.class);
/** Creates a new instance of Publication */
public Publication(String id, String servletContextPath) {
! log.debug("Servlet Context Path: " + servletContextPath);
assert id != null;
this.id = id;
environment = new PublishingEnvironment(servletContextPath, id);
}
--- 17,33 ----
*/
public class Publication {
/** Creates a new instance of Publication */
public Publication(String id, String servletContextPath) {
!
assert id != null;
this.id = id;
+
+ assert servletContextPath != null;
+ File servletContext = new File(servletContextPath);
+ assert servletContext.exists();
+ this.servletContext = servletContext;
+
+ // FIXME: remove PublishingEnvironment from publication
environment = new PublishingEnvironment(servletContextPath, id);
}
***************
*** 38,40 ****
--- 45,62 ----
}
+ private File servletContext;
+
+ public File getServletContext() {
+ return servletContext;
+ }
+
+ public static final String PUBLICATION_PREFIX = "lenya" + File.separator + "pubs";
+
+ /**
+ * Returns the publication directory.
+ */
+ public File getDirectory() {
+ return new File(getServletContext(), PUBLICATION_PREFIX + File.separator + getId());
+ }
+
}