Package com.ocpsoft.pretty

Examples of com.ocpsoft.pretty.PrettyContext


*/
public class PrettyFacesActionUrlProvider implements FacesActionUrlProvider
{
   public String getActionURL(final FacesContext context, final String viewId)
   {
      PrettyContext prettyContext = PrettyContext.getCurrentInstance(context);
      String result = null;
      if (prettyContext.isPrettyRequest() && (viewId != null)
               && viewId.equals(context.getViewRoot().getViewId()))
      {
         ExtractedValuesURLBuilder builder = new ExtractedValuesURLBuilder();
         UrlMapping mapping = prettyContext.getCurrentMapping();
         result = prettyContext.getContextPath() + builder.buildURL(mapping) + builder.buildQueryString(mapping);
      }
      return result;
   }
View Full Code Here


         request.setAttribute(PrettyContext.CONFIG_KEY, config);
      }

      // build the PrettyContext and attach it to the request
      if (request.getAttribute(UrlMappingRuleAdaptor.REWRITE_MAPPING_ID_KEY) == null) {
         PrettyContext context = PrettyContext.newDetachedInstance(request);
         PrettyContext.setCurrentContext(event.getRequest(), context);
      }

   }
View Full Code Here

   }

   @Override
   public boolean evaluate(final Rewrite event, final EvaluationContext ec)
   {
      PrettyContext context = PrettyContext.getCurrentInstance(((HttpServletRewrite) event).getRequest());
      if ((event instanceof HttpInboundServletRewrite)
               && PFUtil.isMappingEnabled(event)
               && mapping.matches(context.getRequestURL()))
      {
         return true;
      }
      else if ((event instanceof HttpOutboundServletRewrite)
               && mapping.isOutbound()) {
View Full Code Here

   }

   @Override
   public void perform(final Rewrite event, final EvaluationContext ec)
   {
      PrettyContext context = PrettyContext.getCurrentInstance(((HttpServletRewrite) event).getRequest());

      if (event instanceof HttpInboundServletRewrite)
      {
         ((HttpServletRewrite) event).getRequest().setAttribute(REWRITE_MAPPING_ID_KEY,
                  REWRITE_MAPPING_ID_KEY + ":" + mapping.getId());

         URL url = context.getRequestURL();
         if (context.shouldProcessDynaview())
         {
            log.trace("Forwarding mapped request [" + url.toURL() + "] to dynaviewId [" + context.getDynaViewId() + "]");
            ((HttpInboundServletRewrite) event).forward(context.getDynaViewId());
         }
         else
         {
            String viewId = mapping.getViewId();
            log.trace("Forwarding mapped request [" + url.toURL() + "] to resource [" + viewId + "]");
            if (url.decode().toURL().equals(viewId))
            {
               ((HttpServletRewrite) event).proceed();
            }
            else
            {
               ((HttpInboundServletRewrite) event).forward(viewId);
            }
         }
      }
      else if ((event instanceof HttpOutboundServletRewrite) && mapping.isOutbound())
      {
         HttpOutboundServletRewrite outboundRewrite = (HttpOutboundServletRewrite) event;
         String newUrl = rewritePrettyMappings(context.getConfig(), ((HttpServletRewrite) event).getContextPath(),
                  outboundRewrite.getOutboundAddress().toString());
         outboundRewrite.setOutboundAddress(AddressBuilder.create(newUrl));
      }
   }
View Full Code Here

public class PrettyFacesRequestParameterProvider implements RequestParameterProvider
{
   @Override
   public Map<String, String[]> getAdditionalParameters(final ServletRequest request, final ServletResponse response)
   {
      PrettyContext context = PrettyContext.getCurrentInstance((HttpServletRequest)request);
      PrettyConfig config = context.getConfig();

      URL url = context.getRequestURL();
      if (config.isURLMapped(url))
      {
         List<PathParameter> params = context.getCurrentMapping().getPatternParser().parse(url);
         QueryString query = QueryString.build(params);

         return query.getParameterMap();
      }
      return null;
View Full Code Here

         log.error("Please set either 'mappingId' or 'url' attribute!");
         return null;
      }

      // try to obtain PrettyContext
      PrettyContext prettyContext = PrettyContext.getCurrentInstance(behaviorContext.getFacesContext());
      if (prettyContext == null)
      {
         log.error("Cannot build script because PrettyContext is not available!");
         return null;
      }

      // find UrlMapping in configuration
      UrlMapping mapping = prettyContext.getConfig().getMappingById(mappingId.trim());
      if (mapping == null)
      {
         log.error("Cannot find URL mapping with id: " + mappingId);
         return null;
      }

      try
      {

         // build path to redirect to
         ExtractedValuesURLBuilder builder = new ExtractedValuesURLBuilder();
         String contextPath = prettyContext.getContextPath();
         String path = contextPath + builder.buildURL(mapping) + builder.buildQueryString(mapping);

         // return the script
         return buildScriptInternal(path);
View Full Code Here

    *
    * @return JSF viewID to which this request resolves.
    */
   public String computeDynaViewId(final FacesContext facesContext)
   {
      PrettyContext context = PrettyContext.getCurrentInstance(facesContext);
      UrlMapping urlMapping = context.getCurrentMapping();

      return calculateDynaviewId(facesContext, urlMapping);
   }
View Full Code Here

   public String calculateDynaviewId(final FacesContext facesContext, UrlMapping urlMapping)
   {
      String result = "";
      if (urlMapping != null)
      {
         PrettyContext context = PrettyContext.getCurrentInstance(facesContext);

         String viewId = urlMapping.getViewId();
         if (viewId == null)
         {
            viewId = "";
         }
         while (elUtils.isEl(viewId))
         {
            Object viewResult = elUtils.invokeMethod(facesContext, viewId);
            if (viewResult == null)
            {
               viewId = "";
               break;
            }
            else
            {
               viewId = viewResult.toString();
            }

            if (context.getConfig().isMappingId(viewId))
            {
               urlMapping = context.getConfig().getMappingById(viewId);
               viewId = urlMapping.getViewId();
               ExtractedValuesURLBuilder builder = new ExtractedValuesURLBuilder();
               result = context.getContextPath() + builder.buildURL(urlMapping).encode()
                         + builder.buildQueryString(urlMapping);
            }
            else
            {
               result = viewId;
            }
         }
         if ("".equals(viewId))
         {
            log.debug("ViewId for mapping with id <" + urlMapping.getId() + "> was blank");
         }
         result = context.stripContextPath(result);
      }
      return result;
   }
View Full Code Here

   private static final FacesElUtils elUtils = new FacesElUtils();

   public void injectParameters(final FacesContext context)
   {
      log.trace("Injecting parameters");
      PrettyContext prettyContext = PrettyContext.getCurrentInstance(context);
      URL url = prettyContext.getRequestURL();
      UrlMapping mapping = prettyContext.getCurrentMapping();

      if (mapping != null)
      {
         injectPathParams(context, url, mapping);
         injectQueryParams(context, mapping, prettyContext);
View Full Code Here

      {
         if (shouldExecute(action, currentPhaseId, FacesStateUtils.isPostback(context)))
         {
            try
            {
               PrettyContext prettyContext = PrettyContext.getCurrentInstance(context);
               log.trace("Invoking method: " + action + ", on request: " + prettyContext.getRequestURL());
               Object result = elUtils.invokeMethod(context, action.getAction().getELExpression());
               if (result != null)
               {
                  mu.saveMessages(context, context.getExternalContext().getSessionMap());
                  String outcome = result.toString();
                  if (!"".equals(outcome))
                  {
                     NavigationHandler handler = context.getApplication().getNavigationHandler();
                     handler.handleNavigation(context, prettyContext.getCurrentViewId(), outcome);
                  }
                  return;
               }
            }
            catch (Exception e)
View Full Code Here

TOP

Related Classes of com.ocpsoft.pretty.PrettyContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.