Java Code Examples for org.restlet.representation.Representation#isAvailable()

The following examples show how to use org.restlet.representation.Representation#isAvailable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FormUtils.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
/**
 * Parses a post into a given form.
 * 
 * @param form
 *            The target form.
 * @param post
 *            The posted form.
 * @param decode
 *            Indicates if the parameters should be decoded.
 */
public static void parse(Form form, Representation post, boolean decode) {
    if (post != null) {
        if (post.isAvailable()) {
            FormReader fr = null;

            try {
                fr = new FormReader(post, decode);
            } catch (IOException ioe) {
                Context.getCurrentLogger().log(Level.WARNING,
                        "Unable to create a form reader. Parsing aborted.",
                        ioe);
            }

            if (fr != null) {
                fr.addParameters(form);
            }
        } else {
            Context.getCurrentLogger()
                    .log(Level.FINE,
                            "The form wasn't changed as the given representation isn't available.");
        }
    }
}
 
Example 2
Source File: CustomPageBarResourceFactory.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected InputStream get(final String exportURL) throws IOException {
    ClientResource clientResource = new ClientResource(exportURL);
    clientResource.getLogger().setLevel(Level.OFF);
    final Representation representation = clientResource.get();
    return representation != null && representation.isAvailable() ? representation.getStream() : null;
}
 
Example 3
Source File: FormUtils.java    From DeviceConnect-Android with MIT License 3 votes vote down vote up
/**
 * Reads the first parameter with the given name.
 * 
 * @param post
 *            The web form representation.
 * @param name
 *            The parameter name to match.
 * @return The parameter.
 * @throws IOException
 */
public static Parameter getFirstParameter(Representation post, String name)
        throws IOException {
    if (!post.isAvailable()) {
        throw new IllegalStateException(
                "The Web form cannot be parsed as no fresh content is available. If this entity has been already read once, caching of the entity is required");
    }

    return new FormReader(post).readFirstParameter(name);
}
 
Example 4
Source File: FormUtils.java    From DeviceConnect-Android with MIT License 3 votes vote down vote up
/**
 * Reads the parameters with the given name.<br>
 * If multiple values are found, a list is returned created.
 * 
 * @param form
 *            The web form representation.
 * @param name
 *            The parameter name to match.
 * @return The parameter value or list of values.
 * @throws IOException
 *             If the parameters could not be read.
 */
public static Object getParameter(Representation form, String name)
        throws IOException {
    if (!form.isAvailable()) {
        throw new IllegalStateException(
                "The Web form cannot be parsed as no fresh content is available. If this entity has been already read once, caching of the entity is required");
    }

    return new FormReader(form).readParameter(name);
}
 
Example 5
Source File: FormUtils.java    From DeviceConnect-Android with MIT License 3 votes vote down vote up
/**
 * Reads the parameters whose name is a key in the given map.<br>
 * If a matching parameter is found, its value is put in the map.<br>
 * If multiple values are found, a list is created and set in the map.
 * 
 * @param post
 *            The web form representation.
 * @param parameters
 *            The parameters map controlling the reading.
 * @throws IOException
 *             If the parameters could not be read.
 */
public static void getParameters(Representation post,
        Map<String, Object> parameters) throws IOException {
    if (!post.isAvailable()) {
        throw new IllegalStateException(
                "The Web form cannot be parsed as no fresh content is available. If this entity has been already read once, caching of the entity is required");
    }

    new FormReader(post).readParameters(parameters);
}