⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 digestingplugin.java

📁 structs源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

            try {
                RuleSet instance =
                    (RuleSet) RequestUtils.applicationInstance(ruleSet);

                digester.addRuleSet(instance);
            } catch (Exception e) {
                // TODO Internationalize msg
                log.error("Exception configuring custom Digester RuleSet", e);
                throw new ServletException(e);
            }
        }
    }

    /**
     * <p>Look up a resource path using one of a set of known path resolution
     * mechanisms and return a URL to the resource.</p>
     *
     * @param path   a String which is meaningful to one of the known
     *               resolution mechanisms.
     * @param source one of the known path resolution mechanisms:
     *
     *               <ul>
     *
     *               <li>file - the path is a fully-qualified filesystem
     *               path.</li>
     *
     *               <li>servlet - the path is a servlet-context relative
     *               path.</li>
     *
     *               <li>classpath - the path is a classpath-relative
     *               path.</li>
     *
     *               </ul>
     * @return a URL pointing to the given path in the given mechanism.
     * @throws java.io.FileNotFoundException
     * @throws java.net.MalformedURLException
     */
    protected URL getConfigURL(String path, String source)
        throws IOException {
        if (SOURCE_CLASSPATH.equals(source)) {
            return this.getClassPathURL(path);
        }

        if (SOURCE_FILE.equals(source)) {
            return this.getFileURL(path);
        }

        if (SOURCE_SERVLET.equals(source)) {
            return this.getServletContextURL(path);
        }

        // TODO Internationalize msg
        throw new IllegalArgumentException("ConfigSource " + source
            + " is not recognized");
    }

    /**
     * Given a string, return a URL to a classpath resource of that name.
     *
     * @param path a Classpath-relative string identifying a resource.
     * @return a URL identifying the resource on the classpath. TODO Do we
     *         need to be smarter about ClassLoaders?
     */
    protected URL getClassPathURL(String path) {
        return getClass().getClassLoader().getResource(path);
    }

    /**
     * Given a string, return a URL to a Servlet Context resource of that
     * name.
     *
     * @param path a Classpath-relative string identifying a resource.
     * @return a URL identifying the resource in the Servlet Context
     * @throws MalformedURLException
     */
    protected URL getServletContextURL(String path)
        throws IOException {
        return this.servlet.getServletContext().getResource(path);
    }

    /**
     * Given a string, return a URL to a Filesystem resource of that name.
     *
     * @param path a path to a file.
     * @return a URL identifying the resource in the in the file system.
     * @throws MalformedURLException
     * @throws FileNotFoundException
     */
    protected URL getFileURL(String path)
        throws IOException {
        File file = new File(path);

        return file.toURL();
    }

    /**
     * @param configPath the path to configuration information for this
     *                   PlugIn.
     * @see #configSource
     */
    public void setConfigPath(String configPath) {
        this.configPath = configPath;
    }

    /**
     * @return the configPath property
     * @see #configSource
     */
    public String getConfigPath() {
        return configPath;
    }

    /**
     * Set the source of the config file.  Should be one of the following:
     * <ul> <li> "classpath" - indicates that the configPath will be resolved
     * by the ClassLoader. </li> <li> "file" - indicates that the configPath
     * is a fully-qualified filesystem path. </li> <li> "servlet" - indicates
     * that the configPath will be found by the ServletContext. </li> </ul>
     *
     * @param configSource the source (lookup method) for the config file.
     * @see #configPath
     */
    public void setConfigSource(String configSource) {
        this.configSource = configSource;
    }

    /**
     * @return the string describing which access method should be used to
     *         resolve configPath.
     * @see #configPath
     */
    public String getConfigSource() {
        return configSource;
    }

    /**
     * This method is called after the Digester runs to store the generated
     * object somewhere.  This implementation places the given object into the
     * ServletContext under the attribute name as defined in
     * <code>key</code>.
     *
     * @param obj The object to save.
     */
    protected void storeGeneratedObject(Object obj) {
        log.debug("Put [" + obj + "] into application context [key:" + this.key
            + "]");
        this.servlet.getServletContext().setAttribute(this.getKey(), obj);
    }

    /**
     * @param key The ServletContext attribute name to store the generated
     *            object under.
     */
    public void setKey(String key) {
        this.key = key;
    }

    /**
     * @return The ServletContext attribute name the generated object is
     *         stored under.
     */
    public String getKey() {
        return key;
    }

    /**
     * <p>A comma-delimited list of one or more classes which implement
     * <code>org.apache.commons.digester.RuleSet</code>. (Optional)</p>
     */
    public void setRulesets(String ruleSets) {
        this.rulesets = ruleSets;
    }

    /**
     * @return The configured list of <code>RuleSet</code> classes.
     */
    public String getRulesets() {
        return this.rulesets;
    }

    /**
     * <p>The path to a Digester XML configuration file, relative to the
     * <code>digesterSource</code> property. (Optional)</p>
     *
     * @see #digesterSource
     * @see #getConfigURL(String, String)
     */
    public void setDigesterPath(String digesterPath) {
        this.digesterPath = digesterPath;
    }

    /**
     * @return the configured path to a Digester XML config file, or null.
     * @see #digesterSource
     * @see #getConfigURL(String, String)
     */
    public String getDigesterPath() {
        return digesterPath;
    }

    /**
     * <p>The lookup mechanism to be used to resolve <code>digesterPath</code>
     * (optional). </p>
     *
     * @param digesterSource
     * @see #getConfigURL(String, String)
     */
    public void setDigesterSource(String digesterSource) {
        this.digesterSource = digesterSource;
    }

    /**
     * @return the configured lookup mechanism for resolving
     *         <code>digesterPath</code>.
     * @see #getConfigURL(String, String)
     */
    public String getDigesterSource() {
        return this.digesterSource;
    }

    /**
     * <p>If set to <code>true</code>, this PlugIn will be pushed onto the
     * Digester stack before the digester <code>parse</code> method is
     * called.</p> <p>Defaults to <code>false</code></p>
     *
     * @param push
     */
    public void setPush(boolean push) {
        this.push = push;
    }

    /**
     * @return Whether or not this <code>PlugIn</code> instance will be pushed
     *         onto the <code>Digester</code> stack before
     *         <code>digester.parse()</code> is called.
     */
    public boolean getPush() {
        return this.push;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -