View Javadoc
1   package ca.uhn.fhir.rest.param;
2   
3   /*
4    * #%L
5    * HAPI FHIR - Core Library
6    * %%
7    * Copyright (C) 2014 - 2018 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  import static org.apache.commons.lang3.StringUtils.defaultString;
23  
24  import org.apache.commons.lang3.StringUtils;
25  import org.apache.commons.lang3.builder.ToStringBuilder;
26  import org.apache.commons.lang3.builder.ToStringStyle;
27  
28  import ca.uhn.fhir.context.FhirContext;
29  import ca.uhn.fhir.model.api.IQueryParameterType;
30  import ca.uhn.fhir.model.primitive.StringDt;
31  import ca.uhn.fhir.model.primitive.UriDt;
32  
33  public class UriParam extends BaseParam implements IQueryParameterType {
34  
35  	private UriParamQualifierEnum myQualifier;
36  	private String myValue;
37  
38  	/**
39  	 * Constructor
40  	 */
41  	public UriParam() {
42  		super();
43  	}
44  
45  	public UriParam(String theValue) {
46  		setValue(theValue);
47  	}
48  
49  	@Override
50  	String doGetQueryParameterQualifier() {
51  		return myQualifier != null ? myQualifier.getValue() : null;
52  	}
53  
54  	@Override
55  	String doGetValueAsQueryToken(FhirContext theContext) {
56  		return ParameterUtil.escape(myValue);
57  	}
58  
59  	@Override
60  	void doSetValueAsQueryToken(FhirContext theContext, String theParamName, String theQualifier, String theValue) {
61  		myQualifier = UriParamQualifierEnum.forValue(theQualifier);
62  		myValue = ParameterUtil.unescape(theValue);
63  	}
64  
65  	/**
66  	 * Gets the qualifier for this param (may be <code>null</code> and generally will be)
67  	 */
68  	public UriParamQualifierEnum getQualifier() {
69  		return myQualifier;
70  	}
71  
72  	public String getValue() {
73  		return myValue;
74  	}
75  
76  	public StringDt getValueAsStringDt() {
77  		return new StringDt(myValue);
78  	}
79  
80  	public UriDt getValueAsUriDt() {
81  		return new UriDt(myValue);
82  	}
83  
84  	public String getValueNotNull() {
85  		return defaultString(myValue);
86  	}
87  
88  	public boolean isEmpty() {
89  		return StringUtils.isEmpty(myValue);
90  	}
91  
92  	/**
93  	 * Sets the qualifier for this param (may be <code>null</code> and generally will be)
94  	 * 
95  	 * @return Returns a reference to <code>this</code> for easy method chanining
96  	 */
97  	public UriParam setQualifier(UriParamQualifierEnum theQualifier) {
98  		myQualifier = theQualifier;
99  		return this;
100 	}
101 
102 	/**
103 	 * Sets the value for this param
104 	 * 
105 	 * @return Returns a reference to <code>this</code> for easy method chanining
106 	 */
107 	public UriParam setValue(String theValue) {
108 		myValue = theValue;
109 		return this;
110 	}
111 
112 	@Override
113 	public String toString() {
114 		ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
115 		builder.append("value", getValue());
116 		return builder.toString();
117 	}
118 
119 }