egovframework.rte.tex.com.web.EgovCommonController.java Source code

Java tutorial

Introduction

Here is the source code for egovframework.rte.tex.com.web.EgovCommonController.java

Source

/*
 * Copyright 2011 MOPAS(Ministry of Public Administration and Security).
 *
 * 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.
 */
package egovframework.rte.tex.com.web;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

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

import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJacksonJsonView;

import egovframework.rte.tex.com.service.EgovUserUtil;
import egovframework.rte.tex.mbr.service.MemberVO;

/**
 *  ?   ? ?.
 * @author   
 * @since 2011.06.07
 * @version 1.0
 * @see <pre>
 *  == ?(Modification Information) ==
 *   
 *   ?      ?           
 *  -------    --------    ---------------------------
 *   2011.06.07             ?
 * 
 * </pre>
 */
@Controller
public class EgovCommonController {

    /** LocaleResolver */
    @Resource
    LocaleResolver localeResolver;

    /**
     * ?  ?    ??.
     * @return "cmmn/EgovAccessDenie"
     * @exception Exception
     */
    @RequestMapping("/com/accessDenied.do")
    public String accessDenied() throws Exception {
        return "cmmn/EgovAccessDenied";
    }

    /**
     *  ? ? ??.
     * @return "main/EgovMain"
     * @exception Exception
     */
    @RequestMapping(value = "/com/egovMain.do", method = RequestMethod.GET)
    protected String changeLocale(HttpServletRequest request, HttpServletResponse response, Model model)
            throws Exception {
        Locale locale = new Locale("kr"); //default = kr
        if (request.getParameter("locale") == null) {
            locale = localeResolver.resolveLocale(request);
        } else {
            locale = new Locale(request.getParameter("locale"));
        }
        // localeResolver? locale 

        System.out.println("locale -------------- " + locale);

        localeResolver.setLocale(request, response, locale);

        MemberVO loginVO = EgovUserUtil.getMemberInfo();
        model.addAttribute("loginVO", loginVO);

        return "main/EgovMain";
    }

    /**
     * AJAX? jQuery ? ? .
     * @param tabName ? 
     * @param request
     * @return ??
     * @throws Exception
     */
    @Resource
    ResourceBundleMessageSource messageSource;
    @Resource
    MappingJacksonJsonView ajaxMainView;

    @RequestMapping(value = "/com/ajax.do")
    protected ModelAndView egovMain(String tabName, HttpServletRequest request) throws Exception {

        Locale locale = localeResolver.resolveLocale(request); //language 

        Map<String, Object> model = new HashMap<String, Object>();

        model.put("divId", "." + tabName);
        model.put("description", messageSource.getMessage(tabName, null, locale));

        return new ModelAndView(ajaxMainView, model);
    }
}