Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Aspect
- public class InternationalizationAspect {
- private static final String LANGUAGE_CODE_ENGLISH = "en";
- private static Logger log = LoggerFactory.getLogger(InternationalizationAspect.class);
- @Autowired
- InternationalizationService internationalizationService;
- @Autowired
- private HttpServletRequest httpServletRequest;
- @Around("execution(* com.***.***.***.***.getDescription(..))")
- public Object getInternationalizedTitleDescription(ProceedingJoinPoint joinPoint) throws Throwable {
- log.info("title getdescription intercepted");
- if (httpServletRequest == null) {
- log.info("http servlet request was not autowired correctly");
- return joinPoint.proceed();
- } else {
- Locale locale = httpServletRequest.getLocale();
- log.info("locale is = " + locale);
- if (locale.getLanguage().equals(new Locale(LANGUAGE_CODE_ENGLISH).getLanguage())) {
- return joinPoint.proceed();
- } else {
- log.info("getting internationalized description");
- Title t = (Title) joinPoint.getTarget();
- return internationalizationService.getTitleDescriptionFromTitleAndLocale(t, locale);
- }
- }
- }
- }
- title getdescription intercepted
- http servlet request was not autowired correctly
- title getdescription intercepted
- http servlet request was not autowired correctly
- title getdescription intercepted
- http servlet request was not autowired correctly
- title getdescription intercepted
- http servlet request was not autowired correctly
- <bean id="internationalizationAspect" class="com.***.***.***.InternationalizationAspect" />
- <context:component-scan base-package="com.***">
- <context:exclude-filter expression=".*_Roo_.*" type="regex"/>
- <context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
- </context:component-scan>
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
- http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
- <display-name>Spring Web Application example</display-name>
- <!-- Configurations for the root application context (parent context) -->
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>
- /META-INF/spring/applicationContext.xml
- </param-value>
- </context-param>
- <!-- Configurations for the DispatcherServlet application context (child context) -->
- <servlet>
- <servlet-name>spring-mvc</servlet-name>
- <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
- <init-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>
- /WEB-INF/spring/mvc/spring-mvc-servlet.xml
- </param-value>
- </init-param>
- </servlet>
- <servlet-mapping>
- <servlet-name>spring-mvc</servlet-name>
- <url-pattern>/admin/*</url-pattern>
- </servlet-mapping>
- </web-app>
- <context:annotation-config />
- <context:component-scan ... />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement