List of usage examples for org.apache.wicket Application get
public static Application get()
From source file:org.odlabs.wiquery.core.commons.merge.WiQueryMergedJavaScriptResourceReference.java
License:Open Source License
/** * {@inheritDoc}/* ww w.j av a2s. co m*/ */ @Override protected Resource newResource() { return new Resource() { private static final long serialVersionUID = 1L; /** * {@inheritDoc} */ public IResourceStream getResourceStream() { String temp = null; Application application = Application.get(); StringBuffer buffer = new StringBuffer(); IJavascriptCompressor compressor = application.getResourceSettings().getJavascriptCompressor(); for (ResourceReference ref : wiQueryHeaderResponse.getJavascript()) { // We bind the resources into the SharedResources ref.bind(Application.get()); // We insert the javascript code into the template try { IResourceStream resource = Application.get().getResourceSettings() .getResourceStreamLocator().locate(getClass(), "/" + Packages.absolutePath(ref.getScope(), "") + "/" + ref.getName()); if (resource != null) temp = Streams.readString(resource.getInputStream()); } catch (Exception e) { temp = null; e.printStackTrace(); LOGGER.error("error in merged processing", e); } if (compressor != null && temp != null) { temp = compressor.compress(temp); } if (temp != null) { buffer.append(temp).append("\r\n"); } } Map<String, Object> genJs = new HashMap<String, Object>(); genJs.put("wiqueryresources", buffer); jstemplate.interpolate(genJs); return new StringResourceStream(jstemplate.asString(), CONTENT_TYPE); } }; }
From source file:org.odlabs.wiquery.core.commons.merge.WiQueryMergedStyleSheetResourceReference.java
License:Open Source License
private IResourceStream newResourceStream() { String temp = null;/* w ww . j av a 2 s. c o m*/ String cssUrl; String name; String old; String match; StringBuffer buffer = new StringBuffer(); HttpServletRequest request = ((WebRequest) RequestCycle.get().getRequest()).getHttpServletRequest(); String baseHost = request.getRequestURL().toString(); baseHost = baseHost.substring(0, baseHost.indexOf(request.getRequestURI())) + request.getContextPath() + "/resources/"; for (ResourceReference ref : wiQueryHeaderResponse.getStylesheet()) { // We bind the resources into the SharedResources ref.bind(Application.get()); // We insert the javascript code into the template try { IResourceStream resource = Application.get().getResourceSettings().getResourceStreamLocator() .locate(getClass(), "/" + Packages.absolutePath(ref.getScope(), "") + "/" + ref.getName()); if (resource != null) temp = Streams.readString(resource.getInputStream()); // Replace of url in the css file (regexp: url\(.*?\) ) name = ref.getName(); cssUrl = baseHost + ref.getScope().getName() + "/" + (name.indexOf("/") < 0 ? "" : name.substring(0, name.lastIndexOf("/") + 1)); Pattern p = Pattern.compile(REGEX); Matcher m = p.matcher(temp); // get a matcher object int count = 0; while (m.find()) { count++; match = m.group(); old = getCssUrl(match, cssUrl); if (!old.equals(match)) { temp = temp.replace(match, old); } } } catch (Exception e) { temp = null; e.printStackTrace(); LOGGER.error("error in merged processing", e); } if (temp != null) { buffer.append(temp).append("\r\n"); } } Map<String, Object> genCss = new HashMap<String, Object>(); genCss.put("wiqueryresources", buffer); csstemplate.interpolate(genCss); return new StringResourceStream(csstemplate.asString(), CONTENT_TYPE); }
From source file:org.odlabs.wiquery.core.commons.WiQuerySettings.java
License:Open Source License
/** * Get {@link WiQuerySettings} for current thread. * //from w ww . j ava 2 s .c om * @return The settings */ public static WiQuerySettings get() { WiQuerySettings instance = Application.get().getMetaData(WiQueryInitializer.WIQUERY_INSTANCE_KEY); if (instance == null) { throw new WicketRuntimeException( "There is no WiQuerySettings attached to the application " + Thread.currentThread().getName()); } return instance; }
From source file:org.odlabs.wiquery.core.commons.WiQuerySettings.java
License:Open Source License
/** * Default constructor/*from w ww . j av a 2 s. c om*/ */ public WiQuerySettings() { super(); this.autoImportJQueryUIResource = true; this.enableWiqueryResourceManagement = true; this.embedGeneratedStatements = false; setAutoImportJQueryResource(true); setEnableResourcesMerging(false); setJQueryCoreResourceReference(null); listeners = new ArrayList<WiQueryPluginRenderingListener>(); IJavascriptCompressor compressor = Application.get().getResourceSettings().getJavascriptCompressor(); setMinifiedResources(compressor != null && !(compressor instanceof NoOpJavascriptCompressor)); }
From source file:org.odlabs.wiquery.core.WiQueryInitializer.java
License:Open Source License
public void init(Application application) { Application.get().getComponentInstantiationListeners().add(new WiQueryPluginInstantiationListener()); // check for WiQuerySettings on the application WiQuerySettings settings = application.getMetaData(WIQUERY_INSTANCE_KEY); // create new one when application has none if (settings == null) { settings = new WiQuerySettings(); // apply IWiQuerySettings to the applications metadata application.setMetaData(WIQUERY_INSTANCE_KEY, settings); // IWiQueryInitializer treatments retrieveAndCallInitializers(application, settings); } else {/*from ww w . j a v a 2s . c om*/ LOGGER.info("application already hasWiQuerySettings"); } }
From source file:org.odlabs.wiquery.core.WiQuerySettings.java
License:Open Source License
/** * Get {@link WiQuerySettings} for current thread. * /* w ww. j av a 2s. c o m*/ * @return The settings */ public static WiQuerySettings get() { WiQuerySettings instance = Application.get().getMetaData(WiQueryInitializer.WIQUERY_INSTANCE_KEY); if (instance == null) { throw new WicketRuntimeException(new StringBuilder() .append("There is no WiQueryInstantiationListener attached to the application ") .append(Thread.currentThread().getName()).toString()); } return instance; }
From source file:org.odlabs.wiquery.core.WiQuerySettings.java
License:Open Source License
public WiQuerySettings() { super();//from w w w.j a va2 s. c om initializers = new ArrayList<IWiQueryInitializer>(); listeners = new ArrayList<WiQueryPluginRenderingListener>(); setAutoImportJQueryResource(true); setAutoImportJQueryUIJavaScriptResource(true); setAutoImportJQueryUIStyleSheetResource(true); setEnableWiqueryResourceManagement(true); ITextResourceCompressor compressor = Application.get().getResourceSettings().getJavaScriptCompressor(); setMinifiedJavaScriptResources(compressor != null && !(compressor instanceof NoOpTextCompressor)); compressor = Application.get().getResourceSettings().getCssCompressor(); setMinifiedStyleSheetResources(compressor != null && !(compressor instanceof NoOpTextCompressor)); getResourceGroupingKeys().add("org.apache.wicket"); getResourceGroupingKeys().add("org.odlabs.wiquery.core"); getResourceGroupingKeys().add("org.odlabs.wiquery.ui"); }
From source file:org.odlabs.wiquery.ui.listener.JQueryUICoreRenderingListener.java
License:Open Source License
public void onRender(IWiQueryPlugin plugin, IHeaderResponse response) { // if css contribution is enabled and component is WiQueryUIPlugin then // contribute css if (WiQuerySettings.get().isAutoImportJQueryUIStyleSheetResource() && plugin.getClass().isAnnotationPresent(WiQueryUIPlugin.class)) { Application application = Application.get(); if (application instanceof IThemableApplication) { // if application is themable, imports the given theme response.renderCSSReference(((IThemableApplication) application).getTheme(Session.get())); } else {/*from www. ja v a 2 s.c om*/ // application is not themed, imports default theme response.renderCSSReference(WiQueryCoreThemeResourceReference.get()); } } // if js contribution is enabled and component is WiQueryUIPlugin then // contribute js if (WiQuerySettings.get().isAutoImportJQueryUIJavaScriptResource() && plugin.getClass().isAnnotationPresent(WiQueryUIPlugin.class)) { response.renderJavaScriptReference(CoreUIJavaScriptResourceReference.get()); } }
From source file:org.onehippo.forge.documenttranslationpicker.NodeChoiceRenderer.java
License:Apache License
@Override public Object getDisplayValue(Node node) { if (node == null) { Localizer localizer = Application.get().getResourceSettings().getLocalizer(); return localizer.getString("translation.none", component); }//from w ww .j av a 2s.co m return new NodeNameBuilder(node).build(); }
From source file:org.onehippo.forge.googleauth.cms.GoogleLoginPanel.java
License:Apache License
protected void loginFailed(final LoginException.Cause cause) { Main main = (Main) Application.get(); main.resetConnection(); info(getReason(cause)); }