代码之家  ›  专栏  ›  技术社区  ›  Pavel

Magnolia cms:资源模块正确使用

  •  0
  • Pavel  · 技术社区  · 12 年前

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

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

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

    我不使用STK模块。

    如果你决定帮助我,谢谢你的耐心。

    Magnolia版本:5.2 CE

    JDK冰茶:1.7.0_51

    操作系统:Linux/OpenUSE 12.3

    1 回复  |  直到 12 年前
        1
  •  2
  •   Jan    12 年前

    我之前(在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'