01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: /* $Id: PageEnvelopeFactory.java 487598 2006-12-15 17:01:14Z andreas $ */
20:
21: package org.apache.lenya.cms.publication;
22:
23: import java.io.File;
24: import java.util.Map;
25:
26: import org.apache.cocoon.environment.Context;
27: import org.apache.cocoon.environment.ObjectModelHelper;
28: import org.apache.cocoon.environment.Request;
29: import org.apache.lenya.util.ServletHelper;
30:
31: /**
32: * Common entry point for creating page envelopes.
33: */
34: public class PageEnvelopeFactory {
35: /**
36: * Creates a new PageEnvelopeFactory.
37: */
38: protected PageEnvelopeFactory() {
39: // do nothing
40: }
41:
42: private static PageEnvelopeFactory instance;
43:
44: /**
45: * Returns the singleton PageEnvelopeFactory.
46: * @return The factory.
47: */
48: public static PageEnvelopeFactory getInstance() {
49: if (instance == null) {
50: instance = new PageEnvelopeFactory();
51: }
52: return instance;
53: }
54:
55: /**
56: * Returns the page envelope for the object model of a Cocoon component.
57: * @param map The document identity map to use.
58: * @param objectModel The object model.
59: * @param pub The publication.
60: * @return A page envelope.
61: * @throws PageEnvelopeException if something went wrong.
62: */
63: public PageEnvelope getPageEnvelope(DocumentFactory map,
64: Map objectModel, Publication pub)
65: throws PageEnvelopeException {
66: Request request = ObjectModelHelper.getRequest(objectModel);
67: String contextPath = request.getContextPath();
68: Context context = ObjectModelHelper.getContext(objectModel);
69: String webappUrl = ServletHelper.getWebappURI(request);
70: String servletContextPath = context.getRealPath("");
71: return getPageEnvelope(map, contextPath, webappUrl, new File(
72: servletContextPath), pub);
73: }
74:
75: /**
76: * Creates a page envelope.
77: * @param map The document identity map to use.
78: * @param contextPath The servlet context prefix.
79: * @param webappUrl The web application URL.
80: * @param servletContext The servlet context directory.
81: * @param pub The publication.
82: * @return A page envelope.
83: * @throws PageEnvelopeException if something went wrong.
84: */
85: public PageEnvelope getPageEnvelope(DocumentFactory map,
86: String contextPath, String webappUrl, File servletContext,
87: Publication pub) throws PageEnvelopeException {
88: PageEnvelope envelope = new PageEnvelope(map, contextPath,
89: webappUrl, servletContext, pub);
90: return envelope;
91: }
92:
93: }
|