From ea4f81f4b7a8797ce6cb8d1c943d90cb8017044b Mon Sep 17 00:00:00 2001 From: jensp Date: Mon, 16 Apr 2018 18:12:33 +0000 Subject: [PATCH] CCM NG: More classes for WebDAV support git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5375 8810af33-2d31-482b-a856-94f89814c4df --- .../libreccm/webdav/xml/elements/TimeOut.java | 2 - .../xml/elements/properties/CreationDate.java | 142 ++++++++++++++++++ .../xml/elements/properties/DisplayName.java | 121 +++++++++++++++ .../xml/elements/properties/package-info.java | 43 ++++++ 4 files changed, 306 insertions(+), 2 deletions(-) create mode 100644 ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/CreationDate.java create mode 100644 ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/DisplayName.java create mode 100644 ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/package-info.java diff --git a/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/TimeOut.java b/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/TimeOut.java index a04138d35..f47130611 100644 --- a/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/TimeOut.java +++ b/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/TimeOut.java @@ -181,8 +181,6 @@ public final class TimeOut { * 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 { diff --git a/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/CreationDate.java b/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/CreationDate.java new file mode 100644 index 000000000..e1c99e163 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/CreationDate.java @@ -0,0 +1,142 @@ +/* + * 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.Rfc3339DateTimeFormat; + +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 creationdate 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.1 "creationdate Property" of RFC 4918 "HTTP Extensions for Web Distributed + * Authoring and Versioning (WebDAV)" + * + */ +@XmlJavaTypeAdapter(CreationDate.Adapter.class) +@XmlRootElement(name = "creationdate") +public final class CreationDate { + + /** + * Singleton empty instance for use as property name only, providing + * improved performance and the ability to compare by same + * instance. + */ + public static final CreationDate CREATIONDATE = new CreationDate(); + + private Date dateTime; + + private CreationDate() { + // For unmarshalling only. + } + + public CreationDate(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 Rfc3339DateTimeFormat().format(this.dateTime); + } + } + + @SuppressWarnings("unused") + private void setXmlValue(final String xmlValue) throws ParseException { + + if (xmlValue == null || xmlValue.isEmpty()) { + dateTime = null; + } else { + dateTime = new Rfc3339DateTimeFormat().parse(xmlValue); + } + } + + @Override + public int hashCode() { + int hash = 7; + hash = 97 * 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 CreationDate)) { + return false; + } + final CreationDate other = (CreationDate) 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(CREATIONDATE); + } + + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/DisplayName.java b/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/DisplayName.java new file mode 100644 index 000000000..a796d3d36 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/DisplayName.java @@ -0,0 +1,121 @@ +/* + * 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 displayname 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.2 "displayname Property" of RFC 4918 "HTTP Extensions for Web Distributed + * Authoring and Versioning (WebDAV)" + * + * + */ +@XmlJavaTypeAdapter(DisplayName.Adapter.class) +@XmlRootElement(name = "displayname") +public final class DisplayName { + + /** + * Singleton empty instance for use as property name only, providing + * improved performance and the ability to compare by same + * instance. + */ + public static final DisplayName DISPLAYNAME = new DisplayName(); + + @XmlValue + private final String name; + + private DisplayName() { + this.name = ""; + } + + public DisplayName(final String name) { + this.name = Objects.requireNonNull(name); + } + + public final String getName() { + return this.name; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 97 * hash + Objects.hashCode(name); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof DisplayName)) { + return false; + } + final DisplayName other = (DisplayName) obj; + return Objects.equals(name, other.getName()); + } + + @Override + public String toString() { + return String.format("%s{ " + + "name = \"%s\"" + + " }", + super.toString(), + name); + } + + /** + * 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(DISPLAYNAME); + } + + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/package-info.java b/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/package-info.java new file mode 100644 index 000000000..4a70d6a29 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/webdav/xml/elements/properties/package-info.java @@ -0,0 +1,43 @@ +/* + * 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 + */ +/** + * This package contains WebDAV Properties. + * + * The classes in this package are 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 + * "DAV Properties" of RFC 4918 "HTTP Extensions for Web Distributed Authoring + * and Versioning (WebDAV)" + */ +@XmlSchema(namespace = "DAV:", + xmlns = @XmlNs(prefix = "D", namespaceURI = "DAV:"), + elementFormDefault = QUALIFIED) +package org.libreccm.webdav.xml.elements.properties; + +import static javax.xml.bind.annotation.XmlNsForm.QUALIFIED; + +import javax.xml.bind.annotation.XmlNs; +import javax.xml.bind.annotation.XmlSchema;