[jboss-cvs] jboss-portal/common/src/main/org/jboss/portal/common/util ...

Chris Laprun chris.laprun at jboss.com
Sat Aug 12 14:51:01 EDT 2006


  User: claprun 
  Date: 06/08/12 14:51:01

  Modified:    common/src/main/org/jboss/portal/common/util  URLTools.java
  Log:
  JBPORTAL-979:
  - Added enforceAbsoluteURL and isURLAbsolute on URLTools.
  - Use URLTool.enforceAbsoluteURL where needed.
  
  Revision  Changes    Path
  1.3       +24 -1     jboss-portal/common/src/main/org/jboss/portal/common/util/URLTools.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: URLTools.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-portal/common/src/main/org/jboss/portal/common/util/URLTools.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- URLTools.java	2 Jun 2006 22:54:02 -0000	1.2
  +++ URLTools.java	12 Aug 2006 18:51:01 -0000	1.3
  @@ -34,7 +34,7 @@
   
   /**
    * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    * @since 2.4 (May 26, 2006)
    */
   public class URLTools
  @@ -43,6 +43,29 @@
      private static final Pattern LINK = Pattern.compile("(?:href|action|src)\\s*=\\s*('|\")\\s*([^'\"]*)\\s*('|\")",
         Pattern.CASE_INSENSITIVE);
   
  +   public static final String HTTP_PREFIX = "http://";
  +   public static final String HTTPS_PREFIX = "https://";
  +   public static final String FILE_PREFIX = "/";
  +
  +   public static boolean isURLAbsolute(String url)
  +   {
  +      return url.startsWith(HTTP_PREFIX) || url.startsWith(HTTPS_PREFIX) || url.startsWith(FILE_PREFIX);
  +   }
  +
  +   /**
  +    * Enforces that the given URL is absolute
  +    *
  +    * @param url the String representation of the URL to be checked
  +    * @throws IllegalArgumentException if the given URL is not absolute
  +    */
  +   public static void enforceAbsoluteURL(String url) throws IllegalArgumentException
  +   {
  +      if (!isURLAbsolute(url))
  +      {
  +         throw new IllegalArgumentException("URL must be absolute. Was: " + url);
  +      }
  +   }
  +
      public static String encodeXWWWFormURL(String s)
      {
         try
  
  
  



More information about the jboss-cvs-commits mailing list