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

📄 tabcontent.java

📁 EOS的一个很好的例子.包括页面构件、展现构件
💻 JAVA
字号:
/** EOS Tag Java File **/
package com.primeton.eos.fbframe.tag;

import java.net.URLEncoder;
import java.util.StringTokenizer;
import org.w3c.dom.*;

import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.JspException;

import com.primeton.tp.common.xml.XmlUtil;
import com.primeton.tp.core.prservice.context.RequestContext;
import com.primeton.tp.web.driver.webdriver.WebDriver;

public class TabContent extends BodyTagSupport {
	private String id;
	private String title;
	private String titleProperty;
	private String tabType;
	private String url;
	private String urlProperty;
	private String param;
	private String selected;
	private String titleStyle;
	private String frameBorder;
	private String frameStyle;
	private String scrolling;

	private String tabId;
	private String tabno;
	private boolean urlQuest;
	
	private Tab parentTab;
	String savebody;
	
	public TabContent() {
		id = WebDriver.REQUEST_REQUEST_CONTEXT;
		title = null;
		tabType = "div";
		url = null;
		urlProperty = null;
		param = null;
		selected = "false";
		titleStyle = null;
		savebody = null;
		frameBorder = null;
		frameStyle = "width:100%;height:100%";
		scrolling = null;
		
		urlQuest = false;
		tabId = null;
		tabno = "0";
		
		parentTab = null;
	}
	
	public int doStartTag() throws JspException {
		//TODO Add your code here. 
		Object tab = getParent();
		while (tab != null && !(tab instanceof com.primeton.eos.fbframe.tag.Tab)) {
			tab = ((javax.servlet.jsp.tagext.TagSupport)tab).getParent();
		}
		if (tab == null || !(tab instanceof com.primeton.eos.fbframe.tag.Tab)) {
			throw new JspException("the tabcontent not include in tab!");
		}
		parentTab = (Tab)tab;
		try
		{
			RequestContext requestcontext = (RequestContext)pageContext.getAttribute(id);
			if (requestcontext == null)
				requestcontext = (RequestContext)pageContext.getRequest().getAttribute(id);
			if (requestcontext == null)
				requestcontext = (RequestContext)pageContext.getSession().getAttribute(id);
			if (requestcontext == null)
				throw new JspException("can not find dom");
			if (titleProperty != null)
				title = requestcontext.getProperty(titleProperty);
		}
		catch (Exception exception)
		{
			throw new JspException("get property fail!");
		}
		if (title == null)
			throw new JspException("tab content need title");
		if (tabType.equalsIgnoreCase("frame")) {
			try {
				getFrameUrl();
			} catch (Exception e) {
				// TODO 自动生成 catch 块
				e.printStackTrace();
				throw new JspException(e.toString());
			}
		}

		StringBuffer buff = new StringBuffer("");
		Tab parentTab = (Tab)tab;
		tabId = String.valueOf(parentTab.getId());
		tabno = String.valueOf(parentTab.getTotal());
		buff.append("  <td><table cellPadding=\"0\" cellSpacing=\"0\" onclick=\"gmobj('");
		buff.append(tabId);
		buff.append("').select_tab(");
		buff.append(tabno);
		buff.append(");\"");
		if (tabType.equalsIgnoreCase("frame")) {
			buff.append(" onmouseover=\"gmobj('");
			buff.append(tabId);
			buff.append("').mouseovertab(");
			buff.append(tabno);
			buff.append(");\" onmouseout=\"gmobj('");
			buff.append(tabId);
			buff.append("').mouseouttab(");
			buff.append(tabno);
			buff.append(");\"");
		}
		buff.append(">\n   <tr>\n");
		if (parentTab.getTotal() == 0) {
			buff.append("    <td><img id=\"");
			buff.append(tabId);
			buff.append("_tab_image_first\" src=\"/fbrole/image/tab/first_select.gif\" border=\"0\"></td>\n");
		}
		buff.append("    <td nowrap id=\"");
		buff.append(tabId);
		buff.append("_tab_text");
		buff.append(tabno);
		buff.append("\"");
		if (titleStyle != null) {
			buff.append(" style=\"");
			buff.append(titleStyle);
			buff.append("\"");
		}
		buff.append(" class=\"tabSelectUp\">");
		buff.append(title);
		buff.append("</td>\n");

		buff.append("    <td><img id=\"");
		buff.append(tabId);
		buff.append("_tab_image_divide");
		buff.append(tabno);
		buff.append("\" src=\"/fbrole/image/tab/select_right.gif\" border=\"0\"></td>\n");
		buff.append("<script>\n");
		if (parentTab.getTotal() == 0) {
			buff.append("createTabTable(gmobj(\"");
			buff.append(tabId);
			buff.append("\"));\n");
		}
		buff.append("gmobj(\"");
		buff.append(tabId);
		buff.append("\").createTabContent(\"");
		if (tabType.equalsIgnoreCase("frame")) {
			buff.append("frame\", \"");
			buff.append(url);
			buff.append("\"");
		}else
			buff.append("div\", null");
		if (selected != null && selected.equalsIgnoreCase("true")) {
			buff.append(", true");
		}
		buff.append(");\n</script>\n   </tr>\n  </table>\n  </td>\n");
		parentTab.appendTitle(buff.toString());
		
		parentTab.append("<div id=\"");
		parentTab.append(tabId);
		parentTab.append("_tab_content_div");
		parentTab.append(tabno);
		parentTab.append("\" style=\"overflow:auto;display:none\">\n");

		return super.doStartTag();
	}

	private void getFrameUrl() throws Exception {
		if (param == null) return;
		RequestContext reqContext = null;
		try
		{
			reqContext = (RequestContext)pageContext.getAttribute(id);
			if (reqContext == null)
				reqContext = (RequestContext)pageContext.getRequest().getAttribute(id);
			if (reqContext == null)
				reqContext = (RequestContext)pageContext.getSession().getAttribute(id);
			if (reqContext == null)
				throw new JspException("can not find dom");
			if (urlProperty != null)
				url = reqContext.getProperty(urlProperty);
		}
		catch (Exception exception)
		{
			throw new JspException("get property fail!");
		}
		if (url == null || url.equals("")) return;
		StringBuffer urlBuff = new StringBuffer(url);
		if (url.indexOf('?') != -1) {
			if (url.endsWith("?")) {
				urlQuest = false;
				urlBuff = new StringBuffer(url.substring(0, url.length()-1));
			} else
				urlQuest = true;
		} else {
			urlQuest = false;
		}
		StringTokenizer st = new StringTokenizer(param, ";");
		while (st.hasMoreTokens()) {
			String xpath = st.nextToken();
			if (xpath == null) continue;
			xpath = xpath.trim();
			if (!"".equals(xpath)) {
				Node n = reqContext.getNode(xpath);
				if (n == null) {
					if (urlQuest)
						urlBuff.append("&");
					else {
						urlBuff.append("?");
						urlQuest = true;
					}
					urlBuff.append(URLEncoder.encode(xpath, "GBK"));
					urlBuff.append("=");
				}
				if (n.getNodeType() == Node.ATTRIBUTE_NODE) {
					if (urlQuest)
						urlBuff.append("&");
					else {
						urlBuff.append("?");
						urlQuest = true;
					}
					urlBuff.append(URLEncoder.encode(xpath, "GBK"));
					urlBuff.append("=");
					urlBuff.append(URLEncoder.encode(checkString(XmlUtil.getNodeValue(n)), "GBK"));
				}
				if (n.getNodeType() == Node.ELEMENT_NODE)
					parseElement(urlBuff, (Element)n, xpath, false);
			}
		}
		url = urlBuff.toString();
	}

	private void parseElement(StringBuffer stringbuffer, Element element, String s, boolean addAttr)
	throws Exception
	{
		StringBuffer stringbuffer1 = new StringBuffer(s);
		if (addAttr) {
			stringbuffer1.append("/");
			stringbuffer1.append(element.getNodeName());
			NamedNodeMap namednodemap = element.getAttributes();
			for (int i = 0; i < namednodemap.getLength(); i++)
			{
				Node node = namednodemap.item(i);
				String s1 = node.getNodeValue();
				if (s1 != null && !s1.equals(""))
				{
					stringbuffer1.append("[@");
					stringbuffer1.append(node.getNodeName());
					stringbuffer1.append("=\"");
					stringbuffer1.append(node.getNodeValue());
					stringbuffer1.append("\"]");
				}
			}
		}
		NodeList nodelist = element.getChildNodes();
		if (nodelist.getLength() == 0)
		{
			if (urlQuest)
				stringbuffer.append("&");
			else {
				stringbuffer.append("?");
				urlQuest = true;
			}
			stringbuffer.append(URLEncoder.encode(stringbuffer1.toString(), "GBK"));
			stringbuffer.append("=");
		}
		for (int j = 0; j < nodelist.getLength(); j++)
		{
			Node node1 = nodelist.item(j);
			if (node1.getNodeType() == 3)
			{
				String s2 = node1.getNodeValue();
				if (s2 == null)
					s2 = "";
				if (urlQuest)
					stringbuffer.append("&");
				else {
					stringbuffer.append("?");
					urlQuest = true;
				}
				stringbuffer.append(URLEncoder.encode(stringbuffer1.toString(), "GBK"));
				stringbuffer.append("=");
				stringbuffer.append(URLEncoder.encode(s2, "GBK"));
			}
			if (node1.getNodeType() == 1)
				parseElement(stringbuffer, (Element)node1, stringbuffer1.toString(), true);
		}

	}

	private String checkString(String s){
		if (s == null) return "";
		return s;
	}

	public int doAfterBody() throws JspException
	{
		if (bodyContent != null)
		{
			String s = bodyContent.getString();
			if (s == null)
				s = "";
			savebody = s.trim();
		}
		return 0;
	}

	/* (非 Javadoc)
	 * @see javax.servlet.jsp.tagext.Tag#release()
	 */
	public void release() {
		// TODO 自动生成方法存根
		id = WebDriver.REQUEST_REQUEST_CONTEXT;
		title = null;
		tabType = "div";
		url = null;
		urlProperty = null;
		param = null;
		selected = "false";
		titleStyle = null;
		savebody = null;
		frameBorder = null;
		frameStyle = "width:100%;height:100%";
		scrolling = null;

		tabId = null;
		tabno = "0";
		
		parentTab = null;
		super.release();
	}

	public int doEndTag() throws JspException {
		//TODO Add your code here. 
		if (tabType.equalsIgnoreCase("frame")) {
			parentTab.append(" <IFRAME  name=\"");
			parentTab.append(tabId);
			parentTab.append("_tab_content_frame");
			parentTab.append(tabno);
			parentTab.append("\"");
			if (frameStyle != null) {
				parentTab.append(" style=\"");
				parentTab.append(frameStyle);
				parentTab.append("\"");
			}
			if (frameBorder != null) {
				parentTab.append(" frameBorder=\"");
				parentTab.append(frameBorder);
				parentTab.append("\"");
			}
			if (scrolling != null) {
				parentTab.append(" scrolling=\"");
				parentTab.append(scrolling);
				parentTab.append("\"");
			} else 
				parentTab.append(" scrolling=\"auto\"");
			parentTab.append(" src=\"\"></IFRAME>");
		} else
			parentTab.append(savebody);
		parentTab.append("\n</div>\n");
		parentTab.addTab();
		release();
		return super.doEndTag();
	}

	public String getTabType() {
		return tabType;
	}
	public void setTabType(String value) {
		this.tabType = value;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String value) {
		this.url = value;
	}
	public String getUrlProperty() {
		return urlProperty;
	}
	public void setUrlProperty(String value) {
		this.urlProperty = value;
	}
	public String getParam() {
		return param;
	}
	public void setParam(String value) {
		this.param = value;
	}
	public String getSelected() {
		return selected;
	}
	public void setSelected(String value) {
		this.selected = value;
	}
	public String getTitleStyle() {
		return titleStyle;
	}
	public void setTitleStyle(String value) {
		this.titleStyle = value;
	}
	/**
	 * @return 返回 frameBorder。
	 */
	public String getFrameBorder() {
		return frameBorder;
	}
	/**
	 * @param frameBorder 要设置的 frameBorder。
	 */
	public void setFrameBorder(String frameBorder) {
		this.frameBorder = frameBorder;
	}
	/**
	 * @return 返回 frameStyle。
	 */
	public String getFrameStyle() {
		return frameStyle;
	}
	/**
	 * @param frameStyle 要设置的 frameStyle。
	 */
	public void setFrameStyle(String frameStyle) {
		this.frameStyle = frameStyle;
	}
	/**
	 * @return 返回 id。
	 */
	public String getId() {
		return id;
	}
	/**
	 * @param id 要设置的 id。
	 */
	public void setId(String id) {
		this.id = id;
	}
	/**
	 * @return 返回 scrolling。
	 */
	public String getScrolling() {
		return scrolling;
	}
	/**
	 * @param scrolling 要设置的 scrolling。
	 */
	public void setScrolling(String scrolling) {
		this.scrolling = scrolling;
	}
	/**
	 * @return 返回 title。
	 */
	public String getTitle() {
		return title;
	}
	/**
	 * @param title 要设置的 title。
	 */
	public void setTitle(String title) {
		this.title = title;
	}
	/**
	 * @return 返回 titleProperty。
	 */
	public String getTitleProperty() {
		return titleProperty;
	}
	/**
	 * @param titleProperty 要设置的 titleProperty。
	 */
	public void setTitleProperty(String titleProperty) {
		this.titleProperty = titleProperty;
	}
}

⌨️ 快捷键说明

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