package com.flexoa.upload.handlers;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import com.flexoa.upload.tool.Utils;
public class ResourceType {
/** The name of the resource type */
private String name;
/** The absolute path of the resource type */
private String path;
/** The allowed extensions */
private Set<String> allowedEextensions;
/** The denied extensions */
private Set<String> deniedExtensions;
/** Map holding a String to ResourceType reference */
private static Map<String, ResourceType> types = new HashMap<String, ResourceType>(
4);
/** Resource type <code>File</code> */
public static final ResourceType FILE = new ResourceType("File",
PropertiesLoader.getFileResourceTypePath(), Utils
.getSet(PropertiesLoader
.getFileResourceTypeAllowedExtensions()), Utils
.getSet(PropertiesLoader
.getFileResourceTypeDeniedExtensions()));
/** Resource type <code>Flash</code> */
public static final ResourceType FLASH = new ResourceType("Flash",
PropertiesLoader.getFlashResourceTypePath(), Utils
.getSet(PropertiesLoader
.getFlashResourceTypeAllowedExtensions()), Utils
.getSet(PropertiesLoader
.getFlashResourceTypeDeniedExtensions()));
/** Resource type <code>Image</code> */
public static final ResourceType IMAGE = new ResourceType("Image",
PropertiesLoader.getImageResourceTypePath(), Utils
.getSet(PropertiesLoader
.getImageResourceTypeAllowedExtensions()), Utils
.getSet(PropertiesLoader
.getImageResourceTypeDeniedExtensions()));
/** Resource type <code>Media</code> */
public static final ResourceType MEDIA = new ResourceType("Media",
PropertiesLoader.getMediaResourceTypePath(), Utils
.getSet(PropertiesLoader
.getMediaResourceTypeAllowedExtensions()), Utils
.getSet(PropertiesLoader
.getMediaResourceTypeDeniedExtensions()));
static {
types.put(FILE.getName(), FILE);
types.put(FLASH.getName(), FLASH);
types.put(IMAGE.getName(), IMAGE);
types.put(MEDIA.getName(), MEDIA);
}
/**
* This constructor has been made intentionally made private to provide
* pre-defined types only.
*
* @param name
* the name of the new resource type
* @param path
* the absolute path of the new resource type
* @param allowedEextensions
* the allowed extensions set of the new resource type
* @param deniedExtensions
* the denied extensions set of the new resource type
* @throws IllegalArgumentException
* if both sets are empty
* @throws IllegalArgumentException
* if both sets contain extensions
*/
private ResourceType(final String name, final String path,
final Set<String> allowedEextensions,
final Set<String> deniedExtensions) {
this.name = name;
this.path = path;
if (allowedEextensions.isEmpty() && deniedExtensions.isEmpty())
throw new IllegalArgumentException(
"Both sets are empty, one has always to be filled");
if (!allowedEextensions.isEmpty() && !deniedExtensions.isEmpty())
throw new IllegalArgumentException(
"Both sets contain extensions, only one can be filled at the same time");
this.allowedEextensions = allowedEextensions;
this.deniedExtensions = deniedExtensions;
}
/**
* Returns the name of this resource type.
*
* @return the name of this resource type
*/
public String getName() {
return name;
}
/**
* Returns the absolute path of this resource type. This path is absolute to
* the userfiles path. To set this path, see the <a
* href="http://java.flexoa/properties.html">configuration</a>.
*
* @return the absolute path of this resource type
*/
public String getPath() {
return path;
}
/**
* Returns a read-only reference to the allowed extensions set.
*
* @return the read-only allowed extensions set of this resource type
*/
public Set<String> getAllowedEextensions() {
return Collections.unmodifiableSet(allowedEextensions);
}
/**
* Returns a read-only reference to the denied extensions set.
*
* @return the read-only denied extensions set of this resource type
*/
public Set<String> getDeniedExtensions() {
return Collections.unmodifiableSet(deniedExtensions);
}
/**
* Returns the resource type constant with the specified name.
*
* @param name
* the name of the constant to return
* @return the resource type constant with the specified name
* @throws IllegalArgumentException
* if this class has no constant with the specified name
* @throws NullPointerException
* if <code>name</code> is null or empty
*/
public static ResourceType valueOf(final String name) {
if (Utils.isEmpty(name))
throw new NullPointerException("Name is null or empty");
ResourceType rt = types.get(name);
if (rt == null)
throw new IllegalArgumentException("No resource type const " + name);
return rt;
}
/**
* Returns <code>true</code> if name represents a valid resource type
* constant.
*
* @param name
* the resource type to check
* @return <code>true</code> if name represents a valid resource type, else
* <code>false</code>
*/
public static boolean isValidType(final String name) {
// HashMap permits null keys, so it will return false in that case
return types.containsKey(name);
}
/**
* Returns the resource type constant with the specified name. In contrast
* to {@link #valueOf(String)} it returns a null instead of throwing an
* exception if a resource type constant was not found.
*
* @param name
* the name of the constant to return
* @return the resource type constant with the specified name, else
* <code>null</code>
*/
public static ResourceType getResourceType(final String name) {
try {
return ResourceType.valueOf(name);
} catch (Exception e) {
return null;
}
}
/**
* Returns the resource type constant with the specified name. In contrast
* to {@link #getResourceType(String)} it returns {@link #FILE} instead of
* returning <code>null</code>.
*
* @param name
* the name of the constant to return
* @return the resource type constant with the specified name, else
* <code>FILE</code>
*/
public static ResourceType getDefaultResourceType(final String name) {
ResourceType rt = getResourceType(name);
return rt == null ? FILE : rt;
}
/**
* Returns <code>true</code> if extension is allowed. Denied extensions set
* takes precedence over allowed extensions set, in other words a negative
* check is made against denied set and if this fails, allowed set is
* checked.
*
* @param extension
* the extension to check, empty will fail
* @return <code>true</code> if extension is allowed, else
* <code>false</code>
*/
public boolean isAllowedExtension(final String extension) {
if (Utils.isEmpty(extension))
return false;
String ext = extension.toLowerCase();
if (allowedEextensions.isEmpty())
return !deniedExtensions.contains(ext);
if (deniedExtensions.isEmpty())
return allowedEextensions.contains(ext);
return false;
}
/**
* This method wraps {@link #isAllowedExtension(String)}. It simply negates
* the return value.
*
* @deprecated Method will be removed in DZGUpload.Java 1, use
* {@link #isDeniedExtension(String)}.
* @see #isDeniedExtension(String)
* @param extension
* Extension string.
* @return <code>true</code> if extension is not fails, else
* <code>false</code>.
*/
@Deprecated
public boolean isNotAllowedExtension(final String extension) {
return !isAllowedExtension(extension);
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
包含文件 1:ajax上传删除,支持多文件实时预览; 2:jstl标签定制, 上传使用servlet,使用跟FCK使用一样,感谢FCK,让我借鉴。支持标签定义上传类型。 当然是跨平台,支持所有浏览器 使用超级方便。
资源推荐
资源详情
资源评论
收起资源包目录
upload.rar (95个子文件)
upload
upload
uploadDefault.properties 0B
META-INF
DZGUpload.tld 3KB
MANIFEST.MF 39B
com
flexoa
upload
tags
MediaTag.java 115B
UploadTag.java 3KB
handlers
uploadDefault.properties 2KB
ResourceType.java 9KB
PropertiesLoader.java 6KB
ExtensionsHandler.java 4KB
DZGUploadConfig.java 1KB
requestcycle
Context.java 1KB
ThreadLocalData.java 1KB
http
servlet
DeleteFileServlet.java 2KB
FileRequestHandler.java 6KB
UploadServlet.java 7KB
FileHttpServletRequest.java 303B
tool
XHtmlTagTool.java 3KB
Utils.java 3KB
DZGUpload.java 4KB
.settings
com.genuitec.eclipse.j2eedt.core.prefs 1KB
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.jsdt.ui.superType.container 49B
.jsdtscope 496B
src
log4j.properties 1KB
com
flexoa
filter
EncodingFilter.java 724B
.project 1KB
.mymetadata 288B
.classpath 915B
web
META-INF
MANIFEST.MF 36B
WEB-INF
web.xml 3KB
classes
uploadDefault.properties 0B
META-INF
DZGUpload.tld 3KB
MANIFEST.MF 39B
log4j.properties 1KB
com
flexoa
upload
tags
UploadTag.class 3KB
MediaTag.class 295B
handlers
uploadDefault.properties 2KB
ResourceType.class 5KB
PropertiesLoader.class 4KB
ExtensionsHandler.class 3KB
requestcycle
Context.class 2KB
ThreadLocalData.class 1KB
http
servlet
UploadServlet.class 8KB
DeleteFileServlet.class 3KB
FileRequestHandler$1.class 1KB
FileRequestHandler.class 7KB
FileHttpServletRequest.class 388B
DZGUpload.class 5KB
tool
Utils.class 2KB
XHtmlTagTool.class 3KB
DZGUploadConfig.class 2KB
filter
EncodingFilter.class 1KB
lib
log4j-1.2.14.jar 359KB
slf4j-log4j12.jar 8KB
commons-logging-1.1.jar 52KB
commons-fileupload-1.2.1.jar 56KB
slf4j-api-1.5.8.jar 23KB
commons-io-1.4.jar 106KB
log4j
upload.log 1KB
DZGUpload
upload
upload.htm 1KB
upload.css 3KB
simpleResponse.xml 67B
style
upload.css 3KB
images
line.gif 44B
select.png 33KB
loadingbar.png 50KB
ajax-loading.gif 2KB
cancel.gif 2KB
del_ico.gif 333B
upload.gif 1KB
select.jpg 669B
ajax-loading.png 33KB
close.gif 828B
bg_02.gif 3KB
loadingbar.gif 13KB
media.jpg 16KB
docIco.jpg 15KB
select.gif 2KB
cancel.png 587B
progressbar.png 211B
selected.jpg 457B
del.gif 2KB
accept.png 781B
add.png 733B
simple.jsp 2KB
common.jsp 313B
scripts
Copy of upload.js 11KB
jquery-1.3.2.js 118KB
Browser-examination-inspection.js 677B
Browser-examination-inspection-Test.js 911B
upload.js 12KB
index.htm 1KB
uploadfile
png
loadingbar.png 36KB
jpg
2_8627.jpg 2KB
doc
dojo tree 代码汇总,基本上功能都全.doc 36KB
.myeclipse
共 95 条
- 1
资源评论
- 小小VS鳄鱼2014-09-22还不错,可以借鉴
- m36215522013-11-15有参考价值 感谢分享
flash8627
- 粉丝: 75
- 资源: 23
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- rainy-day.jpg
- IMG_20240501_171218.jpg
- Swift-内购封装swift版本
- 经典CNN网络之ResNet 图像分类网络实战项目:7种小麦叶片病害分类(迁移学习)
- Java毕设之ssm010基于ssm的新能源汽车在线租赁管理系统+vue.rar
- Java毕设之ssm009毕业生就业信息统计系统+vue.rar
- Java毕设之ssm008医院门诊挂号系统+jsp.rar
- Java毕设之ssm007亚盛汽车配件销售业绩管理统+jsp.rar
- Java毕设之ssm006基于java的少儿编程网上报名系统+vue.rar
- Java毕设之ssm005基于SSM框架的购物商城系统+jsp.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功