cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rica...@locus.apache.org
Subject cvs commit: xml-cocoon/src/org/apache/cocoon/processor/xsp XSPUtil.java
Date Sun, 09 Jan 2000 02:47:25 GMT
ricardo     00/01/08 18:47:24

  Modified:    src/org/apache/cocoon/processor/xsp XSPUtil.java
  Log:
  Added counter library methods
  
  Revision  Changes    Path
  1.7       +54 -27    xml-cocoon/src/org/apache/cocoon/processor/xsp/XSPUtil.java
  
  Index: XSPUtil.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/processor/xsp/XSPUtil.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XSPUtil.java	2000/01/07 13:20:50	1.6
  +++ XSPUtil.java	2000/01/09 02:47:24	1.7
  @@ -1,4 +1,4 @@
  -/*-- $Id: XSPUtil.java,v 1.6 2000/01/07 13:20:50 ricardo Exp $ -- 
  +/*-- $Id: XSPUtil.java,v 1.7 2000/01/09 02:47:24 ricardo Exp $ -- 
   
    ============================================================================
                      The Apache Software License, Version 1.1
  @@ -61,7 +61,7 @@
   
   /**
    * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  - * @version $Revision: 1.6 $ $Date: 2000/01/07 13:20:50 $
  + * @version $Revision: 1.7 $ $Date: 2000/01/09 02:47:24 $
    */
   public class XSPUtil {
     public static String pathComponent(String filename) {
  @@ -129,11 +129,11 @@
       return
         (
           new File(
  -	  new File(
  -	    requestRealPath(request, context)
  -	  ).getParent(),
  -	  filename
  -	)
  +          new File(
  +            requestRealPath(request, context)
  +          ).getParent(),
  +          filename
  +        )
         ).getCanonicalPath();
     }
   
  @@ -145,20 +145,6 @@
       return relativeFilename(filename, request, null);
     }
   
  -  public static String getFileContents(String filename) throws IOException {
  -    return getFileContents(new FileReader(filename));
  -  }
  -
  -  public static String getFileContents(Reader reader) throws IOException {
  -    int len;
  -    char[] chr = new char[4096];
  -    StringBuffer buffer = new StringBuffer();
  -    while ((len = reader.read(chr)) > 0) {
  -      buffer.append(chr, 0, len);
  -    }
  -    return buffer.toString();
  -  }
  -
     public static String requestRealPath(
       HttpServletRequest request,
       ServletContext context
  @@ -372,14 +358,14 @@
         } else if (c[i] == ' ') {
           buffer.append('+');
         } else {
  -	buffer.append('%');
  +        buffer.append('%');
           String hex = Integer.toHexString((byte) c[i]).toUpperCase();
   
  -	if (hex.length() < 2) {
  -	  buffer.append('0');
  -	}
  +        if (hex.length() < 2) {
  +          buffer.append('0');
  +        }
   
  -	buffer.append(hex);
  +        buffer.append(hex);
         }
       }
   
  @@ -389,8 +375,32 @@
     public static String formDecode(String text) throws Exception {
       return URLDecoder.decode(text);
     }
  +
  +  /* Library Utility Methods */
  +  // Inclusion
  +  public static String getURLContents(String url) throws IOException {
  +    return getContents(new URL(url).openStream());
  +  }
  +
  +  public static String getFileContents(String filename) throws IOException {
  +    return getContents(new FileReader(filename));
  +  }
   
  -  /* Date */
  +  public static String getContents(InputStream in) throws IOException {
  +    return getContents(new InputStreamReader(in));
  +  }
  +
  +  public static String getContents(Reader reader) throws IOException {
  +    int len;
  +    char[] chr = new char[4096];
  +    StringBuffer buffer = new StringBuffer();
  +    while ((len = reader.read(chr)) > 0) {
  +      buffer.append(chr, 0, len);
  +    }
  +    return buffer.toString();
  +  }
  +
  +  // Date
     public static String formatDate(Date date, String pattern) {
       if (pattern == null || pattern.length() == 0) {
         pattern = "yyyy/MM/dd hh:mm:ss aa";
  @@ -400,5 +410,22 @@
       } catch (Exception e) {
         return date.toString();
       }
  +  }
  +
  +  // Counters
  +  private static int count = 0;
  +
  +  public static synchronized int getCount() {
  +    return ++count;
  +  }
  +
  +  public static synchronized int getSessionCount(HttpSession session) {
  +    Integer integer = (Integer) session.getValue("util.counter");
  +    if (integer == null) {
  +      integer = new Integer(0);
  +    }
  +    int cnt = integer.intValue() + 1;
  +    session.putValue("util.counter", new Integer(cnt));
  +    return cnt;
     }
   }
  
  
  

Mime
View raw message