View | Details | Raw Unified | Return to bug 40241
Collapse All | Expand All

(-)../apache-tomcat-5.5.17-src/container/catalina/src/share/org/apache/catalina/servlets/DefaultServlet.java (-62 / +67 lines)
Lines 41-46 Link Here
41
import javax.naming.NamingEnumeration;
41
import javax.naming.NamingEnumeration;
42
import javax.naming.NamingException;
42
import javax.naming.NamingException;
43
import javax.naming.directory.DirContext;
43
import javax.naming.directory.DirContext;
44
import javax.servlet.ServletConfig;
44
import javax.servlet.ServletException;
45
import javax.servlet.ServletException;
45
import javax.servlet.ServletOutputStream;
46
import javax.servlet.ServletOutputStream;
46
import javax.servlet.UnavailableException;
47
import javax.servlet.UnavailableException;
Lines 208-268 Link Here
208
    public void destroy() {
209
    public void destroy() {
209
    }
210
    }
210
211
212
    private boolean getBooleanInitParameter(final ServletConfig config,
213
        final String key, final boolean defaultVal) {
214
        boolean booleanValue = defaultVal;
215
        final String value = config.getInitParameter(key);
216
217
        if (value != null) {
218
            booleanValue = Boolean.getBoolean(value);
219
        }
220
        return booleanValue;
221
    }
222
223
    private int getIntInitParameter(final ServletConfig config,
224
        final String key, final int defaultVal) {
225
        int intValue = defaultVal;
226
        final String value = config.getInitParameter(key);
227
228
        if (value != null) {
229
            try {
230
                intValue = Integer.parseInt(value);
231
            } catch(NumberFormatException e) {
232
                intValue = defaultVal;
233
                log("DefaultServlet.init: Unable to parse init parameter \""
234
                    + key + "\"; expected integer, but found \""
235
                    + value + "\".");
236
            }
237
        }
238
        return intValue;
239
    }
211
240
212
    /**
241
    /**
213
     * Initialize this servlet.
242
     * Initialize this servlet.
214
     */
243
     */
215
    public void init() throws ServletException {
244
    public void init() throws ServletException {
245
        final String value;
216
246
217
        // Set our properties from the initialization parameters
247
        // Set our properties from the initialization parameters
218
        String value = null;
248
        this.debug = getIntInitParameter(getServletConfig(), "debug", this.debug);
219
        try {
249
        this.input = getIntInitParameter(getServletConfig(), "input", this.input);
220
            value = getServletConfig().getInitParameter("debug");
250
        this.listings = getBooleanInitParameter(getServletConfig(), "listings", this.listings);
221
            debug = Integer.parseInt(value);
251
        this.readOnly = getBooleanInitParameter(getServletConfig(), "readonly", this.readOnly);
222
        } catch (Throwable t) {
252
        this.output = getIntInitParameter(getServletConfig(), "output", this.output);
223
            ;
253
224
        }
254
        value = getServletConfig().getInitParameter("sendfileSize");
225
        try {
255
        if (value != null) {
226
            value = getServletConfig().getInitParameter("input");
256
            int temp;
227
            input = Integer.parseInt(value);
257
            try {
228
        } catch (Throwable t) {
258
                temp = Integer.parseInt(value) * 1024;
229
            ;
259
                this.sendfileSize = temp;
230
        }
260
            }  catch(NumberFormatException e) {
231
        try {
261
                log("DefaultServlet.init: Unable to parse init parameter \""
232
            value = getServletConfig().getInitParameter("listings");
262
                    + "sendfileSize" + "\"; expected integer, but found \""
233
            listings = (new Boolean(value)).booleanValue();
263
                    + value + "\".");
234
        } catch (Throwable t) {
264
            }
235
            ;
236
        }
237
        try {
238
            value = getServletConfig().getInitParameter("readonly");
239
            if (value != null)
240
                readOnly = (new Boolean(value)).booleanValue();
241
        } catch (Throwable t) {
242
            ;
243
        }
244
        try {
245
            value = getServletConfig().getInitParameter("output");
246
            output = Integer.parseInt(value);
247
        } catch (Throwable t) {
248
            ;
249
        }
250
        try {
251
            value = getServletConfig().getInitParameter("sendfileSize");
252
            sendfileSize = Integer.parseInt(value) * 1024;
253
        } catch (Throwable t) {
254
            ;
255
        }
256
        try {
257
            value = getServletConfig().getInitParameter("fileEncoding");
258
            fileEncoding = value;
259
        } catch (Throwable t) {
260
            ;
261
        }
265
        }
262
266
263
        globalXsltFile = getServletConfig().getInitParameter("globalXsltFile");
267
        this.fileEncoding = getServletConfig().getInitParameter("fileEncoding");
264
        localXsltFile = getServletConfig().getInitParameter("localXsltFile");
268
        this.globalXsltFile = getServletConfig().getInitParameter("globalXsltFile");
265
        readmeFile = getServletConfig().getInitParameter("readmeFile");
269
        this.localXsltFile = getServletConfig().getInitParameter("localXsltFile");
270
        this.readmeFile = getServletConfig().getInitParameter("readmeFile");
266
271
267
        // Sanity check on the specified buffer sizes
272
        // Sanity check on the specified buffer sizes
268
        if (input < 256)
273
        if (input < 256)
Lines 1454-1463 Link Here
1454
1459
1455
                    return buffer.toString();
1460
                    return buffer.toString();
1456
                 }
1461
                 }
1457
             } catch(Throwable e) {
1462
             } catch(IOException e) {
1458
                 ; /* Should only be IOException or NamingException
1463
                // Ignored
1459
                    * can be ignored
1464
             } catch(NamingException e) {
1460
                    */
1465
                // Ignored
1461
             }
1466
             }
1462
        }
1467
        }
1463
1468
Lines 1478-1487 Link Here
1478
                    if (is!=null)
1483
                    if (is!=null)
1479
                        return is;
1484
                        return is;
1480
                }
1485
                }
1481
             } catch(Throwable e) {
1486
             } catch(IOException e) {
1482
                 ; /* Should only be IOException or NamingException
1487
                // Ignored
1483
                    * can be ignored
1488
             } catch(NamingException e) {
1484
                    */
1489
                // Ignored
1485
             }
1490
             }
1486
        }
1491
        }
1487
1492
Lines 1499-1512 Link Here
1499
                    fis.read(b);
1504
                    fis.read(b);
1500
                    return new ByteArrayInputStream(b);
1505
                    return new ByteArrayInputStream(b);
1501
                }
1506
                }
1502
            } catch(Throwable e) {
1507
            } catch(IOException e) {
1503
                log("This shouldn't happen (?)...", e);
1508
                log("This shouldn't happen (?)...", e);
1504
                return null;
1509
                return null;
1505
            } finally {
1510
            } finally {
1506
                try {
1511
                try {
1507
                    if (fis!=null)
1512
                    if (fis!=null)
1508
                        fis.close();
1513
                        fis.close();
1509
                } catch(Throwable e){
1514
                } catch(IOException e){
1510
                    ;
1515
                    ;
1511
                }
1516
                }
1512
            }
1517
            }
Lines 1762-1768 Link Here
1762
        // Clean up the input stream
1767
        // Clean up the input stream
1763
        try {
1768
        try {
1764
            istream.close();
1769
            istream.close();
1765
        } catch (Throwable t) {
1770
        } catch (IOException t) {
1766
            ;
1771
            ;
1767
        }
1772
        }
1768
1773
Lines 1809-1815 Link Here
1809
        // Clean up the reader
1814
        // Clean up the reader
1810
        try {
1815
        try {
1811
            reader.close();
1816
            reader.close();
1812
        } catch (Throwable t) {
1817
        } catch (IOException t) {
1813
            ;
1818
            ;
1814
        }
1819
        }
1815
1820
Lines 1844-1850 Link Here
1844
        // Clean up the input stream
1849
        // Clean up the input stream
1845
        try {
1850
        try {
1846
            istream.close();
1851
            istream.close();
1847
        } catch (Throwable t) {
1852
        } catch (IOException t) {
1848
            ;
1853
            ;
1849
        }
1854
        }
1850
1855
Lines 1886-1892 Link Here
1886
        // Clean up the input stream
1891
        // Clean up the input stream
1887
        try {
1892
        try {
1888
            reader.close();
1893
            reader.close();
1889
        } catch (Throwable t) {
1894
        } catch (IOException t) {
1890
            ;
1895
            ;
1891
        }
1896
        }
1892
1897
Lines 1938-1944 Link Here
1938
1943
1939
            try {
1944
            try {
1940
                istream.close();
1945
                istream.close();
1941
            } catch (Throwable t) {
1946
            } catch (IOException t) {
1942
                ;
1947
                ;
1943
            }
1948
            }
1944
1949
Lines 2001-2007 Link Here
2001
2006
2002
            try {
2007
            try {
2003
                reader.close();
2008
                reader.close();
2004
            } catch (Throwable t) {
2009
            } catch (IOException t) {
2005
                ;
2010
                ;
2006
            }
2011
            }

Return to bug 40241