From a8efc382c45f65f903ffcae1cd28c50dcd38ada6 Mon Sep 17 00:00:00 2001 From: jensp Date: Tue, 17 Apr 2018 16:43:00 +0000 Subject: [PATCH] CCM NG: Some classes for representing WebDAV properties git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5376 8810af33-2d31-482b-a856-94f89814c4df --- .../properties/GetContentLanguage.java | 114 +++++++++++++ .../elements/properties/GetContentLength.java | 153 ++++++++++++++++++ .../elements/properties/GetContentType.java | 115 +++++++++++++ .../xml/elements/properties/GetETag.java | 122 ++++++++++++++ .../elements/properties/GetLastModified.java | 149 +++++++++++++++++ .../elements/properties/LockDiscovery.java | 126 +++++++++++++++ .../xml/elements/properties/ResourceType.java | 131 +++++++++++++++ .../elements/properties/SupportedLock.java | 126 +++++++++++++++ 8 files changed, 1036 insertions(+) create mode 100644 ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/GetContentLanguage.java create mode 100644 ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/GetContentLength.java create mode 100644 ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/GetContentType.java create mode 100644 ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/GetETag.java create mode 100644 ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/GetLastModified.java create mode 100644 ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/LockDiscovery.java create mode 100644 ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/ResourceType.java create mode 100644 ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/SupportedLock.java diff --git a/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/GetContentLanguage.java b/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/GetContentLanguage.java new file mode 100644 index 000000000..095739145 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/GetContentLanguage.java @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2018 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.webdav.xml.elements.properties; + +import org.libreccm.webdav.ConstantsAdapter; + +import java.util.Collection; +import java.util.Collections; +import java.util.Objects; + +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlValue; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; + +/** + * WebDAV getcontentlanguage Property. + * + * The class is based on a class/interface from java.net WebDAV Project: + * + * https://gitlab.com/headcrashing/webdav-jaxrs/blob/master/src/main/java/net/java/dev/webdav/jaxrs/Headers.java + * + * + * @author Markus KARG (mkarg@java.net) + * @author Jens Pelzetter + * + * @see + * Chapter + * 15.3 "getcontentlanguage Property" of RFC 4918 "HTTP Extensions for Web + * Distributed Authoring and Versioning (WebDAV)" + * + */ +@XmlJavaTypeAdapter(GetContentLanguage.Adapter.class) +@XmlRootElement(name = "getcontentlanguage") +public final class GetContentLanguage { + + public static final GetContentLanguage GETCONTENTLANGUAGE + = new GetContentLanguage(); + + @XmlValue + private final String languageTag; + + private GetContentLanguage() { + this.languageTag = ""; + } + + public GetContentLanguage(final String languageTag) { + this.languageTag = Objects.requireNonNull(languageTag); + } + + public final String getLanguageTag() { + return this.languageTag; + } + + @Override + public int hashCode() { + int hash = 5; + hash = 67 * hash + Objects.hashCode(languageTag); + return hash; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof GetContentLanguage)) { + return false; + } + final GetContentLanguage other = (GetContentLanguage) obj; + return Objects.equals(languageTag, other.getLanguageTag()); + } + + @Override + public String toString() { + return String.format("%s{ languageTag = \"%s\" }", + languageTag); + } + + /** + * Guarantees that any unmarshalled enum constants effectively are the + * constant Java instances itself, so that {@code ==} can be used form + * comparison. + * + */ + protected static final class Adapter + extends ConstantsAdapter { + + @Override + protected final Collection getConstants() { + return Collections.singleton(GETCONTENTLANGUAGE); + } + + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/GetContentLength.java b/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/GetContentLength.java new file mode 100644 index 000000000..f7242d473 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/GetContentLength.java @@ -0,0 +1,153 @@ +/* + * Copyright (C) 2018 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.webdav.xml.elements.properties; + +import org.libreccm.webdav.ConstantsAdapter; + +import java.util.Collection; +import java.util.Collections; +import java.util.Objects; + +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlValue; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; + +import static javax.xml.bind.annotation.XmlAccessType.*; + +/** + * + * WebDAV getcontentlength Property. + * + * The class is based on a class/interface from java.net WebDAV Project: + * + * https://gitlab.com/headcrashing/webdav-jaxrs/blob/master/src/main/java/net/java/dev/webdav/jaxrs/Headers.java + * + * @author Markus KARG (mkarg@java.net) + * @author Jens Pelzetter + * + * @see + * Chapter + * 15.4 "getcontentlength Property" of RFC 4918 "HTTP Extensions for Web + * Distributed Authoring and Versioning (WebDAV)" + * + * + */ +@XmlAccessorType(NONE) +@XmlJavaTypeAdapter(GetContentLength.Adapter.class) +@XmlRootElement(name = "getcontentlength") +public final class GetContentLength { + + /** + * Singleton empty instance for use as property name only, providing + * improved performance and the ability to compare by same + * instance. + * + * @since 1.2 + */ + public static final GetContentLength GETCONTENTLENGTH + = new GetContentLength(); + + private Long contentLength; + + @SuppressWarnings("unused") + private String getXmlValue() { + + if (contentLength == null) { + return null; + } else { + return Long.toString(contentLength); + } + } + + @XmlValue + private void setXmlValue(final String xmlValue) { + + if (xmlValue == null || xmlValue.isEmpty()) { + contentLength = null; + } else { + contentLength = Long.parseLong(xmlValue); + } + + this.contentLength = xmlValue == null || xmlValue.isEmpty() ? null + : Long.parseLong(xmlValue); + } + + private GetContentLength() { + // For unmarshalling only + } + + public GetContentLength(final long contentLength) { + this.contentLength = contentLength; + } + + public final long getContentLength() { + if (contentLength == null) { + return 0; + } else { + return contentLength; + } + } + + @Override + public int hashCode() { + int hash = 7; + hash = 47 * hash + Objects.hashCode(contentLength); + return hash; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof GetContentLength)) { + return false; + } + final GetContentLength other = (GetContentLength) obj; + return Objects.equals(contentLength, other.getContentLength()); + } + + @Override + public String toString() { + return String.format("%s{ contentLength = %d }", + super.toString(), + contentLength); + } + + /** + * Guarantees that any unmarshalled enum constants effectively are the + * constant Java instances itself, so that {@code ==} can be used form + * comparison. + * + */ + protected static final class Adapter + extends ConstantsAdapter { + + @Override + protected final Collection getConstants() { + return Collections.singleton(GETCONTENTLENGTH); + } + + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/GetContentType.java b/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/GetContentType.java new file mode 100644 index 000000000..c4172930e --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/GetContentType.java @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2018 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.webdav.xml.elements.properties; + +import org.libreccm.webdav.ConstantsAdapter; + +import java.util.Collection; +import java.util.Collections; +import java.util.Objects; + +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlValue; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; + +/** + * WebDAV getcontenttype Property. + * + * The class is based on a class/interface from java.net WebDAV Project: + * + * https://gitlab.com/headcrashing/webdav-jaxrs/blob/master/src/main/java/net/java/dev/webdav/jaxrs/Headers.java + * + * + * @author Markus KARG (mkarg@java.net) + * @author Jens Pelzetter + * + * @see + * Chapter + * 15.5 "getcontenttype Property" of RFC 4918 "HTTP Extensions for Web + * Distributed Authoring and Versioning (WebDAV)" + * + * + */ +@XmlJavaTypeAdapter(GetContentType.Adapter.class) +@XmlRootElement(name = "getcontenttype") +public final class GetContentType { + + /** + * Singleton empty instance for use as property name only, providing + * improved performance and the ability to compare by same + * instance. + * + */ + public static final GetContentType GETCONTENTTYPE = new GetContentType(); + + @XmlValue + private final String mediaType; + + private GetContentType() { + this.mediaType = ""; + } + + public GetContentType(final String mediaType) { + this.mediaType = Objects.requireNonNull(mediaType); + } + + public final String getMediaType() { + return this.mediaType; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 61 * hash + Objects.hashCode(mediaType); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof GetContentType)) { + return false; + } + final GetContentType other = (GetContentType) obj; + return Objects.equals(mediaType, other.getMediaType()); + } + + @Override + public String toString() { + return String.format("%s{ mediaType = \"%s\" }", + super.toString(), + mediaType); + } + + protected static final class Adapter + extends ConstantsAdapter { + + @Override + protected final Collection getConstants() { + return Collections.singleton(GETCONTENTTYPE); + } + + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/GetETag.java b/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/GetETag.java new file mode 100644 index 000000000..dc120249b --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/GetETag.java @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2018 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.webdav.xml.elements.properties; + +import org.libreccm.webdav.ConstantsAdapter; + +import java.util.Collection; +import java.util.Collections; +import java.util.Objects; + +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlValue; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; + +/** + * + * WebDAV getetag Property. + * + * The class is based on a class/interface from java.net WebDAV Project: + * + * https://gitlab.com/headcrashing/webdav-jaxrs/blob/master/src/main/java/net/java/dev/webdav/jaxrs/Headers.java + * + * + * @author Markus KARG (mkarg@java.net) + * @author Jens Pelzetter + * + * @see + * Chapter + * 15.6 "getetag Property" of RFC 4918 "HTTP Extensions for Web Distributed + * Authoring and Versioning (WebDAV)" + * + * + */ +@XmlJavaTypeAdapter(GetETag.Adapter.class) +@XmlRootElement(name = "getetag") +public final class GetETag { + + /** + * Singleton empty instance for use as property name only, providing + * improved performance and the ability to compare by same + * instance. + * + */ + public static final GetETag GETETAG = new GetETag(); + + @XmlValue + private final String entityTag; + + private GetETag() { + this.entityTag = ""; + } + + public GetETag(final String entityTag) { + this.entityTag = Objects.requireNonNull(entityTag); + } + + public final String getEntityTag() { + return entityTag; + } + + @Override + public int hashCode() { + int hash = 5; + hash = 37 * hash + Objects.hashCode(entityTag); + return hash; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof GetETag)) { + return false; + } + final GetETag other = (GetETag) obj; + return Objects.equals(entityTag, other.getEntityTag()); + } + + @Override + public String toString() { + return String.format("%s{ entityTag = \"%s\" }", + super.toString(), + entityTag); + } + + /** + * Guarantees that any unmarshalled enum constants effectively are the + * constant Java instances itself, so that {@code ==} can be used form + * comparison. + * + * @since 1.2 + */ + protected static final class Adapter extends ConstantsAdapter { + + @Override + protected final Collection getConstants() { + return Collections.singleton(GETETAG); + } + + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/GetLastModified.java b/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/GetLastModified.java new file mode 100644 index 000000000..f846f5768 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/GetLastModified.java @@ -0,0 +1,149 @@ +/* + * Copyright (C) 2018 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.webdav.xml.elements.properties; + +import org.libreccm.webdav.ConstantsAdapter; +import org.libreccm.webdav.xml.elements.Rfc1123DateFormat; + +import java.text.ParseException; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.Objects; + +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlValue; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; + +/** + * + * WebDAV getlastmodified Property. + * + * The class is based on a class/interface from java.net WebDAV Project: + * + * https://gitlab.com/headcrashing/webdav-jaxrs/blob/master/src/main/java/net/java/dev/webdav/jaxrs/Headers.java + * + * + * @author Markus KARG (mkarg@java.net) + * @author Jens Pelzetter + * + * @see + * Chapter + * 15.7 "getlastmodified Property" of RFC 4918 "HTTP Extensions for Web + * Distributed Authoring and Versioning (WebDAV)" + * + */ +@XmlJavaTypeAdapter(GetLastModified.Adapter.class) +@XmlRootElement(name = "getlastmodified") +public final class GetLastModified { + + /** + * Singleton empty instance for use as property name only, providing + * improved performance and the ability to compare by same + * instance. + * + */ + public static final GetLastModified GETLASTMODIFIED = new GetLastModified(); + + private Date dateTime; + + private GetLastModified() { + // For unmarshalling only. + } + + public GetLastModified(final Date dateTime) { + this.dateTime = Objects.requireNonNull(dateTime); + } + + public final Date getDateTime() { + + if (dateTime == null) { + return null; + } else { + return (Date) dateTime.clone(); + } + } + + @XmlValue + private String getXmlValue() { + + if (dateTime == null) { + return null; + } else { + return new Rfc1123DateFormat().format(dateTime); + } + } + + @SuppressWarnings("unused") + private void setXmlValue(final String xmlValue) throws ParseException { + + if (xmlValue == null || xmlValue.isEmpty()) { + dateTime = null; + } else { + dateTime = new Rfc1123DateFormat().parse(xmlValue); + } + + } + + @Override + public int hashCode() { + int hash = 3; + hash = 79 * hash + Objects.hashCode(dateTime); + return hash; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof GetLastModified)) { + return false; + } + final GetLastModified other = (GetLastModified) obj; + return Objects.equals(dateTime, other.getDateTime()); + } + + @Override + public String toString() { + return String.format("%s{ dateTime = %s }", + super.toString(), + Objects.toString(dateTime)); + } + + /** + * Guarantees that any unmarshalled enum constants effectively are the + * constant Java instances itself, so that {@code ==} can be used form + * comparison. + * + */ + protected static final class Adapter + extends ConstantsAdapter { + + @Override + protected final Collection getConstants() { + return Collections.singleton(GETLASTMODIFIED); + } + + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/LockDiscovery.java b/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/LockDiscovery.java new file mode 100644 index 000000000..9c03a6551 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/LockDiscovery.java @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2018 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.webdav.xml.elements.properties; + +import org.libreccm.webdav.ConstantsAdapter; +import org.libreccm.webdav.xml.elements.ActiveLock; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; + +/** + * WebDAV lockdiscovery Property. + * + * + * The class is based on a class/interface from java.net WebDAV Project: + * + * https://gitlab.com/headcrashing/webdav-jaxrs/blob/master/src/main/java/net/java/dev/webdav/jaxrs/Headers.java + * + * + * @author Markus KARG (mkarg@java.net) + * @author Jens Pelzetter + * + * @see + * Chapter + * 15.8 "lockdiscovery Property" of RFC 4918 "HTTP Extensions for Web + * Distributed Authoring and Versioning (WebDAV)" + * + */ +@XmlJavaTypeAdapter(LockDiscovery.Adapter.class) +@XmlRootElement(name = "lockdiscovery") +public final class LockDiscovery { + + /** + * Singleton empty instance for use as property name only, providing + * improved performance and the ability to compare by same + * instance. + * + */ + public static final LockDiscovery LOCKDISCOVERY = new LockDiscovery(); + + @XmlElement(name = "activelock") + private final List activeLocks; + + private LockDiscovery() { + this.activeLocks = new LinkedList<>(); + } + + public LockDiscovery(final ActiveLock... activeLocks) { + + this.activeLocks = Arrays.asList(Objects.requireNonNull(activeLocks)); + } + + public final List getActiveLocks() { + return Collections.unmodifiableList(activeLocks); + } + + @Override + public int hashCode() { + int hash = 3; + hash = 61 * hash + Objects.hashCode(activeLocks); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof LockDiscovery)) { + return false; + } + final LockDiscovery other = (LockDiscovery) obj; + return Objects.equals(activeLocks, other.getActiveLocks()); + } + + @Override + public String toString() { + return String.format("%s{ activeLocks = %s }", + super.toString(), + Objects.toString(activeLocks)); + } + + /** + * Guarantees that any unmarshalled enum constants effectively are the + * constant Java instances itself, so that {@code ==} can be used form + * comparison. + * + */ + protected static final class Adapter + extends ConstantsAdapter { + + @Override + protected final Collection getConstants() { + return Collections.singleton(LOCKDISCOVERY); + } + + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/ResourceType.java b/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/ResourceType.java new file mode 100644 index 000000000..57ec6e513 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/ResourceType.java @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2018 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.webdav.xml.elements.properties; + +import org.libreccm.webdav.ConstantsAdapter; +import org.libreccm.webdav.xml.elements.Collection; + +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; + +import javax.xml.bind.annotation.XmlAnyElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; + +/** + * WebDAV resourcetype Property. + * + * The class is based on a class/interface from java.net WebDAV Project: + * + * https://gitlab.com/headcrashing/webdav-jaxrs/blob/master/src/main/java/net/java/dev/webdav/jaxrs/Headers.java + * + * + * @author Markus KARG (mkarg@java.net) + * @author Jens Pelzetter + * + * @see + * Chapter + * 15.9 "resourcetype Property" of RFC 4918 "HTTP Extensions for Web Distributed + * Authoring and Versioning (WebDAV)" + * + * + */ +@XmlJavaTypeAdapter(ResourceType.Adapter.class) +@XmlRootElement(name = "resourcetype") +public final class ResourceType { + + /** + * Singleton empty instance for use as property name only, providing + * improved performance and the ability to compare by same + * instance. + * + * @since 1.2 + */ + public static final ResourceType RESOURCETYPE = new ResourceType(); + + @XmlAnyElement(lax = true) + private final List resourceTypes; + + public static final ResourceType COLLECTION = new ResourceType( + Collection.COLLECTION); + + private ResourceType() { + this.resourceTypes = new LinkedList<>(); + } + + public ResourceType(final Object... resourceTypes) { + + this.resourceTypes = Arrays.asList( + Objects.requireNonNull(resourceTypes)); + + } + + public final List getResourceTypes() { + return Collections.unmodifiableList(this.resourceTypes); + } + + @Override + public int hashCode() { + int hash = 3; + hash = 97 * hash + Objects.hashCode(resourceTypes); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof ResourceType)) { + return false; + } + final ResourceType other = (ResourceType) obj; + return Objects.equals(resourceTypes, other.getResourceTypes()); + } + + @Override + public String toString() { + return String.format("%s{ resourceTypes = %s }", + super.toString(), + Objects.toString(resourceTypes)); + } + + /** + * Guarantees that any unmarshalled enum constants effectively are the + * constant Java instances itself, so that {@code ==} can be used form + * comparison. + * + */ + protected static final class Adapter + extends ConstantsAdapter { + + @Override + protected final java.util.Collection getConstants() { + return Arrays.asList(RESOURCETYPE, COLLECTION); + } + + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/SupportedLock.java b/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/SupportedLock.java new file mode 100644 index 000000000..841c5871b --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/SupportedLock.java @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2018 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.webdav.xml.elements.properties; + +import org.libreccm.webdav.ConstantsAdapter; +import org.libreccm.webdav.xml.elements.LockEntry; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; + +/** + * + * WebDAV supportedlock Property. + * + * The class is based on a class/interface from java.net WebDAV Project: + * + * https://gitlab.com/headcrashing/webdav-jaxrs/blob/master/src/main/java/net/java/dev/webdav/jaxrs/Headers.java + * + * + * @author Markus KARG (mkarg@java.net) + * @author Jens Pelzetter + * + * @see + * Chapter + * 15.10 "supportedlock Property" of RFC 4918 "HTTP Extensions for Web + * Distributed Authoring and Versioning (WebDAV)" + * + */ +@XmlJavaTypeAdapter(SupportedLock.Adapter.class) +@XmlRootElement(name = "supportedlock") +public final class SupportedLock { + + /** + * Singleton empty instance for use as property name only, providing + * improved performance and the ability to compare by same + * instance. + * + */ + public static final SupportedLock SUPPORTEDLOCK = new SupportedLock(); + + @XmlElement(name = "lockentry") + private final List lockEntries; + + private SupportedLock() { + this.lockEntries = new LinkedList<>(); + } + + public SupportedLock(final LockEntry... lockEntries) { + + this.lockEntries = Arrays.asList(Objects.requireNonNull(lockEntries)); + } + + public final List getLockEntries() { + return Collections.unmodifiableList(lockEntries); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 29 * hash + Objects.hashCode(lockEntries); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof SupportedLock)) { + return false; + } + final SupportedLock other = (SupportedLock) obj; + return Objects.equals(lockEntries, other.getLockEntries()); + } + + @Override + public String toString() { + return String.format("%s{ lockEntries = %s }", + super.toString(), + Objects.toString(lockEntries)); + } + + /** + * Guarantees that any unmarshalled enum constants effectively are the + * constant Java instances itself, so that {@code ==} can be used form + * comparison. + * + */ + protected static final class Adapter + extends ConstantsAdapter { + + @Override + protected final Collection getConstants() { + return Collections.singleton(SUPPORTEDLOCK); + } + + } + +}