Java tutorial
/* * Copyright (C) 2006 Jordi Marqus Ferr * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file DUROTY.txt. * * Author: Jordi Marqus Ferr * c/Mallorca 295 principal B 08037 Barcelona Spain * Phone: +34 625397324 */ /** * */ package com.duroty.application.home.actions; import java.util.Vector; import com.duroty.application.home.interfaces.Home; import com.duroty.application.home.utils.FeedObj; import com.duroty.application.home.utils.HomeDefaultAction; import com.duroty.constants.Constants; import com.duroty.constants.ExceptionCode; import com.duroty.utils.exceptions.ExceptionUtilities; import com.duroty.utils.log.DLog; import com.duroty.utils.log.DMessage; import org.apache.commons.lang.StringUtils; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; import org.apache.struts.action.ActionMessages; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * @author durot * */ public class GetFeedAction extends HomeDefaultAction { /** * DOCUMENT ME! */ private static final String FEEDS = "feeds"; /** * */ public GetFeedAction() { super(); // TODO Auto-generated constructor stub } /* (non-Javadoc) * @see com.duroty.controller.actions.DefaultAction#doExecute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ protected ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ActionMessages errors = new ActionMessages(); //String name = request.getParameter("name"); int channel = 0; String name = request.getParameter("name"); try { channel = Integer.valueOf(request.getParameter("channel")); } catch (Exception ex) { } try { if (!StringUtils.isBlank(name)) { Home homeInstance = getHomeInstance(request); Vector aux = new Vector(); FeedObj obj = homeInstance.getFeed(channel, name); if (obj != null) { aux.addElement(obj.getValue()); } request.setAttribute(FEEDS, aux); } } catch (Exception ex) { String errorMessage = ExceptionUtilities.parseMessage(ex); if (errorMessage == null) { errorMessage = "NullPointerException"; } errors.add("general", new ActionMessage(ExceptionCode.ERROR_MESSAGES_PREFIX + "general", errorMessage)); request.setAttribute("exception", errorMessage); doTrace(request, DLog.ERROR, getClass(), errorMessage); } finally { } if (errors.isEmpty()) { doTrace(request, DLog.INFO, getClass(), "OK"); return mapping.findForward(Constants.ACTION_SUCCESS_FORWARD); } else { saveErrors(request, errors); return mapping.findForward(Constants.ACTION_FAIL_FORWARD); } } /* (non-Javadoc) * @see com.duroty.controller.actions.DefaultAction#doTrace(javax.servlet.http.HttpServletRequest, int, java.lang.Class, java.lang.String) */ protected void doTrace(HttpServletRequest request, int level, Class classe, String message) throws Exception { DLog.log(level, classe, DMessage.toString(request, message)); } }