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

Download as Zip folder with custom folder type

当我下载类型不是 cm:folder 的 zip 文件夹时,我得到空的 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 方法 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);
    }
  }
}

由于自定义文件夹的类型为 ef:folder 此检查 returns false:

if (ContentModel.TYPE_FOLDER.equals(nodeService.getType(nodeRef)))

并且文件夹未添加到 zip。

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

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

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

我不得不解决同样的问题。为了修复它,您确实需要检查 cm:folder 的子类型,因此您需要在 class 中包含字典服务。这样做很乏味,但这是我的解决方案:

覆盖 ID 为 "createDownloadArchiveAction" 的 bean,并将 serviceregistry 引入其中=>

 <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>

在这个新的 class 中,您必须将 serviceregistry 转发到 ZipDownloadExporter =>

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());

在这个 class 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))
        { ....