protected void setVelocityProperties()

in src/java/org/apache/turbine/services/velocity/TurbineVelocityService.java [500:585]


    protected void setVelocityProperties(VelocityEngine velocity, Configuration conf)
            throws Exception
    {
        // Fix up all the template resource loader pathes to be
        // webapp relative. Copy all other keys verbatim into the
        // veloConfiguration.

        for (Iterator<String> i = conf.getKeys(); i.hasNext();)
        {
            String key = i.next();
            if (!key.endsWith(RESOURCE_LOADER_PATH))
            {
                Object value = conf.getProperty(key);
                if (value instanceof List<?>)
                {
                    for (Object name2 : ((List<?>) value))
                    {
                        velocity.addProperty(key, name2);
                    }
                }
                else
                {
                    velocity.addProperty(key, value);
                }
                log.debug("Adding {} -> {}", key, value);
                continue; // for()
            }

            List<Object> paths = conf.getList(key, null);
            if (paths == null)
            {
                // We don't copy this into VeloProperties, because
                // null value is unhealthy for the ExtendedProperties object...
                continue; // for()
            }

            // Translate the supplied pathes given here.
            // the following three different kinds of
            // pathes must be translated to be webapp-relative
            //
            // jar:file://path-component!/entry-component
            // file://path-component
            // path/component
            for (Object p : paths)
            {
            	String path = (String)p;
                log.debug("Translating {}", path);

                if (path.startsWith(JAR_PREFIX))
                {
                    // skip jar: -> 4 chars
                    if (path.substring(4).startsWith(ABSOLUTE_PREFIX))
                    {
                        // We must convert up to the jar path separator
                        int jarSepIndex = path.indexOf("!/");

                        // jar:file:// -> skip 11 chars
                        path = (jarSepIndex < 0)
                            ? Turbine.getRealPath(path.substring(11))
                        // Add the path after the jar path separator again to the new url.
                            : (Turbine.getRealPath(path.substring(11, jarSepIndex)) + path.substring(jarSepIndex));

                        log.debug("Result (absolute jar path): {}", path);
                    }
                }
                else if(path.startsWith(ABSOLUTE_PREFIX))
                {
                    // skip file:// -> 7 chars
                    path = Turbine.getRealPath(path.substring(7));

                    log.debug("Result (absolute URL Path): {}", path);
                }
                // Test if this might be some sort of URL that we haven't encountered yet.
                else if(path.indexOf("://") < 0)
                {
                    path = Turbine.getRealPath(path);

                    log.debug("Result (normal fs reference): {}", path);
                }

                log.debug("Adding {} -> {}", key, path);
                // Re-Add this property to the configuration object
                velocity.addProperty(key, path);
            }
        }
    }