Rework body formatting wiring
[netconf.git] / protocol / restconf-api / src / main / java / org / opendaylight / restconf / api / query / PrettyPrintParam.java
1 /*
2  * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.restconf.api.query;
9
10 import java.net.URI;
11 import org.eclipse.jdt.annotation.NonNull;
12
13 /**
14  * OpenDaylight extension parameter. When used as {@code odl-pretty-print=true}, it will instruct outbound XML/JSON
15  * formatters to make the output easier for humans to understand.
16  */
17 public final class PrettyPrintParam implements RestconfQueryParam<PrettyPrintParam> {
18     // API consistency: must not be confused with enum constants
19     @SuppressWarnings("checkstyle:ConstantName")
20     public static final String uriName = "odl-pretty-print";
21
22     public static final @NonNull PrettyPrintParam FALSE = new PrettyPrintParam(false);
23     public static final @NonNull PrettyPrintParam TRUE = new PrettyPrintParam(true);
24
25     private static final @NonNull URI CAPABILITY =
26         URI.create("urn:opendaylight:params:restconf:capability:pretty-print:1.0");
27
28     private final boolean value;
29
30     private PrettyPrintParam(final boolean value) {
31         this.value = value;
32     }
33
34     public static @NonNull PrettyPrintParam of(final boolean value) {
35         return value ? TRUE : FALSE;
36     }
37
38     public static @NonNull PrettyPrintParam forUriValue(final String uriValue) {
39         return switch (uriValue) {
40             case "false" -> FALSE;
41             case "true" -> TRUE;
42             default -> throw new IllegalArgumentException(
43                 "Invalid " + uriName + " value: Value can be 'false' or 'true', not '" + uriValue + "'");
44         };
45     }
46
47     @Override
48     public Class<PrettyPrintParam> javaClass() {
49         return PrettyPrintParam.class;
50     }
51
52     @Override
53     public String paramName() {
54         return uriName;
55     }
56
57     @Override
58     public String paramValue() {
59         return String.valueOf(value);
60     }
61
62     public boolean value() {
63         return value;
64     }
65
66     public static @NonNull URI capabilityUri() {
67         return CAPABILITY;
68     }
69 }