@Override
  public Url mapHandler(IRequestHandler requestHandler) {
    Url url = systemMapper.mapHandler(requestHandler);
    if (ThreadPortletContext.getPortletRequest() == null) {
      return url;
    }

    if (requestHandler instanceof RenderPageRequestHandler) {
      if (ThreadPortletContext.isAjax()) {
        url = encodeRenderUrl(url, true);
      }
    } else if (requestHandler instanceof SharedResourceReference) {
      url = encodeSharedResourceUrl(url);
    } else if (requestHandler instanceof ResourceReferenceRequestHandler) {
      ResourceReferenceRequestHandler resourceReferenceRequestHandler =
          (ResourceReferenceRequestHandler) requestHandler;
      IResource resource = resourceReferenceRequestHandler.getResource();

      if (resource instanceof PackageResource) {
        url = encodeSharedResourceUrl(url);
      } else {
        url = encodeResourceUrl(url);
      }
    } else if (requestHandler instanceof BookmarkablePageRequestHandler) {
      url = encodeRenderUrl(url, true);
    } else if (requestHandler instanceof ListenerInterfaceRequestHandler) {
      ListenerInterfaceRequestHandler listenerInterfaceRequestHandler =
          (ListenerInterfaceRequestHandler) requestHandler;

      RequestListenerInterface listenerInterface =
          listenerInterfaceRequestHandler.getListenerInterface();
      Class<?> listenerClass = listenerInterface.getMethod().getDeclaringClass();

      if ((IResourceListener.class.isAssignableFrom(listenerClass))
          || (IBehaviorListener.class.isAssignableFrom(listenerClass))) {
        url = encodeResourceUrl(url);
      } else if (IRedirectListener.class.isAssignableFrom(listenerClass)) {
        if (ThreadPortletContext.isAjax()) {
          url = encodeRenderUrl(url, true);
        } else {
          url = encodeRenderUrl(url, false);
        }
      } else {
        if (ThreadPortletContext.isAjax()) {
          url = encodeActionUrl(url, true);
        } else {
          url = encodeActionUrl(url, false);
        }
      }
    }

    return url;
  }
  /**
   * THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.
   *
   * <p>In previous versions of Wicket, request listeners were manually registered by calling this
   * method. Now there is a first class RequestListenerInterface object which should be constructed
   * as a constant member of the interface to enable automatic interface registration.
   *
   * <p>Adds a request listener interface to the map of interfaces that can be invoked by outsiders.
   *
   * @param requestListenerInterface The request listener interface object
   */
  private void registerRequestListenerInterface(
      final RequestListenerInterface requestListenerInterface) {
    // Check that a different interface method with the same name has not
    // already been registered
    final RequestListenerInterface existingInterface =
        RequestListenerInterface.forName(requestListenerInterface.getName());
    if (existingInterface == null) {
      // Save this interface method by the non-qualified class name
      interfaces.put(requestListenerInterface.getName(), requestListenerInterface);

      log.info("registered listener interface " + this);
    }
  }
Esempio n. 3
0
 @Override
 public Url mapHandler(IRequestHandler requestHandler) {
   if (requestHandler instanceof BrixNodeRequestHandler) {
     BrixNodeRequestHandler handler = (BrixNodeRequestHandler) requestHandler;
     String nodeURL = handler.getNodeURL();
     return encode(nodeURL, handler.getPageParameters(), null);
   } else if (requestHandler instanceof ListenerInterfaceRequestHandler) {
     ListenerInterfaceRequestHandler handler = (ListenerInterfaceRequestHandler) requestHandler;
     if (handler.getPage() instanceof BrixNodeWebPage) {
       BrixNodeWebPage page = (BrixNodeWebPage) handler.getPage();
       String componentPath = handler.getComponentPath();
       RequestListenerInterface listenerInterface = handler.getListenerInterface();
       Integer renderCount = null;
       if (listenerInterface.isIncludeRenderCount()) {
         renderCount = page.getRenderCount();
       }
       PageInfo pageInfo = new PageInfo(page.getPageId());
       ComponentInfo componentInfo =
           new ComponentInfo(
               renderCount,
               requestListenerInterfaceToString(listenerInterface),
               componentPath,
               handler.getBehaviorIndex());
       PageComponentInfo info = new PageComponentInfo(pageInfo, componentInfo);
       Url url = encode(page);
       encodePageComponentInfo(url, info);
       return url;
     } else {
       return null;
     }
   } else if (requestHandler instanceof RenderPageRequestHandler) {
     RenderPageRequestHandler handler = (RenderPageRequestHandler) requestHandler;
     if (handler.getPage() instanceof BrixNodeWebPage) {
       BrixNodeWebPage page = (BrixNodeWebPage) handler.getPage();
       PageInfo i = new PageInfo(page.getPageId());
       PageComponentInfo info = new PageComponentInfo(i, null);
       Url url = encode(page);
       encodePageComponentInfo(url, info);
       return url;
     } else {
       return null;
     }
   } else if (requestHandler instanceof BookmarkableListenerInterfaceRequestHandler) {
     BookmarkableListenerInterfaceRequestHandler target =
         (BookmarkableListenerInterfaceRequestHandler) requestHandler;
     BrixNodeWebPage page = (BrixNodeWebPage) target.getPage();
     BrixNode node = page.getModelObject();
     PageInfo info = new PageInfo(page.getPageId());
     return encode(node, page.getBrixPageParameters(), info);
   } else if (requestHandler instanceof BookmarkablePageRequestHandler
       && ((BookmarkablePageRequestHandler) requestHandler)
           .getPageClass()
           .equals(HomePage.class)) {
     BrixNode node =
         ((BrixRequestCycleProcessor) RequestCycle.get().getActiveRequestHandler())
             .getNodeForUriPath(Path.ROOT);
     return mapHandler(new BrixNodeRequestHandler(new BrixNodeModel(node)));
   } else {
     return null;
   }
 }