dleslie     00/11/10 07:59:43

  Modified:    java/samples/servlet ApplyXSLT.java
                        DefaultApplyXSLTProperties.java
  Log:
  Fixes to accomodate new trax/serializer/etc.,
  and Ritesh Kumar's fix for detecting and using the correct
  server port.
  
  Revision  Changes    Path
  1.10      +2 -2      xml-xalan/java/samples/servlet/ApplyXSLT.java
  
  Index: ApplyXSLT.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/samples/servlet/ApplyXSLT.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ApplyXSLT.java    2000/11/07 21:29:43     1.9
  +++ ApplyXSLT.java    2000/11/10 15:59:42     1.10
  @@ -1,5 +1,5 @@
   
/*****************************************************************************************************
  - * $Id: ApplyXSLT.java,v 1.9 2000/11/07 21:29:43 dleslie Exp $
  + * $Id: ApplyXSLT.java,v 1.10 2000/11/10 15:59:42 dleslie Exp $
    *
    * Copyright (c) 1998-1999 Lotus Corporation, Inc. All Rights Reserved.
    *                           This software is provided without a warranty of 
any kind.
  @@ -116,7 +116,7 @@
       ourDefaultParameters = new DefaultApplyXSLTProperties(config);
     }
     
  -    /**
  +  /**
      * Loads the media properties file specified by the given string.
      * @param mediaURLstring Location of the media properties file.  Can be 
either a full URL or a path relative
      * to the System's server.root /servlets directory.  If this parameter is 
null,
  
  
  
  1.5       +101 -78   
xml-xalan/java/samples/servlet/DefaultApplyXSLTProperties.java
  
  Index: DefaultApplyXSLTProperties.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/samples/servlet/DefaultApplyXSLTProperties.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultApplyXSLTProperties.java   2000/10/18 17:56:51     1.4
  +++ DefaultApplyXSLTProperties.java   2000/11/10 15:59:42     1.5
  @@ -1,5 +1,5 @@
   
/*****************************************************************************************************
  - * $Id: DefaultApplyXSLTProperties.java,v 1.4 2000/10/18 17:56:51 dleslie 
Exp $
  + * $Id: DefaultApplyXSLTProperties.java,v 1.5 2000/11/10 15:59:42 dleslie 
Exp $
    * 
    * Copyright (c) 1998-1999 Lotus Corporation, Inc. All Rights Reserved.
    *                           This software is provided without a warranty of 
any kind.
  @@ -40,6 +40,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.
  @@ -59,12 +64,12 @@
         */
       public DefaultApplyXSLTProperties(ServletConfig config)
       {
  -     super(config);
  -     String cat = config.getInitParameter("catalog");
  -     if (cat != null) DEFAULT_catalog = cat;
  -     else DEFAULT_catalog = null;
  -     setLocalHost();
  -     setSystemProperties();
  +         super(config);
  +         String cat = config.getInitParameter("catalog");
  +         if (cat != null) DEFAULT_catalog = cat;
  +         else DEFAULT_catalog = null;
  +         setLocalHost();
  +         setSystemProperties();
       }
   
       /**
  @@ -74,11 +79,14 @@
         */
       protected void setLocalHost()
       {
  -     try { 
  -         localHost = InetAddress.getLocalHost().getHostName();
  -     } catch (Exception uhe) {
  -         localHost = null;
  -     }
  +         try 
  +         { 
  +             localHost = InetAddress.getLocalHost().getHostName();
  +         } 
  +         catch (Exception uhe) 
  +         {
  +           localHost = null;
  +         }
       }
   
       /**
  @@ -88,7 +96,7 @@
         */
       public String getLocalHost()
       {
  -     return localHost;
  +         return localHost;
       }
   
       /**
  @@ -99,34 +107,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");
  -         }
  -     }
  -     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");
  -     }
  +      // 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, 
  +                                      port, tempURL.getFile());
  +         } 
  +      catch (MalformedURLException mue) 
  +      {
  +           throw new MalformedURLException("toSafeURL(): " + xURL + 
  +                                                                 " could not 
be converted to local host");
  +         }
       }
   
       /**
  @@ -140,10 +162,10 @@
       public String getXMLurl(HttpServletRequest request)
       throws MalformedURLException
       {
  -     URL url = toSafeURL(getRequestParmString(request, "URL"));
  -     if (url == null)
  -         return super.getXMLurl(null);
  -     return url.toExternalForm();
  +         URL url = toSafeURL(getRequestParmString(request, "URL"),request);
  +         if (url == null)
  +           return super.getXMLurl(null);
  +         return url.toExternalForm();
       }
   
       /**
  @@ -157,10 +179,10 @@
       public String getXSLRequestURL(HttpServletRequest request)
       throws MalformedURLException
       {
  -     URL url = toSafeURL(getRequestParmString(request, "xslURL"));
  -     if (url == null)
  -         return null;
  -     return url.toExternalForm();
  +         URL url = toSafeURL(getRequestParmString(request, 
"xslURL"),request);
  +         if (url == null)
  +             return null;
  +         return url.toExternalForm();
       }
   
       /**
  @@ -174,10 +196,10 @@
       public String getXSLurl(HttpServletRequest request)
       throws MalformedURLException
       {
  -     String reqURL = getXSLRequestURL(request);
  -     if (reqURL != null)
  -         return reqURL;
  -     return super.getXSLurl(null);
  +         String reqURL = getXSLRequestURL(request);
  +         if (reqURL != null)
  +             return reqURL;
  +         return super.getXSLurl(null);
       }
   
       /**
  @@ -191,21 +213,23 @@
         */
       public String[] getCatalog(HttpServletRequest request)
       {
  -     String temp[] = request.getParameterValues("catalog");
  -     if (DEFAULT_catalog == null)
  -         return temp;
  -     if (temp == null) {
  -         String defaultArray[] = new String [1];
  -         defaultArray[0] = DEFAULT_catalog;
  -         return defaultArray;
  -     }
  -     int i, len = temp.length + 1;
  -     String newCatalogs[] = new String[len];
  -     newCatalogs[0] = DEFAULT_catalog;
  -     for (i=1; i < len; i++) {
  -         newCatalogs[i] = temp[i-1];
  -     }
  -     return newCatalogs;
  +         String temp[] = request.getParameterValues("catalog");
  +         if (DEFAULT_catalog == null)
  +             return temp;
  +         if (temp == null) 
  +      {
  +           String defaultArray[] = new String [1];
  +           defaultArray[0] = DEFAULT_catalog;
  +           return defaultArray;
  +         }
  +         int i, len = temp.length + 1;
  +         String newCatalogs[] = new String[len];
  +         newCatalogs[0] = DEFAULT_catalog;
  +         for (i=1; i < len; i++) 
  +      {
  +           newCatalogs[i] = temp[i-1];
  +         }
  +         return newCatalogs;
       }
        
         /**
  @@ -215,19 +239,18 @@
       protected void setSystemProperties()
        {
          Properties props = new Properties();
  -       props.put("org.apache.trax.processor.xslt", 
"org.apache.xalan.processor.StylesheetProcessor");
  +//     props.put("org.apache.trax.processor.xslt", 
"org.apache.xalan.processor.StylesheetProcessor");
          props.put("org.xml.sax.driver", 
"org.apache.xerces.parsers.SAXParser");
  -       props.put("serialize.methods", "xml,html,Text");
  -       props.put("serialize.xml", 
"org.apache.xml.serialize.transition.XMLSerializer");       
  -       props.put("serialize.html", 
"org.apache.xml.serialize.transition.HTMLSerializer");     
  -       props.put("serialize.text", 
"org.apache.xml.serialize.transition.XTextSerializer");    
  -       props.put("serialize.xhtml", 
"org.apache.xml.serialize.transition.XHTMLSerializer");   
  -       props.put("serialize.wml", 
"org.apache.xml.serialize.transition.XWMLSerializer");     
  -       props.put("serialize.format.xml", 
"serialize.format.XMLOutputFormat");         
  -       props.put("serialize.format.html", 
"serialize.format.XMLOutputFormat");        
  -       props.put("serialize.format.text", 
"serialize.format.XMLOutputFormat");        
  -       props.put("serialize.format.xhtml", 
"serialize.format.XHTMLOutputFormat");     
  -       props.put("serialize.format.text", 
"serialize.format.TextOutputFormat");       
  +       props.put("serialize.methods", "xml,html,xhtml,Text");
  +       props.put("serialize.xml", 
"org.apache.xalan.serialize.FormatterToXML");       
  +       props.put("serialize.html", 
"org.apache.xalan.serialize.FormatterToHTML");     
  +       props.put("serialize.text", 
"org.apache.xalan.serialize.FormatterToText");     
  +       props.put("serialize.xhtml", 
"org.apache.xalan.serialize.FormatterToXML"); 
  +       props.put("serialize.wml", 
"org.apache.xalan.serialize.transition.WMLSerializer");    
  +       props.put("serialize.format.xml", 
"org.apache.serialize.helpers.XMLOutputFormat");     
  +       props.put("serialize.format.html", 
"org.apache.serialize.helpers.HTMLOutputFormat");   
  +       props.put("serialize.format.xhtml", 
"org.apache.serialize.helpers.XHTMLOutputFormat");         
  +       props.put("serialize.format.text", 
"org.apache.serialize.helpers.TextOutputFormat");   
          
         Properties systemProps = System.getProperties();
         Enumeration propEnum = props.propertyNames();
  
  
  

Reply via email to