1 | /* |
2 | * Copyright 2003,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 | package org.apache.pluto.driver.url; |
17 | |
18 | import javax.servlet.http.HttpServletRequest; |
19 | |
20 | /** |
21 | * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a> |
22 | * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a> |
23 | */ |
24 | public class PortalURLFactory { |
25 | |
26 | private static final String KEY = PortalURL.class.getName(); |
27 | |
28 | /** The singleton factory instance. */ |
29 | private static final PortalURLFactory FACTORY = new PortalURLFactory(); |
30 | |
31 | |
32 | // Constructor ------------------------------------------------------------- |
33 | |
34 | /** |
35 | * Private constructor that prevents external instantiation. |
36 | */ |
37 | private PortalURLFactory() { |
38 | // Do nothing. |
39 | } |
40 | |
41 | /** |
42 | * Returns the singleton factory instance. |
43 | * @return the singleton factory instance. |
44 | */ |
45 | public static PortalURLFactory getFactory() { |
46 | return FACTORY; |
47 | } |
48 | |
49 | |
50 | // Public Methods ---------------------------------------------------------- |
51 | |
52 | /** |
53 | * Creates a portal URL from the servlet request. If the servlet request |
54 | * does not contain a portal URL (in request scope), the method creates a |
55 | * portal URL and saves it into the request scope. |
56 | * @param request the servlet request. |
57 | * @return a portal URL created from the servlet request. |
58 | */ |
59 | public PortalURL createPortalURL(HttpServletRequest request) { |
60 | PortalURL portalURL = (PortalURL) request.getAttribute(KEY); |
61 | if (portalURL == null) { |
62 | portalURL = PortalURLParser.getParser().parse(request); |
63 | request.setAttribute(KEY, portalURL); |
64 | } |
65 | return (PortalURL) portalURL.clone(); |
66 | } |
67 | |
68 | } |