Package org.magicbox.controller

Source Code of org.magicbox.controller.RssController

/*
* Copyright Massimiliano Dessi' (desmax74@yahoo.it)
*
* Licensed for non-commercial use,
* under Apache License Version 2.0
* (http://www.apache.org/licenses/LICENSE-2.0),
*
* for commercial use, under
* GNU General Public License Version 2 or later (the "GPL")
* http://www.gnu.org/licenses/gpl.html
*/
package org.magicbox.controller;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.magicbox.controller.util.WebUtils;
import org.magicbox.domain.AnnuncioImpl;
import org.magicbox.domain.Annuncio;
import org.magicbox.service.PubblicazioniFacade;
import org.magicbox.util.Constant;
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.validation.BindException;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

/**
* Controller per creazione feed
*
* @author Massimiliano Dessì (desmax74@yahoo.it)
* @since jdk 1.6.0
* @version 3.0
*/
public class RssController extends SimpleFormController {

    public RssController() {
        setCommandClass(AnnuncioImpl.class);
        setCommandName(Constant.FEED);
        setFormView("comunicazioni/rssEditor");
        setSuccessView(Constant.REDIRECT_WELCOME_USER);
    }

    public void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) {

        StringTrimmerEditor trimmerEditor = new StringTrimmerEditor(false);
        binder.registerCustomEditor(String.class, trimmerEditor);
    }

    public ModelAndView onSubmit(HttpServletRequest req, HttpServletResponse res, Object command, BindException errors) throws Exception {

        pubblicazioniFacade.pubblicaRss(getAnnuncio(req, command));
        return new ModelAndView(getSuccessView());
    }

    private Annuncio getAnnuncio(HttpServletRequest req, Object command) throws Exception {
        AnnuncioImpl annuncio = (AnnuncioImpl) command;
        annuncio.setIdCentro(WebUtils.getIdCentro(req));
        annuncio.setData(new Date());
        annuncio.setTipo(Constant.TYPE_FEED);
        return annuncio;
    }

    public void setPubblicazioniFacade(PubblicazioniFacade pubblicazioniFacade) {
        this.pubblicazioniFacade = pubblicazioniFacade;
    }

    private PubblicazioniFacade pubblicazioniFacade;
}
TOP

Related Classes of org.magicbox.controller.RssController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.