From: <cm...@us...> - 2006-12-21 00:27:30
|
Revision: 264 http://svn.sourceforge.net/obo/?rev=264&view=rev Author: cmpich Date: 2006-12-20 16:27:27 -0800 (Wed, 20 Dec 2006) Log Message: ----------- Added a new jsp tag to suppress the directory path of the obo files when displayed on the admin page (for security reasons) Modified Paths: -------------- phenote/trunk/src/java/phenote/util/FileUtil.java phenote/trunk/src/java/test/phenote/util/FileUtilTest.java phenote/trunk/src/web/WEB-INF/jsp/admin.jsp phenote/trunk/src/web/WEB-INF/tld/phenote-tags.tld Added Paths: ----------- phenote/trunk/src/java/phenote/presentation/tags/FileUtilTag.java Added: phenote/trunk/src/java/phenote/presentation/tags/FileUtilTag.java =================================================================== --- phenote/trunk/src/java/phenote/presentation/tags/FileUtilTag.java (rev 0) +++ phenote/trunk/src/java/phenote/presentation/tags/FileUtilTag.java 2006-12-21 00:27:27 UTC (rev 264) @@ -0,0 +1,86 @@ +package phenote.presentation.tags; + +import org.apache.commons.lang.StringUtils; +import org.apache.struts.taglib.TagUtils; +import phenote.util.FileUtil; + +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.tagext.Tag; +import javax.servlet.jsp.tagext.TagSupport; +import java.io.IOException; + +/** + * Tag that creates the display name for a relationship of a term to a child or a parent. + */ +public class FileUtilTag extends TagSupport { + + private String type; + private String beanName; + private String property; + private String scope; + + + public int doStartTag() throws JspException { + + // Default scope is 'Page' scope + if (StringUtils.isEmpty(scope)) + scope = "Page"; + String fileName = (String) TagUtils.getInstance().lookup(pageContext, beanName, property, scope); + String pureFileName = FileUtil.getPureFileName(fileName); + + try { + pageContext.getOut().print(pureFileName); + } catch (IOException ioe) { + throw new JspException("Error: IOException while writing to client" + ioe.getMessage()); + } + release(); + return Tag.SKIP_BODY; + } + + /** + * Release all allocated resources. + */ + public void release() { + super.release(); + + type = null; + property = null; + beanName = null; + id = null; + scope = null; + + } + + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getBeanName() { + return beanName; + } + + public void setBeanName(String beanName) { + this.beanName = beanName; + } + + public String getScope() { + return scope; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public String getProperty() { + return property; + } + + public void setProperty(String property) { + this.property = property; + } +} Modified: phenote/trunk/src/java/phenote/util/FileUtil.java =================================================================== --- phenote/trunk/src/java/phenote/util/FileUtil.java 2006-12-20 17:31:17 UTC (rev 263) +++ phenote/trunk/src/java/phenote/util/FileUtil.java 2006-12-21 00:27:27 UTC (rev 264) @@ -1,6 +1,7 @@ package phenote.util; import org.apache.log4j.Logger; +import org.apache.commons.lang.StringUtils; import java.io.*; import java.net.MalformedURLException; @@ -188,4 +189,16 @@ } } + /** + * Strip off all the path information from a file name. + * @param filename + */ + public static String getPureFileName(String filename){ + if(StringUtils.isEmpty(filename) ) + return filename; + + File file = new File(filename); + return file.getName(); + } + } Modified: phenote/trunk/src/java/test/phenote/util/FileUtilTest.java =================================================================== --- phenote/trunk/src/java/test/phenote/util/FileUtilTest.java 2006-12-20 17:31:17 UTC (rev 263) +++ phenote/trunk/src/java/test/phenote/util/FileUtilTest.java 2006-12-21 00:27:27 UTC (rev 264) @@ -83,6 +83,18 @@ } + public void testPureFilename(){ + String fileNameOnly = "filenameAlpha.txt"; + String filename = FileUtil.FILE_SEPARATOR + "dire" + FileUtil.FILE_SEPARATOR + fileNameOnly; + String pureFilename = FileUtil.getPureFileName(filename); + assertEquals("Pure File Name", fileNameOnly, pureFilename); + + fileNameOnly = ""; + pureFilename = FileUtil.getPureFileName(fileNameOnly); + assertEquals("Pure File Name", fileNameOnly, pureFilename); + } + + /** * Create the test directories before the tests are run. */ Modified: phenote/trunk/src/web/WEB-INF/jsp/admin.jsp =================================================================== --- phenote/trunk/src/web/WEB-INF/jsp/admin.jsp 2006-12-20 17:31:17 UTC (rev 263) +++ phenote/trunk/src/web/WEB-INF/jsp/admin.jsp 2006-12-21 00:27:27 UTC (rev 264) @@ -1,5 +1,6 @@ <%@ page import="phenote.main.PhenoteVersion"%> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> +<%@ taglib prefix="phenote" uri="/WEB-INF/tld/phenote-tags.tld" %> <html> <head> @@ -42,9 +43,10 @@ <c:out value='${item.name}'/> </td> <td class="listContent"> + <c:out value='${item.version}'/> </td> <td class="listContent"> - <c:out value='${item.source}'/> + <phenote:pureFileName beanName="item" property="source" /> </td> <td class="listContent"> </td> Modified: phenote/trunk/src/web/WEB-INF/tld/phenote-tags.tld =================================================================== --- phenote/trunk/src/web/WEB-INF/tld/phenote-tags.tld 2006-12-20 17:31:17 UTC (rev 263) +++ phenote/trunk/src/web/WEB-INF/tld/phenote-tags.tld 2006-12-21 00:27:27 UTC (rev 264) @@ -38,4 +38,20 @@ </attribute> </tag> + <tag> + <name>pureFileName</name> + <tagclass>phenote.presentation.tags.FileUtilTag</tagclass> + <info>Remove any directory info on a file name </info> + <attribute> + <name>beanName</name> + <required>true</required> + <rtexprvalue>false</rtexprvalue> + </attribute> + <attribute> + <name>property</name> + <required>true</required> + <rtexprvalue>false</rtexprvalue> + </attribute> + </tag> + </taglib> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |