代码之家  ›  专栏  ›  技术社区  ›  Luan Kevin Ferreira

是否可以使用sardine将自定义属性放在目录中?

  •  1
  • Luan Kevin Ferreira  · 技术社区  · 7 年前

    我正试图在WebDAV目录中放置一些自定义属性,但它只处理文件。

    我正在使用sardine库和jackrabbit,例如:

    public static void main(String[] args) throws IOException {
        Sardine sardine = SardineFactory.begin();
        String someUrl = "http://localhost:8080/repository/default/temp/";
        int depthInfiniteRecursion = -1;
    
        // 1. Set custom properties on a resource:
        List<DavResource> resourcesBefore = sardine.list(someUrl, depthInfiniteRecursion);
    
        for (DavResource resource : resourcesBefore) {
            Map<QName, String> addProps = new LinkedHashMap<>();         
            QName author = new QName("http://luankevinferreira.github.io", "author", "playground");
            addProps.put(author, "Luan K. Ferreira");
            sardine.patch(resource.getHref().toURL().toString(), addProps);
        }
    
        // 2. Retrieve custom properties on a resource:
        List<DavResource> resources = sardine.list(someUrl, depthInfiniteRecursion);
    
        for (DavResource resource : resources) {
            Map<String, String> customProps = resource.getCustomProps();
            // Use custom properties...
            System.out.println("Resource: " + resource);
            System.out.println("Properties: " + customProps);
        }
    }
    

    使用一个目录和一个文件执行的结果是:

    Resource: /repository/default/temp/
    Properties: {createdBy=admin, created=2018-08-21T18:37:10.446Z, iscollection=1}
    Resource: /repository/default/temp/test.txt
    Properties: {author=Luan K. Ferreira, iscollection=0}
    

    是否仍要将属性放在目录中?

    0 回复  |  直到 7 年前