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

📄 configurable.java

📁 freemaker安装软件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        properties.setProperty(TIME_ZONE_KEY, timeZone.getID());
    }

    /**
     * Returns the assumed locale when searching for template files with no
     * explicit requested locale. Defaults to system locale.
     */
    public Locale getLocale() {
        return locale != null ? locale : parent.getLocale();
    }

    /**
     * Sets the number format used to convert numbers to strings.
     */
    public void setNumberFormat(String numberFormat) {
        if (numberFormat == null) throw new IllegalArgumentException("Setting \"number_format\" can't be null");
        this.numberFormat = numberFormat;
        properties.setProperty(NUMBER_FORMAT_KEY, numberFormat);
    }

    /**
     * Returns the default number format used to convert numbers to strings.
     * Defaults to <tt>"number"</tt>
     */
    public String getNumberFormat() {
        return numberFormat != null ? numberFormat : parent.getNumberFormat();
    }

    public void setBooleanFormat(String booleanFormat) {
        if (booleanFormat == null) {
            throw new IllegalArgumentException("Setting \"boolean_format\" can't be null");
        } 
        int comma = booleanFormat.indexOf(COMMA);
        if(comma == -1) {
            throw new IllegalArgumentException("Setting \"boolean_format\" must consist of two comma-separated values for true and false respectively");
        }
        trueFormat = booleanFormat.substring(0, comma);
        falseFormat = booleanFormat.substring(comma + 1);
        properties.setProperty(BOOLEAN_FORMAT_KEY, booleanFormat);
    }
    
    public String getBooleanFormat() {
        if(trueFormat == null) {
            return parent.getBooleanFormat(); 
        }
        return trueFormat + COMMA + falseFormat;
    }
    
    String getBooleanFormat(boolean value) {
        return value ? getTrueFormat() : getFalseFormat(); 
    }
    
    private String getTrueFormat() {
        return trueFormat != null ? trueFormat : parent.getTrueFormat(); 
    }
    
    private String getFalseFormat() {
        return falseFormat != null ? falseFormat : parent.getFalseFormat(); 
    }

    /**
     * Sets the date format used to convert date models representing time-only
     * values to strings.
     */
    public void setTimeFormat(String timeFormat) {
        if (timeFormat == null) throw new IllegalArgumentException("Setting \"time_format\" can't be null");
        this.timeFormat = timeFormat;
        properties.setProperty(TIME_FORMAT_KEY, timeFormat);
    }

    /**
     * Returns the date format used to convert date models representing
     * time-only dates to strings.
     * Defaults to <tt>"time"</tt>
     */
    public String getTimeFormat() {
        return timeFormat != null ? timeFormat : parent.getTimeFormat();
    }

    /**
     * Sets the date format used to convert date models representing date-only
     * dates to strings.
     */
    public void setDateFormat(String dateFormat) {
        if (dateFormat == null) throw new IllegalArgumentException("Setting \"date_format\" can't be null");
        this.dateFormat = dateFormat;
        properties.setProperty(DATE_FORMAT_KEY, dateFormat);
    }

    /**
     * Returns the date format used to convert date models representing 
     * date-only dates to strings.
     * Defaults to <tt>"date"</tt>
     */
    public String getDateFormat() {
        return dateFormat != null ? dateFormat : parent.getDateFormat();
    }

    /**
     * Sets the date format used to convert date models representing datetime
     * dates to strings.
     */
    public void setDateTimeFormat(String dateTimeFormat) {
        if (dateTimeFormat == null) throw new IllegalArgumentException("Setting \"datetime_format\" can't be null");
        this.dateTimeFormat = dateTimeFormat;
        properties.setProperty(DATETIME_FORMAT_KEY, dateTimeFormat);
    }

    /**
     * Returns the date format used to convert date models representing datetime
     * dates to strings.
     * Defaults to <tt>"datetime"</tt>
     */
    public String getDateTimeFormat() {
        return dateTimeFormat != null ? dateTimeFormat : parent.getDateTimeFormat();
    }

    /**
     * Sets the exception handler used to handle template exceptions. 
     *
     * @param templateExceptionHandler the template exception handler to use for 
     * handling {@link TemplateException}s. By default, 
     * {@link TemplateExceptionHandler#HTML_DEBUG_HANDLER} is used.
     */
    public void setTemplateExceptionHandler(TemplateExceptionHandler templateExceptionHandler) {
        if (templateExceptionHandler == null) throw new IllegalArgumentException("Setting \"template_exception_handler\" can't be null");
        this.templateExceptionHandler = templateExceptionHandler;
        properties.setProperty(TEMPLATE_EXCEPTION_HANDLER_KEY, templateExceptionHandler.getClass().getName());
    }

    /**
     * Retrieves the exception handler used to handle template exceptions. 
     */
    public TemplateExceptionHandler getTemplateExceptionHandler() {
        return templateExceptionHandler != null
                ? templateExceptionHandler : parent.getTemplateExceptionHandler();
    }

    /**
     * Sets the arithmetic engine used to perform arithmetic operations.
     *
     * @param arithmeticEngine the arithmetic engine used to perform arithmetic
     * operations.By default, {@link ArithmeticEngine#BIGDECIMAL_ENGINE} is 
     * used.
     */
    public void setArithmeticEngine(ArithmeticEngine arithmeticEngine) {
        if (arithmeticEngine == null) throw new IllegalArgumentException("Setting \"arithmetic_engine\" can't be null");
        this.arithmeticEngine = arithmeticEngine;
        properties.setProperty(ARITHMETIC_ENGINE_KEY, arithmeticEngine.getClass().getName());
    }

    /**
     * Retrieves the arithmetic engine used to perform arithmetic operations.
     */
    public ArithmeticEngine getArithmeticEngine() {
        return arithmeticEngine != null
                ? arithmeticEngine : parent.getArithmeticEngine();
    }

    /**
     * Sets the object wrapper used to wrap objects to template models.
     *
     * @param objectWrapper the object wrapper used to wrap objects to template
     * models.By default, {@link ObjectWrapper#DEFAULT_WRAPPER} is used.
     */
    public void setObjectWrapper(ObjectWrapper objectWrapper) {
        if (objectWrapper == null) throw new IllegalArgumentException("Setting \"object_wrapper\" can't be null");
        this.objectWrapper = objectWrapper;
        properties.setProperty(OBJECT_WRAPPER_KEY, objectWrapper.getClass().getName());
    }

    /**
     * Retrieves the object wrapper used to wrap objects to template models.
     */
    public ObjectWrapper getObjectWrapper() {
        return objectWrapper != null
                ? objectWrapper : parent.getObjectWrapper();
    }
    
    /**
     * Sets the output encoding. Allows <code>null</code>, which means that the
     * output encoding is not known.
     */
    public void setOutputEncoding(String outputEncoding) {
        this.outputEncoding = outputEncoding;
        // java.util.Properties doesn't allow null value!
        if (outputEncoding != null) {
            properties.setProperty(OUTPUT_ENCODING_KEY, outputEncoding);
        } else {
            properties.remove(OUTPUT_ENCODING_KEY);
        }
        outputEncodingSet = true;
    }
    
    public String getOutputEncoding() {
        return outputEncodingSet
                ? outputEncoding
                : (parent != null ? parent.getOutputEncoding() : null);
    }
    
    /**
     * Sets the URL escaping charset. Allows <code>null</code>, which means that the
     * output encoding will be used for URL escaping.
     */
    public void setURLEscapingCharset(String urlEscapingCharset) {
        this.urlEscapingCharset = urlEscapingCharset;
        // java.util.Properties doesn't allow null value!
        if (urlEscapingCharset != null) {
            properties.setProperty(URL_ESCAPING_CHARSET_KEY, urlEscapingCharset);
        } else {
            properties.remove(URL_ESCAPING_CHARSET_KEY);
        }
        urlEscapingCharsetSet = true;
    }
    
    public String getURLEscapingCharset() {
        return urlEscapingCharsetSet
                ? urlEscapingCharset
                : (parent != null ? parent.getURLEscapingCharset() : null);
    }
    
    /**
     * Sets a setting by a name and string value.
     * 
     * <p>List of supported names and their valid values:
     * <ul>
     *   <li><code>"locale"</code>: local codes with the usual format, such as <code>"en_US"</code>.
     *   <li><code>"classic_compatible"</code>:
     *       <code>"true"</code>, <code>"false"</code>, <code>"yes"</code>, <code>"no"</code>,
     *       <code>"t"</code>, <code>"f"</code>, <code>"y"</code>, <code>"n"</code>.
     *       Case insensitive.
     *   <li><code>"template_exception_handler"</code>:  If the value contains dot, then it is
     *       interpreted as class name, and the object will be created with
     *       its parameterless constructor. If the value does not contain dot,
     *       then it must be one of these special values:
     *       <code>"rethrow"</code>, <code>"debug"</code>,
     *       <code>"html_debug"</code>, <code>"ignore"</code> (case insensitive).
     *   <li><code>"arithmetic_engine"</code>: If the value contains dot, then it is
     *       interpreted as class name, and the object will be created with
     *       its parameterless constructor. If the value does not contain dot,
     *       then it must be one of these special values:
     *       <code>"bigdecimal"</code>, <code>"conservative"</code> (case insensitive).  
     *   <li><code>"object_wrapper"</code>: If the value contains dot, then it is
     *       interpreted as class name, and the object will be created with
     *       its parameterless constructor. If the value does not contain dot,
     *       then it must be one of these special values:
     *       <code>"simple"</code>, <code>"beans"</code>, <code>"jython"</code> (case insensitive).
     *   <li><code>"number_format"</code>: pattern as <code>java.text.DecimalFormat</code> defines.
     *   <li><code>"boolean_format"</code>: the textual value for boolean true and false,
     *       separated with comma. For example <code>"yes,no"</code>.
     *   <li><code>"date_format", "time_format", "datetime_format"</code>: patterns as
     *       <code>java.text.SimpleDateFormat</code> defines.
     *   <li><code>"time_zone"</code>: time zone, with the format as
     *       <code>java.util.TimeZone.getTimeZone</code> defines. For example <code>"GMT-8:00"</code> or
     *       <code>"America/Los_Angeles"</code>
     *   <li><code>"output_encoding"</code>: Informs FreeMarker about the charset
     *       used for the output. As FreeMarker outputs character stream (not
     *       byte stream), it is not aware of the output charset unless the
     *       software that encloses it tells it explicitly with this setting.
     *       Some templates may use FreeMarker features that require this.</code>
     *   <li><code>"url_escaping_charset"</code>: If this setting is set, then it
     *       overrides the value of the <code>"output_encoding"</code> setting when
     *       FreeMarker does URL encoding.
     * </ul>
     * 
     * @param key the name of the setting.
     * @param value the string that describes the new value of the setting.
     * 
     * @throws UnknownSettingException if the key is wrong.
     * @throws TemplateException if the new value of the setting can't be set
     *     for any other reasons.
     */
    public void setSetting(String key, String value) throws TemplateException {
        try {
            if (LOCALE_KEY.equals(key)) {
                setLocale(StringUtil.deduceLocale(value));
            } else if (NUMBER_FORMAT_KEY.equals(key)) {
                setNumberFormat(value);

⌨️ 快捷键说明

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