Example usage for org.apache.wicket.protocol.http WebApplication getResourceSettings

List of usage examples for org.apache.wicket.protocol.http WebApplication getResourceSettings

Introduction

In this page you can find the example usage for org.apache.wicket.protocol.http WebApplication getResourceSettings.

Prototype

public final ResourceSettings getResourceSettings() 

Source Link

Usage

From source file:codetroopers.wicket.web.HotReloadingWicketFilter.java

License:Apache License

/**
 * Reset the class resolver, it removes stale classes.
 * Optimization is possible by removing from the map only changed classes
 *
 * NOTICE :  as long as we don't touch the HomePage, this seems to work
 *///from w  w  w.  j a  va2s .c  o m
private void resetClassAndResourcesCaches() {
    final WebApplication application = getApplication();
    if (application != null) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Resetting the Application's ClassResolver and Resource Finders");
        }
        application.getApplicationSettings().setClassResolver(new HotReloadingClassResolver());
        //we reset the resourceStreamLocator cache by recreating resource finders
        List<IResourceFinder> resourceFinders = Lists.newArrayList();
        resourceFinders
                .add(new org.apache.wicket.util.file.Path(compilationManager.getDestination().toString()));
        resourceFinders.add(new ClassPathResourceFinder(""));
        application.getResourceSettings().setResourceFinders(resourceFinders);
    }
}

From source file:com.googlecode.wicket.kendo.ui.Initializer.java

License:Apache License

@Override
public void init(Application application) {
    if (application instanceof WebApplication) {
        WebApplication webApplication = (WebApplication) application;
        webApplication.getAjaxRequestTargetListeners().add(new KendoDestroyListener());

        // registers .js.map pattern //
        IPackageResourceGuard packageResourceGuard = webApplication.getResourceSettings()
                .getPackageResourceGuard();

        if (packageResourceGuard instanceof SecurePackageResourceGuard) {
            ((SecurePackageResourceGuard) packageResourceGuard).addPattern("+*.js.map");
        }//from  ww w  .j  a va2 s  .  c  o m
    }
}

From source file:de.alpharogroup.wicket.base.util.application.ApplicationExtensions.java

License:Apache License

/**
 * Adds the given resourcePath to the resource finder from the given application.
 *
 * @param application/*from   w  ww  . ja  va2s  .c  om*/
 *            the application
 * @param resourcePath
 *            the resource path
 * @see org.apache.wicket.settings.ResourceSettings#getResourceFinders()
 */
public static void addResourceFinder(final WebApplication application, final String resourcePath) {
    application.getResourceSettings().getResourceFinders()
            .add(new WebApplicationPath(application.getServletContext(), resourcePath));
}

From source file:de.alpharogroup.wicket.base.util.application.ApplicationExtensions.java

License:Apache License

/**
 * Sets a set of default development settings for development mode for the given application.
 *
 * @param application/*from  www.j a  va 2 s .co  m*/
 *            the new debug settings for development
 */
public static void setDefaultDebugSettingsForDevelopment(final WebApplication application) {
    ApplicationExtensions.setHtmlHotDeploy(application);
    ApplicationExtensions.setDebugSettingsForDevelopment(application);
    ApplicationExtensions.setExceptionSettingsForDevelopment(application);
    // set the behavior if an missing resource is found...
    application.getResourceSettings().setThrowExceptionOnMissingResource(true);
}

From source file:de.alpharogroup.wicket.base.util.application.ApplicationExtensions.java

License:Apache License

/**
 * Use this method to enable hot deploy of your html templates on development. Works only with
 * jetty. Only for//from   w w  w .  j  ava 2s  . c  om
 *
 * @param application
 *            the new html hot deploy
 */
public static void setHtmlHotDeploy(final WebApplication application) {
    application.getResourceSettings().setResourcePollFrequency(Duration.ONE_SECOND);
    final String slash = "/";
    String realPath = application.getServletContext().getRealPath(slash);
    if ((realPath != null) && !realPath.endsWith(slash)) {
        realPath += slash;
    }
    final String javaSourcePath = realPath + "../java";
    final String resourcesPath = realPath + "../resources";
    addResourceFinder(application, javaSourcePath);
    addResourceFinder(application, resourcesPath);
}

From source file:fiftyfive.wicket.resource.MergedResourceBuilder.java

License:Apache License

/**
 * Constructs and returns a special merged resource request mapper using the path and resources
 * options specified in this builder./*from w  w  w.  j  a  va  2  s . c om*/
 * <p>
 * This method may only be called after all of the options have been set.
 * <p>
 * Use this method if your application has a complex configuration that requires you to deal
 * with request mappers directly (e.g. you need to wrap or combine them in clever ways).
 * Most applications will be better served by {@link #install install()}, which
 * handles creating the mapper and mounting it in one easy step.
 * 
 * @throws IllegalStateException if a path or resources have not been
 *         specified prior to calling this method.
 *
 * @since 3.0
 */
public IRequestMapper buildRequestMapper(final WebApplication app) {
    if (!this.frozen)
        assertRequiredOptionsAndFreeze();

    return new MergedResourceMapper(this.path, this.references, new PageParametersEncoder(),
            new IProvider<IResourceCachingStrategy>() {
                public IResourceCachingStrategy get() {
                    return app.getResourceSettings().getCachingStrategy();
                }
            });
}

From source file:org.brixcms.Brix.java

License:Apache License

/**
 * Performs any {@link WebApplication} specific initialization
 *
 * @param application/*from  www. ja  v  a 2 s. c om*/
 */
public void attachTo(WebApplication application) {
    if (application == null) {
        throw new IllegalArgumentException("Application cannot be null");
    }

    // store brix instance in applicaton's metadata so it can be retrieved
    // easily later
    application.setMetaData(APP_KEY, this);

    /*
       * XXX we are coupling to nodepage plugin here instead of using the
       * usual register mechanism - we either need to make plugins application
       * aware so they can install their own listeners or have some brix-level
       * registery
       */
    application.getComponentPreOnBeforeRenderListeners().add(new PageParametersAwareEnabler());

    // allow brix to handle any url that wicket cant
    application.getRootRequestMapperAsCompound().add(new BrixRequestMapper(this));
    // application.mount(new BrixNodePageUrlMapper());

    // register a string resource loader that allows any object that acts as
    // an extension supply its own resource bundle for the UI
    BrixExtensionStringResourceLoader loader = new BrixExtensionStringResourceLoader();
    application.getResourceSettings().getStringResourceLoaders().add(loader);
    config.getRegistry().register(loader, true);
}

From source file:org.jaulp.wicket.base.util.application.ApplicationUtils.java

License:Apache License

/**
 * Use this method to enable hot deploy of your html templates on development. Works only with
 * jetty. Only for/*from   ww w . j av a2  s. c  o m*/
 *
 * @param application
 *            the new html hot deploy
 */
public static void setHtmlHotDeploy(final WebApplication application) {
    application.getResourceSettings().setResourcePollFrequency(Duration.ONE_SECOND);
    String slash = "/";
    String realPath = application.getServletContext().getRealPath(slash);
    if (realPath != null && !realPath.endsWith(slash)) {
        realPath += slash;
    }
    String javaSourcePath = realPath + "../java";
    String resourcesPath = realPath + "../resources";
    addResourceFinder(application, javaSourcePath);
    addResourceFinder(application, resourcesPath);
}

From source file:org.jaulp.wicket.base.util.application.ApplicationUtils.java

License:Apache License

/**
 * Adds the given resourcePath to the resource finder from the given application.
 *
 * @see IResourceSettings#getResourceFinders()
 *
 * @param application/*from  www .  j  a v  a 2 s.  c o m*/
 *            the application
 * @param resourcePath
 *            the resource path
 */
public static void addResourceFinder(final WebApplication application, String resourcePath) {
    application.getResourceSettings().getResourceFinders()
            .add(new WebApplicationPath(application.getServletContext(), resourcePath));
}

From source file:org.ops4j.pax.wicket.api.PaxWicketApplicationFactory.java

License:Apache License

private WebApplication createWicketApplicationViaCustomFactory() {
    WebApplication paxWicketApplication;
    paxWicketApplication = applicationFactory.createWebApplication(new ApplicationLifecycleListener() {
        private final List<ServiceRegistration> m_serviceRegistrations = new ArrayList<ServiceRegistration>();
        private PageMounterTracker mounterTracker;
        private ComponentInstantiationListenerFacade componentInstanciationListener;

        public void onInit(WebApplication wicketApplication) {
            componentInstanciationListener = new ComponentInstantiationListenerFacade(
                    delegatingComponentInstanciationListener);
            wicketApplication.addComponentInstantiationListener(componentInstanciationListener);

            IApplicationSettings applicationSettings = wicketApplication.getApplicationSettings();
            applicationSettings.setClassResolver(delegatingClassResolver);
            addWicketService(IApplicationSettings.class, applicationSettings);

            ISessionSettings sessionSettings = wicketApplication.getSessionSettings();
            sessionSettings.setPageFactory(pageFactory);
            addWicketService(ISessionSettings.class, sessionSettings);

            addWicketService(IDebugSettings.class, wicketApplication.getDebugSettings());
            addWicketService(IExceptionSettings.class, wicketApplication.getExceptionSettings());
            addWicketService(IFrameworkSettings.class, wicketApplication.getFrameworkSettings());
            addWicketService(IMarkupSettings.class, wicketApplication.getMarkupSettings());
            addWicketService(IPageSettings.class, wicketApplication.getPageSettings());
            addWicketService(IRequestCycleSettings.class, wicketApplication.getRequestCycleSettings());
            addWicketService(IResourceSettings.class, wicketApplication.getResourceSettings());
            addWicketService(ISecuritySettings.class, wicketApplication.getSecuritySettings());

            if (pageMounter != null) {
                for (MountPointInfo bookmark : pageMounter.getMountPoints()) {
                    wicketApplication.mount(bookmark.getCodingStrategy());
                }//from  w ww  .  j  av a2  s. c  o  m
            }

            // Now add a tracker so we can still mount pages later
            mounterTracker = new PageMounterTracker(bundleContext, wicketApplication, getApplicationName());
            mounterTracker.open();

            for (final IInitializer initializer : initializers) {
                initializer.init(wicketApplication);
            }
        }

        private <T> void addWicketService(Class<T> service, T serviceImplementation) {
            Properties props = new Properties();

            // Note: This is kept for legacy
            props.setProperty("applicationId", getApplicationName());
            props.setProperty(APPLICATION_NAME, getApplicationName());

            String serviceName = service.getName();
            ServiceRegistration registration = bundleContext.registerService(serviceName, serviceImplementation,
                    props);
            m_serviceRegistrations.add(registration);
        }

        public void onDestroy(WebApplication wicketApplication) {
            wicketApplication.removeComponentInstantiationListener(componentInstanciationListener);

            if (mounterTracker != null) {
                mounterTracker.close();
                mounterTracker = null;
            }

            for (ServiceRegistration reg : m_serviceRegistrations) {
                reg.unregister();
            }
            m_serviceRegistrations.clear();
        }
    });
    return paxWicketApplication;
}