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

📄 basetag.java

📁 本代码是一个权限管理系统源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.seavision.PermissionManage.common;

/**
 * 
 * @author  xutao.huang 
 * 
 * @version  1.0
 */





import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringWriter;
import java.net.URL;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;







public class BaseTag extends TagSupport {
	public static int encodingFlag = 2; //编码控制值

	private ParamChecking pc = new ParamChecking(); //参数校验对象

	public StringBuffer stringBuffer;

	private ServletRequest request;

	private HttpSession session;

	private boolean printFlag = true; //显示控制,true为打印

	private JspWriter writer;

	public static final String NUMBER = "-.0123456789";

	private static final int EVAL_BODY_INCLUDE = TagSupport.EVAL_BODY_INCLUDE;

	protected static final int EVAL_PAGE = TagSupport.EVAL_PAGE;

	private static final String INDENTSIZE = "    ";

	public static final String SHOWXML = "showxml"; //显示XML标签判断参数名

	private String xslUri;

	private boolean xslCache;

	private static final Log log = LogFactory.getLog(BaseTag.class);

	public BaseTag() {

	}

	/**
	 * 初始化 Tag,设置编码集
	 * @param className 类名称
	 */
	public void initializeTag(String className) {
		try {
			this.request = this.pageContext.getRequest();
			this.session = this.pageContext.getSession();
			this.writer = this.pageContext.getOut();
			this.stringBuffer = new StringBuffer();
			this.session.setMaxInactiveInterval(-1);

			if (encodingFlag == 1) {
				request.setCharacterEncoding("UTF-8");
			} else if (encodingFlag == 2) {
				request.setCharacterEncoding("GB2312");
			}

			this.print("进入 [" + className + "] Tag.");
		} catch (Exception e) {
			e.printStackTrace();
			this.print("设置编码异常! ");
		}

		this.print(this.xslUri);

	}

	/*
	 * 
	 *  这个方法是action判断用户是否登录. 调用该方法.如果返回true说明用户已经登录
	 * 如果返回的是false 说明用户没登录或者长时间没进行操作..
	 * 
	 * */

	private boolean checkUserIsLogin() {

		boolean result = true;

		if (this.check(session.getAttribute("loginUserBean"))) {
			//如果调用方法返回的是true说明这个对象在session中不存在

			result = false;

		}

		return result;

	}

	/**
	 * 初始化 Tag,根据编码标志判断是否设置编码集
	 * @param changeEncoding 转码标志
	 * @param className 类名称
	 */
	public void initializeTag(boolean changeEncoding, String className) {
		try {
			this.request = this.pageContext.getRequest();
			this.session = this.pageContext.getSession();
			this.writer = this.pageContext.getOut();
			this.stringBuffer = new StringBuffer();

			if (changeEncoding) {
				if (encodingFlag == 1) {
					request.setCharacterEncoding("UTF-8");
				} else if (encodingFlag == 2) {
					request.setCharacterEncoding("GB2312");
				}
			}

			this.print("进入 [" + className + "] Tag.");
		} catch (Exception e) {
			e.printStackTrace();
			this.print("设置编码异常! ");
		}

	}
	public void setAttribute2(String paramName, Object paramValue) {
		this.request.setAttribute(paramName, paramValue);

		log.debug("mmmmmmmmmmmmmmm" + this.request.getAttribute("message"));

	}

	public void finalizeTag(String className) {
		this.request = null;
		this.session = null;
		this.pc = null;
		this.stringBuffer = null;
		this.writer = null;
		this.xslUri = "";
		this.xslCache = false;

		this.print("结束 [" + className + "] : Tag.");
	}

	public boolean check(String param) {
		if (param == null || param.trim().length() == 0) {
			return true;
		} else {
			return false;
		}
	}

	public boolean check(String[] param) {
		if (param == null || param.length == 0) {
			return true;
		} else {
			return false;
		}
	}

	public boolean check(Object obj) {
		if (obj == null)
			return true;
		else
			return false;
	}

	public String[] trim(String[] param) {
		for (int i = 0; i < param.length; i++) {
			param[i] = param[i].trim();
		}

		return param;
	}

	/**
	 * 打印字符串
	 * @param str 字符串
	 */
	public void print(String str) {
		if (printFlag)
			System.out.println(str);
	}

	public void print(int i) {
		if (printFlag)
			System.out.println(i);
	}

	public void print(Float f) {
		if (printFlag)
			System.out.println(f);
	}

	public void print(boolean b) {
		if (printFlag)
			System.out.println(b);
	}

	public void print(String s[]) {
		for (int i = 0; i < s.length; i++) {
			if (printFlag)
				System.out.print(s[i] + "  ");
		}

		if (printFlag)
			System.out.println();
	}

	public void print(String arrayName, String s[]) {
		for (int i = 0; i < s.length; i++) {
			if (printFlag)
				System.out.println(arrayName + "[" + i + "] : " + s[i]);
		}
	}

	/**
	 * 获取参数
	 * @param paramName 参数名
	 * @return 该参数名对应值
	 */
	public String getParameter(String paramName) {
		String paramValue = request.getParameter(paramName);

		paramValue = this.exchangeStrParam(paramValue);

		this.print("从 request 接受参数 - " + paramName + " 为 : " + paramValue);

		return paramValue;
	}

	/**
	 * 获取参数数组
	 * @param paramName 参数名
	 * @return 该参数名对应数组
	 */
	public String[] getParameterValues(String paramName) {
		String[] paramValue = request.getParameterValues(paramName);

		paramValue = this.exchangeStrParam(paramValue);

		if (paramValue != null) {
			for (int i = 0; i < paramValue.length; i++)
				this.print("从 request 接受数组参数 - " + paramName + "[" + i + "] 为 : " + paramValue[i]);
		} else
			paramValue = new String[0];

		return paramValue;
	}

	public Object getAttribute(String paramName) {

		Object obj = this.session.getAttribute(paramName);

		if (obj instanceof String) {
			String paramValue = (String)obj;

			paramValue = this.exchangeStrParam(paramValue);

			this.print("从 session 接受参数 - " + paramName + " 为 : " + paramValue);

			return paramValue;
		} else if (obj instanceof String[]) {
			String[] paramValue = (String[])obj;

			paramValue = this.exchangeStrParam(paramValue);

			if (paramValue != null) {
				for (int i = 0; i < paramValue.length; i++)
					this.print("从 session 接受数组参数 - " + paramName + "[" + i + "] 为 : " + paramValue[i]);
			}

			return paramValue;
		} else {
			return obj;
		}
	}

	public Object requestGetAttribute(String paramName) {

		Object obj = this.request.getAttribute(paramName);

		if (obj instanceof String) {
			String paramValue = (String)obj;

			paramValue = this.exchangeStrParam(paramValue);

			this.print("从 session 接受参数 - " + paramName + " 为 : " + paramValue);

			return paramValue;
		} else if (obj instanceof String[]) {
			String[] paramValue = (String[])obj;

			paramValue = this.exchangeStrParam(paramValue);

			if (paramValue != null) {
				for (int i = 0; i < paramValue.length; i++)
					this.print("从 session 接受数组参数 - " + paramName + "[" + i + "] 为 : " + paramValue[i]);
			}

			return paramValue;
		} else {
			return obj;
		}
	}

	public void setAttribute(String paramName, Object paramValue) {
		this.session.setAttribute(paramName, paramValue);
	}

	public void removeAttribute(String paramName) {
		this.session.removeAttribute(paramName);
	}

	public void appendMessage(String s) {
		this.stringBuffer.append(s + "\r\n");
	}

	public void appendMessage(StringBuffer sb) {
		this.stringBuffer.append(sb.toString() + "\r\n");
	}

	public void appendMessage(String s, int indent) {

⌨️ 快捷键说明

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