Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. @Aspect
  2. public class InternationalizationAspect {
  3.  
  4. private static final String LANGUAGE_CODE_ENGLISH = "en";
  5. private static Logger log = LoggerFactory.getLogger(InternationalizationAspect.class);
  6.  
  7. @Autowired
  8. InternationalizationService internationalizationService;
  9.  
  10. @Autowired
  11. private HttpServletRequest httpServletRequest;
  12.  
  13. @Around("execution(* com.***.***.***.***.getDescription(..))")
  14. public Object getInternationalizedTitleDescription(ProceedingJoinPoint joinPoint) throws Throwable {
  15. log.info("title getdescription intercepted");
  16. if (httpServletRequest == null) {
  17. log.info("http servlet request was not autowired correctly");
  18. return joinPoint.proceed();
  19. } else {
  20. Locale locale = httpServletRequest.getLocale();
  21. log.info("locale is = " + locale);
  22. if (locale.getLanguage().equals(new Locale(LANGUAGE_CODE_ENGLISH).getLanguage())) {
  23. return joinPoint.proceed();
  24. } else {
  25. log.info("getting internationalized description");
  26. Title t = (Title) joinPoint.getTarget();
  27. return internationalizationService.getTitleDescriptionFromTitleAndLocale(t, locale);
  28. }
  29. }
  30. }
  31. }
  32.  
  33. title getdescription intercepted
  34. http servlet request was not autowired correctly
  35. title getdescription intercepted
  36. http servlet request was not autowired correctly
  37. title getdescription intercepted
  38. http servlet request was not autowired correctly
  39. title getdescription intercepted
  40. http servlet request was not autowired correctly
  41.  
  42. <bean id="internationalizationAspect" class="com.***.***.***.InternationalizationAspect" />
  43. <context:component-scan base-package="com.***">
  44. <context:exclude-filter expression=".*_Roo_.*" type="regex"/>
  45. <context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
  46. </context:component-scan>
  47.  
  48. <?xml version="1.0" encoding="UTF-8"?>
  49. <web-app xmlns="http://java.sun.com/xml/ns/javaee"
  50. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  51. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  52. http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
  53.  
  54. <display-name>Spring Web Application example</display-name>
  55.  
  56. <!-- Configurations for the root application context (parent context) -->
  57. <listener>
  58. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  59. </listener>
  60. <context-param>
  61. <param-name>contextConfigLocation</param-name>
  62. <param-value>
  63. /META-INF/spring/applicationContext.xml
  64. </param-value>
  65. </context-param>
  66.  
  67. <!-- Configurations for the DispatcherServlet application context (child context) -->
  68. <servlet>
  69. <servlet-name>spring-mvc</servlet-name>
  70. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  71. <init-param>
  72. <param-name>contextConfigLocation</param-name>
  73. <param-value>
  74. /WEB-INF/spring/mvc/spring-mvc-servlet.xml
  75. </param-value>
  76. </init-param>
  77. </servlet>
  78. <servlet-mapping>
  79. <servlet-name>spring-mvc</servlet-name>
  80. <url-pattern>/admin/*</url-pattern>
  81. </servlet-mapping>
  82.  
  83. </web-app>
  84.  
  85. <context:annotation-config />
  86.  
  87. <context:component-scan ... />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement