#141 - Added model to build ALPS documents.
Added the necessary abstractions to build an ALPS [0] document. [0] http://alps.io
This commit is contained in:
69
src/main/java/org/springframework/hateoas/alps/Alps.java
Normal file
69
src/main/java/org/springframework/hateoas/alps/Alps.java
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed 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 org.springframework.hateoas.alps;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Value;
|
||||
import lombok.experimental.Builder;
|
||||
|
||||
import org.springframework.hateoas.alps.Descriptor.DescriptorBuilder;
|
||||
import org.springframework.hateoas.alps.Doc.DocBuilder;
|
||||
import org.springframework.hateoas.alps.Ext.ExtBuilder;
|
||||
|
||||
/**
|
||||
* An ALPS document.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @since 0.15
|
||||
* @see http://alps.io
|
||||
* @see http://alps.io/spec/#prop-alps
|
||||
*/
|
||||
@Value
|
||||
@Builder(builderMethodName = "alps")
|
||||
public class Alps {
|
||||
|
||||
private final String version = "1.0";
|
||||
private final Doc doc;
|
||||
private final List<Descriptor> descriptors;
|
||||
|
||||
/**
|
||||
* Returns a new {@link DescriptorBuilder}.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static DescriptorBuilder descriptor() {
|
||||
return Descriptor.builder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new {@link DocBuilder}.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static DocBuilder doc() {
|
||||
return Doc.builder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retruns a new {@link ExtBuilder}.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static ExtBuilder ext() {
|
||||
return Ext.builder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed 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 org.springframework.hateoas.alps;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Value;
|
||||
import lombok.experimental.Builder;
|
||||
|
||||
/**
|
||||
* A value object for an ALPS descriptor.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @since 0.15
|
||||
* @see http://alps.io/spec/#prop-descriptor
|
||||
*/
|
||||
@Value
|
||||
@Builder
|
||||
public class Descriptor {
|
||||
|
||||
private final String id, href, name;
|
||||
private final Doc doc;
|
||||
private final Type type;
|
||||
private final Ext ext;
|
||||
private final String rt;
|
||||
private final List<Descriptor> descriptors;
|
||||
}
|
||||
54
src/main/java/org/springframework/hateoas/alps/Doc.java
Normal file
54
src/main/java/org/springframework/hateoas/alps/Doc.java
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed 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 org.springframework.hateoas.alps;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Value;
|
||||
import lombok.experimental.Builder;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A value object for an ALPS doc element.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @since 0.15
|
||||
* @see http://alps.io/spec/#prop-doc
|
||||
*/
|
||||
@Value
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class Doc {
|
||||
|
||||
private final String href, value;
|
||||
private final Format format;
|
||||
|
||||
/**
|
||||
* Creates a new {@link Doc} instance with the given value and {@link Format}.
|
||||
*
|
||||
* @param value must not be {@literal null} or empty.
|
||||
* @param format must not be {@literal null}.
|
||||
*/
|
||||
public Doc(String value, Format format) {
|
||||
|
||||
Assert.hasText(value, "Value must not be null or empty!");
|
||||
Assert.notNull(format, "Format must not be null!");
|
||||
|
||||
this.href = null;
|
||||
this.value = value;
|
||||
this.format = format;
|
||||
}
|
||||
}
|
||||
34
src/main/java/org/springframework/hateoas/alps/Ext.java
Normal file
34
src/main/java/org/springframework/hateoas/alps/Ext.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed 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 org.springframework.hateoas.alps;
|
||||
|
||||
import lombok.Value;
|
||||
import lombok.experimental.Builder;
|
||||
|
||||
/**
|
||||
* A value object for an ALPS ext element.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @since 0.15
|
||||
* @see http://alps.io/spec/#prop-ext
|
||||
*/
|
||||
@Value
|
||||
@Builder
|
||||
public class Ext {
|
||||
|
||||
private final String href;
|
||||
private final String value;
|
||||
}
|
||||
38
src/main/java/org/springframework/hateoas/alps/Format.java
Normal file
38
src/main/java/org/springframework/hateoas/alps/Format.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed 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 org.springframework.hateoas.alps;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Enum for all ALPS doc formats.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @since 0.15
|
||||
* @see http://alps.io/spec/#prop-format
|
||||
*/
|
||||
public enum Format {
|
||||
|
||||
TEXT, HTML, ASCIIDOC;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Enum#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
return name().toLowerCase(Locale.US);
|
||||
}
|
||||
}
|
||||
38
src/main/java/org/springframework/hateoas/alps/Type.java
Normal file
38
src/main/java/org/springframework/hateoas/alps/Type.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed 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 org.springframework.hateoas.alps;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* An enum for ALPS descriptor types
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @since 0.15
|
||||
* @see http://alps.io/spec/#prop-type
|
||||
*/
|
||||
public enum Type {
|
||||
|
||||
SEMANTIC, SAFE, IDEMPOTENT, UNSAFE;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Enum#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
return name().toLowerCase(Locale.US);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user