KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > servlets > UUIDRequestDispatcher


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.servlets;
14
15 import info.magnolia.cms.beans.config.ContentRepository;
16 import info.magnolia.cms.core.Path;
17
18 import java.io.IOException JavaDoc;
19
20 import javax.servlet.RequestDispatcher JavaDoc;
21 import javax.servlet.ServletException JavaDoc;
22 import javax.servlet.http.HttpServlet JavaDoc;
23 import javax.servlet.http.HttpServletRequest JavaDoc;
24 import javax.servlet.http.HttpServletResponse JavaDoc;
25
26 import org.apache.commons.lang.StringUtils;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30
31 /**
32  * @author Sameer Charles
33  * @version $Revision: 6341 $ ($Author: philipp $)
34  */

35 public class UUIDRequestDispatcher extends HttpServlet JavaDoc {
36
37     /**
38      * Generated
39      */

40     private static final long serialVersionUID = 1725760548580236125L;
41
42     /**
43      * Logger
44      */

45     private static Logger log = LoggerFactory.getLogger(UUIDRequestDispatcher.class);
46
47     /**
48      * repository name parameter
49      */

50     public static final String JavaDoc ATTRIBUTE_REPOSITRY_NAME = "mgnlRepositoryName";
51
52     /**
53      * workspace name parameter
54      */

55     public static final String JavaDoc ATTRIBUTE_WORKSPACE_NAME = "mgnlWorkspaceName";
56
57     /**
58      * uuid
59      */

60     public static final String JavaDoc ATTRIBUTE_UUID = "mgnlUUID";
61
62     /**
63      * @param request
64      * @param response
65      * @throws javax.servlet.ServletException
66      * @throws java.io.IOException
67      */

68     public void doGet(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws ServletException JavaDoc, IOException JavaDoc {
69         String JavaDoc repositoryName = request.getParameter(ATTRIBUTE_REPOSITRY_NAME);
70         String JavaDoc workspaceName = request.getParameter(ATTRIBUTE_WORKSPACE_NAME);
71         String JavaDoc uuid = request.getParameter(ATTRIBUTE_UUID);
72         String JavaDoc extension = Path.getExtension(request);
73         if (StringUtils.isEmpty(repositoryName)) {
74             repositoryName = ContentRepository.WEBSITE;
75         }
76         if (StringUtils.isEmpty(workspaceName)) {
77             workspaceName = ContentRepository.getDefaultWorkspace(repositoryName);
78         }
79         try {
80             String JavaDoc handle = ContentRepository
81                 .getHierarchyManager(repositoryName, workspaceName)
82                 .getContentByUUID(uuid)
83                 .getHandle();
84             handle = (handle + "." + extension);
85             RequestDispatcher JavaDoc dispatcher = request.getRequestDispatcher(handle);
86             dispatcher.forward(request, response);
87         }
88         catch (Exception JavaDoc e) {
89             log.error("Failed to retrieve content for UUID : " + uuid + " , " + e.getMessage());
90             if (log.isDebugEnabled()) {
91                 log.debug("Exception caught", e);
92             }
93         }
94
95     }
96
97     /**
98      * @param request
99      * @param response
100      * @throws javax.servlet.ServletException
101      * @throws java.io.IOException
102      */

103     public void doPost(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws ServletException JavaDoc, IOException JavaDoc {
104         doGet(request, response);
105     }
106
107 }
108
Popular Tags