下载为自定义文件夹类型的Zip文件夹

时间:2015-06-19 10:00:47

标签: java alfresco alfresco-share

当我下载文件夹作为zip类型不是cm:文件夹我得到空的zip存档。对于具有cm:content类型的文件夹和文档,它可以正常工作。

更多详情:

在我们的项目中,我们创建了一个自定义文件夹类型,父类型为cm:folder

<type name="ef:folder">
  <title>Parent of all folders</title>
  <parent>cm:folder</parent>
  <mandatory-aspects>
    <aspect>ef:typed</aspect>
  </mandatory-aspects>
</type>

问题是,当我按下所选文件夹的下载为Zip 按钮时,我会得到空的zip文件。它来自startNode的{​​{1}}方法:

ZipDownloadExporter.java

由于自定义文件夹的类型为@Override public void startNode(NodeRef nodeRef) { this.currentName = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); path.push(new Pair<String, NodeRef>(currentName, nodeRef)); if (ContentModel.TYPE_FOLDER.equals(nodeService.getType(nodeRef))) { String path = getPath() + PATH_SEPARATOR; ZipArchiveEntry archiveEntry = new ZipArchiveEntry(path); try { zipStream.putArchiveEntry(archiveEntry); zipStream.closeArchiveEntry(); } catch (IOException e) { throw new ExporterException("Unexpected IOException adding folder entry", e); } } } ,因此此检查将返回false:

ef:folder

并且文件夹未添加到zip。

这是一个错误(也许正确的解决方案不仅要检查节点的类型,还要检查父类型)?

如何在不为自定义文件夹类型创建自定义导出器的情况下修复它?

由于项目限制,文件夹类型无法更改为cm:文件夹。

1 个答案:

答案 0 :(得分:4)

我不得不解决同样的问题。为了修复它,您确实需要检查cm:文件夹的子类型,因此您需要在此类中包含字典服务。这样做非常繁琐,但这是我的解决方案:

覆盖id为“createDownloadArchiveAction”的bean,并将serviceregistry提取到其中=&gt;

 <bean id="createDownloadArchiveAction" class="org.alfresco.repo.download.CreateDownloadArchiveActionSR" parent="action-executer">
  <property name="checkOutCheckInSerivce" ref="checkOutCheckInService"/>
  <property name="contentServiceHelper" ref="downloadContentServiceHelper" />
  <property name="downloadStorage" ref="downloadStorage" />
  <property name="exporterService" ref="exporterComponent" />
  <property name="maximumContentSize" value="${download.maxContentSize}" />
  <property name="nodeService" ref="nodeService" />
  <property name="publicAction" value="false"/>
  <property name="transactionHelper" ref="retryingTransactionHelper"/>
  <property name="updateService" ref="downloadStatusUpdateService"/>
  <property name="serviceRegistry">
    <ref bean="ServiceRegistry" />
  </property>

在这个新课程中,您必须将serviceregistry转发到ZipDownloadExporter =&gt;

private void createDownload(final NodeRef actionedUponNodeRef, ExporterCrawlerParameters crawlerParameters, SizeEstimator estimator)
    {
        // perform the actual export
        final File tempFile = TempFileProvider.createTempFile(TEMP_FILE_PREFIX, TEMP_FILE_SUFFIX);
        final MyZipDownloadExporter handler = new MyZipDownloadExporter (tempFile, checkOutCheckInService, nodeService, transactionHelper, updateService, downloadStorage,serviceRegistry, actionedUponNodeRef, estimator.getSize(), estimator.getFileCount());

在此类MyZipDownloadExporter中,您现在可以执行子类型检查:

 public void startNode(NodeRef nodeRef)
    {
        this.currentName = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
        path.push(new Pair<String, NodeRef>(currentName, nodeRef));
        if (this.sr.getDictionaryService().isSubClass((nodeService.getType(nodeRef), ContentModel.TYPE_FOLDER))
        { ....