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的更多相关文章

  1. java hadoop file system API

    org.apache.hadoop.fs Class FileSystem java.lang.Object org.apache.hadoop.fs.FileSystem All Implement ...

  2. java.nio.file.Path

    public interface Path extends Comparable<Path>, Iterable<Path>, Watchable 1. A Path repr ...

  3. Java篇-File类之常用操作

    /** * */ package com.io.file; import java.io.File; import java.io.IOException; /** * <pre> * & ...

  4. Java篇-File类之创建删除

    /** * */ package com.io.file; import java.io.File; import java.io.IOException; import org.junit.Test ...

  5. IO:File类(java.io.File)

    public class File extends Object implements Serializable, Comparable<File> 构造方法: public File(S ...

  6. Java class file format specfication

    Java class file format spec Link: https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html Her ...

  7. java.io.file

    package cn.edu.tongji.cims.wade.system;     import java.io.*;     public class FileOperate {     pub ...

  8. java获取指定路径下的指定文件/java.io.File.listFiles(FilenameFilter filter)

    java.io.File.listFiles(FilenameFilter filter) 返回抽象路径名数组,表示在目录中此抽象路径名表示,满足指定过滤器的文件和目录. 声明 以下是java.io. ...

  9. 【java IO File】统计项目代码总共多少行

    统计项目代码总共有多少行 思想: 1.首先将不需要迭代的文件夹,保存在集合中,不满足的就是需要迭代的文件夹 2.将需要进行统计行数的代码文件保存在集合中,满足的就是需要计算文件行数的文件 3.迭代方法 ...

随机推荐

  1. OC 语言新特性

    前言 相对于 Java,OC 语言是一门古老的语言了,而它又是一门不断发展完善的语言.一些新的编译特性,为 OC 语言带来了许多新的活力. 在 Xcode7 中,iOS9 的 SDK 已经全面兼容了 ...

  2. UIViewController函数调用顺序

    /*********** 0 执行1次而已 ******************/ + (void)load { NSLog(@" 0:%s", __func__); } /*** ...

  3. AISing Programming Contest 2019C(DFS,BFS)

    #include<bits/stdc++.h>using namespace std;int n,m;long long a=0,b=0,ans=0;char s[407][407];in ...

  4. [SinGuLaRiTy] NOIP模拟赛(TSY)-Day 2

    [SinGuLaRiTy-2033] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved.                              ...

  5. server12装.NET 3.5

    参考:https://support.microsoft.com/en-us/help/2734782/net-framework-3-5-installation-error-0x800f0906- ...

  6. (multi)set的某些操作

    (multi)set的某些操作 我们可以把multiset当作平衡树用~ 注意,必须定义小于运算符. s.begin() 返回指向第一个元素的迭代器. s.end() 返回指向最后元素的后面那个虚拟元 ...

  7. 条件概率全概率公式-Tribles

    条件概率,全概率公式,贝叶斯公式 条件概率:在另外一个事件 B 已经发生的条件下,事件 A 发生的概率叫做在 A 对于 B 的条件概率,记作 \(p(A|B)\).显然\(p(AB)=p(A|B)p( ...

  8. spring cloud 超时时间

    zuul.host.socket-timeout-millis=60000 #zuul socket连接超时zuul.host.connect-timeout-millis=60000 #zull 请 ...

  9. 读经典——《CLR via C#》(Jeffrey Richter著) 笔记_值类型的装箱和拆箱(二)

    [注意]:如果知道自己写的代码会造成编译器反复对一个值类型进行装箱,请改成用手动方式对值类型进行装箱. [好处]:代码会变得更小.更快. [例子]: using System; public seal ...

  10. aerospike(2)-java client

    地址:https://www.aerospike.com/download/client/java/4.3.1/ 例子顺序:https://github.com/aerospike/aerospike ...