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

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

Introduction

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

Prototype

public void mount(final IRequestMapper mapper) 

Source Link

Document

Mounts an encoder at the given path.

Usage

From source file:com.visural.wicket.aturl.AtAnnotation.java

License:Apache License

private static void mountPage(WebApplication app, Class page) {
    At at = (At) page.getAnnotation(At.class);
    switch (at.type()) {
    case Standard:
        if (at.urlParameters().length == 0) {
            app.mountBookmarkablePage(at.url(), page);
        } else {//w w w . j  av a  2 s  .c  om
            app.mount(new MixedParamUrlCodingStrategy(at.url(), page, at.urlParameters()));
        }
        break;
    case Indexed:
        app.mount(new IndexedParamUrlCodingStrategy(at.url(), page));
        break;
    case StateInURL:
        app.mount(new HybridUrlCodingStrategy(at.url(), page));
        break;
    case IndexedStateInURL:
        app.mount(new IndexedHybridUrlCodingStrategy(at.url(), page));
        break;
    }

}

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

License:Apache License

/**
 * Constructs a special merged resource using the path and resources options specified in this
 * builder, and mounts the result in the application by calling
 * {@link WebApplication#mount(IRequestMapper) WebApplication.mount()}.
 * <p>//w ww  . j a v a  2 s . co m
 * This method may only be called after all of the options have been set.
 *
 * @return {@code this} for chaining
 *
 * @throws IllegalStateException if a path or resources have not been
 *         specified prior to calling this method.
 * 
 * @since 3.0
 */
public MergedResourceBuilder install(WebApplication app) {
    app.mount(buildRequestMapper(app));
    return this;
}

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

License:Apache License

/**
 * Install this {@code SimpleCDN} into the given application. The {@code SimpleCDN} instance
 * will not have any effect unless it is installed.
 *///from   w  ww. j  ava2  s .com
public void install(WebApplication app) {
    this.delegate = app.getRootRequestMapperAsCompound();
    app.mount(this);
}

From source file:fiftyfive.wicket.shiro.ShiroWicketPlugin.java

License:Apache License

/**
 * Installs this {@code ShiroWicketPlugin} by doing the following:
 * <ul>//  w  w w.java  2s.co  m
 * <li>Sets itself as the {@link IAuthorizationStrategy}</li>
 * <li>And as the {@link IUnauthorizedComponentInstantiationListener}</li>
 * <li>And as an {@link IRequestCycleListener}</li>
 * <li>Mounts the login page</li>
 * <li>Mounts the logout page</li>
 * </ul>
 */
public void install(WebApplication app) {
    Args.notNull(app, "app");

    ISecuritySettings settings = app.getSecuritySettings();
    settings.setAuthorizationStrategy(this);
    settings.setUnauthorizedComponentInstantiationListener(this);
    app.getRequestCycleListeners().add(this);

    // Mount bookmarkable URLs
    if (this.loginPath != null) {
        app.mount(new MountedMapper(this.loginPath, this.loginPage));
    }
    if (this.logoutPath != null) {
        app.mount(new MountedMapper(this.logoutPath, this.logoutPage));
    }

    // Install self in app metadata so that static get() can work
    ShiroWicketPlugin.set(app, this);
}

From source file:jp.xet.uncommons.wicket.utils.SimpleCDN.java

License:Apache License

/**
 * Install this {@code SimpleCDN} into the given application. The {@code SimpleCDN} instance
 * will not have any effect unless it is installed.
 * /*from w ww.  jav  a2s. co m*/
 * @param app {@link WebApplication}
 */
public void install(WebApplication app) {
    delegate = app.getRootRequestMapperAsCompound();
    app.mount(this);
}

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 a  v a 2 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;
}

From source file:org.wicketstuff.annotation.scan.AnnotatedMountList.java

License:Apache License

/**
 * Iterate through list and call {@link WebApplication#mount(IRequestMapper)} for each item.
 * <p>//from w  w w .  j a  va  2 s .  c  o m
 * Typically called from {@link WebApplication#init()} method
 * 
 * @param app
 *            The web application.
 * @see AnnotatedMountScanner
 */
public void mount(WebApplication app) {
    for (IRequestMapper strategy : this) {
        app.mount(strategy);
    }
}

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

License:Apache License

/**
 * same as {@link #mount(WebApplication)}, but returns an
 * {@link AbstractHeaderContributor} to use in components
 * //from w w w  .j av  a2s. c  o  m
 * @param application
 *            the application
 * @param cssMediaType
 *            CSS media type, e.g. "print" or <code>null</code> for no media
 *            type
 * @return {@link AbstractHeaderContributor} to be used in components, all
 *         files ending with '.css' will be rendered with passed
 *         cssMediaType
 */
public AbstractHeaderContributor build(final WebApplication application, String cssMediaType) {
    if (_resourceSpecs.size() == 0) {
        // nothing to do
        return null;
    }

    try {
        List<Pair<String, ResourceSpec[]>> specsList;

        boolean merge = doMerge();
        if (merge) {
            specsList = new ArrayList<Pair<String, ResourceSpec[]>>(1);
            specsList.add(new Pair<String, ResourceSpec[]>(null, getResourceSpecs()));
        } else {
            specsList = new ArrayList<Pair<String, ResourceSpec[]>>(_resourceSpecs.size());
            for (ResourceSpec spec : _resourceSpecs) {
                specsList.add(new Pair<String, ResourceSpec[]>(
                        _resourceSpecs.size() > 1 ? spec.getFile() : null, new ResourceSpec[] { spec }));
            }
        }

        final List<ResourceReference> refs = new ArrayList<ResourceReference>(specsList.size());
        for (Pair<String, ResourceSpec[]> p : specsList) {
            ResourceSpec[] specs = p.getSecond();

            String path = getPath(p.getFirst(), specs);
            String unversionedPath = getPath(p.getFirst(), null);

            checkSuffixes(unversionedPath, Arrays.asList(specs));

            boolean versioned = !unversionedPath.equals(path);

            String name = specs.length == 1 ? specs[0].getFile() : unversionedPath;

            final ResourceReference ref = newResourceReference(getScope(specs), name, getLocale(specs),
                    getStyle(specs), getCacheDuration(specs, versioned), specs, _preProcessor);
            refs.add(ref);
            ref.bind(application);
            application.mount(newStrategy(path, ref, merge));

            if (_mountRedirect && versioned) {
                application.mount(newRedirectStrategy(unversionedPath, path));
            }

            initResource(ref);
        }
        return newHeaderContributor(refs, cssMediaType);
    } catch (VersionException e) {
        throw new WicketRuntimeException("failed to mount resource ('" + _path + "')", e);
    } catch (IncompatibleVersionsException e) {
        throw new WicketRuntimeException("failed to mount resource ('" + _path + "')", e);
    } catch (ResourceStreamNotFoundException e) {
        throw new WicketRuntimeException("failed to mount resource ('" + _path + "')", e);
    }
}

From source file:org.wicketstuff.wicket.mount.core.AutoMounter.java

License:Apache License

public static boolean mountAll(WebApplication app) {
    final String mapInfoClassName = app.getClass().getCanonicalName() + "MountInfo";
    try {//from w  ww.  ja  va2s. c  om
        final MountInfo mountInfo = (MountInfo) WicketObjects.newInstance(mapInfoClassName);
        for (IRequestMapper mapper : mountInfo.getMountList()) {
            app.mount(mapper);
        }

        return true;
    } catch (Exception ex) {
        LOG.warn("Failed to automount pages.", ex);
        return false;
    }
}

From source file:org.yes.cart.web.theme.impl.WicketPagesMounterImpl.java

License:Apache License

/** {@inheritDoc} */
public void mountPages(final WebApplication webApplication) {

    for (Map.Entry<String, Map<String, Class<IRequestablePage>>> pageMappingEntry : pageMapping.entrySet()) {
        final String url = pageMappingEntry.getKey();
        final Map<String, Class<IRequestablePage>> pages = pageMappingEntry.getValue();
        final ClassProvider classProvider;
        if (pages.size() == 1) {
            // there is only default mapping for this url
            classProvider = ClassProvider.of(pages.entrySet().iterator().next().getValue());
            if (LOG.isInfoEnabled()) {
                LOG.info("Mounting url '{}' to page '{}'", url, classProvider.get().getCanonicalName());
            }/*from  www. j av a  2 s  .  c o m*/
        } else {
            // more than one mapping - need a theme dependent class provider
            classProvider = new ThemePageProvider(pages);
            if (LOG.isInfoEnabled()) {
                LOG.info("Mounting url '{}' to pages:", url);
                for (final Map.Entry<String, Class<IRequestablePage>> entry : pages.entrySet()) {
                    LOG.info("theme: '{}', page: '{}'", entry.getKey(), entry.getValue());
                }
            }
        }
        if (encoderEnabledUrls.contains(url)) {
            webApplication.mount(new MountedMapper(url, classProvider, encoder));
        } else {
            webApplication.mount(new MountedMapper(url, classProvider));
        }
        if (loginUrl.equals(url)) {
            loginPage = classProvider;
            if (LOG.isInfoEnabled()) {
                LOG.info("This is a login url");
            }
        } else if ("/".equals(url)) {
            homePage = classProvider;
            if (LOG.isInfoEnabled()) {
                LOG.info("This is a home url");
            }
        }
        pageByUri.put(url, classProvider);
    }
}