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.netconf.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 final String uriParameterName;
21 UriParameters(final String uriParameterName) {
22 this.uriParameterName = uriParameterName;
26 public String toString() {
27 return uriParameterName;
31 public static WriterParameters parseWriterParameters(final UriInfo info) {
32 WriterParameters.WriterParametersBuilder wpBuilder = new WriterParameters.WriterParametersBuilder();
34 return wpBuilder.build();
37 String param = info.getQueryParameters(false).getFirst(UriParameters.DEPTH.toString());
38 if (!Strings.isNullOrEmpty(param) && !"unbounded".equals(param)) {
40 final int depth = Integer.valueOf(param);
42 throw new RestconfDocumentedException(new RestconfError(RestconfError.ErrorType.PROTOCOL, RestconfError.ErrorTag.INVALID_VALUE,
43 "Invalid depth parameter: " + depth, null,
44 "The depth parameter must be an integer > 1 or \"unbounded\""));
46 wpBuilder.setDepth(depth);
47 } catch (final NumberFormatException e) {
48 throw new RestconfDocumentedException(new RestconfError(RestconfError.ErrorType.PROTOCOL, RestconfError.ErrorTag.INVALID_VALUE,
49 "Invalid depth parameter: " + e.getMessage(), null,
50 "The depth parameter must be an integer > 1 or \"unbounded\""));
53 param = info.getQueryParameters(false).getFirst(UriParameters.PRETTY_PRINT.toString());
54 wpBuilder.setPrettyPrint("true".equals(param));
55 return wpBuilder.build();