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/library XSPRequestLibrary.java
Date Sun, 09 Jan 2000 02:47:15 GMT
ricardo     00/01/08 18:47:14

  Modified:    src/org/apache/cocoon/processor/xsp/library
                        XSPRequestLibrary.java
  Log:
  Removed redundant methods. Added Servlet 2.2 methods. Made all methods static. Removed Java2
dependency
  
  Revision  Changes    Path
  1.4       +65 -125   xml-cocoon/src/org/apache/cocoon/processor/xsp/library/XSPRequestLibrary.java
  
  Index: XSPRequestLibrary.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/processor/xsp/library/XSPRequestLibrary.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XSPRequestLibrary.java	2000/01/06 17:56:23	1.3
  +++ XSPRequestLibrary.java	2000/01/09 02:47:14	1.4
  @@ -67,31 +67,19 @@
   
   public class XSPRequestLibrary {
     // ServletRequest
  -  public static Object getAttribute(HttpServletRequest request, String name) {
  -    if (name == null || name.length() == 0) {
  -      return null;
  -    }
  -
  -    return request.getAttribute(name);
  -  }
  -
     public static Element getAttribute(HttpServletRequest request, String name, Document
document) {
  -    Object value = getAttribute(request, name);
  -
  -    if (value == null) {
  -      return null;
  -    }
  -
  +    Object value = request.getAttribute(name);
       Element element = document.createElement("request:attribute");
  -
       element.setAttribute("name", name);
   
  -    if (value instanceof XObject) {
  -      DocumentFragment fragment = document.createDocumentFragment();
  -      ((XObject) value).toDOM(fragment);
  -      element.appendChild(fragment);
  -    } else {
  -      element.appendChild(document.createTextNode(value.toString()));
  +    if (value != null) {
  +      if (value instanceof XObject) {
  +        DocumentFragment fragment = document.createDocumentFragment();
  +        ((XObject) value).toDOM(fragment);
  +        element.appendChild(fragment);
  +      } else {
  +        element.appendChild(document.createTextNode(value.toString()));
  +      }
       }
   
       return element;
  @@ -107,7 +95,6 @@
   
       String[] attributeNames = new String[v.size()];
       v.copyInto(attributeNames);
  -    Arrays.sort(attributeNames); // Since Java2
   
       return attributeNames;
     }
  @@ -126,26 +113,24 @@
       return element;
     }
   
  -  public Element getCharacterEncoding(HttpServletRequest request, Document document) {
  +  public static Element getCharacterEncoding(HttpServletRequest request, Document document)
{
       Element element = document.createElement("request:character-encoding");
       element.appendChild(document.createTextNode(request.getCharacterEncoding()));
       return element;
     }
   
  -  public Element getContentLength(HttpServletRequest request, Document document) {
  +  public static Element getContentLength(HttpServletRequest request, Document document)
{
       Element element = document.createElement("request:content-length");
       element.appendChild(document.createTextNode(String.valueOf(request.getContentLength())));
       return element;
     }
   
  -  public Element getContentType(HttpServletRequest request, Document document) {
  +  public static Element getContentType(HttpServletRequest request, Document document) {
       Element element = document.createElement("request:content-type");
       element.appendChild(document.createTextNode(request.getContentType()));
       return element;
     }
   
  -  // Not supported by JSDK versions prior to 2.2
  -  /*
     public static Element getLocale(HttpServletRequest request, Document document) {
       Element property = null;
       Locale locale = request.getLocale();
  @@ -165,10 +150,7 @@
   
       return element;
     }
  -  */
   
  -  // Not supported by JSDK versions prior to 2.2
  -  /*
     public static Locale[] getLocales(HttpServletRequest request) {
       Vector v = new Vector();
       Enumeration e = request.getLocales();
  @@ -179,14 +161,10 @@
   
       Locale[] locales = new Locale[v.size()];
       v.copyInto(locales);
  -    Arrays.sort(locales); // Since Java2
   
       return locales;
     }
  -  */
   
  -  // Not supported by JSDK versions prior to 2.2
  -  /*
     public static Element getLocales(HttpServletRequest request, Document document) {
       Enumeration e = request.getLocales();
       Element list = document.createElement("request:locales");
  @@ -197,7 +175,6 @@
   
       return list;
     }
  -  */
   
     public static String[] getParameterNames(HttpServletRequest request) {
       Vector v = new Vector();
  @@ -209,7 +186,6 @@
   
       String[] attributeNames = new String[v.size()];
       v.copyInto(attributeNames);
  -    Arrays.sort(attributeNames); // Since Java2
   
       return attributeNames;
     }
  @@ -229,114 +205,96 @@
   
     public static Element getParameter(HttpServletRequest request, String name, Document
document) {
       String value = request.getParameter(name);
  -
  -    if (value == null) {
  -      return null;
  -    }
  -
       Element element = document.createElement("request:parameter");
  -
       element.setAttribute("name", name);
  -    element.appendChild(document.createTextNode(value));
   
  +    if (value != null) {
  +      element.appendChild(document.createTextNode(value));
  +    }
  +
       return element;
     }
   
     public static Element getParameterValues(HttpServletRequest request, String name, Document
document) {
  -    if (name == null || name.length() == 0) {
  -      return null;
  -    }
  -
       String[] values = request.getParameterValues(name);
  -
  -    if (values == null) {
  -      return null;
  -    }
  -
       Element element = document.createElement("request:parameter-values");
       element.setAttribute("name", name);
   
  -    for (int i = 0; i < values.length; i++) {
  -      Element valueElement = document.createElement("request:parameter-value");
  -      valueElement.appendChild(document.createTextNode(values[i]));
  -      element.appendChild(valueElement);
  +    if (values != null) {
  +      for (int i = 0; i < values.length; i++) {
  +        Element valueElement = document.createElement("request:parameter-value");
  +        valueElement.appendChild(document.createTextNode(values[i]));
  +        element.appendChild(valueElement);
  +      }
       }
   
       return element;
     }
   
  -  public Element getProtocol(HttpServletRequest request, Document document) {
  +  public static Element getProtocol(HttpServletRequest request, Document document) {
       Element element = document.createElement("request:protocol");
       element.appendChild(document.createTextNode(request.getProtocol()));
       return element;
     }
   
   
  -  public Element getRemoteAddr(HttpServletRequest request, Document document) {
  +  public static Element getRemoteAddr(HttpServletRequest request, Document document) {
       Element element = document.createElement("request:remote-address");
       element.appendChild(document.createTextNode(request.getRemoteAddr()));
       return element;
     }
   
  -  public Element getRemoteHost(HttpServletRequest request, Document document) {
  +  public static Element getRemoteHost(HttpServletRequest request, Document document) {
       Element element = document.createElement("request:remote-host");
       element.appendChild(document.createTextNode(request.getRemoteHost()));
       return element;
     }
   
  -  public Element getScheme(HttpServletRequest request, Document document) {
  +  public static Element getScheme(HttpServletRequest request, Document document) {
       Element element = document.createElement("request:scheme");
       element.appendChild(document.createTextNode(request.getScheme()));
       return element;
     }
   
  -  public Element getServerName(HttpServletRequest request, Document document) {
  +  public static Element getServerName(HttpServletRequest request, Document document) {
       Element element = document.createElement("request:server-name");
       element.appendChild(document.createTextNode(String.valueOf(request.getServerName())));
       return element;
     }
   
  -  public Element getServerPort(HttpServletRequest request, Document document) {
  +  public static Element getServerPort(HttpServletRequest request, Document document) {
       Element element = document.createElement("request:server-port");
       element.appendChild(document.createTextNode(String.valueOf(request.getServerPort())));
       return element;
     }
   
  -  // Not supported by JSDK versions prior to 2.2
  -  /*
  -  public Element isSecure(HttpServletRequest request, Document document) {
  +  public static Element isSecure(HttpServletRequest request, Document document) {
       Element element = document.createElement("request:is-secure");
       element.appendChild(document.createTextNode(String.valueOf(request.isSecure())));
       return element;
     }
  -  */
   
     // HttpServletRequest
  -  public Element getAuthType(HttpServletRequest request, Document document) {
  +  public static Element getAuthType(HttpServletRequest request, Document document) {
       Element element = document.createElement("request:auth-type");
       element.appendChild(document.createTextNode(request.getAuthType()));
       return element;
     }
   
  -  // Not supported by JSDK versions prior to 2.2
  -  /*
  -  public Element getContextPath(HttpServletRequest request, Document document) {
  +  public static Element getContextPath(HttpServletRequest request, Document document) {
       Element element = document.createElement("request:context-path");
       element.appendChild(document.createTextNode(request.getContextPath()));
       return element;
     }
  -  */
   
     public static Element getCookies(HttpServletRequest request, Document document) {
       Cookie[] cookies = request.getCookies();
  -
  -    if (cookies == null) {
  -      return null;
  -    }
  -
       Element element = document.createElement("request:cookies");
  -    for (int i = 0; i < cookies.length; i++) {
  -      element.appendChild(XSPCookieLibrary.getCookie(cookies[i], document));
  +
  +    if (cookies != null) {
  +      for (int i = 0; i < cookies.length; i++) {
  +        element.appendChild(XSPCookieLibrary.getCookie(cookies[i], document));
  +      }
       }
   
       return element;
  @@ -348,31 +306,25 @@
       }
   
       long dateHeader = request.getDateHeader(name);
  -
  -    if (dateHeader == -1) {
  -      return null;
  -    }
  -
  -    String header = XSPUtil.formatDate(new Date(dateHeader), format.trim());
  -
       Element element = document.createElement("request:date-header");
       element.setAttribute("name", name);
  -    element.appendChild(document.createTextNode(header));
   
  +    if (dateHeader != -1) {
  +      String header = XSPUtil.formatDate(new Date(dateHeader), format.trim());
  +      element.appendChild(document.createTextNode(header));
  +    }
  +
       return element;
     }
   
     public static Element getHeader(HttpServletRequest request, String name, Document document)
{
       String value = request.getHeader(name);
  -
  -    if (value == null) {
  -      return null;
  -    }
  -
       Element element = document.createElement("request:header");
  -
       element.setAttribute("name", name);
  -    element.appendChild(document.createTextNode(value));
  +
  +    if (value != null) {
  +      element.appendChild(document.createTextNode(value));
  +    }
   
       return element;
     }
  @@ -387,7 +339,6 @@
   
       String[] headerNames = new String[v.size()];
       v.copyInto(headerNames);
  -    Arrays.sort(headerNames); // Since Java2
   
       return headerNames;
     }
  @@ -406,8 +357,6 @@
       return element;
     }
   
  -  // Not supported by JSDK versions prior to 2.2
  -  /*
     public static String[] getHeaders(HttpServletRequest request, String name) {
       Vector v = new Vector();
       Enumeration e = request.getHeaders(name);
  @@ -418,7 +367,6 @@
   
       String[] headers = new String[v.size()];
       v.copyInto(headers);
  -    Arrays.sort(headers); // Since Java2
   
       return headers;
     }
  @@ -436,103 +384,95 @@
   
       return element;
     }
  -  */
   
  -  public Element getIntHeader(HttpServletRequest request, String name, Document document)
{
  +  public static Element getIntHeader(HttpServletRequest request, String name, Document
document) {
       Element element = document.createElement("request:int-header");
       element.appendChild(document.createTextNode(String.valueOf(request.getIntHeader(name))));
       return element;
     }
   
  -  public Element getMethod(HttpServletRequest request, Document document) {
  +  public static Element getMethod(HttpServletRequest request, Document document) {
       Element element = document.createElement("request:method");
       element.appendChild(document.createTextNode(request.getMethod()));
       return element;
     }
   
  -  public Element getPathInfo(HttpServletRequest request, Document document) {
  +  public static Element getPathInfo(HttpServletRequest request, Document document) {
       Element element = document.createElement("request:path-info");
       element.appendChild(document.createTextNode(request.getPathInfo()));
       return element;
     }
   
  -  public Element getPathTranslated(HttpServletRequest request, Document document) {
  +  public static Element getPathTranslated(HttpServletRequest request, Document document)
{
       Element element = document.createElement("request:path-translated");
       element.appendChild(document.createTextNode(request.getPathTranslated()));
       return element;
     }
   
  -  public Element getQueryString(HttpServletRequest request, Document document) {
  +  public static Element getQueryString(HttpServletRequest request, Document document) {
       Element element = document.createElement("request:query-string");
       element.appendChild(document.createTextNode(request.getQueryString()));
       return element;
     }
   
  -  public Element getRemoteUser(HttpServletRequest request, Document document) {
  +  public static Element getRemoteUser(HttpServletRequest request, Document document) {
       Element element = document.createElement("request:remote-user");
       element.appendChild(document.createTextNode(request.getRemoteUser()));
       return element;
     }
   
  -  public Element getRequestedSessionId(HttpServletRequest request, Document document) {
  +  public static Element getRequestedSessionId(HttpServletRequest request, Document document)
{
       Element element = document.createElement("request:requested-session-id");
       element.appendChild(document.createTextNode(request.getRequestedSessionId()));
       return element;
     }
   
  -  public Element getRequestURI(HttpServletRequest request, Document document) {
  +  public static Element getRequestURI(HttpServletRequest request, Document document) {
       Element element = document.createElement("request:request-uri");
       element.appendChild(document.createTextNode(request.getRequestURI()));
       return element;
     }
   
  -  public Element getServletPath(HttpServletRequest request, Document document) {
  +  public static Element getServletPath(HttpServletRequest request, Document document) {
       Element element = document.createElement("request:servlet-path");
       element.appendChild(document.createTextNode(request.getServletPath()));
       return element;
     }
   
  -  // Not supported by JSDK versions prior to 2.2
  -  /*
  -  public Element getUserPrincipal(HttpServletRequest request, Document document) {
  +  public static Element getUserPrincipal(HttpServletRequest request, Document document)
{
       Principal principal = request.getUserPrincipal();
  -    if (principal == null) {
  -      return null;
  -    }
  -
       Element element = document.createElement("request:user-principal");
  -    Element nameElement = document.createElement("principal:name");
  -    nameElement.appendChild(document.createTextNode(principal.getName()));
  -    element.appendChild(nameElement);
  +
  +    if (principal != null) {
  +      Element nameElement = document.createElement("principal:name");
  +      nameElement.appendChild(document.createTextNode(principal.getName()));
  +      element.appendChild(nameElement);
  +    }
   
       return element;
     }
  -  */
   
  -  public Element isRequestedSessionIdFromCookie(HttpServletRequest request, Document document)
{
  +  public static Element isRequestedSessionIdFromCookie(HttpServletRequest request, Document
document) {
       Element element = document.createElement("request:is-requested-session-id-from-cookie");
       element.appendChild(document.createTextNode(String.valueOf(request.isRequestedSessionIdFromCookie())));
       return element;
     }
   
  -  public Element isRequestedSessionIdFromURL(HttpServletRequest request, Document document)
{
  +  public static Element isRequestedSessionIdFromURL(HttpServletRequest request, Document
document) {
       Element element = document.createElement("request:is-requested-session-id-from-url");
       element.appendChild(document.createTextNode(String.valueOf(request.isRequestedSessionIdFromURL())));
       return element;
     }
   
  -  public Element isRequestedSessionIdValid(HttpServletRequest request, Document document)
{
  +  public static Element isRequestedSessionIdValid(HttpServletRequest request, Document
document) {
       Element element = document.createElement("request:is-requested-session-id-valid");
       element.appendChild(document.createTextNode(String.valueOf(request.isRequestedSessionIdValid())));
       return element;
     }
   
  -  // Not supported by JSDK versions prior to 2.2
  -  /*
  -  public Element isUserInRole(HttpServletRequest request, String role, Document document)
{
  +  public static Element isUserInRole(HttpServletRequest request, String role, Document
document) {
       Element element = document.createElement("request:is-requested-session-id-valid");
       element.appendChild(document.createTextNode(String.valueOf(request.isUserInRole(role))));
       return element;
     }
  -  */
   }
  
  
  

Mime
View raw message