Example usage for org.apache.wicket Application get

List of usage examples for org.apache.wicket Application get

Introduction

In this page you can find the example usage for org.apache.wicket Application get.

Prototype

public static Application get() 

Source Link

Document

Get Application for current thread.

Usage

From source file:org.wicketstuff.js.ext.util.ExtResourcesHeaderItem.java

License:Apache License

@Override
public Iterable<? extends HeaderItem> getDependencies() {
    final Application application = Application.get();
    IJavaScriptLibrarySettings jsLibrarySettings = application.getJavaScriptLibrarySettings();

    final IDebugSettings debugSettings = application.getDebugSettings();
    if (debugSettings.isAjaxDebugModeEnabled()) {
        return Arrays.asList(JavaScriptHeaderItem.forReference(jsLibrarySettings.getWicketAjaxDebugReference()),
                JavaScriptHeaderItem.forScript("Wicket.Ajax.DebugWindow.enabled=true;",
                        "wicket-ajax-debug-enable"));
    } else {//  w w w .ja va2 s.com
        ResourceReference wicketAjaxReference = jsLibrarySettings.getWicketAjaxReference();
        return Arrays.asList(JavaScriptHeaderItem.forReference(wicketAjaxReference));
    }
}

From source file:org.wicketstuff.jslibraries.JSLib.java

License:Apache License

/**
 * @param versionDescriptor//from   w ww  .  j  ava2  s .  com
 * @param production
 *            if true tried to serve minimized versions
 * @param providers
 *            list of alternative providers (might be ignored if setOverrideProviders was used
 * @return matching HeaderContributor from the first matching provider
 */
public static IHeaderContributor getHeaderContribution(final VersionDescriptor versionDescriptor,
        final boolean production, final Provider... providers) {

    Provider[] prov = Application.get().getMetaData(PROVIDER_KEY);
    if (prov == null) {
        prov = providers;
    }

    if (prov != null) {
        for (final Provider provider : prov) {
            final IHeaderContributor hc = provider.getHeaderContributor(versionDescriptor, production);
            if (hc != null) {
                return hc;
            }
        }
    }

    return null;
}

From source file:org.wicketstuff.jslibraries.JSLibTest.java

License:Apache License

public void testSettings() throws Exception {
    new WicketTester();

    final StringBuffer sb = new StringBuffer(128);

    IHeaderContributor hc = JSLib.getHeaderContribution(VersionDescriptor.exactVersion(Library.JQUERY, 1, 3, 1),
            CDN.GOOGLE);/*from  w w w.  j av  a 2s .  c om*/
    HeaderResponse mockResponse = new HeaderResponse() {

        @Override
        protected Response getRealResponse() {

            return new Response() {

                @Override
                public void write(CharSequence arg0) {
                    sb.append(arg0);
                }

                @Override
                public Object getContainerResponse() {
                    throw new UnsupportedOperationException();
                }

                @Override
                public String encodeURL(CharSequence url) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public void write(byte[] array) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public void write(byte[] array, int offset, int length) {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
    hc.renderHead(mockResponse);
    String scriptTag = sb.toString();
    assertTrue(scriptTag.contains("google")); // must be in as selected
    assertFalse(scriptTag.contains("resources/org.wicketstuff.jsl"));
    sb.setLength(0);

    // now set applicationwide setting to local only:
    JSLib.setOverrideProviders(Application.get(), LocalProvider.DEFAULT);

    // and retest
    hc = JSLib.getHeaderContribution(VersionDescriptor.exactVersion(Library.JQUERY, 1, 3, 1), CDN.GOOGLE);

    hc.renderHead(mockResponse);
    scriptTag = sb.toString();
    assertTrue(
            scriptTag.contains("wicket/resource/org.wicketstuff.jslibraries.JSReference/js/jquery-1.3.1.js"));
}

From source file:org.wicketstuff.jslibraries.util.WicketDeploymentState.java

License:Apache License

public static boolean isProduction() {
    return RuntimeConfigurationType.DEPLOYMENT == Application.get().getConfigurationType();
}

From source file:org.wicketstuff.lazymodel.reflect.CachingMethodResolver.java

License:Apache License

private IMethodResolver getResolver() {
    Object key;/*from   w  w w . j  ava2s .  c  o m*/
    if (Application.exists()) {
        key = Application.get();
    } else {
        key = CachingMethodResolver.class;
    }

    IMethodResolver result = scopes.get(key);
    if (result == null) {
        IMethodResolver tmpResult = scopes.putIfAbsent(key, result = new ApplicationScope());
        if (tmpResult != null) {
            result = tmpResult;
        }
    }

    return result;
}

From source file:org.wicketstuff.lazymodel.reflect.CachingProxyFactory.java

License:Apache License

private IProxyFactory getFactory() {
    Object key;/*w ww .ja  v a 2 s.c  om*/
    if (Application.exists()) {
        key = Application.get();
    } else {
        key = CachingProxyFactory.class;
    }

    IProxyFactory result = scopes.get(key);
    if (result == null) {
        IProxyFactory tmpResult = scopes.putIfAbsent(key, result = new ApplicationScope());
        if (tmpResult != null) {
            result = tmpResult;
        }
    }

    return result;
}

From source file:org.wicketstuff.lightbox2.references.LightboxJavascriptResourceReference.java

License:Apache License

@Override
public List<HeaderItem> getDependencies() {
    List<HeaderItem> dependencies = new ArrayList<>();
    for (Iterator<? extends HeaderItem> iterator = super.getDependencies().iterator(); iterator.hasNext();) {
        HeaderItem headerItem = iterator.next();
        dependencies.add(headerItem);/*from  w  w w  .j a  v  a 2s  .  c o  m*/
    }
    dependencies.add(JavaScriptHeaderItem
            .forReference(Application.get().getJavaScriptLibrarySettings().getJQueryReference()));
    return dependencies;
}

From source file:org.wicketstuff.mergedresources.ResourceMount.java

License:Apache License

/**
 * load resource stream once in order to load it into memory
 * //  w  w  w. j ava 2 s .c o  m
 * @param ref
 * @throws ResourceStreamNotFoundException
 */
private void initResource(final ResourceReference ref) throws ResourceStreamNotFoundException {
    boolean gzip = Application.get().getResourceSettings().getDisableGZipCompression();
    try {
        Application.get().getResourceSettings().setDisableGZipCompression(true);
        ref.getResource().getResourceStream().getInputStream();
    } finally {
        Application.get().getResourceSettings().setDisableGZipCompression(gzip);
    }
}

From source file:org.wicketstuff.mergedresources.resources.CompressedMergedCssResource.java

License:Apache License

@Override
protected IResourceStream newResourceStream(final Locale locale, final String style, final ResourceSpec[] specs,
        IResourcePreProcessor preProcessor) {
    return new MergedResourceStream(specs, locale, style, preProcessor) {
        private static final long serialVersionUID = 1L;

        // still using deprecated stripJavascriptCommentsAndWhitespace
        // property for CSS
        @SuppressWarnings("deprecation")
        @Override//from  w w w  . j  a va 2s . c o  m
        protected byte[] toContent(final byte[] content) {

            ICssCompressor compressor = ResourceMount.getCssCompressor(Application.get());
            if (compressor != null) {
                return compressor.compress(content, ICssCompressor.UTF_8);
            } else if (Application.get().getResourceSettings()
                    // use the JS settings for CSS - deprecated as of WMR 3.1
                    .getStripJavascriptCommentsAndWhitespace()) {
                return YuiCompressorUtil.compress(content, ICssCompressor.UTF_8);
            } else {
                return content;
            }
        }

        @Override
        public String getContentType() {
            return "text/css";
        }
    };
}

From source file:org.wicketstuff.mergedresources.resources.CompressedMergedJsResource.java

License:Apache License

@Override
protected IResourceStream newResourceStream(final Locale locale, final String style, final ResourceSpec[] specs,
        IResourcePreProcessor preProcessor) {
    return new MergedResourceStream(specs, locale, style, preProcessor) {
        private static final long serialVersionUID = 1L;

        @Override//from  w w  w . ja  va 2  s . com
        protected byte[] toContent(final byte[] content) {
            try {
                final IJavascriptCompressor compressor = Application.get().getResourceSettings()
                        .getJavascriptCompressor();
                if (compressor != null) {
                    return compressor.compress(new String(content)).getBytes();
                }
                return content;
            } catch (Exception e) {
                log.error("Error while stripping content", e);
                return content;
            }
        }

        @Override
        public String getContentType() {
            return "application/x-javascript";
        }
    };
}