All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.milton.http.fs.SimplePropertyManager Maven / Gradle / Ivy

Go to download

Milton Community Edition: Supports DAV level 1 and is available on Apache2 license

There is a newer version: 4.0.3.2215
Show newest version
package io.milton.http.fs;

import io.milton.cache.CacheManager;
import io.milton.http.PropertyManager;
import io.milton.http.webdav.WebDavProtocol;
import io.milton.property.PropertySource;
import io.milton.resource.MultiNamespaceCustomPropertyResource;

import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Keys on getUniqueID of the locked resource.
 */
public class SimplePropertyManager implements PropertyManager {

    private final Map> propertiesByUniqueId;

    public SimplePropertyManager(CacheManager cacheManager) {
        this.propertiesByUniqueId = cacheManager.getMap("fuse-properties-byuniqueId");
    }

    @Override
    public Object getProperty(QName name, MultiNamespaceCustomPropertyResource resource) {
        final Map resourceProperties = propertiesByUniqueId.get(resource.getUniqueId());
        if (resourceProperties != null) {
            return resourceProperties.get(name);
        }
        return null;
    }

    @Override
    public void setProperty(QName name, Object value, MultiNamespaceCustomPropertyResource resource) {
        propertiesByUniqueId.computeIfAbsent(resource.getUniqueId(), k -> new HashMap<>());
        final Map map = propertiesByUniqueId.get(resource.getUniqueId());
        if (value == null) {
            map.remove(name);
        } else {
            map.put(name, value);
        }
    }

    @Override
    public PropertySource.PropertyMetaData getPropertyMetaData(QName name, MultiNamespaceCustomPropertyResource resource) {
        if (!name.getNamespaceURI().equals(WebDavProtocol.NS_DAV.getName()) && !name.getNamespaceURI().contains("caldav") && !name.getNamespaceURI().contains("carddav")) {
            final Map map = propertiesByUniqueId.get(resource.getUniqueId());
            if (map != null && map.containsKey(name)) {
                return new PropertySource.PropertyMetaData(PropertySource.PropertyAccessibility.WRITABLE, String.class);
            } else {
                return new PropertySource.PropertyMetaData(PropertySource.PropertyAccessibility.UNKNOWN, String.class, true);
            }
        }
        return null;
    }

        @Override
        public List getAllPropertyNames (MultiNamespaceCustomPropertyResource resource){
            final Map resourceProperties = propertiesByUniqueId.get(resource.getUniqueId());
            if (resourceProperties != null) {
                return new ArrayList<>(resourceProperties.keySet());
            }
            return null;
        }
    }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy