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

io.milton.http.webdav.PropertiesRequest Maven / Gradle / Ivy

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package io.milton.http.webdav;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.xml.namespace.QName;

/**
 *
 * @author bradm
 */
public class PropertiesRequest {

	private final boolean allProp;
	private final Map properties;

	public static PropertiesRequest toProperties(Set set) {
		Set props = new HashSet<>();
		for (QName n : set) {
			props.add(new Property(n, null));
		}
		return new PropertiesRequest(props);
	}

	public PropertiesRequest() {
		this.allProp = true;
		this.properties = new HashMap<>();
	}

	public PropertiesRequest(Collection set) {
		this.allProp = false;
		this.properties = new HashMap<>();
		for (Property p : set) {
			properties.put(p.getName(), p);
		}
	}

	public Property get(QName name) {
		return properties.get(name);
	}

	public void add(QName name) {
		properties.put(name, new Property(name, null));
	}

	public boolean isAllProp() {
		return allProp;
	}

	public Set getNames() {
		return properties.keySet();
	}

	public Collection getProperties() {
		return properties.values();
	}

	public static class Property {

		private final QName name;
		private final Map nested;

		public Property(QName name, Set nestedSet) {
			this.name = name;
			this.nested = new HashMap<>();
			if (nestedSet != null) {
				for (Property p : nestedSet) {
					nested.put(p.name, p);
				}
			}
		}

		public QName getName() {
			return name;
		}

		public Collection getNested() {
			return nested.values();
		}

		public Map getNestedMap() {
			return nested;
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy