001package ca.uhn.fhir.rest.param; 002 003/* 004 * #%L 005 * HAPI FHIR - Core Library 006 * %% 007 * Copyright (C) 2014 - 2021 Smile CDR, Inc. 008 * %% 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 * #L% 021 */ 022 023import ca.uhn.fhir.context.FhirContext; 024import ca.uhn.fhir.model.primitive.UriDt; 025import org.apache.commons.lang3.StringUtils; 026import org.apache.commons.lang3.builder.ToStringBuilder; 027import org.apache.commons.lang3.builder.ToStringStyle; 028 029import static org.apache.commons.lang3.StringUtils.defaultString; 030 031public class SpecialParam extends BaseParam /*implements IQueryParameterType*/ { 032 033 private String myValue; 034 035 /** 036 * Constructor 037 */ 038 public SpecialParam() { 039 super(); 040 } 041 042 @Override 043 String doGetQueryParameterQualifier() { 044 return null; 045 } 046 047 /** 048 * {@inheritDoc} 049 */ 050 @Override 051 String doGetValueAsQueryToken(FhirContext theContext) { 052 return ParameterUtil.escape(getValue()); 053 } 054 055 /** 056 * {@inheritDoc} 057 */ 058 @Override 059 void doSetValueAsQueryToken(FhirContext theContext, String theParamName, String theQualifier, String theParameter) { 060 setValue(ParameterUtil.unescape(theParameter)); 061 } 062 063 /** 064 * Returns the value for the token (generally the value to the right of the 065 * vertical bar on the URL) 066 */ 067 public String getValue() { 068 return myValue; 069 } 070 071 public String getValueNotNull() { 072 return defaultString(myValue); 073 } 074 075 public boolean isEmpty() { 076 return StringUtils.isEmpty(myValue); 077 } 078 079 080 public SpecialParam setValue(String theValue) { 081 myValue = theValue; 082 return this; 083 } 084 085 @Override 086 public String toString() { 087 ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); 088 builder.append("value", getValue()); 089 if (getMissing() != null) { 090 builder.append(":missing", getMissing()); 091 } 092 return builder.toString(); 093 } 094 095 private static String toSystemValue(UriDt theSystem) { 096 return theSystem.getValueAsString(); 097 } 098 099}