001package ca.uhn.fhir.rest.param;
002
003/*
004 * #%L
005 * HAPI FHIR - Core Library
006 * %%
007 * Copyright (C) 2014 - 2016 University Health Network
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 */
022import static org.apache.commons.lang3.StringUtils.defaultString;
023
024import org.apache.commons.lang3.StringUtils;
025import org.apache.commons.lang3.builder.ToStringBuilder;
026import org.apache.commons.lang3.builder.ToStringStyle;
027
028import ca.uhn.fhir.model.api.IQueryParameterType;
029import ca.uhn.fhir.model.primitive.StringDt;
030import ca.uhn.fhir.model.primitive.UriDt;
031
032public class UriParam extends BaseParam implements IQueryParameterType {
033
034        private String myValue;
035
036        public UriParam() {
037        }
038
039        public UriParam(String theValue) {
040                setValue(theValue);
041        }
042
043        @Override
044        String doGetQueryParameterQualifier() {
045                return null;
046        }
047
048        @Override
049        String doGetValueAsQueryToken() {
050                return ParameterUtil.escape(myValue);
051        }
052
053        @Override
054        void doSetValueAsQueryToken(String theQualifier, String theValue) {
055                myValue = ParameterUtil.unescape(theValue);
056        }
057
058        public String getValue() {
059                return myValue;
060        }
061
062        public StringDt getValueAsStringDt() {
063                return new StringDt(myValue);
064        }
065
066        public UriDt getValueAsUriDt() {
067                return new UriDt(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 void setValue(String theValue) {
079                myValue = theValue;
080        }
081
082        @Override
083        public String toString() {
084                ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
085                builder.append("value", getValue());
086                return builder.toString();
087        }
088
089}