buildfolderpathlinktag.java

来自「Java的框架」· Java 代码 · 共 115 行

JAVA
115
字号
package mcaps.core.docman.webapp.taglib;

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

import mcaps.core.docman.util.DocManUtil;

import org.springframework.web.util.ExpressionEvaluationUtils;

/**
 * Tag for building the folder path link
 *
 * @author Chan Chin Wei
 * @date May 19, 2006
 * @version 1.0.1.0
 */
public class BuildFolderPathLinkTag extends TagSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6101480289391067419L;
	//private String url;
	private String fullPath;
	
	/*
	public void setUrl(String url) {
		//get url from EL expressions
		try  {
			this.url = (String) ExpressionEvaluationUtils
							.evaluate ("url", url, String.class, pageContext);
		}
		catch (JspException e) {
		}
		
		//if url cant be get from EL expressions
		if (this.url == null || this.url.equals("")) {
			this.url = url;
		}
	}
	*/
	
	public void setFullPath(String fullPath) {
		//get fullPath from EL expressions
		try  {
			this.fullPath = (String) ExpressionEvaluationUtils
							.evaluate ("fullPath", fullPath, String.class, pageContext);
		}
		catch (JspException e) {
		}
		
		//if fullPath cant be get from EL expressions
		if ((this.fullPath == null || this.fullPath.equals("")) && fullPath != null && fullPath.indexOf("${") != 0) {
			this.fullPath = fullPath;
		}
	}
	
	/**
	 * Process the start of this tag.
	 * @return
	 * @exception JspException if a JSP exception has occurred
	 * @see javax.servlet.jsp.tagext.Tag#doStartTag()
	 */
	public int doStartTag () throws JspException {
		JspWriter out = pageContext.getOut ();
		
		if (fullPath != null && !fullPath.equals( (""))) {
			try  {
				out.println(constructPathLink ());
			}
			catch (java.io.IOException e)  {
				throw new JspException ("Unable to output result.");
			}
		}
		return (SKIP_BODY);
	}
	
	private String constructPathLink () {
		String actionPath = "docMan.action?path=";
		String pathLink = null;
		
		int index = fullPath.lastIndexOf("/");
		String rpath = fullPath;
		String folderName;
		String folderPath;
		while (index != -1) {
			folderName = fullPath.substring(index+1);
			int eindex = folderName.indexOf("/");
			if (eindex != -1)
				folderName = folderName.substring(0, eindex);
			folderPath = "<a href='" + actionPath + DocManUtil.urlEncodePath (rpath) +
									"'>" + folderName + "</a>";
			if (pathLink != null)
				pathLink = folderPath + "/" + pathLink;
			else
				pathLink = folderPath;
			
			rpath = rpath.substring(0, index);
			index = rpath.lastIndexOf("/");
		}
		
		folderPath = "<a href='" + actionPath + DocManUtil.urlEncodePath (rpath) +
						"'>" + rpath + "</a>";

		if (pathLink != null)
			pathLink = folderPath + "/" + pathLink;
		else
			pathLink = folderPath;
		
		return pathLink;
	}
	
}

⌨️ 快捷键说明

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