Java Code Examples for org.apache.wicket.Application#exists()

The following examples show how to use org.apache.wicket.Application#exists() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApplicationHelper.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
public static IApplication ensureApplication() {
	if (Application.exists()) {
		return (IApplication)Application.get();
	}
	synchronized (SYNC_OBJ) {
		if (Application.exists()) {
			return (IApplication)Application.get();
		}
		WebApplication app = createApp((WebApplication)Application.get(getWicketApplicationName()));
		LabelDao.initLanguageMap();
		if (app != null) {
			if (!isInitComplete()) {
				initApp(app);
			}
			ThreadContext.setApplication(app);
		}
		return (IApplication)Application.get(getWicketApplicationName());
	}
}
 
Example 2
Source File: SassCacheManager.java    From webanno with Apache License 2.0 5 votes vote down vote up
/**
 * @return the registered instance of this manager during the start up of the application
 */
public static SassCacheManager get()
{
    if (Application.exists()) {
        return get(Application.get());
    }

    throw new IllegalStateException("there is no active application assigned to this thread.");
}
 
Example 3
Source File: WebResources.java    From etcd-viewer with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<? extends HeaderItem> getDependencies() {

    final ResourceReference backingLibraryReference;
    if (Application.exists()) {
        backingLibraryReference = Application.get().getJavaScriptLibrarySettings().getJQueryReference();
    } else {
        backingLibraryReference = JQueryResourceReference.get();
    }

    return Arrays.asList(CssHeaderItem.forReference(BOOTSTRAP_CSS), JavaScriptHeaderItem.forReference(backingLibraryReference));
}
 
Example 4
Source File: OrientDbWebApplication.java    From wicket-orientdb with Apache License 2.0 5 votes vote down vote up
protected static <T extends OrientDbWebApplication> T lookupApplication(Class<T> appClass)
{
	Application app = Application.exists()?Application.get():null;
	if(app!=null && appClass.isInstance(app)) return (T)app;
	else
	{
		for(String appKey: Application.getApplicationKeys())
		{
			app = Application.get(appKey);
			if(appClass.isInstance(app)) return (T)app;
		}
	}
	return null;
}
 
Example 5
Source File: WicketApplicationFilter.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException
{
  // Sollte eigentlich immer NULL ergeben, aber man weiss nie ...
  final Application previousOne = (Application.exists() == true) ? Application.get() : null;
  org.apache.wicket.ThreadContext.setApplication(this.application);
  try {
    chain.doFilter(request, response);
  } finally {
    if (previousOne != null) {
      org.apache.wicket.ThreadContext.setApplication(previousOne);
    } else {
      org.apache.wicket.ThreadContext.setApplication(null);
    }
  }
}
 
Example 6
Source File: ConfigurationDao.java    From openmeetings with Apache License 2.0 4 votes vote down vote up
public void updateCsp() {
	setGaCode(getString(CONFIG_GOOGLE_ANALYTICS_CODE, null));

	if (!getBool(CONFIG_CSP_ENABLED, true)) {
		StringBuilder sb = new StringBuilder("\n");
		getLine(sb, "", '#');
		getLine(sb, "CSP headers are DISABLED", ' ');
		getLine(sb, "Disabling CSP can lead to XSS attacks! Use this mode only if you must!", ' ');
		getLine(sb, "", '#');
		log.warn(sb.toString());
		WebApplication.get().getCspSettings().blocking().disabled();
		return;
	}

	setCspFontSrc(getString(CONFIG_CSP_FONT, DEFAULT_CSP_FONT));
	setCspFrameSrc(getString(CONFIG_CSP_FRAME, SELF.getValue()));
	setCspImageSrc(getString(CONFIG_CSP_IMAGE, DEFAULT_CSP_DATA));
	setCspMediaSrc(getString(CONFIG_CSP_MEDIA, DEFAULT_CSP_DATA));
	setCspScriptSrc(getString(CONFIG_CSP_SCRIPT, STRICT_DYNAMIC.getValue()));
	setCspStyleSrc(getString(CONFIG_CSP_STYLE, DEFAULT_CSP_STYLE));
	if (Application.exists()) {
		final CSPHeaderConfiguration cspConfig = WebApplication.get().getCspSettings().blocking().strict();
		addCspRule(cspConfig, CSPDirective.FONT_SRC, getCspFontSrc());
		addCspRule(cspConfig, CSPDirective.FRAME_SRC, getCspFrameSrc());
		addCspRule(cspConfig, CSPDirective.IMG_SRC, getCspImageSrc());
		addCspRule(cspConfig, CSPDirective.MEDIA_SRC, getCspMediaSrc());
		addCspRule(cspConfig, CSPDirective.SCRIPT_SRC, getCspScriptSrc());
		addCspRule(cspConfig, CSPDirective.STYLE_SRC, getCspStyleSrc());
		addCspRule(cspConfig, CSPDirective.CONNECT_SRC, app.getWsUrl(), false); // special code for Safari browser
		if (!Strings.isEmpty(getGaCode())) {
			// https://developers.google.com/tag-manager/web/csp#universal_analytics_google_analytics
			addCspRule(cspConfig, CSPDirective.IMG_SRC, "https://www.google-analytics.com");
			addCspRule(cspConfig, CSPDirective.SCRIPT_SRC, "https://www.google-analytics.com, https://ssl.google-analytics.com");
		}
		oauthDao.getActive().forEach(oauth -> {
			if (!Strings.isEmpty(oauth.getIconUrl())) {
				addCspRule(cspConfig, CSPDirective.IMG_SRC, oauth.getIconUrl(), false);
			}
		});
	}
}