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

📄 filterset.java

📁 Use the links below to download a source distribution of Ant from one of our mirrors. It is good pra
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            throw new BuildException("endToken must not be empty");        }        this.endOfToken = endOfToken;    }    /**     * Get the end token for this filterset.     *     * @return the filter set's end token for replacement delimiting.     */    public String getEndToken() {        if (isReference()) {            return getRef().getEndToken();        }        return endOfToken;    }    /**     * Set whether recursive token expansion is enabled.     * @param recurse <code>boolean</code> whether to recurse.     */    public void setRecurse(boolean recurse) {        this.recurse = recurse;    }    /**     * Get whether recursive token expansion is enabled.     * @return <code>boolean</code> whether enabled.     */    public boolean isRecurse() {        return recurse;    }    /**     * Read the filters from the given file.     *     * @param filtersFile        the file from which filters are read.     * @exception BuildException when the file cannot be read.     */    public synchronized void readFiltersFromFile(File filtersFile) throws BuildException {        if (isReference()) {            throw tooManyAttributes();        }        if (!filtersFile.exists()) {           handleMissingFile("Could not read filters from file "                                     + filtersFile + " as it doesn't exist.");        }        if (filtersFile.isFile()) {           log("Reading filters from " + filtersFile, Project.MSG_VERBOSE);           FileInputStream in = null;           try {              Properties props = new Properties();              in = new FileInputStream(filtersFile);              props.load(in);              Enumeration e = props.propertyNames();              Vector filts = getFilters();              while (e.hasMoreElements()) {                 String strPropName = (String) e.nextElement();                 String strValue = props.getProperty(strPropName);                 filts.addElement(new Filter(strPropName, strValue));              }           } catch (Exception ex) {              throw new BuildException("Could not read filters from file: "                  + filtersFile, ex);           } finally {              FileUtils.close(in);           }        } else {           handleMissingFile(               "Must specify a file rather than a directory in "               + "the filtersfile attribute:" + filtersFile);        }        filterHash = null;    }    /**     * Does replacement on the given string with token matching.     * This uses the defined begintoken and endtoken values which default     * to @ for both.     * This resets the passedTokens and calls iReplaceTokens to     * do the actual replacements.     *     * @param line  The line in which to process embedded tokens.     * @return      The input string after token replacement.     */    public synchronized String replaceTokens(String line) {        return iReplaceTokens(line);    }    /**     * Add a new filter.     *     * @param filter the filter to be added.     */    public synchronized void addFilter(Filter filter) {        if (isReference()) {            throw noChildrenAllowed();        }        filters.addElement(filter);        filterHash = null;    }    /**     * Create a new FiltersFile.     *     * @return The filtersfile that was created.     */    public FiltersFile createFiltersfile() {        if (isReference()) {            throw noChildrenAllowed();        }        return new FiltersFile();    }    /**     * Add a new filter made from the given token and value.     *     * @param token The token for the new filter.     * @param value The value for the new filter.     */    public synchronized void addFilter(String token, String value) {        if (isReference()) {            throw noChildrenAllowed();        }        addFilter(new Filter(token, value));    }    /**     * Add a Filterset to this filter set.     *     * @param filterSet the filterset to be added to this filterset     */    public synchronized void addConfiguredFilterSet(FilterSet filterSet) {        if (isReference()) {            throw noChildrenAllowed();        }        for (Enumeration e = filterSet.getFilters().elements(); e.hasMoreElements();) {            addFilter((Filter) e.nextElement());        }    }    /**    * Test to see if this filter set has filters.    *    * @return Return true if there are filters in this set.    */    public synchronized boolean hasFilters() {        return getFilters().size() > 0;    }    /**     * Clone the filterset.     *     * @return a deep clone of this filterset.     *     * @throws BuildException if the clone cannot be performed.     */    public synchronized Object clone() throws BuildException {        if (isReference()) {            return ((FilterSet) getRef()).clone();        }        try {            FilterSet fs = (FilterSet) super.clone();            fs.filters = (Vector) getFilters().clone();            fs.setProject(getProject());            return fs;        } catch (CloneNotSupportedException e) {            throw new BuildException(e);        }    }    /**     * Set the behavior WRT missing filtersfiles.     * @param onMissingFiltersFile the OnMissing describing the behavior.     */    public void setOnMissingFiltersFile(OnMissing onMissingFiltersFile) {        this.onMissingFiltersFile = onMissingFiltersFile;    }    /**     * Get the onMissingFiltersFile setting.     * @return the OnMissing instance.     */    public OnMissing getOnMissingFiltersFile() {        return onMissingFiltersFile;    }    /**     * Does replacement on the given string with token matching.     * This uses the defined begintoken and endtoken values which default     * to @ for both.     *     * @param line  The line to process the tokens in.     * @return      The string with the tokens replaced.     */    private synchronized String iReplaceTokens(String line) {        String beginToken = getBeginToken();        String endToken = getEndToken();        int index = line.indexOf(beginToken);        if (index > -1) {            Hashtable tokens = getFilterHash();            try {                StringBuffer b = new StringBuffer();                int i = 0;                String token = null;                String value = null;                while (index > -1) {                    //can't have zero-length token                    int endIndex = line.indexOf(endToken,                        index + beginToken.length() + 1);                    if (endIndex == -1) {                        break;                    }                    token                        = line.substring(index + beginToken.length(), endIndex);                    b.append(line.substring(i, index));                    if (tokens.containsKey(token)) {                        value = (String) tokens.get(token);                        if (recurse && !value.equals(token)) {                            // we have another token, let's parse it.                            value = replaceTokens(value, token);                        }                        log("Replacing: " + beginToken + token + endToken                            + " -> " + value, Project.MSG_VERBOSE);                        b.append(value);                        i = index + beginToken.length() + token.length()                            + endToken.length();                    } else {                        // just append beginToken and search further                        b.append(beginToken);                        i = index + beginToken.length();                    }                    index = line.indexOf(beginToken, i);                }                b.append(line.substring(i));                return b.toString();            } catch (StringIndexOutOfBoundsException e) {                return line;            }        } else {           return line;        }    }    /**     * This parses tokens which point to tokens.     * It also maintains a list of currently used tokens, so we cannot     * get into an infinite loop.     * @param line the value / token to parse.     * @param parent the parent token (= the token it was parsed from).     */    private synchronized String replaceTokens(String line, String parent)        throws BuildException {        String beginToken = getBeginToken();        String endToken = getEndToken();        if (recurseDepth == 0) {            passedTokens = new Vector();        }        recurseDepth++;        if (passedTokens.contains(parent) && !duplicateToken) {            duplicateToken = true;            System.out.println(                "Infinite loop in tokens. Currently known tokens : "                + passedTokens.toString() + "\nProblem token : " + beginToken                + parent + endToken + " called from " + beginToken                + passedTokens.lastElement().toString() + endToken);            recurseDepth--;            return parent;        }        passedTokens.addElement(parent);        String value = iReplaceTokens(line);        if (value.indexOf(beginToken) == -1 && !duplicateToken                && recurseDepth == 1) {            passedTokens = null;        } else if (duplicateToken) {            // should always be the case...            if (passedTokens.size() > 0) {                value = (String) passedTokens.remove(passedTokens.size() - 1);                if (passedTokens.size() == 0) {                    value = beginToken + value + endToken;                    duplicateToken = false;                }            }        }        recurseDepth--;        return value;    }    private void handleMissingFile(String message) {        switch (onMissingFiltersFile.getIndex()) {        case OnMissing.IGNORE_INDEX:            return;        case OnMissing.FAIL_INDEX:            throw new BuildException(message);        case OnMissing.WARN_INDEX:            log(message, Project.MSG_WARN);            return;        default:            throw new BuildException("Invalid value for onMissingFiltersFile");        }    }}

⌨️ 快捷键说明

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