org.apache.wicket.request.component.IRequestablePage Java Examples

The following examples show how to use org.apache.wicket.request.component.IRequestablePage. 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: AbstractMountedMapper.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
/**
 * Ensure that request is for this mapper
 * @param requestHandler request handler for handle request
 * @return url if this mapper can handle this request
 */
@Override
public Url mapHandler(IRequestHandler requestHandler) {
    if (requestHandler instanceof IPageClassRequestHandler) {
        IPageClassRequestHandler handler = (IPageClassRequestHandler) requestHandler;
        PageParameters params = null;
        if (handler instanceof IPageRequestHandler) {
            IRequestablePage page = ((IPageRequestHandler)handler).getPage();
            if (page != null) {
                params = page.getPageParameters();
            }
        }

        if (params == null) {
            params = handler.getPageParameters();
        }
        return isMatch(params) ? super.mapHandler(requestHandler) : null;
    } else {
        return super.mapHandler(requestHandler);
    }
}
 
Example #2
Source File: WicketPagesMounterImpl.java    From yes-cart with Apache License 2.0 5 votes vote down vote up
public WicketPagesMounterImpl(final IPageParametersEncoder encoder,
                              final Map<String, Map<String, Class<IRequestablePage>>> pageMapping,
                              final String loginUrl,
                              final List<String> encoderEnabledUrls) {
    this.encoder = encoder;
    this.loginUrl = loginUrl;
    this.pageMapping = pageMapping;
    this.encoderEnabledUrls = encoderEnabledUrls;
}
 
Example #3
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 #4
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");
			}
		}
	}
}
 
Example #5
Source File: AbstractODocumentAliasMapper.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
public AbstractODocumentAliasMapper(String mountPath, Supplier<Class<? extends IRequestablePage>> pageProvider,
                                    OQueryModel<ODocument> queryModel, String parameter, IPageParametersEncoder encoder) {
    super(mountPath, pageProvider, encoder);
    this.queryModel = queryModel;
    this.parameter = parameter;
    this.mountPath = mountPath;
}
 
Example #6
Source File: ThemePageProvider.java    From yes-cart with Apache License 2.0 5 votes vote down vote up
public ThemePageProvider(final Map<String, Class<IRequestablePage>> pages) {
    super(IRequestablePage.class);

    Assert.notEmpty(pages, "Must have pages mapping");
    Assert.isTrue(pages.containsKey("default"), "Must have mapping for default theme");

    for (final Map.Entry<String, Class<IRequestablePage>> entry : pages.entrySet()) {
        this.pages.put(entry.getKey(), ClassReference.of(entry.getValue()));
    }
}
 
Example #7
Source File: ThemePageProvider.java    From yes-cart with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public Class<IRequestablePage> get() {
    List<String> themeChain = ApplicationDirector.getCurrentThemeChain();
    for (final String theme : themeChain) {
        if (this.pages.containsKey(theme)) {
            return this.pages.get(theme).get();
        }
    }
    return this.pages.get("default").get();
}
 
Example #8
Source File: AbstractODocumentAliasMapper.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
public AbstractODocumentAliasMapper(String mountPath,
                                    Class<? extends IRequestablePage> pageClass,
                                    OQueryModel<ODocument> queryModel,
                                    String parameter,
                                    IPageParametersEncoder pageParametersEncoder) {
    super(mountPath, pageClass, pageParametersEncoder);
    this.queryModel = queryModel;
    this.parameter = parameter;
    this.mountPath = mountPath;
}
 
Example #9
Source File: AbstractMountedMapper.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public AbstractMountedMapper(String mountPath, Class<? extends IRequestablePage> pageClass) {
    super(mountPath, pageClass);
}
 
Example #10
Source File: AbstractComponentTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Class<? extends IRequestablePage> getPageClass() {
	return inner.getPageClass();
}
 
Example #11
Source File: AbstractMountedMapper.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public AbstractMountedMapper(String mountPath, Supplier<Class<? extends IRequestablePage>> pageClassProvider) {
    super(mountPath, pageClassProvider);
}
 
Example #12
Source File: AbstractMountedMapper.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public AbstractMountedMapper(String mountPath, Class<? extends IRequestablePage> pageClass, IPageParametersEncoder pageParametersEncoder) {
    super(mountPath, pageClass, pageParametersEncoder);
}
 
Example #13
Source File: AbstractMountedMapper.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public AbstractMountedMapper(String mountPath, Supplier<Class<? extends IRequestablePage>> pageClassProvider, IPageParametersEncoder pageParametersEncoder) {
    super(mountPath, pageClassProvider, pageParametersEncoder);
}
 
Example #14
Source File: PagesMountedMapper.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
private static Class<? extends IRequestablePage> getPageClass(ODocument page) {
	Boolean embedded = page.field(PagesModule.OPROPERTY_EMBEDDED);
	return embedded == null || embedded ? EmbeddedWebPage.class : FullWebPage.class;
}
 
Example #15
Source File: PageParameterAwareMountedMapper.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
public PageParameterAwareMountedMapper(String mountPath, Class< ? extends IRequestablePage> pageClass)
{
  super(mountPath, pageClass);
}
 
Example #16
Source File: PageParameterAwareMountedMapper.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected IRequestHandler processHybrid(PageInfo pageInfo, Class< ? extends IRequestablePage> pageClass, PageParameters pageParameters,
    Integer renderCount)
{
  IRequestHandler handler = null;
  try {
    handler = super.processHybrid(pageInfo, pageClass, pageParameters, renderCount);
  } catch (PageExpiredException e) {
    // in case of pageExpiredException at this point, we just redirect to previous bookmarkable resource
    return processBookmarkable(pageClass, pageParameters);
  }
  if (handler != null && handler instanceof RenderPageRequestHandler) {
    // in the current implementation (wicket 1.5.6) super.processHybrid
    // returns a RenderPageRequestHandler
    RenderPageRequestHandler renderPageHandler = (RenderPageRequestHandler) handler;
    if (renderPageHandler.getPageProvider() instanceof PageProvider) {
      PageProvider provider = (PageProvider) renderPageHandler.getPageProvider();
      // This check is necessary to prevent a RestartResponseAtInterceptPageException at the wrong time in request cycle
      if (provider.hasPageInstance()) {
        // get page classes
        Class< ? extends IRequestablePage> oldPageClass = renderPageHandler.getPageClass();
        Class< ? extends IRequestablePage> newPageClass = renderPageHandler.getPageProvider().getPageClass();

        // get page parameters
        PageParameters newPageParameters = renderPageHandler.getPageParameters();
        PageParameters oldPageParameters = renderPageHandler.getPageProvider().getPageInstance().getPageParameters();

        if (oldPageClass != null && oldPageClass.equals(newPageClass) == false) {
          return processBookmarkable(newPageClass, newPageParameters);
        }

        // if we recognize a change between the page parameter of the loaded
        // page and the page parameter of the current request, we redirect
        // to a fresh bookmarkable instance of that page.
        if (!PageParameters.equals(oldPageParameters, newPageParameters)) {
          return processBookmarkable(newPageClass, newPageParameters);
        }
      }
    }
  }
  return handler;
}
 
Example #17
Source File: NoVersionMountMapper.java    From nextreports-server with Apache License 2.0 4 votes vote down vote up
public NoVersionMountMapper(final Class<? extends IRequestablePage> pageClass) {
    this("/", pageClass);
}
 
Example #18
Source File: NoVersionMountMapper.java    From nextreports-server with Apache License 2.0 4 votes vote down vote up
public NoVersionMountMapper(String mountPath, final Class<? extends IRequestablePage> pageClass) {
    super(mountPath, pageClass, new PageParametersEncoder());
}
 
Example #19
Source File: SyncopeUIRequestCycleListener.java    From syncope with Apache License 2.0 4 votes vote down vote up
@Override
public IRequestHandler onException(final RequestCycle cycle, final Exception e) {
    LOG.error("Exception found", e);

    PageParameters errorParameters = new PageParameters();

    IRequestablePage errorPage;
    if (instanceOf(e, UnauthorizedInstantiationException.class) != null) {
        errorParameters.add("errorMessage", BaseSession.Error.AUTHORIZATION.fallback());
        errorPage = getErrorPage(errorParameters);
    } else if (instanceOf(e, AccessControlException.class) != null) {
        if (StringUtils.containsIgnoreCase(instanceOf(e, AccessControlException.class).getMessage(), "expired")) {
            errorParameters.add("errorMessage", BaseSession.Error.SESSION_EXPIRED.fallback());
        } else {
            errorParameters.add("errorMessage", BaseSession.Error.AUTHORIZATION.fallback());
        }
        errorPage = getErrorPage(errorParameters);
    } else if (instanceOf(e, PageExpiredException.class) != null || !isSignedIn()) {
        errorParameters.add("errorMessage", BaseSession.Error.SESSION_EXPIRED.fallback());
        errorPage = getErrorPage(errorParameters);
    } else if (instanceOf(e, BadRequestException.class) != null
            || instanceOf(e, WebServiceException.class) != null
            || instanceOf(e, SyncopeClientException.class) != null) {

        errorParameters.add("errorMessage", BaseSession.Error.REST.fallback());
        errorPage = getErrorPage(errorParameters);
    } else {
        Throwable cause = instanceOf(e, ForbiddenException.class);
        if (cause == null) {
            // redirect to default Wicket error page
            errorPage = new ExceptionErrorPage(e, null);
        } else {
            errorParameters.add("errorMessage", cause.getMessage());
            errorPage = getErrorPage(errorParameters);
        }
    }

    if (errorPage instanceof BaseLogin) {
        try {
            invalidateSession();
        } catch (Throwable t) {
            // ignore
            LOG.debug("Unexpected error while forcing logout after error", t);
        }
    }

    return new RenderPageRequestHandler(new PageProvider(errorPage));
}
 
Example #20
Source File: WebSocketRequestHandler.java    From onedev with MIT License 4 votes vote down vote up
@Override
public Class<? extends IRequestablePage> getPageClass()
{
	return page.getPageClass();
}
 
Example #21
Source File: Application.java    From openmeetings with Apache License 2.0 4 votes vote down vote up
public NoVersionMapper(String mountPath, final Class<? extends IRequestablePage> pageClass) {
	super(mountPath, pageClass, new PageParametersEncoder());
}
 
Example #22
Source File: Application.java    From openmeetings with Apache License 2.0 4 votes vote down vote up
public NoVersionMapper(final Class<? extends IRequestablePage> pageClass) {
	this("/", pageClass);
}
 
Example #23
Source File: ThemePageProviderTest.java    From yes-cart with Apache License 2.0 4 votes vote down vote up
@Test
public void testGet() throws Exception {

    final ThemeService themeServiceDefault = mockery.mock(ThemeService.class, "themeServiceDefault");
    final ThemeService themeServiceTheme1 = mockery.mock(ThemeService.class, "themeServiceTheme1");
    final ThemeService themeServiceTheme2 = mockery.mock(ThemeService.class, "themeServiceTheme2");

    final ThemePageProvider page = new ThemePageProvider(new HashMap() {{
        put("default", IRequestablePage.class);
        put("theme1", IRequestablePageTheme1.class);
        put("theme2", IRequestablePageTheme2.class);
    }});


    final Shop shopDefault = mockery.mock(Shop.class, "default");
    final Shop shopTheme1 = mockery.mock(Shop.class, "theme1,default");
    final Shop shopTheme2 = mockery.mock(Shop.class, "theme2,theme1,default");


    mockery.checking(new Expectations() {{
        allowing(shopDefault).getShopId();
        will(returnValue(1L));
        allowing(themeServiceDefault).getThemeChainByShopId(1L, null);
        will(returnValue(Arrays.asList("default")));

        allowing(shopTheme1).getShopId();
        will(returnValue(2L));
        allowing(themeServiceTheme1).getThemeChainByShopId(2L, null);
        will(returnValue(Arrays.asList("theme1","default")));

        allowing(shopTheme2).getShopId();
        will(returnValue(3L));
        allowing(themeServiceTheme2).getThemeChainByShopId(3L, null);
        will(returnValue(Arrays.asList("theme2","theme1","default")));
    }});

    new ApplicationDirector();

    ApplicationDirector.setCurrentThemeChain(Arrays.asList("default"));
    ApplicationDirector.setCurrentShop(shopDefault);
    assertSame(IRequestablePage.class, page.get());
    ApplicationDirector.clear();

    ApplicationDirector.setCurrentThemeChain(Arrays.asList("theme1","default"));
    ApplicationDirector.setCurrentShop(shopTheme1);
    assertSame(IRequestablePageTheme1.class, page.get());
    ApplicationDirector.clear();

    ApplicationDirector.setCurrentThemeChain(Arrays.asList("theme2","theme1","default"));
    ApplicationDirector.setCurrentShop(shopTheme2);
    assertSame(IRequestablePageTheme2.class, page.get());
    ApplicationDirector.clear();

}
 
Example #24
Source File: WicketPagesMounterImpl.java    From yes-cart with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public ClassReference<IRequestablePage> getPageProviderByUri(final String uri) {
    return pageByUri.get(uri);
}
 
Example #25
Source File: WicketPagesMounterImpl.java    From yes-cart with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public ClassReference<IRequestablePage> getLoginPageProvider() {
    return loginPage;
}
 
Example #26
Source File: WicketPagesMounterImpl.java    From yes-cart with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public ClassReference<IRequestablePage> getHomePageProvider() {
    return homePage;
}
 
Example #27
Source File: OnePageMapper.java    From onedev with MIT License 4 votes vote down vote up
public OnePageMapper(String mountPath, Class<? extends IRequestablePage> pageClass) {
	super(mountPath, pageClass);
}
 
Example #28
Source File: WicketPagesMounter.java    From yes-cart with Apache License 2.0 2 votes vote down vote up
/**
 * Get page class by URI
 *
 * @param uri mounted URI
 *
 * @return page provider that returns theme specific login page.
 */
ClassReference<IRequestablePage> getPageProviderByUri(String uri);
 
Example #29
Source File: WicketPagesMounter.java    From yes-cart with Apache License 2.0 2 votes vote down vote up
/**
 * @return page provider that returns theme specific login page.
 */
ClassReference<IRequestablePage> getLoginPageProvider();
 
Example #30
Source File: WicketPagesMounter.java    From yes-cart with Apache License 2.0 2 votes vote down vote up
/**
 * @return page provider that returns theme specific home page.
 */
ClassReference<IRequestablePage> getHomePageProvider();