package dk.hansen; import javax.servlet.http.*; import org.apache.log4j.Logger; import org.apache.struts.action.*; public final class DetailCDAction extends CommonCDAction { private static Logger logger = Logger.getLogger(DetailCDAction.class.getName()); public ActionForward commonExecute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { ActionErrors errors = new ActionErrors(); // Get the index of the CD (given in the hyperlink) DetailCDForm df = (DetailCDForm) form; String index = df.getId(); if (index == null || index.equals("")) { // Logging the error: String message = "No id given to the detail action"; logger.fatal(message); // Message for the user: errors.add("label", new ActionError("error.noindex")); saveErrors(request, errors); // Save the exception: request.setAttribute("MYEXCEPTION", new DAOException(message)); // Return to the error page return (mapping.findForward("error")); } // Get the factory class HttpSession session = request.getSession(); CDManagerFactoryIF factory = (CDManagerFactoryIF) session.getAttribute("cdfactory"); CDManagerIF manager = factory.createCDManager(); // Transfer the data from the cd bean to the ActionForm CD cd = null; try { cd = manager.getCD(index); } catch (DAOException e) { // Logging the error: String message = "CD could not be listed. id=" + index; logger.fatal(message, e); // Message for the user: errors.add("label", new ActionError("error.detailfailed")); saveErrors(request, errors); // Save the chained exceptions: request.setAttribute("MYEXCEPTION", new DAOException(message, e)); // Return to the error page return (mapping.findForward("error")); } if (cd == null) { // Logging the error: String message = "CD could not be listed. id=" + index; logger.fatal(message); // Message for the user: errors.add("label", new ActionError("error.detailfailed")); saveErrors(request, errors); // Save the chained exceptions: request.setAttribute("MYEXCEPTION", new DAOException(message)); // Return to the error page return (mapping.findForward("error")); } df.setTitle(cd.getTitle()); df.setAuthor(cd.getAuthor()); df.setYear(cd.getYear()); // Forward control to the list page return (mapping.findForward("detail")); } }