Package com.ocpsoft.pretty.faces.url

Examples of com.ocpsoft.pretty.faces.url.URLPatternParser


   public String build(final UrlMapping urlMapping, final boolean encodeUrl, final List<UIParameter> parameters)
   {
      String result = "";
      if (urlMapping != null)
      {
         URLPatternParser parser = urlMapping.getPatternParser();
         List<String> pathParams = new ArrayList<String>();
         List<QueryParameter> queryParams = new ArrayList<QueryParameter>();

         if(parameters != null)
         {
            // TODO this logic should be in the components, not in the builder
            if (parameters.size() == 1)
            {
               UIParameter firstParam = parameters.get(0);
               if (((firstParam.getValue() != null)) && (firstParam.getName() == null))
               {
                  if (firstParam.getValue() instanceof List<?>)
                  {
                     URL url = parser.getMappedURL(firstParam.getValue());
                     return url.toURL();
                  }
                  else if (firstParam.getValue().getClass().isArray())
                  {
                     // The Object[] cast here is required, otherwise Java treats
                     // getValue() as a single Object.
                     List<Object> list = Arrays.asList((Object[]) firstParam.getValue());
                     URL url = parser.getMappedURL(list);
                     return url.toURL();
                  }
               }
            }
  
            for (UIParameter parameter : parameters)
            {
               String name = parameter.getName();
               Object value = parameter.getValue();
  
               if ((name == null) && (value != null))
               {
                  pathParams.add(value.toString());
               }
               else
               {
                  List<?> values = null;
                  if ((value != null) && value.getClass().isArray())
                  {
                     values = Arrays.asList((Object[]) value);
                  }
                  else if (value instanceof List<?>)
                  {
                     values = (List<?>) value;
                  }
                  else if (value != null)
                  {
                     values = Arrays.asList(value);
                  }
  
                  if (values != null)
                  {
                     for (Object object : values)
                     {
                        String tempValue = null;
                        if (object != null)
                        {
                           tempValue = object.toString();
                        }
                        queryParams.add(new QueryParameter(name, tempValue));
                     }
                  }
                  else
                  {
                     queryParams.add(new QueryParameter(name, null));
                  }
               }
            }
         }

         // build URL object for given path parameter set
         URL mappedURL = parser.getMappedURL(pathParams.toArray());
        
         // create encoded/unicode URL
         String url = encodeUrl ? mappedURL.encode().toURL() : mappedURL.toURL();
        
         // append query string
View Full Code Here


    */
   public URLPatternParser getPatternParser()
   {
      if ((parser == null) && (pattern != null))
      {
         this.parser = new URLPatternParser(pattern);
      }
      return parser;
   }
View Full Code Here

      Object value = null;
      try
      {
         FacesContext context = FacesContext.getCurrentInstance();

         URLPatternParser parser = mapping.getPatternParser();
         List<PathParameter> parameters = parser.getPathParameters();
         List<String> parameterValues = new ArrayList<String>();
         for (PathParameter injection : parameters)
         {
            // read value of the path parameter
            expression = injection.getExpression().getELExpression();
            value = elUtils.getValue(context, expression);
            if (value == null)
            {
               throw new PrettyException("PrettyFaces: Exception occurred while building URL for MappingId < "
                        + mapping.getId() + " >, Required value " + " < " + expression + " > was null");
            }

            // convert the value to a string using the correct converter
            Converter converter = context.getApplication().createConverter(value.getClass());
            if (converter != null)
            {
               String convertedValue = converter.getAsString(context, new NullComponent(), value);
               if (convertedValue == null)
               {
                  throw new PrettyException("PrettyFaces: The converter <" + converter.getClass().getName()
                           + "> returned null while converting the object <" + value.toString() + ">!");
               }
               value = convertedValue;
            }

            parameterValues.add(value.toString());
         }

         result = parser.getMappedURL(parameterValues).encode();
      }
      catch (ELException e)
      {
         throw new PrettyException("PrettyFaces: Exception occurred while building URL for MappingId < "
                  + mapping.getId() + " >, Error occurred while extracting values from backing bean" + " < "
View Full Code Here

   }

   @Test
   public void testGetPatternParser()
   {
      URLPatternParser parser = m.getPatternParser();
      assertEquals(1, parser.getParameterCount());
   }
View Full Code Here

    */
   public URLPatternParser getPatternParser()
   {
      if (((parser == null) || dirty) && (pattern != null))
      {
         this.parser = new URLPatternParser(pattern);
      }
      return parser;
   }
View Full Code Here

   public String build(final UrlMapping urlMapping, final boolean encodeUrl, final List<UIParameter> parameters)
   {
      String result = "";
      if (urlMapping != null)
      {
         URLPatternParser parser = new URLPatternParser(urlMapping.getPattern());
         List<String> pathParams = new ArrayList<String>();
         List<QueryParameter> queryParams = new ArrayList<QueryParameter>();

         if(parameters != null)
         {
            // TODO this logic should be in the components, not in the builder
            if (parameters.size() == 1)
            {
               UIParameter firstParam = parameters.get(0);
               if (((firstParam.getValue() != null)) && (firstParam.getName() == null))
               {
                  if (firstParam.getValue() instanceof List<?>)
                  {
                     URL url = parser.getMappedURL(firstParam.getValue());
                     return url.toURL();
                  }
                  else if (firstParam.getValue().getClass().isArray())
                  {
                     // The Object[] cast here is required, otherwise Java treats
                     // getValue() as a single Object.
                     List<Object> list = Arrays.asList((Object[]) firstParam.getValue());
                     URL url = parser.getMappedURL(list);
                     return url.toURL();
                  }
               }
            }
  
            for (UIParameter parameter : parameters)
            {
               String name = parameter.getName();
               Object value = parameter.getValue();
  
               if ((name == null) && (value != null))
               {
                  pathParams.add(value.toString());
               }
               else
               {
                  List<?> values = null;
                  if ((value != null) && value.getClass().isArray())
                  {
                     values = Arrays.asList((Object[]) value);
                  }
                  else if (value instanceof List<?>)
                  {
                     values = (List<?>) value;
                  }
                  else if (value != null)
                  {
                     values = Arrays.asList(value);
                  }
  
                  if (values != null)
                  {
                     for (Object object : values)
                     {
                        String tempValue = null;
                        if (object != null)
                        {
                           tempValue = object.toString();
                        }
                        queryParams.add(new QueryParameter(name, tempValue));
                     }
                  }
                  else
                  {
                     queryParams.add(new QueryParameter(name, null));
                  }
               }
            }
         }

         // build URL object for given path parameter set
         URL mappedURL = parser.getMappedURL(pathParams.toArray());
        
         // create encoded/unicode URL
         String url = encodeUrl ? mappedURL.encode().toURL() : mappedURL.toURL();
        
         // append query string
View Full Code Here

      Object value = null;
      try
      {
         FacesContext context = FacesContext.getCurrentInstance();

         URLPatternParser parser = new URLPatternParser(mapping.getPattern());
         List<PathParameter> parameters = parser.getPathParameters();
         List<String> parameterValues = new ArrayList<String>();
         for (PathParameter injection : parameters)
         {
            // read value of the path parameter
            expression = injection.getExpression().getELExpression();
            value = elUtils.getValue(context, expression);
            if (value == null)
            {
               throw new PrettyException("PrettyFaces: Exception occurred while building URL for MappingId < "
                        + mapping.getId() + " >, Required value " + " < " + expression + " > was null");
            }

            // convert the value to a string using the correct converter
            Converter converter = context.getApplication().createConverter(value.getClass());
            if (converter != null)
            {
               String valueAsString = converter.getAsString(context, new NullComponent(), value);
               if (valueAsString == null)
               {
                  throw new PrettyException("PrettyFaces: The converter <" + converter.getClass().getName()
                        + "> returned null while converting the object <" + value.toString() + ">!");
               }
               parameterValues.add(valueAsString);
            }
            else
            {
               parameterValues.add(value.toString());
            }
           
         }

         result = parser.getMappedURL(parameterValues);
      }
      catch (ELException e)
      {
         throw new PrettyException("PrettyFaces: Exception occurred while building URL for MappingId < "
                  + mapping.getId() + " >, Error occurred while extracting values from backing bean" + " < "
View Full Code Here

TOP

Related Classes of com.ocpsoft.pretty.faces.url.URLPatternParser

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.