protected Properties getProperties()

in velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityView.java [522:578]


    protected Properties getProperties(String path, boolean required)
    {
        if (getLog().isTraceEnabled())
        {
            getLog().trace("Searching for properties at {} ", path);
        }
        InputStream inputStream = ServletUtils.getInputStream(path, this.servletContext);
        if (inputStream == null)
        {
            String msg = "Did not find resource at: "+path;
            if (required)
            {
                getLog().error(msg);
                throw new ResourceNotFoundException(msg);
            }
            else
            {
                getLog().debug(msg);
            }
            return null;
        }

        Properties properties = new Properties();
        try
        {
            /* For backward compatibility reasons, keep using an ExtProperties at load time,
             so that redundant properties become multivalued.
              */
            ExtProperties extProps = new ExtProperties();
            extProps.load(inputStream);
            properties.putAll(extProps);
        }
        catch (IOException ioe)
        {
            String msg = "Failed to load properties at: "+path;
            getLog().error(msg, ioe);
            if (required)
            {
                throw new RuntimeException(msg, ioe);
            }
        }
        finally
        {
            try
            {
                if (inputStream != null)
                {
                    inputStream.close();
                }
            }
            catch (IOException ioe)
            {
                getLog().error("Failed to close input stream for {}", path, ioe);
            }
        }
        return properties;
    }