`
dhj
  • 浏览: 111011 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

通过spring取得国际化文件

    博客分类:
  • java
 
阅读更多
/* 
 * @(#) ScheduleController.java 2010-4-8
 * 
 * Copyright 2010 by TravelSkay Corporation.
 * No. 11 Huixinxijie, Beijing
 * 
 * All rights reserved.
 * 
 * This software is the confidential and proprietary information of
 * TravelSkay Corporation ("Confidential Information").  You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with TravelSkay.
 * 
 */
package com.travelsky.pss.flight.base.web;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

import com.travelsky.pss.abframe.base.util.Crypt;
import com.travelsky.pss.core.dao.tapi.TAPIConnection;
import com.travelsky.pss.core.exception.ApplicationException;
import com.travelsky.pss.flight.base.dao.entity.DAEntity;
import com.travelsky.pss.flight.base.service.IFlightService;
import com.travelsky.pss.flight.base.web.vo.FlightVo;



/**
 * 
 * 登录控制 Copyright: Copyright (c) 2011 Company: 
 * 
 * @author 
 * @version 1.0 2011-6-20下午02:52:41
 * @see HISTORY 2011-6-20下午02:52:41 创建文件
 ************************************************* 
 */
@Controller
@RequestMapping("/flight")
public class FlightController {
	
	/**
	 * 注入用户管理服务接口
	 */

	@Autowired
	private IFlightService flightService = null;

	private MessageSourceAccessor messages;// 获取国际化文件内�?

	@Autowired
	public void setMessages(MessageSource messageSource) {
		messages = new MessageSourceAccessor(messageSource);
	}

	/**
	 * 
	 * 跳转到航班控制页�?
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 *             Date: 2011-6-17下午05:22:46
	 */
	@RequestMapping(value = "forwardMain", method = RequestMethod.GET)
	public ModelAndView forwardMain(HttpServletRequest request)
			throws Exception {
	
		String topId = request.getParameter("selectId");
		ModelAndView mav = new ModelAndView("flight/base/flightLogin");
		mav.addObject("topId", topId);
		return mav;
	}

	
	/**
	 * 
	 * 切换Office
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 *             Date: 2011-6-20下午02:50:58
	 */
	@RequestMapping(value = "changeOffice", method = RequestMethod.GET)
	public ModelAndView changeOffice(HttpServletRequest request)
			throws Exception {

		long id = (Long) request.getSession().getAttribute("OperatorId");
		String topId = request.getParameter("topId");
		// OperatorVo opeVo = operatorService.getOperatorVoById(ope.getId()+"");
		FlightVo fliVo = flightService.getFlightVoById(id + "");
		String icsId = fliVo.getIcsId();
		String icsPwd = Crypt.decrypt(fliVo.getIcsPwd());
		String icsLev = fliVo.getIcsSecurityLevel().toString();
		String offices = fliVo.getOffice();
		String[] office = offices.split(",");
		List<String> officeList = Arrays.asList(office);
		String officeUsas = request.getParameter("office");
		boolean soResult = false;
		TAPIConnection tapiConnection = (TAPIConnection) request.getSession()
				.getAttribute("tapiConnection");
		if (tapiConnection == null
				|| tapiConnection.getCurrentSession() == null
				|| !tapiConnection.getCurrentSession().isConnected()) {
			throw new ApplicationException(
					"error.flight.common.usas.cannotconnect");
		}
		ModelAndView mav = new ModelAndView("flight/base/flightWelcome");
		try {
			soResult = flightService.execSO(tapiConnection.getCurrentSession());
			
			if (soResult) {
				tapiConnection.getCurrentSession().executeCommand(
						"SI:" + icsId + "/" + icsPwd + "/" + icsLev + "/"
								+ officeUsas);
			}
			List<DAEntity> daList = flightService.queryDAList(tapiConnection
					.getCurrentSession());
			mav.addObject("officeUsas", officeUsas);
			mav.addObject("office", officeList);
			mav.addObject("daList", daList);
			mav.addObject("topId", topId);
			return mav;
		} catch (Exception e1) {
			String errorTAPI = e1.getMessage();
			Locale locale = (Locale) request.getSession().getAttribute(
					SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME);
			String errorMessage = messages.getMessage(
					"error.flight.common.usas.notconnect", locale);//转换消息
			mav.addObject("errorMessage", errorMessage);
			mav.addObject("errorTAPI", errorTAPI);
			mav.addObject("officeUsas", officeUsas);
			mav.addObject("office", officeList);
			mav.addObject("topId", topId);
			return mav;
		}
	}
	/**
	 * 
	 * 跳转到其他URL
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 *             Date: 2011-6-17下午05:22:22
	 */
	@RequestMapping(value = "loadPage", method = RequestMethod.GET)
	public ModelAndView loadPage(HttpServletRequest request) throws Exception {
		String url = request.getParameter("url");

		return new ModelAndView("flight/" + url);
	}
	/**
	 * 
	 * 退出主机登录,跳转到首�?
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 *             Date: 2011-6-22下午04:52:37
	 */
	@RequestMapping(value = "forwardSystemIndex", method = RequestMethod.GET)
	public ModelAndView execSO(HttpServletRequest request) throws Exception {
		ModelAndView mav = new ModelAndView("/welcome");
		TAPIConnection tapiConnection = (TAPIConnection) request.getSession().getAttribute(
				"tapiConnection");
		try {
			flightService.execSO(tapiConnection.getCurrentSession());
			return mav;}
		catch(Exception e){
			return mav;
		}
		
	}

	/**
	 * 
	 * 跳转到框架页�?
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 *             Date: 2011-7-13下午02:10:58
	 */
	@RequestMapping(value = "forwardFlightMain", method = RequestMethod.GET)
	public ModelAndView forwardFlightMain(HttpServletRequest request)
			throws Exception {
		long id = (Long) request.getSession().getAttribute("OperatorId");
		// OperatorVo opeVo = operatorService.getOperatorVoById(ope.getId()+"");
		FlightVo fliVo = flightService.getFlightVoById(id + "");
		String offices = fliVo.getOffice();
		String[] office = offices.split(",");
		List<String> officeList = Arrays.asList(office);
		String officeUsas = request.getParameter("office");
		String topId = request.getParameter("topId");
		String selectId = request.getParameter("selectId");
		String welcome = request.getParameter("welcome");
		ModelAndView mav = new ModelAndView("flight/base/flightMain");
		mav.addObject("officeUsas", officeUsas);
		mav.addObject("office", officeList);
		mav.addObject("topId", topId);
		mav.addObject("selectId", selectId);
		mav.addObject("welcome", welcome);
		return mav;
	}

	/**
	 * 
	 * 跳转到到欢迎�?
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 *             Date: 2011-7-13下午02:10:58
	 */
	@RequestMapping(value = "forwardWelcome", method = RequestMethod.GET)
	public ModelAndView forwardWelcome(HttpServletRequest request)
			throws Exception {
		String url = request.getParameter("url");
		ModelAndView mav = new ModelAndView(url);
		return mav;
	}
}
分享到:
评论

相关推荐

    SpringMVCDemo:Spring MVC 框架知识案例

    6.Spring MVC 国际化案例 7.Spring MVC 请求转发与请求重定向案例 8.Spring MVC 下载 Excel 文档的需求案例 9.Spring MVC RESTful 风格的请求方式案例 10.Spring + Spring MVC + JDBCTemplate 整合并通过 RESTful ...

    Spring 2.0 开发参考手册

    3.8.1. 利用MessageSource实现国际化 3.8.2. 事件 3.8.3. 底层资源的访问 3.8.4. ApplicationContext在WEB应用中的实例化 3.9. 粘合代码和可怕的singleton 3.9.1. 使用Singleton-helper类 4. 资源 4.1. 简介 ...

    Spring-Reference_zh_CN(Spring中文参考手册)

    3.8.1. 利用MessageSource实现国际化 3.8.2. 事件 3.8.3. 底层资源的访问 3.8.4. ApplicationContext在WEB应用中的实例化 3.9. 粘合代码和可怕的singleton 3.9.1. 使用Singleton-helper类 4. 资源 4.1. 简介 4.2. ...

    Spring中文帮助文档

    3.8.2. 利用MessageSource实现国际化 3.8.3. 事件 3.8.4. 底层资源的访问 3.8.5. ApplicationContext在WEB应用中的实例化 3.9. 粘合代码和可怕的singleton 3.10. 以J2EE RAR文件的形式部署Spring ...

    Spring API

    3.8.2. 利用MessageSource实现国际化 3.8.3. 事件 3.8.4. 底层资源的访问 3.8.5. ApplicationContext在WEB应用中的实例化 3.9. 粘合代码和可怕的singleton 3.10. 以J2EE RAR文件的形式部署Spring ...

    spring chm文档

    3.8.1. 利用MessageSource实现国际化 3.8.2. 事件 3.8.3. 底层资源的访问 3.8.4. ApplicationContext在WEB应用中的实例化 3.9. 粘合代码和可怕的singleton 3.9.1. 使用Singleton-helper类 4. 资源 4.1. 简介 ...

    Spring.3.x企业应用开发实战(完整版).part2

    5.5.3 容器级的国际化信息资源 5.6 容器事件 5.6.1 Spring事件类结构 5.6.2 解构Spring事件体系的具体实现 5.6.3 一个实例 5.7 小结 第6章 Spring AOP基础 6.1 AOP概述 6.1.1 AOP到底是什么 6.1.2 AOP术语 6.1.3 AOP...

    Spring攻略(第二版 中文高清版).part1

    11.7 国际化(I18n)信息属性 458 11.7.1 问题 458 11.7.2 解决方案 458 11.7.3 工作原理 458 11.8 改变永久性存储系统 461 11.8.1 问题 461 11.8.2 解决方案 461 11.4.3 工作原理 461 11.9 日志 ...

    Spring攻略(第二版 中文高清版).part2

    11.7 国际化(I18n)信息属性 458 11.7.1 问题 458 11.7.2 解决方案 458 11.7.3 工作原理 458 11.8 改变永久性存储系统 461 11.8.1 问题 461 11.8.2 解决方案 461 11.4.3 工作原理 461 11.9 日志 ...

    Spring3.x企业应用开发实战(完整版) part1

    5.5.3 容器级的国际化信息资源 5.6 容器事件 5.6.1 Spring事件类结构 5.6.2 解构Spring事件体系的具体实现 5.6.3 一个实例 5.7 小结 第6章 Spring AOP基础 6.1 AOP概述 6.1.1 AOP到底是什么 6.1.2 AOP术语 6.1.3 AOP...

    基于i18n利用springboot实现后台国际化+源代码+文档说明

    项目做到尾声,临时需要添加国际化内容,开始只是前台展示的页面添加了国际化支持,后来发现一些后台提示很不友好,遂也选择进行国际化处理。 ## 实现 **Springboot对国际化支持的很好,我们就用自带的i18n实现国际...

    4、Spring Security 安全权限管理手册

    1、区分Authentication(验证)与 Authorization(授权) 验证 这个用户是谁? 用户身份可靠吗? 授权 某用户A是否可以访问资源R 某用户A是否可以执行M操作 某用户A是否可以对资源R执行...11、本地化消息输出(国际化)

    Spring面试题

    Spring 上下文包括企业服务,例如 JNDI、EJB、电子邮件、国际化、校验和调度功能。 ☆ Spring AOP:通过配置管理特性,Spring AOP 模块直接将面向方面的编程功能集成到了 Spring 框架中。所以,可以很容易地使 ...

    springboot知识点整理

    4.8.2 登录页面国际化 74 4.8.3 登录 80 4.8.4 拦截器进行登录检查 81 4.8.5 实验要求(没按要求做,不想改了!) 82 4.8.6 CRUD-员工列表 83 4.8.7 CRUD-员工修改 86 4.8.8 CRUD-员工添加 87 4.8.9 CRUD-员工删除 ...

    Struts2属性文件详解

    该属性设置是否每次HTTP请求到达时,系统都重新加载资源文件(允许国际化文件重载).该属性默认值是false.在开发阶段将该属性设置为true会更有利于开发,但在产品发布阶段应将该属性设置为false. 提示: 开发阶段将该属性...

    jquery-i18n:基于jquery的国际化工具类,支持同时引入多个语言资源文件,更友好的支持中文环境,在中文环境下无需引入资源文件

    用于前端文本国际化,支持同时引入多个语言资源文件,更友好的支持中文环境,在中文环境下无需引入资源文件 使用方法 文件引入 该插件依赖于jquery 和 js-cookie,可修改源代码取消对后者的依赖 [removed][removed] ...

    OpenProcessing-i18n:这是OpenProcessing国际化文件的公共存储库。 随意贡献自己的语言或进行更改

    OpenProcessing-i18n 该项目包括OpenProcessing转换和国际化文件。 随意贡献自己的语言或进行更改。状态该项目目前正处于测试阶段,来自PCD2021 Japan的参与者对此做出了贡献,并且支持非常有限。 目前支持的语言是...

    尚硅谷Spring boot核心技术篇(上)

    -国际化 36、尚硅谷_SpringBoot_web开发-【实验】-登陆&拦截器 37、尚硅谷_SpringBoot_web开发-【实验】-Restful实验要求 38、尚硅谷_SpringBoot_web开发-【实验】-员工列表-公共页抽取 39、尚硅谷_SpringBoot_web...

    struts2.1宝典

    10.国际化资源文件占位符 为资源文件传参数 22 没有JUNIT 22 OGNL 22 技巧一 30 Action类及Action Name的命名规范 31 擅长使用Dispatch的模式 32 不断的提炼公用的Action 33 将一个模块中的Action放置在一起 34 擅与...

Global site tag (gtag.js) - Google Analytics