Refine search
/** * Creates a new parameter. Can be overridden. * * @param name * The parameter name. * @param value * The parameter value or null. * @return The new parameter. */ protected Parameter createParameter(String name, String value) { return new Parameter(name, value); }
/** * Encodes the parameter using the standard URI encoding mechanism. * * @param characterSet * The supported character encoding. * @return The encoded string. * @throws IOException */ public String encode(CharacterSet characterSet) throws IOException { final StringBuilder sb = new StringBuilder(); encode(sb, characterSet); return sb.toString(); }
Parameter param; Object currentValue = null; for (final Iterator<E> iter = iterator(); iter.hasNext();) { param = iter.next(); if (params.containsKey(param.getName())) { currentValue = params.get(param.getName()); params.put(param.getName(), values); if (param.getValue() == null) { values.add(Series.EMPTY_VALUE); } else { values.add(param.getValue()); if (param.getValue() == null) { params.put(param.getName(), Series.EMPTY_VALUE); } else { params.put(param.getName(), param.getValue());
/** * Returns the list of request headers. * * @return The list of request headers. */ @Override @SuppressWarnings("unchecked") public Series<Parameter> getRequestHeaders() { if (this.requestHeaders == null) { this.requestHeaders = new Form(); // Copy the headers from the request object String headerName; String headerValue; for (final Enumeration<String> names = getRequest() .getHeaderNames(); names.hasMoreElements();) { headerName = names.nextElement(); for (final Enumeration<String> values = getRequest() .getHeaders(headerName); values.hasMoreElements();) { headerValue = values.nextElement(); this.requestHeaders.add(new Parameter(headerName, headerValue)); } } } return this.requestHeaders; }
public static boolean getParameterAsBoolean(Parameter parameter, boolean fallback) { if (parameter == null) { return fallback; } return Boolean.parseBoolean(parameter.getValue()); }
/** * Extract the media parameters. Only leave as the quality parameter if * found. Modifies the parameters list. * * @param parameters * All the preference parameters. * @return The media parameters. */ protected Series<Parameter> extractMediaParams(Series<Parameter> parameters) { Series<Parameter> result = null; boolean qualityFound = false; Parameter param = null; if (parameters != null) { result = new Series<Parameter>(Parameter.class); for (final Iterator<Parameter> iter = parameters.iterator(); !qualityFound && iter.hasNext();) { param = iter.next(); if (param.getName().equals("q")) { qualityFound = true; } else { iter.remove(); result.add(param); } } } return result; }
/** * Test method for {@link org.restlet.security.Realm#setParameters(org.restlet.util.Series)}. */ @Test public final void testSetParameters() { Assert.assertEquals(0, this.testRealm.getParameters().size()); final List<Parameter> list = new ArrayList<Parameter>(1); list.add(new Parameter("testName", "123")); this.testRealm.setParameters(new Series<Parameter>(Parameter.class, list)); Assert.assertEquals(1, this.testRealm.getParameters().size()); final Parameter parameter = this.testRealm.getParameters().get(0); Assert.assertEquals("testName", parameter.getName()); Assert.assertEquals("123", parameter.getValue()); }
for(Parameter parameter : getContext().getParameters()) this.log.trace("context parameter: <{}> <{}>", parameter.getName(), parameter.getValue()); this.getContext().getParameters().getFirstValue("oasproperties", true, "oas"); this.log.info("Setting up property util using: {}", propertyBundleName); this.propertyUtil = new PropertyUtil(propertyBundleName);
/** * Returns a list of all the values associated to the parameter name. * * @param name * The parameter name. * @param ignoreCase * Indicates if the name comparison is case sensitive. * @return The list of values. */ public Series<E> subList(String name, boolean ignoreCase) { final Series<E> result = createSeries(null); for (final E param : this) { if (equals(param.getName(), name, ignoreCase)) { result.add(param); } } return result; }
/** * Compares this object with the specified object for order. * * @param o * The object to be compared. * @return A negative integer, zero, or a positive integer as this object is * less than, equal to, or greater than the specified object. */ public int compareTo(Parameter o) { return getName().compareTo(o.getName()); }
/** * Returns the value of the first parameter found with the given name. * * @param name * The parameter name. * @param ignoreCase * Indicates if the name comparison is case sensitive. * @param defaultValue * The default value to return if no matching parameter found. * @return The value of the first parameter found with the given name or the * default value. */ public String getFirstValue(String name, boolean ignoreCase, String defaultValue) { String result = defaultValue; final Parameter param = getFirst(name, ignoreCase); if (param != null) { result = param.getValue(); } return result; }
/** * Removes all the parameters with a given name. * * @param name * The parameter name. * @param ignoreCase * Indicates if the name comparison is case sensitive. * @return True if the list changed. */ public boolean removeAll(String name, boolean ignoreCase) { boolean changed = false; Parameter param = null; for (final Iterator<E> iter = iterator(); iter.hasNext();) { param = iter.next(); if (equals(param.getName(), name, ignoreCase)) { iter.remove(); changed = true; } } return changed; }
/** * Returns an array of all the values associated to the given parameter * name. * * @param name * The parameter name to match. * @param ignoreCase * Indicates if the name comparison is case sensitive. * @return The array of values. */ public String[] getValuesArray(String name, boolean ignoreCase) { final List<E> params = subList(name, ignoreCase); final String[] result = new String[params.size()]; for (int i = 0; i < params.size(); i++) { result[i] = params.get(i).getValue(); } return result; }
/** * Returns the first parameter found with the given name. * * @param name * The parameter name. * @param ignoreCase * Indicates if the name comparison is case sensitive. * @return The first parameter found with the given name. */ public E getFirst(String name, boolean ignoreCase) { for (final E param : this) { if (equals(param.getName(), name, ignoreCase)) { return param; } } return null; }
/** * Extract the quality value. If the value is not found, 1 is returned. * * @param parameters * The preference parameters. * @return The quality value. */ protected float extractQuality(Series<Parameter> parameters) { float result = 1F; boolean found = false; if (parameters != null) { Parameter param = null; for (final Iterator<Parameter> iter = parameters.iterator(); !found && iter.hasNext();) { param = iter.next(); if (param.getName().equals("q")) { result = readQuality(param.getValue()); found = true; // Remove the quality parameter as we will directly store it // in the Preference object iter.remove(); } } } return result; }
/** * Returns the list of request headers. * * @return The list of request headers. */ @Override @SuppressWarnings("unchecked") public Series<Parameter> getRequestHeaders() { if (this.requestHeaders == null) { this.requestHeaders = new Form(); // Copy the headers from the request object String headerName; String headerValue; for (final Enumeration<String> names = getRequest() .getHeaderNames(); names.hasMoreElements();) { headerName = names.nextElement(); for (final Enumeration<String> values = getRequest() .getHeaders(headerName); values.hasMoreElements();) { headerValue = values.nextElement(); this.requestHeaders.add(new Parameter(headerName, headerValue)); } } } return this.requestHeaders; }