`EditFileEntryAction.java` 文件路徑在資料庫中的dlfileentry中存儲,與bundle/data/document_library的對應關係如下: | Table Column | companyid | folderid | treepath | name | | ...
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這張表中
...待續