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

📄 tabpage.java

📁 一个用css+javascript+html写的一个标签切换的东东.拿出来与大家分享.
💻 JAVA
字号:
/**
 * @(#) TabPage.java 2006-8-18
 *
 * @author Roger Wang / Forever
 *
 * Copyright @ 2006 by primeton.com
 * All rights reserved.
 */
package com.digitalchina.power.taglib;

import java.io.IOException;
import java.net.URLEncoder;
import java.util.StringTokenizer;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;

import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

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 TabPage extends TagSupport
{
	private String tabPageId;
	private String title;
	private String width;
	private String href;
	private String param;
	private String onclick;
	private String targetFrame;
	private String cache;
	
	private String target;
	private String tabPaneId;
	private boolean urlQuest;
	
	public TabPage()
	{
		tabPageId = null;
		title = null;
		width = "100";
		href = null;
		param = null;
		onclick = null;
	}
	
	public int doStartTag() throws JspException
	{
		try
		{
			getFrameHref();
			getTabPaneInfo();
		}
		catch( Exception e )
		{
			e.printStackTrace();
			throw new JspException( e.toString() );
		}
		
		StringBuffer buf = new StringBuffer();
		buf.append( "<td " );
		buf.append( "width=\"" );
		buf.append( width );
		buf.append( "\" " );
		buf.append( "align=\"center\" valign=\"bottom\" class=\"nav_md\" id=\"_tabpane_nav_"+ tabPaneId +"\" tabPageId=\""+ tabPaneId +"_" );
		buf.append( tabPageId );
		buf.append( "\" target=\"" );
		buf.append( target );
		buf.append( "\" cache=\"" );
		buf.append( checkString( cache ) );
		buf.append( "\" href=\"" );
		buf.append( checkString( href ) );
		buf.append( "\" style=\"cursor:hand\" " );

		buf.append( "onclick=\"" );
		boolean b = onclick !=null && onclick.trim().length() > 0;
		if( b )
		{
			String m = onclick;
			if( m.endsWith( ";" ) )
			{
				m = m.substring( 0, m.length() - 1 );
			}
			buf.append( "if( " ).append( m ).append( " == true ){" );
		}
		buf.append( tabPaneId +".selectTabPageById('" );
		buf.append( tabPageId );
		buf.append( "');" );
		if( b )
		{
			buf.append( "}" );
		}
		buf.append( "\" " );
		
		String refImgId = "ref_" + tabPaneId + "_" + tabPageId;
		if( "true".equals( cache ) )
		{
			buf.append( " refImageId=\"" );
			buf.append( refImgId );
			buf.append( "\" " );
		}
		buf.append( "" );
		buf.append( "nowrap>" );
		buf.append( title );
		if( "true".equals( cache ) )
		{
			buf.append( "&nbsp" );
			buf.append( "<img src=\"/internet/htc/tabpane/tab_refresh.gif\" " );
			buf.append( "id=\"" );
			buf.append( refImgId );
			buf.append( "\" border=\"0\" onclick=\"" );
			buf.append( tabPaneId );
			buf.append( ".refreshContent('" );
			buf.append( tabPageId );
			buf.append( "');\" style=\"display:none;cursor:hand;\" valign=\"middle\" width=\"16\" height=\"16\" title=\"刷新\">" );
		}
		buf.append( "</td>\n" );
		buf.append( "<td width=\"6\" align=\"center\" valign=\"bottom\" class=\"nav_ldrd\" id=\"_tabpane_bou_"+ tabPaneId +"\"></td>\n" );
		try
		{
			JspWriter jspwriter = pageContext.getOut();
			jspwriter.print( buf.toString() );
		}
		catch( IOException e )
		{
			e.printStackTrace();
			throw new JspException( e.toString() );
		}
		return super.doStartTag();
	}
	
	public void release()
	{
		tabPageId = null;
		title = null;
		width = "100";
		href = null;
		param = null;
		onclick = null;
		
		super.release();
	}
	
	private void getTabPaneInfo()
	{
		target = targetFrame;
		Tag tag = getParent();
		while( tag != null && !(tag instanceof TabPane) )
		{
			tag = tag.getParent();
		}
		if(tag instanceof TabPane)
		{
			TabPane p = (TabPane)tag;
			if( TabPane.isBlankOrNull( targetFrame ) )
			{
				if( TabPane.notBlankOrNull( p.getFrameNames() ) )
				{
					String[] frms = p.getFrameNames().split( ";" );
					target = frms[0];
				}
			}
			tabPaneId = p.getTabPaneId();
		}
		else
		{
			throw new IllegalStateException( "TabPage必须位于TagPane标签内部!" );
		}
		
		if( target == null )
		{
			target = "";
		}
	}
	
	private void getFrameHref() throws Exception
	{
		if( param == null )
			return;
		if( href == null || href.equals( "" ) )
			return;
		RequestContext reqContext = null;
		try
		{
			reqContext = (RequestContext)pageContext.getAttribute( WebDriver.REQUEST_REQUEST_CONTEXT );
			if( reqContext == null )
				reqContext = (RequestContext)pageContext.getRequest().getAttribute( WebDriver.REQUEST_REQUEST_CONTEXT );
			if( reqContext == null )
				reqContext = (RequestContext)pageContext.getSession().getAttribute( WebDriver.REQUEST_REQUEST_CONTEXT );
			if( reqContext == null )
				throw new JspException( "can not find dom" );
		}
		catch( Exception exception )
		{
			throw new JspException( "get property fail!" );
		}

		StringBuffer urlBuff = new StringBuffer( href );
		if( href.indexOf( '?' ) != -1 )
		{
			if( href.endsWith( "?" ) )
			{
				urlQuest = false;
				urlBuff = new StringBuffer( href.substring( 0, href.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( "=" );
				}
				else 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" ) );
				}
				else if( n.getNodeType() == Node.ELEMENT_NODE )
				{
					parseElement( urlBuff, (Element)n, xpath, false );
				}
			}
		}
		href = 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;
	}
	
	
	/**
	 * @return 返回 href。
	 */
	public String getHref()
	{
		return href;
	}
	/**
	 * @param href 要设置的 href。
	 */
	public void setHref( String href )
	{
		this.href = href;
	}
	/**
	 * @return 返回 param。
	 */
	public String getParam()
	{
		return param;
	}
	/**
	 * @param param 要设置的 param。
	 */
	public void setParam( String param )
	{
		this.param = param;
	}
	/**
	 * @return 返回 tabPageId。
	 */
	public String getTabPageId()
	{
		return tabPageId;
	}
	/**
	 * @param tabPageId 要设置的 tabPageId。
	 */
	public void setTabPageId( String tabPageId )
	{
		this.tabPageId = tabPageId;
	}
	/**
	 * @return 返回 title。
	 */
	public String getTitle()
	{
		return title;
	}
	/**
	 * @param title 要设置的 title。
	 */
	public void setTitle( String title )
	{
		this.title = title;
	}
	/**
	 * @return 返回 width。
	 */
	public String getWidth()
	{
		return width;
	}
	/**
	 * @param width 要设置的 width。
	 */
	public void setWidth( String width )
	{
		this.width = width;
	}
	
	
	/**
	 * @return 返回 onclick。
	 */
	public String getOnclick()
	{
		return onclick;
	}
	/**
	 * @param onclick 要设置的 onclick。
	 */
	public void setOnclick( String onclick )
	{
		this.onclick = onclick;
	}
	
	
	/**
	 * @return 返回 cache。
	 */
	public String getCache()
	{
		return cache;
	}
	/**
	 * @param cache 要设置的 cache。
	 */
	public void setCache( String cache )
	{
		this.cache = cache;
	}
	/**
	 * @return 返回 targetFrame。
	 */
	public String getTargetFrame()
	{
		return targetFrame;
	}
	/**
	 * @param targetFrame 要设置的 targetFrame。
	 */
	public void setTargetFrame( String targetFrame )
	{
		this.targetFrame = targetFrame;
	}
}

⌨️ 快捷键说明

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