All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bitbucket.rosseti.http.client.PartialResponse Maven / Gradle / Ivy

package org.bitbucket.rosseti.http.client;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
 *
 */
final class PartialResponse {
  @Nullable
  private final Element changes;

  @Nullable
  private final Element redirect;

  PartialResponse(Document response) {
    changes = response.selectFirst("changes");
    redirect = response.selectFirst("redirect");
  }

  @Nullable
  String viewState() {
    return getUpdate("j_id1:javax.faces.ViewState:0");
  }

  @Nullable
  Growl growl() {
    //noinspection SpellCheckingInspection
    String growl = getUpdate("messagesform:growl");
    return
      growl != null
        ? new Growl(growl)
        : null;
  }

  @Nonnull
  Document getTable(@Nonnull String id) {
    return
      Jsoup.parse(
        "" + getUpdate(id) + "
" ); } @Nullable private String getUpdate(@Nonnull String id) { if (changes != null) { Element update = changes.selectFirst("update[id='" + id + "']"); if (update != null) { return update.text(); } } return null; } @Nullable String redirect() { return redirect != null ? redirect.attr("url") : null; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy