/* Copyright (C) 2005-2012, by the President and Fellows of Harvard College. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Dataverse Network - A web application to share, preserve and analyze research data. Developed at the Institute for Quantitative Social Science, Harvard University. Version 3.0. */ /* * StudyGlobalIdServlet.java * * Created on June 14, 2007, 2:10 PM */ package edu.harvard.iq.dvn.core.web.servlet; import edu.harvard.iq.dvn.core.study.Study; import edu.harvard.iq.dvn.core.study.StudyServiceLocal; import edu.harvard.iq.dvn.core.util.PropertyUtil; import java.io.*; import javax.ejb.EJB; import javax.servlet.*; import javax.servlet.http.*; /** * * @author gdurand * @version */ public class StudyGlobalIdServlet extends HttpServlet { @EJB StudyServiceLocal studyService; /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * @param request servlet request * @param response servlet response */ protected void processRequest(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String globalId = req.getParameter("globalId"); if (globalId != null) { Study study = studyService.getStudyByGlobalId( globalId ); if (study != null) { res.sendRedirect("http://" + PropertyUtil.getHostUrl() + "/dvn/dv/" + study.getOwner().getAlias() + "/faces/study/StudyPage.xhtml?globalId=" + study.getGlobalId() ); } else { createErrorResponse(res, "No study exists for the specified Global Id."); } } else { createErrorResponse(res, "Global Id not specified."); } } private void createErrorResponse(HttpServletResponse res, String message) { res.setContentType("text/html"); try { PrintWriter out = res.getWriter(); out.println("<HTML>"); out.println("<HEAD><TITLE>Study</TITLE></HEAD>"); out.println("<BODY>"); out.println("<BIG>" + message + "</BIG>"); out.println("</BODY></HTML>"); } catch (IOException ex) { ex.printStackTrace(); } } // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> /** Handles the HTTP <code>GET</code> method. * @param request servlet request * @param response servlet response */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** Handles the HTTP <code>POST</code> method. * @param request servlet request * @param response servlet response */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** Returns a short description of the servlet. */ public String getServletInfo() { return "Short description"; } // </editor-fold> }