KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > publication > PageEnvelopeFactory


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 /* $Id: PageEnvelopeFactory.java 42598 2004-03-01 16:18:28Z gregor $ */
19
20 package org.apache.lenya.cms.publication;
21
22 import java.util.Map JavaDoc;
23
24 import org.apache.cocoon.environment.ObjectModelHelper;
25 import org.apache.cocoon.environment.Request;
26
27
28 /**
29  * Common entry point for creating page envelopes.
30  */

31 public class PageEnvelopeFactory {
32     /**
33      * Creates a new PageEnvelopeFactory.
34      */

35     protected PageEnvelopeFactory() {
36     }
37
38     private static PageEnvelopeFactory instance;
39
40     /**
41      * Returns the singleton PageEnvelopeFactory.
42      * @return The factory.
43      */

44     public static PageEnvelopeFactory getInstance() {
45         if (instance == null) {
46             instance = new PageEnvelopeFactory();
47         }
48         return instance;
49     }
50
51     /**
52      * Returns the page envelope for the object model of a Cocoon component.
53      * @param objectModel The object model.
54      * @return A page envelope.
55      * @throws PageEnvelopeException if something went wrong.
56      */

57     public PageEnvelope getPageEnvelope(Map JavaDoc objectModel)
58         throws PageEnvelopeException {
59         Request request = ObjectModelHelper.getRequest(objectModel);
60         PageEnvelope envelope = (PageEnvelope) request.getAttribute(PageEnvelope.class.getName());
61
62         envelope = new PageEnvelope(objectModel, true);
63         request.setAttribute(PageEnvelope.class.getName(), envelope);
64
65         return envelope;
66     }
67     
68 }
69
Popular Tags