[Java][Liferay] File system in liferay
EditFileEntryAction.java
protected FileEntry updateFileEntry(PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse)
throws Exception {
/* 此处强转获取uploadPortletRequest,用于获取InputStream,也可以使用如下代码:
* HttpServletRequest request = serviceContext.getRequest();
* UploadRequest uploadRequest = PortalUtil.getUploadServletRequest(request);
* inputStream = uploadRequest.getFileAsStream(fieldName);
*/
UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);
...
// 获取folderId, 如果自己创建的话,要走DLFolderLocalServiceUtil.java
if (folderId > 0) {
Folder folder = DLAppServiceUtil.getFolder(folderId);
if (folder.getGroupId() != themeDisplay.getScopeGroupId()) {
throw new NoSuchFolderException("{folderId=" + folderId + "}");
}
}
InputStream inputStream = null;
try {
String contentType = uploadPortletRequest.getContentType("file");
// inputStream.available()用于获取size
long size = uploadPortletRequest.getSize("file");
...
// 获取inputStream
inputStream = uploadPortletRequest.getFileAsStream("file");
ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFileEntry.class.getName(), uploadPortletRequest);
FileEntry fileEntry = null;
// Add file entry
fileEntry = DLAppServiceUtil.addFileEntry(
repositoryId, folderId, sourceFileName, contentType, title,
description, changeLog, inputStream, size, serviceContext);
// Update file entry and checkin
fileEntry = DLAppServiceUtil.updateFileEntryAndCheckIn(
fileEntryId, sourceFileName, contentType, title,
description, changeLog, majorVersion, inputStream, size,
serviceContext);
}
DLAppServiceUtil.java
public FileEntry addFileEntry(long repositoryId, long folderId, String sourceFileName, String mimeType, String title,
String description, String changeLog, InputStream is, long size, ServiceContext serviceContext)
throws PortalException, SystemException {
...
File file = null;
try {
/* 创建tempFile,inputStream读取的文件放在tomcat-7.0.62/temp/xxxfile
* 根据inputStream创建一个tempFile,然后存储对应的关系到数据库,文件根据数据库中的路径存放在bundle/data/document_library下
*/
file = FileUtil.createTempFile(is);
return addFileEntry(repositoryId, folderId, sourceFileName, mimeType, title,
description, changeLog, file, serviceContext);
} catch (IOException ioe) {
throw new SystemException("Unable to write temporary file", ioe);
} finally {
// 不论addFile是否成功都会删除临时文件
FileUtil.delete(file);
}
}
}
...
}
文件路径在数据库中的dlfileentry中存储,与bundle/data/document_library的对应关系如下:
| Table Column | companyid | folderid | treepath | name |
|---|---|---|---|---|
| Path | document_library/ | companyid | folderid | /folderid/ |
存储的文件名会有1。0,2.0之类的,标记的是文件的版本,具体在dlfileversion这张表中
...待续
[Java][Liferay] File system in liferay的更多相关文章
- java hadoop file system API
org.apache.hadoop.fs Class FileSystem java.lang.Object org.apache.hadoop.fs.FileSystem All Implement ...
- java.nio.file.Path
public interface Path extends Comparable<Path>, Iterable<Path>, Watchable 1. A Path repr ...
- Java篇-File类之常用操作
/** * */ package com.io.file; import java.io.File; import java.io.IOException; /** * <pre> * & ...
- Java篇-File类之创建删除
/** * */ package com.io.file; import java.io.File; import java.io.IOException; import org.junit.Test ...
- IO:File类(java.io.File)
public class File extends Object implements Serializable, Comparable<File> 构造方法: public File(S ...
- Java class file format specfication
Java class file format spec Link: https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html Her ...
- java.io.file
package cn.edu.tongji.cims.wade.system; import java.io.*; public class FileOperate { pub ...
- java获取指定路径下的指定文件/java.io.File.listFiles(FilenameFilter filter)
java.io.File.listFiles(FilenameFilter filter) 返回抽象路径名数组,表示在目录中此抽象路径名表示,满足指定过滤器的文件和目录. 声明 以下是java.io. ...
- 【java IO File】统计项目代码总共多少行
统计项目代码总共有多少行 思想: 1.首先将不需要迭代的文件夹,保存在集合中,不满足的就是需要迭代的文件夹 2.将需要进行统计行数的代码文件保存在集合中,满足的就是需要计算文件行数的文件 3.迭代方法 ...
随机推荐
- CHSaveData
NSData数据 NSStream文件流 NSCache缓存 SQLite NSFileManager文件管理 NSUserDefaults数据存储 PList数据存储 NSKeyedArchiver ...
- 为什么使用docker
为什么要使用Docker? 作为一种新兴的虚拟化方式,Docker跟传统的虚拟化方式相比具有众多的优势. 更高效的利用系统资源 由于容器不需要进行硬件虚拟及运行完整操作系统等额外开销,Docker对系 ...
- A - Chips
Gerald plays the following game. He has a checkered field of size n × n cells, where m various cells ...
- ubuntu部署django详细教程
教程使用的软件版本:Ubuntu 18.04.1 LTS,django2.0,Python 3.6.5.nginx-1.13.7.uWSGI (2.0.17.1),Ubuntu是纯净的,全新的.下面我 ...
- hyperledger fabric 中java chaincode 支持离线打包
联盟链由于其本身的特性,目前应用在一些大型国有企业银行比较多.出于安全考虑,这些企业一般会隔离外网环境.所以在实际生产需求中可能存在需要在一个离线的环境中打包安装chaincode的情况. 本文基于这 ...
- Shell脚本标准
#!/bin/bash #Usage: # ./shell.sh dbname user passwd #----------------------------------------------- ...
- Java内存区域与内存溢出异常---对象的创建
对象的创建 在语言层面,创建一个对象通常仅仅是一个new关键字而已.在虚拟机层面,虚拟机遇到一个new指令时,首先回去检查这个指令的参数是能在常量池中定位到一个类的符号引用,并检查这个符号引用代表 ...
- 本地命令上传文件到服务器以及linux编辑过程中非正常退出问题
一.上传文件到linux服务器首先从你本地切换到你要上传文件的目录,接下来:scp 文件名字 服务器用户名字@服务器ip:存储路径例子:scp index.html root@106.75.229 ...
- mysql 备份时间 %date~0,4%和 %time~0,2%等用法详解
比如在windowscmd命令行窗口执行date命令后这个环境变量的值为 当前日期:2014-09-01 星期六 或2014/09/01 周六 那么如下的各个操作的意义如下:%date:~0,4% 表 ...
- Flowerpot(又是尺取。。)
题目:http://172.21.85.56/oj/exercise/problem?problem_id=21568 题目大意:老板需要你帮忙浇花.给出N滴水的坐标,y表示水滴的高度,x表示它下落到 ...