List of usage examples for org.apache.wicket Application exists
public static boolean exists()
Application
threadlocal is set in this thread From source file:at.molindo.wicketutils.utils.MockUtilsTest.java
License:Apache License
@Test public void withSession() throws Exception { DummyApplication testApp = new DummyApplication(); try {//from w w w . j a v a 2 s . c o m assertFalse(Application.exists()); assertFalse(Session.exists()); assertFalse(RequestCycle.get() != null); String stringResource = MockUtils.withRequest(testApp, new MockRequestCallback<String>() { @Override public String call() { // some basic testing assertTrue(Application.exists()); assertFalse(Session.exists()); assertTrue(RequestCycle.get() != null); return new StringResourceModel("someResource", (IModel<?>) null, Model.of("default value")) .getString(); } }); assertEquals("default value", stringResource); String url = MockUtils.withRequest(testApp, new MockRequestCallback<String>() { @Override public String call() { return RequestCycle.get().urlFor(HomePage.class, null).toString(); } }); assertEquals(".", url); Locale locale = MockUtils.withRequest(testApp, new IMockRequestCallback<Locale>() { @Override public void configure(MockRequest request) { request.setLocale(Locale.GERMAN); } @Override public Locale call() { return Session.get().getLocale(); } }); assertEquals(Locale.GERMAN, locale); assertFalse(Application.exists()); assertFalse(Session.exists()); assertFalse(RequestCycle.get() != null); } finally { testApp.destroy(); } }
From source file:at.molindo.wicketutils.utils.WicketUtils.java
License:Apache License
/** * replacement for {@link Classes}.resolveClass(String) * // www .ja va 2 s . c om * @param <T> * class type * @param className * Class to resolve * @return Resolved class */ @SuppressWarnings("unchecked") public static <T> Class<T> resolveClass(final String className) { if (className == null) { return null; } try { if (Application.exists()) { return (Class<T>) Application.get().getApplicationSettings().getClassResolver() .resolveClass(className); } return (Class<T>) Class.forName(className); } catch (ClassNotFoundException e) { log.warn("Could not resolve class: " + className); return null; } }
From source file:com.evolveum.midpoint.web.component.SecurityContextAwareCallable.java
License:Apache License
protected void setupContext(Application application, Session session) { if (!Application.exists() && application != null) { ThreadContext.setApplication(application); }//from w ww. j av a 2s . co m if (!Session.exists() && session != null) { ThreadContext.setSession(session); } }
From source file:com.evolveum.midpoint.web.util.MidPointResourceStreamLocator.java
License:Apache License
@Override public IResourceNameIterator newResourceNameIterator(String path, Locale locale, String style, String variation, String extension, boolean strict) { String pathWithoutExtension = path; String ext = extension;//from w w w. j a v a 2 s.co m if (ext == null && path != null) { String[] array = path.split("\\."); ext = array.length > 1 ? array[array.length - 1] : null; int extLength = ext != null ? ext.length() + 1 : 0; pathWithoutExtension = StringUtils.left(path, path.length() - extLength); } if (!containsIgnoreCase(EXTENSIONS, ext)) { return super.newResourceNameIterator(path, locale, style, variation, extension, strict); } List<String> extensions = new ArrayList<>(); if (containsIgnoreCase(MIMIFIED_EXTENSIONS, ext) && Application.exists() && Application.get().getResourceSettings().getUseMinifiedResources() && !pathWithoutExtension.endsWith(".min")) { extensions.add("min." + ext); } extensions.add(ext); return new SimpleResourceNameIterator(pathWithoutExtension, extensions); }
From source file:com.gitblit.utils.GitBlitDiffFormatter.java
License:Apache License
/** * Determines a limit to use for HTML diff output. * * @param key/*from w ww . j a va 2s. c om*/ * to use to read the value from the GitBlit settings, if available. * @param minimum * minimum value to enforce * @param maximum * maximum (and default) value to enforce * @return the limit */ private int getLimit(String key, int minimum, int maximum) { if (Application.exists()) { Application application = Application.get(); if (application instanceof GitBlitWebApp) { GitBlitWebApp webApp = (GitBlitWebApp) application; int configValue = webApp.settings().getInteger(key, maximum); if (configValue < minimum) { return minimum; } else if (configValue < maximum) { return configValue; } } } return maximum; }
From source file:com.gitblit.utils.GitBlitDiffFormatter.java
License:Apache License
/** * Returns a localized message string, if there is a localization; otherwise the given default value. * * @param key//w w w.j av a 2 s . c o m * message key for the message * @param defaultValue * to use if no localization for the message can be found * @return the possibly localized message */ private String getMsg(String key, String defaultValue) { if (Application.exists()) { Localizer localizer = Application.get().getResourceSettings().getLocalizer(); if (localizer != null) { // Use getStringIgnoreSettings because we don't want exceptions here if the key is missing! return localizer.getStringIgnoreSettings(key, null, null, defaultValue); } } return defaultValue; }
From source file:com.gmail.volodymyrdotsenko.jqxwicket.core.JQueryAbstractBehavior.java
License:Apache License
/** * Gets the {@link JQueryLibrarySettings} * //from w w w . j a v a2s .c o m * @return The {@link JQueryLibrarySettings} or <tt>null</tt> if * {@link Application}'s {@link IJavaScriptLibrarySettings} is not * an instance of {@link JQueryLibrarySettings} */ public static JQueryLibrarySettings getJQueryLibrarySettings() { if (Application.exists() && (Application.get().getJavaScriptLibrarySettings() instanceof JQueryLibrarySettings)) { return (JQueryLibrarySettings) Application.get().getJavaScriptLibrarySettings(); } return null; }
From source file:com.googlecode.wicket.jquery.core.JQueryAbstractBehavior.java
License:Apache License
/** * Gets the {@link IJQueryLibrarySettings} * @return the {@link IJQueryLibrarySettings} *//*from w ww .j av a2 s. c o m*/ public static IJQueryLibrarySettings getJQueryLibrarySettings() { if (Application.exists() && (Application.get().getJavaScriptLibrarySettings() instanceof IJQueryLibrarySettings)) { return (IJQueryLibrarySettings) Application.get().getJavaScriptLibrarySettings(); } return JQueryLibrarySettings.get(); }
From source file:com.googlecode.wicket.jquery.core.JQueryAbstractBehavior.java
License:Apache License
@Override public void onConfigure(Component component) { super.onConfigure(component); if (Application.exists() && Application.get().usesDevelopmentConfig()) { if (!Application.get().getMarkupSettings().getStripWicketTags()) { LOG.warn(/*ww w. jav a2 s. co m*/ "Application>MarkupSettings>StripWicketTags setting is currently set to false. It is highly recommended to set it to true to prevent widget misbehaviors."); } } }
From source file:com.googlecode.wicket.jquery.ui.calendar.CalendarBehavior.java
License:Apache License
/** * Gets the {@link ICalendarLibrarySettings} * * @return null if Application's {@link IJavaScriptLibrarySettings} is not an instance of {@link ICalendarLibrarySettings} *//*from w ww . ja v a 2s . c o m*/ private static ICalendarLibrarySettings getLibrarySettings() { if (Application.exists() && (Application.get().getJavaScriptLibrarySettings() instanceof ICalendarLibrarySettings)) { return (ICalendarLibrarySettings) Application.get().getJavaScriptLibrarySettings(); } return CalendarLibrarySettings.get(); }