zoukankan      html  css  js  c++  java
  • [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这张表中

    ...待续

  • 相关阅读:
    Jquery的小案例4、实现表单的验证(用户名和邮箱)
    Ubuntu下安装Python
    ListView列宽自适应
    IPtables 版本升级到 v1.4.9
    穿过已知点画平滑曲线(3次贝塞尔曲线)
    贪心算法——NY 14 会场安排问题
    零是奇数还是偶数?
    免费淘宝IP地址库简介及PHP/C#调用实例
    html锚点(mao dian)特殊的超链接
    怎么查看自己电脑的IP地址
  • 原文地址:https://www.cnblogs.com/chenyongblog/p/6005224.html
Copyright © 2011-2022 走看看