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