org.apache.wicket.core.request.mapper.MountedMapper Java Examples

The following examples show how to use org.apache.wicket.core.request.mapper.MountedMapper. 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: WicketPagesMounterImpl.java    From yes-cart with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
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 ClassReference classProvider;
        if (pages.size() == 1) {
            // there is only default mapping for this url
            classProvider = ClassReference.of(pages.entrySet().iterator().next().getValue());
            LOG.info("Mounting url '{}' to page '{}'", url, classProvider.get().getCanonicalName());
        } 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;
            LOG.info("Login url [{}], class {}", loginUrl, loginPage);
        } else if ("/".equals(url)) {
            homePage = classProvider;
            LOG.info("Home url [/], class {}", homePage);
        }
        pageByUri.put(url, classProvider);
    }
}
 
Example #2
Source File: OrienteerWebApplication.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
private void mountOrUnmountPackage(String packageName, ClassLoader classLoader, boolean mount) {
	ClassPath classPath;
	try {
		classPath = ClassPath.from(classLoader);
	} catch (IOException e) {
		throw new WicketRuntimeException("Can't scan classpath", e);
	}
	
	for(ClassInfo classInfo : classPath.getTopLevelClassesRecursive(packageName)) {
		Class<?> clazz = classInfo.load();
		MountPath mountPath = clazz.getAnnotation(MountPath.class);
		if(mountPath!=null) {
			if(IRequestablePage.class.isAssignableFrom(clazz)) { 
				Class<? extends IRequestablePage> pageClass = (Class<? extends IRequestablePage>) clazz;
				forEachOnMountPath(mountPath, path -> {
									if(mount) {
										if ("/".equals(path)) {
											mount(new HomePageMapper(pageClass));
										}
										mount(new MountedMapper(path, pageClass));
									} else {
										unmount(path);
									}
								});
			} else if(IResource.class.isAssignableFrom(clazz)) {
				if(mount) {
					String resourceKey = clazz.getName();
					getSharedResources().add(resourceKey, (IResource) getServiceInstance(clazz));
					SharedResourceReference reference = new SharedResourceReference(resourceKey);
					forEachOnMountPath(mountPath, path -> mountResource(path, reference));
				} else {
					forEachOnMountPath(mountPath, this::unmount);
				}
			} else {
				throw new WicketRuntimeException("@"+MountPath.class.getSimpleName()+" should be only on pages or resources");
			}
		}
	}
}