View Javadoc
1   package ca.uhn.fhir.rest.gclient;
2   
3   import static org.apache.commons.lang3.StringUtils.isBlank;
4   
5   import java.util.Collection;
6   
7   import org.apache.commons.lang3.StringUtils;
8   
9   import ca.uhn.fhir.context.FhirContext;
10  import ca.uhn.fhir.rest.param.ParamPrefixEnum;
11  import ca.uhn.fhir.rest.param.ParameterUtil;
12  
13  /*
14   * #%L
15   * HAPI FHIR - Core Library
16   * %%
17   * Copyright (C) 2014 - 2018 University Health Network
18   * %%
19   * Licensed under the Apache License, Version 2.0 (the "License");
20   * you may not use this file except in compliance with the License.
21   * You may obtain a copy of the License at
22   * 
23   *      http://www.apache.org/licenses/LICENSE-2.0
24   * 
25   * Unless required by applicable law or agreed to in writing, software
26   * distributed under the License is distributed on an "AS IS" BASIS,
27   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28   * See the License for the specific language governing permissions and
29   * limitations under the License.
30   * #L%
31   */
32  
33  class StringCriterion<A extends IParam> implements ICriterion<A>, ICriterionInternal {
34  
35  	private String myValue;
36  	private String myName;
37  	private ParamPrefixEnum myPrefix;
38  
39  	public StringCriterion(String theName, String theValue) {
40  		myName=theName;
41  		myValue = ParameterUtil.escapeWithDefault(theValue);
42  	}
43  
44  	public StringCriterion(String theName, ParamPrefixEnum thePrefix, String theValue) {
45  		myName=theName;
46  		myPrefix = thePrefix;
47  		myValue = ParameterUtil.escapeWithDefault(theValue);
48  	}
49  
50  	public StringCriterion(String theName, Collection<String> theValue) {
51  		myName=theName;
52  		StringBuilder b = new StringBuilder();
53  		for (String next : theValue) {
54  			if (StringUtils.isBlank(next)) {
55  				continue;
56  			}
57  			if (b.length() > 0) {
58  				b.append(',');
59  			}
60  			b.append(ParameterUtil.escape(next));
61  		}
62  		myValue = b.toString();
63  	}
64  
65  	@Override
66  	public String getParameterName() {
67  		return myName;
68  	}
69  
70  	@Override
71  	public String getParameterValue(FhirContext theContext) {
72  		if (isBlank(myValue)) {
73  			return "";
74  		}
75  		if (myPrefix != null) {
76  			return myPrefix.getValue() + myValue;
77  		}
78  		return myValue;
79  	}
80  
81  }