@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;
  }
 /**
  * Construct.
  *
  * @param refHandler
  */
 public ResourceReferenceLogData(ResourceReferenceRequestHandler refHandler) {
   super(
       refHandler.getResourceReference().getName(),
       refHandler.getLocale(),
       refHandler.getStyle(),
       refHandler.getVariation());
   resourceReferenceClass = refHandler.getResourceReference().getClass();
   scope = refHandler.getResourceReference().getScope();
   pageParameters = refHandler.getPageParameters();
 }
  @Override
  public Url mapHandler(IRequestHandler requestHandler) {
    if (!(requestHandler instanceof ResourceReferenceRequestHandler)) {
      return null;
    }

    ResourceReferenceRequestHandler handler = (ResourceReferenceRequestHandler) requestHandler;

    // see if request handler addresses the resource reference we serve
    if (!handlesRequest(handler)) {
      return null;
    }

    Url url = new Url();

    // add mount path segments
    for (String segment : mountSegments) {
      url.getSegments().add(segment);
    }

    // replace placeholder parameters
    PageParameters parameters = new PageParameters(handler.getPageParameters());

    for (int index = 0; index < mountSegments.length; ++index) {
      String placeholder = getPlaceholder(mountSegments[index]);

      if (placeholder != null) {
        url.getSegments().set(index, parameters.get(placeholder).toString(""));
        parameters.remove(placeholder);
      }
    }

    // add caching information
    addCachingDecoration(url, parameters);

    // create url
    return encodePageParameters(url, parameters, parametersEncoder);
  }
Example #4
0
 private String renderUrl(Url url, IRequestHandler handler) {
   if (url != null) {
     String renderedUrl = getUrlRenderer().renderUrl(url);
     if (handler instanceof ResourceReferenceRequestHandler) {
       ResourceReferenceRequestHandler rrrh = (ResourceReferenceRequestHandler) handler;
       IResource resource = rrrh.getResource();
       if (resource instanceof IStaticCacheableResource == false) {
         renderedUrl = getOriginalResponse().encodeURL(renderedUrl);
       }
     } else if (handler instanceof ResourceRequestHandler) {
       ResourceRequestHandler rrh = (ResourceRequestHandler) handler;
       IResource resource = rrh.getResource();
       if (resource instanceof IStaticCacheableResource == false) {
         renderedUrl = getOriginalResponse().encodeURL(renderedUrl);
       }
     } else {
       renderedUrl = getOriginalResponse().encodeURL(renderedUrl);
     }
     return renderedUrl;
   } else {
     return null;
   }
 }
 protected boolean handlesRequest(ResourceReferenceRequestHandler handler) {
   return resourceReference.equals(handler.getResourceReference())
       || mergedKeys.contains(handler.getResourceReference().toString());
 }