1 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 ; 19 20 import javax.servlet.RequestDispatcher ; 21 import javax.servlet.ServletException ; 22 import javax.servlet.http.HttpServlet ; 23 import javax.servlet.http.HttpServletRequest ; 24 import javax.servlet.http.HttpServletResponse ; 25 26 import org.apache.commons.lang.StringUtils; 27 import org.slf4j.Logger; 28 import org.slf4j.LoggerFactory; 29 30 31 35 public class UUIDRequestDispatcher extends HttpServlet { 36 37 40 private static final long serialVersionUID = 1725760548580236125L; 41 42 45 private static Logger log = LoggerFactory.getLogger(UUIDRequestDispatcher.class); 46 47 50 public static final String ATTRIBUTE_REPOSITRY_NAME = "mgnlRepositoryName"; 51 52 55 public static final String ATTRIBUTE_WORKSPACE_NAME = "mgnlWorkspaceName"; 56 57 60 public static final String ATTRIBUTE_UUID = "mgnlUUID"; 61 62 68 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException , IOException { 69 String repositoryName = request.getParameter(ATTRIBUTE_REPOSITRY_NAME); 70 String workspaceName = request.getParameter(ATTRIBUTE_WORKSPACE_NAME); 71 String uuid = request.getParameter(ATTRIBUTE_UUID); 72 String 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 handle = ContentRepository 81 .getHierarchyManager(repositoryName, workspaceName) 82 .getContentByUUID(uuid) 83 .getHandle(); 84 handle = (handle + "." + extension); 85 RequestDispatcher dispatcher = request.getRequestDispatcher(handle); 86 dispatcher.forward(request, response); 87 } 88 catch (Exception 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 103 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException , IOException { 104 doGet(request, response); 105 } 106 107 } 108 | Popular Tags |