/** * Gets the {@link JQueryLibrarySettings} * * @return The {@link JQueryLibrarySettings} or {@code null} if {@link Application}'s {@link * JavaScriptLibrarySettings} 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; }
private void onInternalDetach() { if (Session.exists()) { Session.get().internalDetach(); } if (Application.exists()) { IRequestLogger requestLogger = Application.get().getRequestLogger(); if (requestLogger != null) requestLogger.performLogging(); } }
/** * Returns a localized message string, if there is a localization; otherwise the given default * value. * * @param key 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; }
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { if (Application.exists() == false) { throw new AssertionFailedError("The application is not available!"); } if (Session.exists() == false) { throw new AssertionFailedError("The session is not available!"); } }
private RequestCycle newRequestCycle(final RuntimeException exception) { final Response originalResponse = newResponse(); Request request = new MockWebRequest(Url.parse("http://wicket.apache.org")); handler = new IRequestHandler() { @Override public void respond(IRequestCycle requestCycle) { if (exception != null) { throw exception; } responses++; } @Override public void detach(IRequestCycle requestCycle) { detaches++; } }; IRequestMapper requestMapper = new IRequestMapper() { @Override public IRequestHandler mapRequest(Request request) { return handler; } @Override public Url mapHandler(IRequestHandler requestHandler) { throw new UnsupportedOperationException(); } @Override public int getCompatibilityScore(Request request) { throw new UnsupportedOperationException(); } }; IExceptionMapper exceptionMapper = new IExceptionMapper() { @Override public IRequestHandler map(Exception e) { exceptionsMapped++; return null; } }; RequestCycleContext context = new RequestCycleContext(request, originalResponse, requestMapper, exceptionMapper); RequestCycle cycle = new RequestCycle(context); if (Application.exists()) { cycle.getListeners().add(Application.get().getRequestCycleListeners()); } return cycle; }
@Override public Iterable<? extends HeaderItem> getDependencies() { final ResourceReference backingLibraryReference; if (Application.exists()) { backingLibraryReference = Application.get().getJavaScriptLibrarySettings().getJQueryReference(); } else { backingLibraryReference = JQueryResourceReference.get(); } return Dependencies.combine( super.getDependencies(), JavaScriptHeaderItem.forReference(backingLibraryReference)); }
/** * WICKET-3470 * * <p>Tests that a page already put in the session (in SessionEntry) can be serialized and later * deserialized without the need of {@link IPageStore} * * @throws ClassNotFoundException * @throws IOException */ @Test public void serializationOutsideWicketLifecyle() throws IOException, ClassNotFoundException { // make sure no leaked threadlocals are present ThreadContext.detach(); // create IPageManager (with IPageStore) and store a page instance IPageManager pageManager = newPersistentPageManager(APP_NAME); TestPage toSerializePage = new TestPage(); pageManager.touchPage(toSerializePage); pageManager.commitRequest(); // get the stored SessionEntry Serializable sessionEntry = pageManager.getContext().getSessionAttribute(null); // destroy the manager and the store pageManager.destroy(); // simulate persisting of the http sessions initiated by the web container byte[] serializedSessionEntry = new JavaSerializer(APP_NAME).serialize(sessionEntry); assertNotNull("Wicket needs to be able to serialize the session entry", serializedSessionEntry); // simulate loading of the persisted http session initiated by the web container // when starting an application ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(serializedSessionEntry)); // WicketFilter is not initialized so there is no Application available yet Assert.assertFalse( "Worker thread should be unaware of Wicket application", Application.exists()); assertEquals(APP_NAME, in.readObject()); // without available IPageStore the read SessionEntry holds // the IManageablePage itself, not SerializedPage Serializable loadedSessionEntry = (Serializable) in.readObject(); assertNotNull( "Wicket needs to be able to deserialize the session entry regardless the application availability", loadedSessionEntry); // provide new IPageStore which will read IManageablePage's or SerializedPage's // from the SessionEntry's IPageManager newPageManager = newPersistentPageManager(APP_NAME); newPageManager.getContext().setSessionAttribute(null, loadedSessionEntry); TestPage deserializedPage = (TestPage) newPageManager.getPage(toSerializePage.getPageId()); assertNotNull(deserializedPage); assertEquals(toSerializePage.instanceID, deserializedPage.instanceID); newPageManager.destroy(); }
/** * Determines a limit to use for HTML diff output. * * @param key 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; }
/** Constructor */ public Behavior() { if (Application.exists()) { Application.get().getBehaviorInstantiationListeners().onInstantiation(this); } }