2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.sal.restconf.impl;
10 import com.google.common.base.Strings;
11 import javax.ws.rs.core.UriInfo;
13 public class QueryParametersParser {
15 private enum UriParameters {
16 PRETTY_PRINT("prettyPrint"),
19 private String uriParameterName;
21 UriParameters(final String uriParameterName) {
22 this.uriParameterName = uriParameterName;
26 public String toString() {
27 return uriParameterName;
31 public static WriterParameters parseKnownWriterParameters(final UriInfo info) {
34 String param = info.getQueryParameters(false).getFirst(UriParameters.DEPTH.toString());
35 if (Strings.isNullOrEmpty(param) || "unbounded".equals(param)) {
36 depth = Integer.MAX_VALUE;
39 depth = Integer.valueOf(param);
41 throw new RestconfDocumentedException(new RestconfError(RestconfError.ErrorType.PROTOCOL, RestconfError.ErrorTag.INVALID_VALUE,
42 "Invalid depth parameter: " + depth, null,
43 "The depth parameter must be an integer > 1 or \"unbounded\""));
45 } catch (final NumberFormatException e) {
46 throw new RestconfDocumentedException(new RestconfError(RestconfError.ErrorType.PROTOCOL, RestconfError.ErrorTag.INVALID_VALUE,
47 "Invalid depth parameter: " + e.getMessage(), null,
48 "The depth parameter must be an integer > 1 or \"unbounded\""));
51 param = info.getQueryParameters(false).getFirst(UriParameters.PRETTY_PRINT.toString());
52 prettyPrint = "true".equals(param);
53 return new WriterParameters(prettyPrint, depth);