List of usage examples for org.apache.wicket Component getLocale
public Locale getLocale()
From source file:com.premiumminds.webapp.wicket.bootstrap.datepicker.BootstrapDatePickerBehaviour.java
License:Open Source License
@Override public void renderHead(Component component, IHeaderResponse response) { super.renderHead(component, response); Collection<SpecialDate> specialDates = getSpecialDates(); if (component.isEnabledInHierarchy()) { response.render(CssReferenceHeaderItem.forReference(DATE_PICKER_CSS)); response.render(JavaScriptHeaderItem.forReference(DATE_PICKER_JAVASCRIPT)); response.render(JavaScriptHeaderItem.forReference(DATE_PICKER_EXTENSION_JAVASCRIPT)); if (!component.getLocale().getLanguage().equals("en")) { response.render(JavaScriptHeaderItem .forReference(new JavaScriptResourceReference(BootstrapDatePickerBehaviour.class, "locales/bootstrap-datepicker." + component.getLocale().getLanguage() + ".js"))); }/*from w ww . j a v a 2 s . c om*/ if (null != specialDates && !specialDates.isEmpty()) { StringBuilder sb = new StringBuilder(); sb.append("["); DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); SpecialDate[] sdArray = specialDates.toArray(new SpecialDate[20]); for (int i = 0; i < specialDates.size(); ++i) { SpecialDate sd = sdArray[i]; sb.append("{dt:new Date('" + df.format(sd.getDt()) + "'), css:'" + sd.getCssClass() + "', tooltip:'" + sd.getTooltip() + "'}"); if (i < specialDates.size() - 1) { sb.append(","); } } sb.append("]"); response.render(OnDomReadyHeaderItem.forScript( "$(\"#" + component.getMarkupId() + "\").datepicker(null, " + sb.toString() + ")")); } else { response.render( OnDomReadyHeaderItem.forScript("$(\"#" + component.getMarkupId() + "\").datepicker()")); } } }
From source file:com.premiumminds.webapp.wicket.bootstrap.datepicker.BootstrapDatePickerBehaviour.java
License:Open Source License
@Override public void onComponentTag(Component component, ComponentTag tag) { super.onComponentTag(component, tag); if (component.isEnabledInHierarchy()) { tag.put("data-date-language", component.getLocale().getLanguage()); }/* w w w . j a v a 2 s. c om*/ }
From source file:com.userweave.pages.components.twoColumnPanel.multiColumnRadioChoicePanel.RadioChoiceColumnPanel.java
License:Open Source License
public static String getLabel(Component component, IModel model, IChoiceRenderer renderer) { Object objectValue = renderer.getDisplayValue(model.getObject()); Class objectClass = objectValue.getClass(); String displayValue = ""; if (objectClass != null && objectClass != String.class) { displayValue = component.getApplication().getConverterLocator().getConverter(objectClass) .convertToString(objectValue, component.getLocale()); //convertToString(objectValue, component.getLocale()); } else if (objectValue != null) { displayValue = objectValue.toString(); }/* www. j a v a 2 s. c o m*/ return displayValue; }
From source file:com.visural.wicket.behavior.dateinput.DateInputBehavior.java
License:Apache License
@Override public void bind(Component component) { setLocale(component.getLocale()); bound.add(component); component.setOutputMarkupId(true); }
From source file:de.micromata.genome.gwiki.wicket.GWikiLocalizer.java
License:Apache License
protected String getI18NFromGWiki(String key, Component component, IModel<?> model) { GWikiWeb wikiWeb = GWikiWeb.getWiki(); Locale loc = component.getLocale(); String lang = loc.getLanguage(); if (StringUtils.isEmpty(lang) == true) { lang = "en"; }//from w w w . j av a 2 s. com for (String mod : modules) { GWikiI18nElement el = (GWikiI18nElement) wikiWeb.getElement(mod); String v = el.getMessage(lang, key); if (v != null) { return v; } } return null; }
From source file:gr.abiss.calipso.wicket.CalipsoApplication.java
License:Open Source License
@Override public void init() { super.init(); // DEVELOPMENT or DEPLOYMENT RuntimeConfigurationType configurationType = this.getConfigurationType(); if (RuntimeConfigurationType.DEVELOPMENT.equals(configurationType)) { logger.info("You are in DEVELOPMENT mode"); // getResourceSettings().setResourcePollFrequency(Duration.ONE_SECOND); // getDebugSettings().setComponentUseCheck(true); getResourceSettings().setResourcePollFrequency(null); getDebugSettings().setComponentUseCheck(false); // getDebugSettings().setSerializeSessionAttributes(true); // getMarkupSettings().setStripWicketTags(false); // getExceptionSettings().setUnexpectedExceptionDisplay( // UnexpectedExceptionDisplay.SHOW_EXCEPTION_PAGE); // getAjaxSettings().setAjaxDebugModeEnabled(true); } else if (RuntimeConfigurationType.DEPLOYMENT.equals(configurationType)) { getResourceSettings().setResourcePollFrequency(null); getDebugSettings().setComponentUseCheck(false); // getDebugSettings().setSerializeSessionAttributes(false); // getMarkupSettings().setStripWicketTags(true); // getExceptionSettings().setUnexpectedExceptionDisplay( // UnexpectedExceptionDisplay.SHOW_INTERNAL_ERROR_PAGE); // getAjaxSettings().setAjaxDebugModeEnabled(false); }/*ww w . j ava 2s . c o m*/ // initialize velocity try { Velocity.init(); if (logger.isInfoEnabled()) { logger.info("Initialized Velocity engine"); } } catch (Exception e) { // TODO Auto-generated catch block logger.error("Failed to initialize velocity engine", e); } // Set custom page for internal errors getApplicationSettings().setInternalErrorPage(CalipsoErrorPage.class); // don't break down on missing resources getResourceSettings().setThrowExceptionOnMissingResource(false); // Redirect to PageExpiredError Page if current page is expired getApplicationSettings().setPageExpiredErrorPage(CalipsoPageExpiredErrorPage.class); // get hold of spring managed service layer (see BasePage, BasePanel etc // for how it is used) ServletContext sc = getServletContext(); applicationContext = WebApplicationContextUtils.getWebApplicationContext(sc); calipsoService = (CalipsoService) applicationContext.getBean("calipsoService"); calipsoPropertiesEditor = new CalipsoPropertiesEditor(); // check if acegi-cas authentication is being used, get reference to // object to be used // by wicket authentication to redirect to right pages for login / // logout try { calipsoCasProxyTicketValidator = (CalipsoCasProxyTicketValidator) applicationContext .getBean("casProxyTicketValidator"); logger.info("casProxyTicketValidator retrieved from application context: " + calipsoCasProxyTicketValidator); } catch (NoSuchBeanDefinitionException nsbde) { logger.info( "casProxyTicketValidator not found in application context, CAS single-sign-on is not being used"); } // delegate wicket i18n support to spring i18n getResourceSettings().getStringResourceLoaders().add(new IStringResourceLoader() { @Override public String loadStringResource(Class<?> clazz, String key, Locale locale, String style, String variation) { return applicationContext.getMessage(key, null, null, locale); } @Override public String loadStringResource(Component component, String key, Locale locale, String style, String variation) { return applicationContext.getMessage(key, null, null, locale); } }); // add DB i18n resources getResourceSettings().getStringResourceLoaders().add(new IStringResourceLoader() { @Override public String loadStringResource(Class<?> clazz, String key, Locale locale, String style, String variation) { if (StringUtils.isNotBlank(locale.getVariant())) { // always ignore the variant locale = new Locale(locale.getLanguage(), locale.getCountry()); } String lang = locale.getLanguage(); I18nStringResource resource = CalipsoApplication.this.calipsoService .loadI18nStringResource(new I18nStringIdentifier(key, lang)); if (resource == null && !lang.equalsIgnoreCase("en")) { resource = CalipsoApplication.this.calipsoService .loadI18nStringResource(new I18nStringIdentifier(key, "en")); } return resource != null ? resource.getValue() : null; } @Override public String loadStringResource(Component component, String key, Locale locale, String style, String variation) { locale = component == null ? Session.get().getLocale() : component.getLocale(); if (StringUtils.isNotBlank(locale.getVariant())) { // always ignore the variant locale = new Locale(locale.getLanguage(), locale.getCountry()); } String lang = locale.getLanguage(); I18nStringResource resource = CalipsoApplication.this.calipsoService .loadI18nStringResource(new I18nStringIdentifier(key, lang)); if (resource == null && !lang.equalsIgnoreCase("en")) { resource = CalipsoApplication.this.calipsoService .loadI18nStringResource(new I18nStringIdentifier(key, "en")); } return resource != null ? resource.getValue() : null; } }); // cache resources. resource cache is cleared when creating/updating a space getResourceSettings().getLocalizer().setEnableCache(true); getSecuritySettings().setAuthorizationStrategy(new IAuthorizationStrategy() { @Override public boolean isActionAuthorized(Component c, Action a) { return true; } @Override public boolean isInstantiationAuthorized(Class clazz) { if (BasePage.class.isAssignableFrom(clazz)) { if (((CalipsoSession) Session.get()).isAuthenticated()) { return true; } if (calipsoCasProxyTicketValidator != null) { // attempt CAS authentication // ========================== // logger.debug("checking if context contains CAS authentication"); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null && authentication.isAuthenticated()) { // logger.debug("security context contains CAS authentication, initializing session"); ((CalipsoSession) Session.get()).setUser((User) authentication.getPrincipal()); return true; } } // attempt remember-me auto login // ========================== if (attemptRememberMeAutoLogin()) { return true; } // attempt *anonymous* guest access if there are // spaces that allow it if (((CalipsoSession) Session.get()).getUser() == null) { List<Space> anonymousSpaces = getCalipso().findSpacesWhereAnonymousAllowed(); if (anonymousSpaces.size() > 0) { // logger.debug("Found "+anonymousSpaces.size() // + // " anonymousSpaces allowing ANONYMOUS access, initializing anonymous user"); User guestUser = new User();//getCalipso().loadUser(2); guestUser.setLoginName("guest"); guestUser.setName("Anonymous"); guestUser.setLastname("Guest"); guestUser.setLocale(Session.get().getLocale().getLanguage()); getCalipso().initImplicitRoles(guestUser, anonymousSpaces, RoleType.ANONYMOUS); // store user in session ((CalipsoSession) Session.get()).setUser(guestUser); return true; } else { if (logger.isDebugEnabled()) { // logger.debug("Found no public spaces."); } } } // allow registration if (clazz.equals(RegisterUserFormPage.class)) { return true; } // not authenticated, go to login page // logger.debug("not authenticated, forcing login, page requested was " // + clazz.getName()); if (calipsoCasProxyTicketValidator != null) { String serviceUrl = calipsoCasProxyTicketValidator.getLoginUrl(); // .getServiceProperties().getService(); String loginUrl = calipsoCasProxyTicketValidator.getLoginUrl(); // logger.debug("cas authentication: service URL: " // + serviceUrl); String redirectUrl = loginUrl + "?service=" + serviceUrl; // logger.debug("attempting to redirect to: " + // redirectUrl); throw new RestartResponseAtInterceptPageException(new RedirectPage(redirectUrl)); } else { throw new RestartResponseAtInterceptPageException(LoginPage.class); } } return true; } }); // TODO: create friendly URLs for all created pages // friendly URLs for selected pages if (calipsoCasProxyTicketValidator != null) { mountPage("/login", CasLoginPage.class); } else { mountPage("/login", LoginPage.class); } mountPage("/register", RegisterAnonymousUserFormPage.class); mountPage("/logout", LogoutPage.class); mountPage("/svn", SvnStatsPage.class); mountPage("/test", TestPage.class); mountPage("/casError", CasLoginErrorPage.class); mountPage("/item/", ItemViewPage.class); mountPage("/item/${itemId}", ItemViewPage.class); mountPage("/itemreport/", ItemTemplateViewPage.class); mountPage("/newItem/${spaceCode}", NewItemPage.class); // MixedParamUrlCodingStrategy newItemUrls = new MixedParamUrlCodingStrategy( // "/newItem", // NewItemPage.class, // new String[]{"spaceCode"} // ); // mount(newItemUrls); //fix for tinyMCE bug, see https://github.com/wicketstuff/core/issues/113 SecurePackageResourceGuard guard = (SecurePackageResourceGuard) getResourceSettings() .getPackageResourceGuard(); guard.addPattern("+*.htm"); this.getRequestCycleSettings().setTimeout(Duration.minutes(6)); this.getPageSettings().setVersionPagesByDefault(true); this.getExceptionSettings().setThreadDumpStrategy(ThreadDumpStrategy.THREAD_HOLDING_LOCK); }
From source file:info.jtrac.wicket.JtracApplication.java
License:Apache License
@Override public void init() { super.init(); /*//from ww w .j a v a 2 s.co m * Get hold of spring managed service layer (see BasePage, BasePanel, * etc. for how it is used). */ ServletContext sc = getServletContext(); applicationContext = WebApplicationContextUtils.getWebApplicationContext(sc); jtrac = (Jtrac) applicationContext.getBean("jtrac"); /* * Check if acegi-cas authentication is being used, get reference to * object to be used by Wicket authentication to redirect to right * pages for login/logout. */ try { jtracCasProxyTicketValidator = (JtracCasProxyTicketValidator) applicationContext .getBean("casProxyTicketValidator"); logger.info("casProxyTicketValidator retrieved from application " + "context: " + jtracCasProxyTicketValidator); } catch (NoSuchBeanDefinitionException nsbde) { logger.debug(nsbde.getMessage()); logger.info("casProxyTicketValidator not found in application " + "context, CAS single-sign-on is not being used"); } /* * Delegate Wicket i18n support to spring i18n */ getResourceSettings().addStringResourceLoader(new IStringResourceLoader() { /* (non-Javadoc) * @see org.apache.wicket.resource.loader.IStringResourceLoader#loadStringResource(java.lang.Class, java.lang.String, java.util.Locale, java.lang.String) */ @Override public String loadStringResource(@SuppressWarnings("rawtypes") Class clazz, String key, Locale locale, String style) { try { return applicationContext.getMessage(key, null, locale == null ? Session.get().getLocale() : locale); } catch (Exception e) { /* * For performance, Wicket expects null instead of * throwing an exception and Wicket may try to * re-resolve using prefixed variants of the key. */ return null; } } /* (non-Javadoc) * @see org.apache.wicket.resource.loader.IStringResourceLoader#loadStringResource(org.apache.wicket.Component, java.lang.String) */ @Override public String loadStringResource(Component component, String key) { String value = loadStringResource(null, key, component == null ? null : component.getLocale(), null); if (logger.isDebugEnabled() && value == null) { logger.debug("i18n failed for key: '" + key + "', component: " + component); } return value; } }); getSecuritySettings().setAuthorizationStrategy(new IAuthorizationStrategy() { /* (non-Javadoc) * @see org.apache.wicket.authorization.IAuthorizationStrategy#isActionAuthorized(org.apache.wicket.Component, org.apache.wicket.authorization.Action) */ @Override public boolean isActionAuthorized(Component c, Action a) { return true; } /* (non-Javadoc) * @see org.apache.wicket.authorization.IAuthorizationStrategy#isInstantiationAuthorized(java.lang.Class) */ @Override public boolean isInstantiationAuthorized(@SuppressWarnings("rawtypes") Class clazz) { if (BasePage.class.isAssignableFrom(clazz)) { if (JtracSession.get().isAuthenticated()) { return true; } if (jtracCasProxyTicketValidator != null) { /* * ============================================ * Attempt CAS authentication * ============================================ */ logger.debug("checking if context contains CAS authentication"); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null && authentication.isAuthenticated()) { logger.debug("security context contains CAS authentication, initializing session"); JtracSession.get().setUser((User) authentication.getPrincipal()); return true; } } /* * ================================================ * Attempt remember-me auto login * ================================================ */ if (attemptRememberMeAutoLogin()) { return true; } /* * ================================================= * Attempt guest access if there are "public" spaces * ================================================= */ List<Space> spaces = getJtrac().findSpacesWhereGuestAllowed(); if (spaces.size() > 0) { logger.debug(spaces.size() + " public space(s) available, initializing guest user"); User guestUser = new User(); guestUser.setLoginName("guest"); guestUser.setName("Guest"); for (Space space : spaces) { guestUser.addSpaceWithRole(space, Role.ROLE_GUEST); } JtracSession.get().setUser(guestUser); // and proceed return true; } /* * Not authenticated, go to login page. */ logger.debug("not authenticated, forcing login, " + "page requested was " + clazz.getName()); if (jtracCasProxyTicketValidator != null) { String serviceUrl = jtracCasProxyTicketValidator.getServiceProperties().getService(); String loginUrl = jtracCasProxyTicketValidator.getLoginUrl(); logger.debug("cas authentication: service URL: " + serviceUrl); String redirectUrl = loginUrl + "?service=" + serviceUrl; logger.debug("attempting to redirect to: " + redirectUrl); throw new RestartResponseAtInterceptPageException(new RedirectPage(redirectUrl)); } else { throw new RestartResponseAtInterceptPageException(LoginPage.class); } } return true; } }); /* * Friendly URLs for selected pages */ if (jtracCasProxyTicketValidator != null) { mountBookmarkablePage("/login", CasLoginPage.class); /* * This matches the value set in: * WEB-INF/applicationContext-acegi-cas.xml */ mountBookmarkablePage("/cas/error", CasLoginErrorPage.class); } else { mountBookmarkablePage("/login", LoginPage.class); } mountBookmarkablePage("/logout", LogoutPage.class); mountBookmarkablePage("/svn", SvnStatsPage.class); mountBookmarkablePage("/options", OptionsPage.class); mountBookmarkablePage("/item/form", ItemFormPage.class); /* * Bookmarkable URL for search and search results */ mount(new QueryStringUrlCodingStrategy("/item/search", ItemSearchFormPage.class)); mount(new QueryStringUrlCodingStrategy("/item/list", ItemListPage.class)); /* * Bookmarkable URL for viewing items */ mount(new IndexedParamUrlCodingStrategy("/item", ItemViewPage.class)); }
From source file:main.java.info.jtrac.wicket.JtracApplication.java
License:Apache License
@Override public void init() { super.init(); // get hold of spring managed service layer (see BasePage, BasePanel etc for how it is used) ServletContext sc = getServletContext(); // applicationContext = WebApplicationContextUtils.getWebApplicationContext(sc); jtrac = (Jtrac) applicationContext.getBean("jtrac"); // check if acegi-cas authentication is being used, get reference to object to be used // by wicket authentication to redirect to right pages for login / logout try {//w w w .j a v a2 s . co m jtracCasProxyTicketValidator = (JtracCasProxyTicketValidator) applicationContext .getBean("casProxyTicketValidator"); logger.info( "casProxyTicketValidator retrieved from application context: " + jtracCasProxyTicketValidator); } catch (NoSuchBeanDefinitionException nsbde) { logger.info( "casProxyTicketValidator not found in application context, CAS single-sign-on is not being used"); } // delegate wicket i18n support to spring i18n getResourceSettings().addStringResourceLoader(new IStringResourceLoader() { public String loadStringResource(Class clazz, String key, Locale locale, String style) { try { return applicationContext.getMessage(key, null, locale); } catch (Exception e) { // have to return null so that wicket can try to resolve again // e.g. without prefixing component id etc. if (logger.isDebugEnabled()) { logger.debug("i18n failed for key: '" + key + "', Class: " + clazz + ", Style: " + style + ", Exception: " + e); } return null; } } public String loadStringResource(Component component, String key) { Class clazz = component == null ? null : component.getClass(); Locale locale = component == null ? Session.get().getLocale() : component.getLocale(); return loadStringResource(clazz, key, locale, null); } }); getSecuritySettings().setAuthorizationStrategy(new IAuthorizationStrategy() { public boolean isActionAuthorized(Component c, Action a) { return true; } public boolean isInstantiationAuthorized(Class clazz) { if (BasePage.class.isAssignableFrom(clazz)) { if (((JtracSession) Session.get()).isAuthenticated()) { return true; } if (jtracCasProxyTicketValidator != null) { // attempt CAS authentication ========================== logger.debug("checking if context contains CAS authentication"); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null && authentication.isAuthenticated()) { logger.debug("security context contains CAS authentication, initializing session"); ((JtracSession) Session.get()).setUser((User) authentication.getPrincipal()); return true; } } // attempt remember-me auto login ========================== if (attemptRememberMeAutoLogin()) { return true; } // attempt guest access if there are "public" spaces ======= List<Space> spaces = getJtrac().findSpacesWhereGuestAllowed(); if (spaces.size() > 0) { logger.debug(spaces.size() + " public space(s) available, initializing guest user"); User guestUser = new User(); guestUser.setLoginName("guest"); guestUser.setName("Guest"); guestUser.addSpaceWithRole(null, "ROLE_GUEST"); for (Space space : spaces) { guestUser.addSpaceWithRole(space, "ROLE_GUEST"); } ((JtracSession) Session.get()).setUser(guestUser); // and proceed return true; } // not authenticated, go to login page logger.debug("not authenticated, forcing login, page requested was " + clazz.getName()); if (jtracCasProxyTicketValidator != null) { String serviceUrl = jtracCasProxyTicketValidator.getServiceProperties().getService(); String loginUrl = jtracCasProxyTicketValidator.getLoginUrl(); logger.debug("cas authentication: service URL: " + serviceUrl); String redirectUrl = loginUrl + "?service=" + serviceUrl; logger.debug("attempting to redirect to: " + redirectUrl); throw new RestartResponseAtInterceptPageException(new RedirectPage(redirectUrl)); } else { throw new RestartResponseAtInterceptPageException(LoginPage.class); } } return true; } }); // friendly urls for selected pages if (jtracCasProxyTicketValidator != null) { mountBookmarkablePage("/login", CasLoginPage.class); } else { mountBookmarkablePage("/login", LoginPage.class); } mountBookmarkablePage("/logout", LogoutPage.class); mountBookmarkablePage("/svn", SvnStatsPage.class); mountBookmarkablePage("/test", TestPage.class); mountBookmarkablePage("/casError", CasLoginErrorPage.class); // bookmarkable url for viewing items mount(new IndexedParamUrlCodingStrategy("/item", ItemViewPage.class)); }
From source file:name.martingeisse.wicket.util.WicketConverterUtil.java
License:Open Source License
/** * Converts a value to a string. The type converter and locale are taken * from the specified context component. Null values are converted to the * empty string.//ww w .j a va 2 s . c o m * * @param value the value to convert * @param context the context that provides the type converter and the locale * @return the converted value */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static String convertValueToString(Object value, Component context) { if (value == null) { return ""; } else { IConverter converter = context.getConverter(value.getClass()); return converter.convertToString(value, context.getLocale()); } }
From source file:nl.knaw.dans.common.wicket.DebugStringResourceLoader.java
License:Apache License
public String loadStringResource(Component component, String key) { Iterator<IStringResourceLoader> iter = rloaders.iterator(); while (iter.hasNext()) { IStringResourceLoader loader = (IStringResourceLoader) iter.next(); String string = loader.loadStringResource(component, key); if (string != null) { return filterStringResource(component.getLocale(), string); }//from w ww . j a va2 s . c om } return null; }