2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ws.rest.params;
23 import jalview.util.MessageManager;
24 import jalview.ws.params.OptionI;
25 import jalview.ws.rest.InputType;
26 import jalview.ws.rest.NoValidInputDataException;
27 import jalview.ws.rest.RestJob;
29 import java.io.UnsupportedEncodingException;
30 import java.net.URLEncoder;
31 import java.util.ArrayList;
32 import java.util.List;
34 import org.apache.http.entity.mime.content.ContentBody;
35 import org.apache.http.entity.mime.content.StringBody;
38 * defines a constant value always provided as a parameter.
43 public class JobConstant extends InputType
55 public JobConstant(String param, String val)
57 // needs no data from the restJob
64 public ContentBody formatForInput(RestJob rj)
65 throws UnsupportedEncodingException, NoValidInputDataException
68 return new StringBody(value);
72 public List<String> getURLEncodedParameter()
74 ArrayList<String> prm = new ArrayList<String>();
76 if (value != null && value.length() > 0)
80 prm.add(URLEncoder.encode(value, "UTF-8"));
81 } catch (UnsupportedEncodingException ex)
83 throw new Error(MessageManager
84 .formatMessage("error.couldnt_encode_as_utf8", new String[]
93 public String getURLtokenPrefix()
99 public boolean configureFromURLtokenString(List<String> tokenstring,
100 StringBuffer warnings)
102 if (tokenstring.size() > 1)
105 "IMPLEMENTATION ERROR: Constant POST parameters cannot have more than one value.");
108 if (tokenstring.size() == 1)
110 value = tokenstring.get(0);
116 public boolean configureProperty(String tok, String val,
117 StringBuffer warnings)
120 "IMPLEMENTATION ERROR: No Properties to configure for a Constant parameter.");
125 public List<OptionI> getOptions()
127 // empty list - this parameter isn't configurable, so don't try.
128 return new ArrayList<OptionI>();