Examples of PathParameter


Examples of com.ocpsoft.pretty.faces.config.mapping.PathParameter

   private void validatePathParams(final FacesContext context, final URL url, final UrlMapping mapping)
   {
      List<PathParameter> params = mapping.getPatternParser().parse(url);

      PathParameter currentParameter = new PathParameter();
      PathValidator currentPathValidator = new PathValidator();
      String currentValidatorId = "";
      try
      {
         for (PathParameter param : params)
         {
            currentParameter = param;

            List<PathValidator> validators = mapping.getValidatorsForPathParam(param);

            if (validators != null && validators.size() > 0)
            {
               String value = param.getValue();
               Object coerced = elUtils.coerceToType(context, param.getExpression().getELExpression(), value);
               for (PathValidator pv : validators)
               {
                  currentPathValidator = pv;
                  for (String id : pv.getValidatorIdList())
                  {
                     currentValidatorId = id;
                     Validator validator = context.getApplication().createValidator(id);
                     validator.validate(context, new NullComponent(), coerced);
                  }
                  if (pv.getValidatorExpression() != null)
                  {
                     elUtils.invokeMethod(context, pv.getValidatorExpression().getELExpression(),
                              new Class<?>[] { FacesContext.class, UIComponent.class, Object.class },
                              new Object[] { context, new NullComponent(), coerced });
                  }
               }
            }
         }
      }
      catch (ELException e)
      {
         FacesMessage message = new FacesMessage("Could not coerce value [" + currentParameter.getValue()
                  + "] on mappingId [" + mapping.getId() + "] to type in location [" + currentParameter.getExpression()
                  + "]");
         handleValidationFailure(context, message, currentPathValidator.getOnError());
      }
      catch (ValidatorException e)
      {
         handleValidationFailure(context, e.getFacesMessage(), currentPathValidator.getOnError());
      }
      catch (FacesException e)
      {
         FacesMessage message = new FacesMessage("Error occurred invoking validator with id [" + currentValidatorId
                  + "] on mappingId [" + mapping.getId() + "] parameter [" + currentParameter.getExpression()
                  + "] at position [" + currentParameter.getPosition() + "]");
         handleValidationFailure(context, message, currentPathValidator.getOnError());
      }
   }
View Full Code Here

Examples of com.ocpsoft.pretty.faces.config.mapping.PathParameter

   {
      URLPatternParser namedParamParser = new URLPatternParser("/foo/#{named}/");
      List<PathParameter> params = namedParamParser.parse(new URL("/foo/love/"));
      assertEquals(1, params.size());

      PathParameter p = params.get(0);
      assertEquals(0, p.getPosition());
      assertEquals("love", p.getValue());
      assertEquals("named", p.getName());
      assertEquals("#{named}", p.getExpression().getELExpression());
   }
View Full Code Here

Examples of com.ocpsoft.pretty.faces.config.mapping.PathParameter

   {
      URLPatternParser namedParamParser = new URLPatternParser("/foo/#{:injected}/");
      List<PathParameter> params = namedParamParser.parse(new URL("/foo/love/"));
      assertEquals(1, params.size());

      PathParameter p = params.get(0);
      assertEquals(0, p.getPosition());
      assertEquals("love", p.getValue());
      assertEquals("#{injected}", p.getExpression().getELExpression());
   }
View Full Code Here

Examples of com.ocpsoft.pretty.faces.config.mapping.PathParameter

   {
      URLPatternParser namedValuedParamParser = new URLPatternParser("/foo/#{named:bean.value}/");
      List<PathParameter> params = namedValuedParamParser.parse(new URL("/foo/love/"));
      assertEquals(1, params.size());

      PathParameter p = params.get(0);
      assertEquals(0, p.getPosition());
      assertEquals("love", p.getValue());
      assertEquals("named", p.getName());
      assertEquals("#{bean.value}", p.getExpression().getELExpression());
   }
View Full Code Here

Examples of com.ocpsoft.pretty.faces.config.mapping.PathParameter

      URLPatternParser parser = new URLPatternParser(
               "/project/#{paramsBean.project}/#{paramsBean.iteration}/#{paramsBean.story}");
      List<PathParameter> params = parser.parse(new URL("/project/starfish1/sprint1/story1"));
      assertEquals(3, params.size());

      PathParameter p = params.get(0);
      assertEquals(0, p.getPosition());
      assertEquals("starfish1", p.getValue());
      assertEquals("#{paramsBean.project}", p.getExpression().getELExpression());

      PathParameter p1 = params.get(1);
      assertEquals(1, p1.getPosition());
      assertEquals("sprint1", p1.getValue());
      assertEquals("#{paramsBean.iteration}", p1.getExpression().getELExpression());

      PathParameter p2 = params.get(2);
      assertEquals(2, p2.getPosition());
      assertEquals("story1", p2.getValue());
      assertEquals("#{paramsBean.story}", p2.getExpression().getELExpression());
   }
View Full Code Here

Examples of com.ocpsoft.pretty.faces.config.mapping.PathParameter

   @Test
   public void testGetValidatorsIdsForPathParam()
   {

      PathParameter p = new PathParameter();
      p.setPosition(0);

      List<PathValidator> validators = m.getValidatorsForPathParam(p);
      assertEquals(1, validators.size());

      PathParameter p2 = new PathParameter();
      p2.setPosition(2);

      validators = m.getValidatorsForPathParam(p2);
      assertEquals(1, validators.size());
   }
View Full Code Here

Examples of com.ocpsoft.pretty.faces.config.mapping.PathParameter

      int paramIndex = 0;
      while (expressionMatcher.find())
      {
         elPattern = true;
         String expression = expressionMatcher.group(1);
         PathParameter param = ExpressionProcessorRunner.process(expression);
         param.setPosition(paramIndex);
         pathParameters.add(param);

         expressionMatcher.appendReplacement(segmentableExpressions, Segment.parameterize(paramIndex));
         paramIndex++;
      }
      expressionMatcher.appendTail(segmentableExpressions);
      this.pathParameters = Collections.unmodifiableList(pathParameters);

      URL segmentedPattern = new URL(segmentableExpressions.toString());

      /*
       * Extract path segments, overlaying regexes found during parameter
       * discovery.
       */
      for (String segmentPattern : segmentedPattern.getSegments())
      {
         Segment segment = new Segment();
         segment.setTemplate(segmentPattern);
         StringBuffer regex = new StringBuffer();

         Matcher parameterMatcher = Segment.getTemplateMatcher(segmentPattern);
         while (parameterMatcher.find())
         {
            String group = parameterMatcher.group(1);
            PathParameter parameter = pathParameters.get(Integer.valueOf(group));
            segment.addParameter(parameter);
            parameterMatcher.appendReplacement(regex, "(" + parameter.getRegex() + ")");
         }
         parameterMatcher.appendTail(regex);

         segment.setRegex(regex.toString());
         pathSegments.add(segment);
View Full Code Here

Examples of com.ocpsoft.pretty.faces.config.mapping.PathParameter

            if (segmentMatcher.find())
            {
               for (int j = 0; j < segment.numParameters(); j++)
               {
                  String value = segmentMatcher.group(j + 1);
                  PathParameter param = segment.getParameter(j).copy();
                  param.setValue(value);
                  result.add(param);
               }

               int regionEnd = segmentMatcher.end();
View Full Code Here

Examples of com.ocpsoft.pretty.faces.config.mapping.PathParameter

   public static final Pattern pattern = Pattern.compile(REGEX);

   public PathParameter process(final PathParameter param)
   {
      PathParameter result = param.copy();

      Matcher matcher = pattern.matcher(param.getExpression().getELExpression());
      if (matcher.matches())
      {
         String regex = matcher.group(3);
         result.setRegex(regex);
         result.setExpression(new ConstantExpression(matcher.group(1) + matcher.group(4)));
         result.setExpressionIsPlainText(false);
      }

      return result;
   }
View Full Code Here

Examples of com.ocpsoft.pretty.faces.config.mapping.PathParameter

      int paramIndex = 0;
      while (expressionMatcher.find())
      {
         elPattern = true;
         String expression = expressionMatcher.group(1);
         PathParameter param = ExpressionProcessorRunner.process(expression);
         param.setPosition(paramIndex);
         pathParameters.add(param);

         expressionMatcher.appendReplacement(segmentableExpressions, Segment.parameterize(paramIndex));
         paramIndex++;
      }
      expressionMatcher.appendTail(segmentableExpressions);
      this.pathParameters = Collections.unmodifiableList(pathParameters);

      URL segmentedPattern = new URL(segmentableExpressions.toString());

      /*
       * Extract path segments, overlaying regexes found during parameter
       * discovery.
       */
      int segmentIndex = 0;
      for (String segmentPattern : segmentedPattern.getSegments())
      {
         Segment segment = new Segment();
         segment.setTemplate(segmentPattern);
         StringBuffer regex = new StringBuffer();

         Matcher parameterMatcher = Segment.getTemplateMatcher(segmentPattern);
         while (parameterMatcher.find())
         {
            String group = parameterMatcher.group(1);
            PathParameter parameter = pathParameters.get(Integer.valueOf(group));
            segment.addParameter(parameter);
            parameterMatcher.appendReplacement(regex, "(" + parameter.getRegex() + ")");
         }
         parameterMatcher.appendTail(regex);

         segment.setRegex(regex.toString());
         pathSegments.add(segment);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.