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

📄 xmlresources.java

📁 java mail,java mailjava mailjava mailjava mail
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            String resKey = resElement.getAttribute("name");            if ( resKey == null ) {                // ignore elements without a "name" attribute.                continue;            }            String resString = resElement.getFirstChild().getNodeValue();            // Do parameter replacements for this string resource.            Iterator paramNames = parameters.keySet().iterator();            while ( paramNames.hasNext() ) {                String paramName = (String)paramNames.next();                String paramValue = (String)parameters.get(paramName);                StringBuffer replaceBuffer =                    new StringBuffer(64)                            .append("${")                            .append(paramName)                            .append("}");                resString = substituteSubString(resString, replaceBuffer.toString(), paramValue);            }            // See if we already have registered a string of this value            String shared = (String) stringTable.get(resString);            // If not, register it -- we will use it next time            if (shared == null) {                stringTable.put(resString, resString);            } else {                resString = shared;            }            // Add to the resMap - either the "default" or the "product" map            resMap.put(resKey, resString);        }        // Copy in default strings, then overwrite product-specific ones.        m_resource.putAll(defaultStrings);        m_resource.putAll(selectTagStrings);    }    /**     * Compares the "select" value against a set of regular expressions     * defined in XML.  The first successful match defines the name of a     * selector tag. This value is then used to choose the specific     * expressions to use.     *     * @param select the String to be checked     * @param matchersElement the XML element containing selector patterns     *     * @return the selector tag that will be used to select custom resources     *     */    private String match(String select, Element matchersElement)        throws MalformedPerl5PatternException    {        String selectTagName = select;            NodeList matchers = matchersElement.getElementsByTagName("matcher");        for ( int i = 0; i < matchers.getLength(); i++ ) {            // Get the values for this matcher element.            Element matcher = (Element)matchers.item(i);            String matchName = matcher.getAttribute("for");            StringBuffer selectTagPatternBuffer =                new StringBuffer(64)                        .append("/")                        .append(matcher.getAttribute("match"))                        .append("/i");            // If the select string matches the pattern, use the match            // name from this matcher.            if ( m_perl5Util.match(selectTagPatternBuffer.toString(), selectTagName) ) {                return matchName;            }        }        return null;    }    /**     * Replace substrings of one string with another string and return altered string.     * @param input input string     * @param find the string to replace     * @param replace the string to replace with     * @return the substituted string     */    static private String substituteSubString( String input,                                                String find,                                               String replace )    {        int find_length = find.length();        int replace_length = replace.length();        StringBuffer output = new StringBuffer(input);        int index = input.indexOf(find);        int outputOffset = 0;        while ( index > -1 ) {            output.replace(index + outputOffset, index + outputOffset + find_length, replace);            outputOffset = outputOffset + (replace_length - find_length);            index = input.indexOf(find, index + find_length);        }        String result = output.toString();        return result;    }    /**     * Returns a named string for the specified key.     *      * @param name   the name of the String resource required.     * @return the requested resource     */    public String getString(String name)    {        return (String)m_resource.get(name);    }    /**     * Returns a named string for the specified key.     *      * @param name     the name of the String resource required.     * @param required true if the resource is required     * @return the requested resource     * @throws ConfigurationException     *         if a required resource cannot be found.     */    public String getString(String name, boolean required)    {        String str = getString(name);        if (str == null && required) {            StringBuffer exceptionBuffer =                new StringBuffer(64)                        .append("Required String resource: '")                        .append(name)                        .append("' was not found.");            throw new IllegalArgumentException(exceptionBuffer.toString());        }        return str;    }    /**     * Returns a named string, replacing parameters with the values set in a Map.     *      * @param name          the name of the String resource required.     * @param parameters    a map of parameters (name-value string pairs) which are     *                      replaced where found in the input strings     * @return the requested resource     */    public String getString(String name, Map parameters)    {        return replaceParameters(getString(name), parameters);    }    /**     * Returns a named string, replacing parameters with the values set in a Map.     *      * @param name          the name of the String resource required.     * @param parameters    a map of parameters (name-value string pairs) which are     *                      replaced where found in the input strings     * @return the requested resource     */    public String getString(String name, Map parameters, boolean required)    {        return replaceParameters(getString(name, required), parameters);    }    /**     * Returns a named string, replacing parameters with the values set.     *      * @param name          the name of the String resource required.     * @param parameters    a map of parameters (name-value string pairs) which are     *                      replaced where found in the input strings     * @return the requested resource     */    static public String replaceParameters(String str, Map parameters)    {        if (str != null && parameters != null) {            // Do parameter replacements for this string resource.            Iterator paramNames = parameters.keySet().iterator();            StringBuffer replaceBuffer = new StringBuffer(64);            while ( paramNames.hasNext() ) {                String paramName = (String)paramNames.next();                String paramValue = (String)parameters.get(paramName);                replaceBuffer.append("${").append(paramName).append("}");                str = substituteSubString(str, replaceBuffer.toString(), paramValue);                if (paramNames.hasNext()) replaceBuffer.setLength(0);            }        }        return str;    }}

⌨️ 快捷键说明

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