16 |
17 |
18 |
--------------------------------------------------------------------------------
/jsonhome-examples/registry/src/main/resources/docs/readme.md:
--------------------------------------------------------------------------------
1 | README
2 | ======
3 |
4 | Lorem ipsum...
5 |
6 | ```json
7 | {
8 | "resources": {
9 | "http://example.org/rel/widgets": {
10 | "href": "/widgets/"
11 | },
12 | "http://example.org/rel/widget": {
13 | "href-template": "/widgets/{widget_id}",
14 | "href-vars": {
15 | "widget_id": "http://example.org/param/widget"
16 | },
17 | "hints": {
18 | "allow": ["GET", "PUT", "DELETE", "PATCH"],
19 | "representations": ["application/json"],
20 | "accept-patch": ["application/json-patch"],
21 | "accept-post": ["application/xml"],
22 | "accept-ranges": ["bytes"]
23 | }
24 | }
25 | }
26 | }
27 | ```
--------------------------------------------------------------------------------
/jsonhome-jersey/src/test/java/de/otto/jsonhome/fixtures/two/Bar.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.fixtures.two;
18 |
19 | import javax.ws.rs.Path;
20 |
21 | @Path("/bar")
22 | public class Bar {
23 | }
24 |
--------------------------------------------------------------------------------
/jsonhome-jersey/src/test/java/de/otto/jsonhome/fixtures/two/Foo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.fixtures.two;
18 |
19 | import javax.ws.rs.Path;
20 |
21 | @Path("/foo")
22 | public class Foo {
23 | }
24 |
--------------------------------------------------------------------------------
/jsonhome-spring/src/test/java/de/otto/jsonhome/fixtures/spring/TestAspectAnnotation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.fixtures.spring;
18 |
19 | import java.lang.annotation.*;
20 |
21 | @Inherited
22 | @Retention(RetentionPolicy.RUNTIME)
23 | @Target(ElementType.METHOD)
24 | public @interface TestAspectAnnotation {
25 |
26 | String value() default "";
27 |
28 | }
--------------------------------------------------------------------------------
/jsonhome-jersey/src/test/java/de/otto/jsonhome/fixtures/one/Bar.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.fixtures.one;
18 |
19 | import de.otto.jsonhome.annotation.Rel;
20 |
21 | import javax.ws.rs.GET;
22 | import javax.ws.rs.Path;
23 |
24 | @Path("/bar") @Rel("http://example.org/rel/barType")
25 | public class Bar {
26 |
27 | @GET
28 | public void bar() {};
29 | }
30 |
--------------------------------------------------------------------------------
/jsonhome-core/src/main/java/de/otto/jsonhome/model/Allow.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.model;
18 |
19 | /**
20 | * The possible values of allowed HTTP methods.
21 | *
22 | * @author Guido Steinacker
23 | * @since 07.10.12
24 | */
25 | public enum Allow {
26 | GET,
27 | PUT,
28 | POST,
29 | PATCH,
30 | DELETE,
31 | HEAD,
32 | OPTIONS
33 | }
34 |
--------------------------------------------------------------------------------
/jsonhome-client/src/main/java/de/otto/jsonhome/client/NotFoundException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.client;
18 |
19 | /**
20 | * @author Guido Steinacker
21 | * @since 27.10.12
22 | */
23 | public class NotFoundException extends HttpStatusException {
24 |
25 | public NotFoundException(final String message) {
26 | super(404, message);
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/jsonhome-jersey/src/test/java/de/otto/jsonhome/fixtures/one/Foo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.fixtures.one;
18 |
19 | import de.otto.jsonhome.annotation.Rel;
20 |
21 | import javax.ws.rs.POST;
22 | import javax.ws.rs.Path;
23 |
24 | @Path("/foo") @Rel("http://example.org/rel/fooType")
25 | public class Foo {
26 |
27 | @POST
28 | public void foo() {}
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/jsonhome-spring/src/main/resources/spring/jsonhome-freemarker-beans.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 | classpath:/jsonhome/freemarker
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/jsonhome-generator/src/main/java/de/otto/jsonhome/generator/JsonHomeSource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.generator;
18 |
19 | import de.otto.jsonhome.model.JsonHome;
20 |
21 | /**
22 | * A source for json-home documents.
23 | *
24 | * @author Guido Steinacker
25 | * @since 20.11.12
26 | */
27 | public interface JsonHomeSource {
28 |
29 | /**
30 | * Returns a JsonHome instance.
31 | *
32 | * @return JsonHome.
33 | */
34 | public JsonHome getJsonHome();
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/jsonhome-jersey/src/test/java/de/otto/jsonhome/JsonHomePropertiesTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome;
18 |
19 |
20 | import org.testng.annotations.Test;
21 |
22 | import java.util.Properties;
23 |
24 | import static org.testng.AssertJUnit.assertEquals;
25 |
26 | public class JsonHomePropertiesTest {
27 |
28 | @Test
29 | public void testReadingProperties() throws Exception {
30 | Properties properties = JsonHomeProperties.getProperties();
31 | assertEquals(3, properties.size());
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/jsonhome-jersey/src/test/java/de/otto/jsonhome/PATCH.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome;
18 |
19 | import javax.ws.rs.HttpMethod;
20 | import java.lang.annotation.ElementType;
21 | import java.lang.annotation.Retention;
22 | import java.lang.annotation.RetentionPolicy;
23 | import java.lang.annotation.Target;
24 |
25 | /**
26 | * Indicates that the annotated method responds to HTTP PATCH requests
27 | * @see javax.ws.rs.HttpMethod
28 | */
29 | @Target({ElementType.METHOD})
30 | @Retention(RetentionPolicy.RUNTIME)
31 | @HttpMethod("PATCH")
32 | public @interface PATCH {
33 | }
34 |
--------------------------------------------------------------------------------
/jsonhome-jersey/src/main/java/de/otto/jsonhome/generator/HttpMethods.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.generator;
18 |
19 | import javax.ws.rs.HttpMethod;
20 | import java.lang.annotation.Annotation;
21 |
22 | /**
23 | * @author Sebastian Schroeder
24 | * @since 09.12.2012
25 | */
26 | final class HttpMethods {
27 |
28 | private HttpMethods() {}
29 |
30 | public static boolean isHttpMethod(final Annotation annotation) {
31 | return annotation != null &&
32 | annotation.annotationType().getAnnotation(HttpMethod.class) != null;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/jsonhome-jersey/src/main/java/de/otto/jsonhome/resource/Responses.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.resource;
18 |
19 | import javax.ws.rs.core.Response;
20 |
21 | /**
22 | * @author Sebastian Schroeder
23 | * @since 28.12.2012
24 | */
25 | public final class Responses {
26 |
27 | private Responses() {}
28 |
29 | public static Response addCacheControlHeaders(Response.ResponseBuilder builder, int maxAge) {
30 | return builder.
31 | header("Vary", "Accept").
32 | header("Cache-Control", "max-age=" + maxAge).build();
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/jsonhome-client/src/main/java/de/otto/jsonhome/client/HttpStatusException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.client;
18 |
19 | /**
20 | * @author Guido Steinacker
21 | * @since 27.10.12
22 | */
23 | public class HttpStatusException extends JsonHomeClientException {
24 |
25 | private final int httpStatusCode;
26 |
27 | public HttpStatusException(final int httpStatusCode, final String message) {
28 | super(message);
29 | this.httpStatusCode = httpStatusCode;
30 | }
31 |
32 | public int getHttpStatusCode() {
33 | return httpStatusCode;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/jsonhome-registry/src/main/java/de/otto/jsonhome/registry/controller/RegistryJsonHomeSource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.registry.controller;
18 |
19 | import de.otto.jsonhome.model.JsonHome;
20 |
21 | /**
22 | * A source for json-home documents.
23 | *
24 | * @author Guido Steinacker
25 | * @since 20.11.12
26 | */
27 | public interface RegistryJsonHomeSource {
28 |
29 | /**
30 | * Returns a JsonHome instance for a specified environment.
31 | *
32 | * The default environment is "".
33 | */
34 | public JsonHome getJsonHome(String environment);
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/jsonhome-spring/src/test/java/de/otto/jsonhome/fixtures/spring/TestAspectAnnotationAspect.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.fixtures.spring;
18 |
19 | import org.aspectj.lang.JoinPoint;
20 | import org.aspectj.lang.annotation.Aspect;
21 | import org.aspectj.lang.annotation.Before;
22 | import org.springframework.stereotype.Component;
23 |
24 | @Aspect
25 | @Component
26 | public class TestAspectAnnotationAspect {
27 |
28 | @Before("@target(org.springframework.stereotype.Component) && @annotation(foo)")
29 | public void assertAuthorized(JoinPoint jp, TestAspectAnnotation foo) {
30 | }
31 |
32 | }
--------------------------------------------------------------------------------
/jsonhome-client/src/main/java/de/otto/jsonhome/client/JsonHomeClientException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.client;
18 |
19 | /**
20 | * @author Guido Steinacker
21 | * @since 27.10.12
22 | */
23 | public class JsonHomeClientException extends RuntimeException {
24 |
25 | public JsonHomeClientException(String message) {
26 | super(message);
27 | }
28 |
29 | public JsonHomeClientException(String message, Throwable cause) {
30 | super(message, cause);
31 | }
32 |
33 | public JsonHomeClientException(Throwable cause) {
34 | super(cause);
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/jsonhome-examples/hellojersey/src/main/resources/freemarker/jsonhome/resources.ftl:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 | json-home
7 |
8 |
9 |
10 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/jsonhome-core/src/main/java/de/otto/jsonhome/annotation/Rel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package de.otto.jsonhome.annotation;
17 |
18 | import java.lang.annotation.*;
19 |
20 | /**
21 | * Specifies the link-relation type of the resource offered by the annotated controller-class or method.
22 | *
23 | * All resources with a link-relation type will be part of the generated json-home document. Resources
24 | * without a link-relation type will NOT be added to the json-home.
25 | *
26 | * @author Guido Steinacker
27 | * @since 15.09.12
28 | */
29 | @Target({ElementType.METHOD, ElementType.TYPE})
30 | @Retention(RetentionPolicy.RUNTIME)
31 | @Documented
32 | public @interface Rel {
33 |
34 | /**
35 | * The URI uniquely identifying the link relation type in a given context.
36 | *
37 | *
38 | * @return URI of the link relation type
39 | */
40 | String value();
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/jsonhome-examples/hellojersey/src/main/java/de/otto/jsonhome/example/hellojersey/HelloWorldResource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.example.hellojersey;
18 |
19 | import de.otto.jsonhome.annotation.Doc;
20 | import de.otto.jsonhome.annotation.Rel;
21 |
22 | import javax.ws.rs.GET;
23 | import javax.ws.rs.Path;
24 | import javax.ws.rs.Produces;
25 | import javax.ws.rs.core.MediaType;
26 | import javax.ws.rs.core.Response;
27 |
28 | /**
29 | * @author Sebastian Schroeder
30 | * @since 11.12.2012
31 | */
32 | @Path("/")
33 | @Rel("/rel/hello-world-example")
34 | @Doc(rel = "/rel/hello-world-example",
35 | value = "The hello-world example resource"
36 | )
37 | public class HelloWorldResource {
38 |
39 | @GET
40 | @Produces(MediaType.TEXT_PLAIN)
41 | public Response helloWorld() {
42 | return Response.ok("Hello World!").build();
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/jsonhome-jersey/src/main/java/de/otto/jsonhome/JsonHomeProperties.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome;
18 |
19 | import java.io.IOException;
20 | import java.io.InputStream;
21 | import java.util.Properties;
22 |
23 | /**
24 | * @author Sebastian Schroeder
25 | * @since 15.12.2012
26 | */
27 | public final class JsonHomeProperties {
28 |
29 | private JsonHomeProperties() {}
30 |
31 | public static Properties getProperties() {
32 | final InputStream is = JsonHomeProperties.class.getResourceAsStream("jsonhome.properties");
33 | final Properties properties = new Properties();
34 | if (is == null) {
35 | return properties;
36 | } else {
37 | try {
38 | properties.load(is);
39 | is.close();
40 | } catch (IOException e) {}
41 | }
42 | return properties;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/jsonhome-examples/hellojersey/src/main/resources/freemarker/jsonhome/directresource.ftl:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 | json-home
7 |
8 |
9 |
47 |
48 |
--------------------------------------------------------------------------------
/jsonhome-examples/shop/src/main/java/de/otto/jsonhome/example/storefront/StorefrontController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package de.otto.jsonhome.example.storefront;
17 |
18 | import de.otto.jsonhome.annotation.Doc;
19 | import de.otto.jsonhome.annotation.Rel;
20 | import org.springframework.stereotype.Controller;
21 | import org.springframework.web.bind.annotation.RequestMapping;
22 |
23 |
24 | /**
25 | * Controller used to handle the /storefront resource of our example web-shop application.
26 | *
27 | * @author Guido Steinacker
28 | * @since 15.09.12
29 | */
30 | @Controller
31 | @RequestMapping(value = "/storefront")
32 | @Rel("/rel/storefront")
33 | @Doc(rel = "/rel/storefront",
34 | link = "docs/rel/storefront.md"
35 | )
36 | public class StorefrontController {
37 |
38 | @RequestMapping(produces = "text/html")
39 | public String getStorefront() {
40 | return "storefront";
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/jsonhome-jersey/src/test/java/de/otto/jsonhome/generator/HttpMethodsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.generator;
18 |
19 |
20 | import org.testng.annotations.Test;
21 |
22 | import javax.ws.rs.GET;
23 |
24 | import static org.testng.AssertJUnit.assertFalse;
25 | import static org.testng.AssertJUnit.assertTrue;
26 |
27 | public class HttpMethodsTest {
28 |
29 | class GetAnnotation {
30 |
31 | @GET
32 | public String getMethod() {
33 | return "";
34 | }
35 |
36 | }
37 |
38 | @Test
39 | public void testGetAnnotation() throws Exception {
40 | assertTrue(HttpMethods.isHttpMethod(GetAnnotation.class.
41 | getMethod("getMethod").getAnnotation(GET.class)));
42 | }
43 |
44 | @Test
45 | public void testNullAnnotation() throws Exception {
46 | assertFalse(HttpMethods.isHttpMethod(null));
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/jsonhome-core/src/main/java/de/otto/jsonhome/annotation/Docs.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package de.otto.jsonhome.annotation;
17 |
18 | import java.lang.annotation.*;
19 |
20 | /**
21 | * A container annotation used to add documentation of multiple link-relation types to a single controller.
22 | *
23 | * Usage:
24 | * {@code
25 | * @Documentation({
26 | * @Doc(rel="/rel/foo-type", value="A reference to a foo"),
27 | * @Doc(rel="/rel/bar-type", value="A reference to a bar")
28 | * })
29 | * }
30 | *
31 | *
32 | * @author Guido Steinacker
33 | * @since 15.09.12
34 | */
35 | @Target(ElementType.TYPE)
36 | @Retention(RetentionPolicy.RUNTIME)
37 | @Documented
38 | public @interface Docs {
39 |
40 | /**
41 | * One or more RelDoc annotations, describing link-relation types.
42 | *
43 | * @return array of RelDoc annotations.
44 | */
45 | Doc[] value();
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/jsonhome-core/src/main/java/de/otto/jsonhome/model/Precondition.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.model;
18 |
19 | /**
20 | * @author Guido Steinacker
21 | * @since 15.10.12
22 | */
23 | public enum Precondition {
24 |
25 | NONE(""), ETAG("etag"), LAST_MODIFIED("last-modified");
26 |
27 | private final String representation;
28 |
29 | private Precondition(final String representation) {
30 | this.representation = representation;
31 | }
32 |
33 | public static Precondition preconditionOf(final String value) {
34 | for (final Precondition precondition : Precondition.values()) {
35 | if (precondition.toString().equals(value)) {
36 | return precondition;
37 | }
38 | }
39 | throw new IllegalArgumentException("Unknown precondition " + value);
40 | }
41 |
42 | public String toString() {
43 | return representation;
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/jsonhome-core/src/main/java/de/otto/jsonhome/annotation/Href.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package de.otto.jsonhome.annotation;
17 |
18 | import java.lang.annotation.*;
19 |
20 | /**
21 | * Overrides the href of a direct resource link.
22 | *
23 | * Use this annotation if you have to override the behaviour of the generator in use (like, for example,
24 | * the SpringJsonHomeGenerator). Generally, you should not use this annotation, because
25 | * if you are specifying the wrong URI, the href link in your json-home will be resolvable by your application.
26 | *
27 | * @author Guido Steinacker
28 | * @since 15.09.12
29 | */
30 | @Target(ElementType.METHOD)
31 | @Retention(RetentionPolicy.RUNTIME)
32 | @Documented
33 | public @interface Href {
34 |
35 | /**
36 | * The fully qualified or relative URI uniquely identifying the href of a linked resource.
37 | *
38 | * @return URI of the linked resource
39 | */
40 | String value();
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/jsonhome-core/src/main/java/de/otto/jsonhome/annotation/Auth.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package de.otto.jsonhome.annotation;
17 |
18 | import java.lang.annotation.Documented;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.RetentionPolicy;
21 | import java.lang.annotation.Target;
22 |
23 | import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
24 |
25 | /**
26 | * Information about the authentication scheme of a HTTP resource described in the Hints.
27 | *
28 | * @author Guido Steinacker
29 | * @since 15.09.12
30 | */
31 | @Target({ANNOTATION_TYPE})
32 | @Retention(RetentionPolicy.RUNTIME)
33 | @Documented
34 | public @interface Auth {
35 |
36 | /**
37 | * The scheme used for authentication
38 | *
39 | * @return authenticat scheme
40 | */
41 | String scheme() default "";
42 |
43 |
44 | /**
45 | * The realms used for authentication
46 | *
47 | * @return authentication realms
48 | */
49 | String[] realms() default {};
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/jsonhome-examples/shop/src/main/java/de/otto/jsonhome/example/products/Product.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package de.otto.jsonhome.example.products;
17 |
18 | import java.util.UUID;
19 |
20 | /**
21 | * A product, having only a few attributes.
22 | *
23 | * @author Guido Steinacker
24 | * @since 29.09.12
25 | */
26 | public final class Product {
27 | private final long id;
28 | private final String title;
29 | private final String price;
30 | private final String etag;
31 |
32 | public Product(final long id, final String title, final String price) {
33 | this.id = id;
34 | this.title = title;
35 | this.price = price;
36 | this.etag = UUID.randomUUID().toString();
37 | }
38 |
39 | public long getId() {
40 | return id;
41 | }
42 |
43 | public String getLink() {
44 | return "products/" + id;
45 | }
46 |
47 | public String getTitle() {
48 | return title;
49 | }
50 |
51 | public String getPrice() {
52 | return price;
53 | }
54 |
55 | public String getETag() {
56 | return etag;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/jsonhome-spring/src/test/resources/testSpringContext.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 | http://example.org
13 | http://specs.example.org
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/jsonhome-core/src/main/java/de/otto/jsonhome/model/Status.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.model;
18 |
19 | /**
20 | * Status of the linked resource.
21 | *
22 | * @author Guido Steinacker
23 | * @since 15.10.12
24 | */
25 | public enum Status {
26 | /** The resource is available. */
27 | OK,
28 | /** The resource is deprecated and should not be used anymore. */
29 | DEPRECATED,
30 | /** The resource is gone, request will be answered as HTTP 410 gone. */
31 | GONE;
32 |
33 | /**
34 | * Merges this status with another one.
35 | *
36 | * This is primarily used internally.
37 | *
38 | * @param other the other status.
39 | * @return Status
40 | */
41 | public Status mergeWith(final Status other) {
42 | return this.ordinal() > other.ordinal() ? this : other;
43 | }
44 |
45 | /**
46 | * {@inheritDoc}
47 | *
48 | * Returns a lower-case representation of the status.
49 | *
50 | * @return ok, deprecated or gone.
51 | */
52 | public String toString() {
53 | return name().toLowerCase();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/jsonhome-generator/src/main/resources/jsonhome/freemarker/directresource.ftl:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 | json-home
8 |
9 |
10 |
52 |
53 |
--------------------------------------------------------------------------------
/jsonhome-core/src/main/java/de/otto/jsonhome/converter/JsonHomeMediaType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.converter;
18 |
19 | import java.util.EnumSet;
20 |
21 | /**
22 | * @author Guido Steinacker
23 | * @since 25.11.12
24 | */
25 | public enum JsonHomeMediaType {
26 |
27 | APPLICATION_JSON("application/json"),
28 | APPLICATION_JSONHOME("application/json-home");
29 |
30 | public static JsonHomeMediaType mediaTypeFrom(final String value) {
31 | for (final JsonHomeMediaType mediaType : EnumSet.allOf(JsonHomeMediaType.class)) {
32 | if (mediaType.toString().equals(value)) {
33 | return mediaType;
34 | }
35 | }
36 | throw new IllegalArgumentException("Unknown media type '" + value + "'.");
37 | }
38 |
39 | private final String value;
40 |
41 | private JsonHomeMediaType(final String value) {
42 | this.value = value;
43 | }
44 |
45 | /**
46 | * Returns the value of the media type: application/json, application/json-home.
47 | * @return value
48 | */
49 | @Override
50 | public String toString() {
51 | return value;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/jsonhome-examples/helloworld/src/main/java/de/otto/jsonhome/example/helloworld/HelloController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package de.otto.jsonhome.example.helloworld;
17 |
18 | import de.otto.jsonhome.annotation.Doc;
19 | import de.otto.jsonhome.annotation.Rel;
20 | import org.springframework.stereotype.Controller;
21 | import org.springframework.web.bind.annotation.RequestMapping;
22 | import org.springframework.web.bind.annotation.ResponseBody;
23 |
24 |
25 | /**
26 | * Controller used to serve the hello-world resource.
27 | *
28 | * @author Guido Steinacker
29 | * @since 15.09.12
30 | */
31 | @Controller
32 | @Rel("/rel/hello-world-example")
33 | @Doc(rel = "/rel/hello-world-example",
34 | value = "The hello-world example resource"
35 | )
36 | public class HelloController {
37 |
38 | @RequestMapping(value = "/", produces = {"text/html", "*/*"})
39 | @ResponseBody
40 | public String getHelloWorld() {
41 | return "
";
42 | }
43 |
44 | @RequestMapping(value = "/", produces = "text/plain")
45 | @ResponseBody
46 | public String getHelloWorldAsPlainText() {
47 | return "Hello World!";
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/jsonhome-jersey/src/main/java/de/otto/jsonhome/resource/JerseyJsonHomeSource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.resource;
18 |
19 | import de.otto.jsonhome.generator.JsonHomeGenerator;
20 | import de.otto.jsonhome.generator.JsonHomeSource;
21 | import de.otto.jsonhome.model.JsonHome;
22 | import de.otto.jsonhome.resource.scanner.AnnotationScanner;
23 |
24 | import java.util.Collection;
25 |
26 | /**
27 | * @author Sebastian Schroeder
28 | * @since 11.12.2012
29 | */
30 | public final class JerseyJsonHomeSource implements JsonHomeSource {
31 |
32 | private final JsonHome jsonHome;
33 |
34 | public JerseyJsonHomeSource(JsonHomeGenerator jsonHomeGenerator, AnnotationScanner annotationScanner) {
35 | jsonHome = jsonHomeGenerator.with(annotationScanner.scanClasses()).generate();
36 | }
37 |
38 | public JerseyJsonHomeSource(JsonHomeGenerator jsonHomeGenerator, Collection> classes) {
39 | jsonHome = jsonHomeGenerator.with(classes).generate();
40 | }
41 |
42 | /**
43 | * Returns a JsonHome instance.
44 | *
45 | * @return JsonHome.
46 | */
47 | @Override
48 | public JsonHome getJsonHome() {
49 | return jsonHome;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/jsonhome-registry/src/test/java/de/otto/jsonhome/registry/store/LinkTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.registry.store;
18 |
19 | import org.testng.annotations.Test;
20 |
21 | import java.net.URI;
22 |
23 | import static org.testng.Assert.assertEquals;
24 |
25 | /**
26 | * @author Guido Steinacker
27 | * @since 18.11.12
28 | */
29 | public class LinkTest {
30 |
31 | public static final String TITLE = "foo";
32 | public static final URI EXAMPLE_DOT_ORG = URI.create("http://example.org");
33 |
34 | @Test()
35 | public void shouldSetTitleToEmptyStringIfTitleIsNull() {
36 | final Link link = new Link(EXAMPLE_DOT_ORG, null);
37 | assertEquals(link.getTitle(), "");
38 | }
39 |
40 | @Test
41 | public void shouldAcceptEmptyTitle() {
42 | final Link link = new Link(EXAMPLE_DOT_ORG, "");
43 | assertEquals(link.getTitle(), "");
44 | }
45 |
46 | @Test(expectedExceptions = NullPointerException.class)
47 | public void shouldThrowExceptionIfHrefIsNull() {
48 | new Link(null, TITLE);
49 | }
50 |
51 | @Test(expectedExceptions = IllegalArgumentException.class)
52 | public void shouldThrowExceptionIfHrefIsNotAbsolute() {
53 | new Link(URI.create("/foo"), TITLE);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/jsonhome-spring/src/main/java/de/otto/jsonhome/generator/SpringHrefVarsGenerator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.generator;
18 |
19 | import org.springframework.web.bind.annotation.PathVariable;
20 | import org.springframework.web.bind.annotation.RequestParam;
21 |
22 | import java.net.URI;
23 |
24 | /**
25 | * A HrefVarsGenerator used to generate HrefVars for Spring-based applications.
26 | */
27 | public class SpringHrefVarsGenerator extends HrefVarsGenerator {
28 |
29 | /**
30 | * Creates a SpringHrefVarsGenerator.
31 | *
32 | * @param relationTypeBaseUri the base URI used to create absolute relation-type URIs.
33 | * @param docRootDir the root classpath directory containing Markdown documents. May be null.
34 | */
35 | public SpringHrefVarsGenerator(final URI relationTypeBaseUri, final String docRootDir) {
36 | super(relationTypeBaseUri, docRootDir);
37 | }
38 |
39 | @Override
40 | protected boolean hasRequestParam(final ParameterInfo parameterInfo) {
41 | return parameterInfo.hasAnnotation(RequestParam.class);
42 | }
43 |
44 | @Override
45 | protected boolean hasPathVariable(final ParameterInfo parameterInfo) {
46 | return parameterInfo.hasAnnotation(PathVariable.class);
47 | }
48 |
49 | }
--------------------------------------------------------------------------------
/jsonhome-core/src/main/java/de/otto/jsonhome/annotation/HrefTemplate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package de.otto.jsonhome.annotation;
17 |
18 | import java.lang.annotation.*;
19 |
20 | /**
21 | * Overrides the href-template and href-vars of a templated resource link.
22 | *
23 | * Use this annotation if you have to override the behaviour of the generator in use (like, for example,
24 | * the SpringJsonHomeGenerator). Use this annotation with care, because
25 | * if you are specifying the wrong URI, the href link in your json-home will be resolvable by your application.
26 | *
27 | * @author Guido Steinacker
28 | * @since 15.09.12
29 | */
30 | @Target(ElementType.METHOD)
31 | @Retention(RetentionPolicy.RUNTIME)
32 | @Documented
33 | public @interface HrefTemplate {
34 |
35 | /**
36 | * The templated URI uniquely identifying the href-template of a linked resource.
37 | *
38 | * The href-vars are parsed from the specified template.
39 | *
40 | * Because it is not possible to associate {@link Doc documentation} with the variables used in the
41 | * href-template, you should consider adding some appropriate documentation to the resource link itself.
42 | *
43 | * @return URI of the linked resource
44 | */
45 | String value();
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/jsonhome-jersey/src/main/java/de/otto/jsonhome/generator/JerseyHrefVarsGenerator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.generator;
18 |
19 | import javax.ws.rs.PathParam;
20 | import javax.ws.rs.QueryParam;
21 | import java.net.URI;
22 |
23 | /**
24 | * @author Sebastian Schroeder
25 | * @since 09.12.2012
26 | */
27 | public final class JerseyHrefVarsGenerator extends HrefVarsGenerator {
28 |
29 | public JerseyHrefVarsGenerator(final URI relationTypeBaseUri, final String docRootDir) {
30 | super(relationTypeBaseUri, docRootDir);
31 | }
32 |
33 | /**
34 | * @param parameterInfo information about a method parameter.
35 | * @return true if the parameterInfo is describing a request parameter, false otherwise.
36 | */
37 | @Override
38 | protected boolean hasRequestParam(ParameterInfo parameterInfo) {
39 | return parameterInfo.hasAnnotation(QueryParam.class);
40 | }
41 |
42 | /**
43 | * @param parameterInfo information about a method parameter.
44 | * @return true if the parameterInfo is describing a path variable, false otherwise.
45 | */
46 | @Override
47 | protected boolean hasPathVariable(ParameterInfo parameterInfo) {
48 | return parameterInfo.hasAnnotation(PathParam.class);
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/jsonhome-registry/src/main/java/de/otto/jsonhome/registry/store/InMemoryRegistryRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.registry.store;
18 |
19 | import java.util.Set;
20 | import java.util.concurrent.ConcurrentHashMap;
21 | import java.util.concurrent.ConcurrentMap;
22 |
23 | /**
24 | * In-memory implementation of the {@link RegistryRepository} interface.
25 | */
26 | public class InMemoryRegistryRepository implements RegistryRepository {
27 |
28 | public final ConcurrentMap registry = new ConcurrentHashMap<>();
29 |
30 | /**
31 | * {@inheritDoc}
32 | */
33 | @Override
34 | public void createOrUpdate(Registry registry) {
35 | this.registry.put(registry.getName(), registry);
36 | }
37 |
38 | /**
39 | * {@inheritDoc}
40 | */
41 | @Override
42 | public void delete(final String name) {
43 | registry.remove(name);
44 | }
45 |
46 | /**
47 | * {@inheritDoc}
48 | */
49 | @Override
50 | public Set getKnownNames() {
51 | return registry.keySet();
52 | }
53 |
54 | @Override
55 | public Registry get(final String registryName) {
56 | return registry.get(registryName);
57 | }
58 |
59 | /**
60 | * {@inheritDoc}
61 | */
62 | @Override
63 | public void clear() {
64 | registry.clear();
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/jsonhome-registry/src/main/java/de/otto/jsonhome/registry/store/RegistryRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.registry.store;
18 |
19 | import java.util.Set;
20 |
21 | /**
22 | * A repository used to store {@link Registry}.
23 | *
24 | * The registries are identified by their names.
25 | *
26 | * @author Guido Steinacker
27 | * @since 14.11.12
28 | */
29 | public interface RegistryRepository {
30 |
31 | /**
32 | * Creates or updates Registry.
33 | *
34 | * An existing Registry instance with the same name as the Registry provided as parameter will be be replaced.
35 | *
36 | * @param registry the Registry instance.
37 | */
38 | public void createOrUpdate(Registry registry);
39 |
40 | /**
41 | * Deletes a {@link Registry} instance identified by it's name.
42 | *
43 | * @param name the name of the deleted registry.
44 | */
45 | public void delete(String name);
46 |
47 | /**
48 | * Returns the names of all known Registry instances.
49 | *
50 | * @return registry names.
51 | */
52 | public Set getKnownNames();
53 |
54 | /**
55 | * Returns the registry with the specifed name, or null if no such registry exists.
56 | */
57 | public Registry get(String registryName);
58 |
59 | /**
60 | * Removes all Registry from the repository.
61 | */
62 | void clear();
63 | }
64 |
--------------------------------------------------------------------------------
/jsonhome-jersey/src/test/java/de/otto/jsonhome/resource/scanner/AnnotationScannerTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.resource.scanner;
18 |
19 | import org.testng.annotations.Test;
20 |
21 | import java.util.Arrays;
22 | import java.util.Collection;
23 | import java.util.HashSet;
24 |
25 | import static org.testng.AssertJUnit.assertEquals;
26 | import static org.testng.AssertJUnit.assertTrue;
27 |
28 | public class AnnotationScannerTest {
29 |
30 | @Test
31 | public void testScanningOnePackage() throws Exception {
32 | Collection> classes = new AnnotationScanner(new HashSet(
33 | Arrays.asList("de.otto.jsonhome.fixtures.one"))).scanClasses();
34 | assertEquals(2, classes.size());
35 | }
36 |
37 | @Test
38 | public void testScanningTwoPackages() throws Exception {
39 | Collection> classes = new AnnotationScanner(new HashSet(
40 | Arrays. asList("de.otto.jsonhome.fixtures.one", "de.otto.jsonhome.fixtures.two"))).scanClasses();
41 | assertEquals(4, classes.size());
42 | }
43 |
44 | @Test
45 | public void testScanningNotExistingPackage() throws Exception {
46 | Collection> classes = new AnnotationScanner(new HashSet(
47 | Arrays. asList("de.otto.jsonhome.fixtures.none"))).scanClasses();
48 | assertTrue(classes.isEmpty());
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/jsonhome-spring/src/test/java/de/otto/jsonhome/controller/DocControllerTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.controller;
18 |
19 | import org.springframework.core.io.ClassPathResource;
20 | import org.springframework.mock.web.MockHttpServletRequest;
21 | import org.testng.annotations.Test;
22 |
23 | import java.io.IOException;
24 |
25 | import static org.testng.Assert.assertTrue;
26 |
27 | /**
28 | * @author Guido Steinacker
29 | * @since 17.02.13
30 | */
31 | public class DocControllerTest {
32 |
33 | @Test
34 | public void shouldReturnMarkdown() throws IOException {
35 | // given
36 | final DocController controller = new DocController();
37 | controller.setRootDir(new ClassPathResource("/test/**"));
38 | // when
39 | final String markdown = controller.getMarkdown(
40 | new MockHttpServletRequest("GET", "/test/doc/test.md"));
41 | // then
42 | assertTrue(markdown.startsWith("Test"));
43 | }
44 |
45 | @Test
46 | public void shouldReturnMarkdownAsHtml() throws IOException {
47 | // given
48 | final DocController controller = new DocController();
49 | controller.setRootDir(new ClassPathResource("/test/**"));
50 | // when
51 | final String markdown = controller.getMarkdownAsHtml(
52 | new MockHttpServletRequest("GET", "/test/doc/test.md"));
53 | // then
54 | assertTrue(markdown.startsWith("
Test
"));
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/jsonhome-generator/build.gradle:
--------------------------------------------------------------------------------
1 |
2 | dependencies {
3 | compile project(':jsonhome-core')
4 | compile 'org.markdown:markdown4j:2.2'
5 | compile 'org.springframework:spring-core:4.1.7.RELEASE'
6 | testCompile 'org.testng:testng:6.9.6'
7 | }
8 |
9 | artifacts {
10 | archives jar
11 | archives javadocJar
12 | archives sourcesJar
13 | }
14 |
15 | signing {
16 | sign configurations.archives
17 | }
18 |
19 | uploadArchives {
20 | repositories {
21 | mavenDeployer {
22 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
23 |
24 | repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
25 | authentication(userName: sonatypeUsername, password: sonatypePassword)
26 | }
27 | snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
28 | authentication(userName: sonatypeUsername, password: sonatypePassword)
29 | }
30 | pom.project {
31 | name 'jsonhome-generator'
32 | packaging 'jar'
33 | description 'Generator library of the jsonhome project.'
34 | url 'http://github.com/otto-de/jsonhome'
35 |
36 | scm {
37 | url 'scm:git@github.com:otto-de/jsonhome.git'
38 | connection 'scm:git@github.com:otto-de/jsonhome.git'
39 | developerConnection 'scm:git@github.com:otto-de/jsonhome.git'
40 | }
41 |
42 | licenses {
43 | license {
44 | name 'The Apache Software License, Version 2.0'
45 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
46 | distribution 'repo'
47 | }
48 | }
49 |
50 | developers {
51 | developer {
52 | id 'gsteinacker'
53 | name 'Guido Steinacker'
54 | }
55 | }
56 | }
57 | }
58 | }
59 | }
--------------------------------------------------------------------------------
/jsonhome-core/src/main/java/de/otto/jsonhome/model/JsonHomeBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package de.otto.jsonhome.model;
17 |
18 | import java.net.URI;
19 | import java.util.Collection;
20 | import java.util.HashMap;
21 | import java.util.Map;
22 |
23 | /**
24 | * A builder used to build JsonHome instances.
25 | */
26 | public final class JsonHomeBuilder {
27 |
28 | private final Map resources = new HashMap();
29 |
30 | private JsonHomeBuilder() {
31 | }
32 |
33 | public static JsonHomeBuilder jsonHomeBuilder() {
34 | return new JsonHomeBuilder();
35 | }
36 |
37 | public static JsonHomeBuilder copyFrom(final JsonHome jsonHome) {
38 | return jsonHomeBuilder().mergeWith(jsonHome);
39 | }
40 |
41 | public JsonHomeBuilder mergeWith(final JsonHome jsonHome) {
42 | resources.putAll(jsonHome.getResources());
43 | return this;
44 | }
45 |
46 | public JsonHomeBuilder addResource(final ResourceLink resource) {
47 | this.resources.put(resource.getLinkRelationType(), resource);
48 | return this;
49 | }
50 |
51 | public JsonHomeBuilder addResources(final Collection resources) {
52 | for (final ResourceLink resource : resources) {
53 | this.resources.put(resource.getLinkRelationType(), resource);
54 | }
55 | return this;
56 | }
57 |
58 | public JsonHome build() {
59 | return JsonHome.jsonHome(resources.values());
60 | }
61 | }
--------------------------------------------------------------------------------
/jsonhome-client/build.gradle:
--------------------------------------------------------------------------------
1 |
2 | dependencies {
3 | compile project(':jsonhome-core')
4 | compile 'org.apache.httpcomponents:httpclient:4.5'
5 | compile 'org.apache.httpcomponents:httpclient-cache:4.5'
6 | testCompile 'org.testng:testng:6.9.6'
7 | }
8 |
9 | artifacts {
10 | archives jar
11 | archives javadocJar
12 | archives sourcesJar
13 | }
14 |
15 | signing {
16 | sign configurations.archives
17 | }
18 |
19 | uploadArchives {
20 | repositories {
21 | mavenDeployer {
22 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
23 |
24 | repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
25 | authentication(userName: sonatypeUsername, password: sonatypePassword)
26 | }
27 | snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
28 | authentication(userName: sonatypeUsername, password: sonatypePassword)
29 | }
30 | pom.project {
31 | name 'jsonhome-client'
32 | packaging 'jar'
33 | description 'Generator library of the jsonhome project.'
34 | url 'http://github.com/otto-de/jsonhome'
35 |
36 | scm {
37 | url 'scm:git@github.com:otto-de/jsonhome.git'
38 | connection 'scm:git@github.com:otto-de/jsonhome.git'
39 | developerConnection 'scm:git@github.com:otto-de/jsonhome.git'
40 | }
41 |
42 | licenses {
43 | license {
44 | name 'The Apache Software License, Version 2.0'
45 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
46 | distribution 'repo'
47 | }
48 | }
49 |
50 | developers {
51 | developer {
52 | id 'gsteinacker'
53 | name 'Guido Steinacker'
54 | }
55 | }
56 | }
57 | }
58 | }
59 | }
--------------------------------------------------------------------------------
/jsonhome-registry/src/test/java/de/otto/jsonhome/registry/controller/RegistryConverterTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.registry.controller;
18 |
19 | import de.otto.jsonhome.registry.store.Registry;
20 | import org.testng.annotations.Test;
21 |
22 | import java.util.Map;
23 |
24 | import static de.otto.jsonhome.registry.controller.RegistryConverter.jsonToRegistry;
25 | import static de.otto.jsonhome.registry.controller.RegistryConverter.registryToJson;
26 | import static de.otto.jsonhome.registry.fixture.RegistryFixture.doubleEntryRegistry;
27 | import static de.otto.jsonhome.registry.fixture.RegistryFixture.registryLiveWithSingleLinkTo;
28 | import static java.net.URI.create;
29 | import static org.testng.Assert.assertEquals;
30 |
31 | /**
32 | * @author Guido Steinacker
33 | * @since 09.02.13
34 | */
35 | public class RegistryConverterTest {
36 |
37 | @Test
38 | public void shouldConvertRegistryWithSingleEntry() {
39 | // given:
40 | final Map linksMap = registryLiveWithSingleLinkTo("foo");
41 | // when:
42 | final Registry registry = jsonToRegistry(linksMap);
43 | // then:
44 | assertEquals(registryToJson(create("http://example.org"), registry), linksMap);
45 | }
46 |
47 | @Test
48 | public void shouldConvertRegistryWithMultipleEntries() {
49 | // given:
50 | final Map linksMap = doubleEntryRegistry();
51 | // when:
52 | final Registry registry = jsonToRegistry(linksMap);
53 | // then:
54 | assertEquals(registryToJson(create("http://example.org"), registry), linksMap);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/jsonhome-registry/src/main/java/de/otto/jsonhome/registry/controller/LinkConverter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Guido Steinacker
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.otto.jsonhome.registry.controller;
18 |
19 | import de.otto.jsonhome.registry.store.Link;
20 |
21 | import java.util.Collection;
22 | import java.util.LinkedHashMap;
23 | import java.util.List;
24 | import java.util.Map;
25 |
26 | import static java.net.URI.create;
27 | import static java.util.stream.Collectors.toList;
28 |
29 | /**
30 | * @author Guido Steinacker
31 | * @since 11.02.13
32 | */
33 | public class LinkConverter {
34 |
35 | private LinkConverter() {}
36 |
37 | public static Map linkToJson(final Link link) {
38 | final Map json = new LinkedHashMap<>();
39 | json.put("href", link.getHref().toString());
40 | if (!link.getTitle().isEmpty()) {
41 | json.put("title", link.getTitle());
42 | }
43 | return json;
44 | }
45 |
46 | public static Link jsonToLink(final Map json) {
47 | return new Link(
48 | create(json.get("href")),
49 | json.get("title")
50 | );
51 | }
52 |
53 | public static List