package dk.hansen; import javax.servlet.http.*; import org.apache.log4j.Logger; import org.apache.struts.action.*; public final class DetailDVDAction extends CommonDVDAction { private static Logger logger = Logger.getLogger(DetailDVDAction.class.getName()); public ActionForward commonExecute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { ActionErrors errors = new ActionErrors(); // Get the index of the DVD (given in the hyperlink) DetailDVDForm df = (DetailDVDForm) 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(); DVDManagerFactoryIF factory = (DVDManagerFactoryIF) session.getAttribute("dvdfactory"); DVDManagerIF manager = factory.createDVDManager(); // Transfer the data from the dvd bean to the ActionForm DVD dvd = null; try { dvd = manager.getDVD(index); } catch (DAOException e) { // Logging the error: String message = "DVD 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 (dvd == null) { // Logging the error: String message = "DVD 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(dvd.getTitle()); // Forward control to the list page return (mapping.findForward("detail")); } }