HTML and CSS Reference
In-Depth Information
public enum OutputTag {
/** Return the output as paragraphs. */
/** Return the output as items in an unordered list. */
* URL to the REST service with five parameters.
private static final String API_URL = " " ;
* Property in the JSON output that we will extract and return.
private static final String PROPERTY_CONTAINING_OUTPUT = "text_out";
* Google's JSON parser for parsing the result from the service.
private JsonParser jsonParser = new JsonParser();
* Gets a random text from the web service.
* @param type Type of random text to return, {@link TextType#gibberish} or
* {@link TextType#lorem}
* @param output Type of output to produce, {@link OutputTag#p} (paragraph
* tags) or {@link OutputTag#ul} (a list)
* @param outputCount Number of outputs to produce (i.e. number of
* paragraphs or list items)
* @param wordCountLower Lowest number of words in a single paragraph or
* list item
* @param wordCountUpper Highest number of words in a single paragraph or
* list item
* @return Random text formatted as {@code type} and {@code output}
* @throws IOException
public String getRandomText(TextType type, OutputTag output, int outputCount,
int wordCountLower, int wordCountUpper) throws IOException {
// Generate URL based on method inptu
String url = String.format(API_URL, type, output, outputCount, wordCountLower,
// Prepare request to the
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
HttpResponse response = client.execute(request);
Search WWH ::

Custom Search