dleslie     00/11/10 08:00:06

  Modified:    samples/Servlet DefaultApplyXSLProperties.java
  Log:
  Ritesh Kumar's fix for detecting and using the correct
  server port.
  
  Revision  Changes    Path
  1.4       +47 -28    xml-xalan/samples/Servlet/DefaultApplyXSLProperties.java
  
  Index: DefaultApplyXSLProperties.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/samples/Servlet/DefaultApplyXSLProperties.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultApplyXSLProperties.java    2000/08/23 14:40:06     1.3
  +++ DefaultApplyXSLProperties.java    2000/11/10 16:00:05     1.4
  @@ -1,5 +1,5 @@
   
/*****************************************************************************************************
  - * $Id: DefaultApplyXSLProperties.java,v 1.3 2000/08/23 14:40:06 dleslie Exp 
$
  + * $Id: DefaultApplyXSLProperties.java,v 1.4 2000/11/10 16:00:05 dleslie Exp 
$
    * 
    * Copyright (c) 1998-1999 Lotus Corporation, Inc. All Rights Reserved.
    *                           This software is provided without a warranty of 
any kind.
  @@ -37,6 +37,11 @@
         * @see #setLocalHost
         */
       protected transient String localHost = null;
  +    
  +    /**
  +     * Server port. Used in toSafeURL() -- fix submitted by Ritesh Kumar.
  +     */
  +    protected static int port =0;    
   
       /**
         * Constructor to use program defaults.
  @@ -94,34 +99,48 @@
         * @see #setLocalHost
         * @see #getLocalHost
         */
  -    public URL toSafeURL(String xURL)
  +    public URL toSafeURL(String xURL, HttpServletRequest request)
       throws MalformedURLException
       {
  -     if (xURL == null)
  -         return null;
  -
  -     if (xURL.startsWith("/")) {
  -         try {
  -             return new URL("http", localHost, xURL);
  -         } catch (MalformedURLException mue) {
  -         throw new MalformedURLException("toSafeURL(): " + xURL + 
  -                                         " did not map to local");
  +      // Fix submitted by Ritesh Kumar. Port is included in construction of 
URL that is returned.
  +      if (port == 0)
  +        port = request.getServerPort();
  +      
  +         if (xURL == null)
  +           return null;
  +
  +         if (xURL.startsWith("/")) 
  +      {
  +           try 
  +        {
  +                   return new URL("http", localHost, port, xURL);
  +           }
  +        catch (MalformedURLException mue) 
  +        {
  +             throw new MalformedURLException("toSafeURL(): " + xURL + 
  +                                                                     " did 
not map to local");
  +           }
            }
  -     }
  -     URL tempURL = null;
  -     try { 
  -         tempURL = new URL(xURL);
  -     } catch (MalformedURLException mue) {
  -         throw new MalformedURLException("toSafeURL(): " + xURL + 
  -                                         " not a valid URL");
  -     }
  -     try { 
  -         return new URL(tempURL.getProtocol(), localHost, 
  -                        tempURL.getPort(), tempURL.getFile());
  -     } catch (MalformedURLException mue) {
  -         throw new MalformedURLException("toSafeURL(): " + xURL + 
  -                                         " could not be converted to local 
host");
  -     }
  +         URL tempURL = null;
  +         try 
  +      { 
  +           tempURL = new URL(xURL);
  +         } 
  +      catch (MalformedURLException mue) 
  +      {
  +           throw new MalformedURLException("toSafeURL(): " + xURL + 
  +                                                                   " not a 
valid URL"); 
  +         }
  +         try 
  +      { 
  +           return new URL(tempURL.getProtocol(), localHost, 
  +                                      port, tempURL.getFile());
  +         } 
  +      catch (MalformedURLException mue) 
  +      {
  +           throw new MalformedURLException("toSafeURL(): " + xURL + 
  +                                                                 " could not 
be converted to local host");
  +         }
       }
   
       /**
  @@ -135,7 +154,7 @@
       public String getXMLurl(HttpServletRequest request)
       throws MalformedURLException
       {
  -     URL url = toSafeURL(getRequestParmString(request, "URL"));
  +     URL url = toSafeURL(getRequestParmString(request, "URL"), request);
        if (url == null)
            return super.getXMLurl(null);
        return url.toExternalForm();
  @@ -152,7 +171,7 @@
       public String getXSLRequestURL(HttpServletRequest request)
       throws MalformedURLException
       {
  -     URL url = toSafeURL(getRequestParmString(request, "xslURL"));
  +     URL url = toSafeURL(getRequestParmString(request, "xslURL"), request);
        if (url == null)
            return null;
        return url.toExternalForm();
  
  
  

Reply via email to