0

我正在学习木兰cms。我正在尝试使用资源模块。我实际上有2个问题。

  1. 无法上传一堆文件。我有一些文件,但过一段时间我将不得不上传更多文件。模块导入功能要我上传一个 xml 文件。但我不知道如何正确生成它。尝试通过 JCR 导入,但之后我在资源应用程序中看不到这些文件。尝试将模块配置为在文件系统中搜索文件:我将 fileSystemLoader 设置为类 info.magnolia.module.resources.loaders.FileSystemResourceLoader 并设置一些路径。它对我也不起作用。也许我只是不明白应该在什么时候激活文件上传功能。在应用程序启动时它不起作用。

  2. 如何在我的模板中正确使用这些资源?我应该使用什么 ftl 标签?

我不使用 STK 模块。

如果您决定帮助我,感谢您的耐心等待。

玉兰版本:5.2 CE

JDK冰茶:1.7.0_51

操作系统:Linux/OpenSUSE 12.3

4

1 回答 1

2

我以前(在 4.5.x 上)使用下面的脚本通过 groovy 模块执行任务。它也应该适用于 5.2。

import static groovy.io.FileType.FILES
import info.magnolia.jcr.util.NodeUtil
import org.apache.commons.lang.StringUtils
import info.magnolia.cms.util.ContentUtil

class Globals {
 static def folderName = '//some/folder/in/filesystem/on/server'
}

def loadImageFolder() {
 session = ctx.getJCRSession("resources")
 parentFolder = session.getNode("/templating-kit/jelinek-image/obrazky-produkty")

 new File(Globals.folderName).eachFileRecurse(FILES) {

  name = it.name
  // set file name
  extension = StringUtils.substringAfterLast(name, '.')
  name = StringUtils.substringBeforeLast(name, '.')

  // persist
  resource = NodeUtil.createPath(parentFolder,name , "mgnl:content")
  // persistResource
  resource.setProperty("mgnl:template", "resources:binary")
  resource.setProperty("extension", extension)

  binary = resource.addNode("binary", "mgnl:resource")
  binary.setProperty("jcr:data", new FileInputStream(it.absolutePath))
  binary.setProperty("extension", extension)
  binary.setProperty("fileName", name)
  binary.setProperty("jcr:mimeType", "image/"+extension)
  binary.setProperty("size", it.length())

 }
 session.save()
}

loadImageFolder() 
return 'done'
于 2014-02-18T20:16:43.147 回答