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

📄 writetag.java

📁 一个实用工具类
💻 JAVA
字号:
/* * Copyright (C) butor.com. All rights reserved. * * This software is published under the terms of the GNU Library General * Public License (GNU LGPL), a copy of which has been included with this * distribution in the LICENSE.txt file.  */package org.butor.web.taglib.bean;import java.text.ParseException;import java.util.Date;import javax.servlet.jsp.JspException;import org.apache.struts.util.RequestUtils;import org.apache.struts.util.ResponseUtils;import org.butor.helper.DateManip;import org.butor.web.taglib.html.TagLibHelper;/**  * @author nacroaz * * To change this generated comment edit the template variable "typecomment": * Window>Preferences>Java>Templates. */public class WriteTag extends org.apache.struts.taglib.bean.WriteTag {	protected static final String POSTAL_CODE_FORMAT = "postal";	protected static final String PHONE_NUMBER_FORMAT = "phone";		protected String keep_format = null;	public String getKeep_format() {		return keep_format;	}		public void setKeep_format(String c) {		keep_format = c;		}		protected Object convertValue(Object value) {		Object convertedValue = null;		if (value instanceof String) {			try {				// Try double conversion				Double doubleValue = Double.valueOf((String) value);				convertedValue = doubleValue;			} catch (NumberFormatException e) {				convertedValue = null;			}			if (convertedValue == null) {				// Try date conversion				try {					Date dateValue = DateManip.parseDate((String) value);					convertedValue = dateValue;				} catch (ParseException e) {					convertedValue = null;					}			}								}				// Keep original value if conversion failed		if (convertedValue == null) {			convertedValue = value;		}				return convertedValue;		}    /**     * Process the start tag.     *     * @exception JspException if a JSP exception has occurred     */    public int doStartTag() throws JspException {        // Look up the requested bean (if necessary)        //Object bean = null;        if (ignore) {            if (RequestUtils.lookup(pageContext, name, scope) == null) {                return (SKIP_BODY);  // Nothing to output            }        }        // Look up the requested property value        Object value =            RequestUtils.lookup(pageContext, name, property, scope);        if (value == null) {            return (SKIP_BODY);  // Nothing to output        }            		// Try to retrieve format string from resources by the key from formatKey. To convertValue to a double or date only		// if their is a format, do we want to format ==> must be a number or a date.        if( ( getFormat() != null ) || ( getFormatKey()!=null ) ) {        	if (POSTAL_CODE_FORMAT.equals(getFormat())) {        		value = TagLibHelper.formatPostalCode(value.toString());        	} else if (PHONE_NUMBER_FORMAT.equals(getFormat())) {        		value = TagLibHelper.formatPhoneNumber(value.toString());        	} else {				value = convertValue(value);        	}        }        // Convert value to the String with some formatting        String output = formatValue( value );                boolean mustFormat = (keep_format == null) ? true :  keep_format.equals("1");        // Print this property value to our output writer, suitably filtered        if (filter) {            //ResponseUtils.write(pageContext, ResponseUtils.filter(output));            output = ResponseUtils.filter(output);    	}        //else            //ResponseUtils.write(pageContext, output);		TagLibHelper.renderText(pageContext, output, false, mustFormat);		        // Continue processing this page        return (SKIP_BODY);    }}

⌨️ 快捷键说明

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