Package de.umass.xml

Examples of de.umass.xml.DomElement


   *
   * @param scrobbleElement DomElement containing scrobble or now playing response data.
   * @param scrobbleResult ScrobbleResult to add the response data to.
   */
  private static void parseIntoScrobbleResult(DomElement scrobbleElement, ScrobbleResult scrobbleResult) {
    DomElement trackElement = scrobbleElement.getChild("track");
    scrobbleResult.setTrack(trackElement.getText());
    scrobbleResult.setArtistCorrected(StringUtilities.convertToBoolean(trackElement.getAttribute("corrected")));

    DomElement artistElement = scrobbleElement.getChild("artist");
    scrobbleResult.setArtist(artistElement.getText());
    scrobbleResult.setArtistCorrected(StringUtilities.convertToBoolean(artistElement.getAttribute("corrected")));

    DomElement albumElement = scrobbleElement.getChild("album");
    scrobbleResult.setAlbum(albumElement.getText());
    scrobbleResult.setAlbumCorrected(StringUtilities.convertToBoolean(albumElement.getAttribute("corrected")));

    DomElement albumArtistElement = scrobbleElement.getChild("albumArtist");
    scrobbleResult.setAlbumArtist(albumArtistElement.getText());
    scrobbleResult.setAlbumArtistCorrected(StringUtilities.convertToBoolean(albumArtistElement.getAttribute("corrected")));

    String timeString = scrobbleElement.getChildText("timestamp");
    if (timeString != null) {
      // will be non-null for scrobble results only
      scrobbleResult.setTimestamp(Integer.parseInt(timeString));
    }

    DomElement ignoredMessageElement = scrobbleElement.getChild("ignoredMessage");
    int ignoredMessageCode = Integer.parseInt(ignoredMessageElement.getAttribute("code"));
    if (ignoredMessageCode > 0) {
      scrobbleResult.setIgnored(true);
      scrobbleResult.setIgnoredMessageCode(IgnoredMessageCode.valueOfCode(ignoredMessageCode));
      scrobbleResult.setIgnoredMessage(ignoredMessageElement.getText());
    }
  }
View Full Code Here


      final String nowPlayingAttr = element.getAttribute("nowplaying");
      if (nowPlayingAttr != null)
        track.nowPlaying = Boolean.valueOf(nowPlayingAttr);
      if (element.hasChild("duration"))
        track.duration = Integer.parseInt(element.getChildText("duration")) / 1000;
      DomElement album = element.getChild("album");
      if (album != null) {
        track.album = album.getText();
        track.albumMbid = album.getAttribute("mbid");
      }
      DomElement artist = element.getChild("artist");
      if (artist.getChild("name") != null) {
        track.artist = artist.getChildText("name");
        track.artistMbid = artist.getChildText("mbid");
      } else {
        track.artist = artist.getText();
        track.artistMbid = artist.getAttribute("mbid");
      }
      DomElement date = element.getChild("date");
      if (date != null) {
        String uts = date.getAttribute("uts");
        long utsTime = Long.parseLong(uts);
        track.playedWhen = new Date(utsTime * 1000);
      }
      DomElement stream = element.getChild("streamable");
      if (stream != null) {
        String s = stream.getAttribute("fulltrack");
        track.fullTrackAvailable = s != null && Integer.parseInt(s) == 1;
      }
      return track;
    }
View Full Code Here

  public static <T> PaginatedResult<T> buildPaginatedResult(Result result, ItemFactory<T> factory) {
    if (!result.isSuccessful()) {
      return new PaginatedResult<T>(0, 0, Collections.<T>emptyList());
    }
    DomElement contentElement = result.getContentElement();
    Collection<DomElement> children = contentElement.getChildren();
    Collection<T> items = new ArrayList<T>(children.size());
    for (DomElement e : children) {
      items.add(factory.createItemFromElement(e));
    }
    int page = Integer.valueOf(contentElement.getAttribute("page"));
    // TODO: last.fm sometimes uses the totalPages spelling and sometimes totalpages :x remove this check when it's fixed.
    String totalPagesAttribute = contentElement.getAttribute("totalPages");
    if (totalPagesAttribute == null)
      totalPagesAttribute = contentElement.getAttribute("totalpages");
    int totalPages = Integer.valueOf(totalPagesAttribute);
    return new PaginatedResult<T>(page, totalPages, items);
  }
View Full Code Here

   */
  public static Collection<String> getTags(String artist, Session session) {
    Result result = Caller.getInstance().call("artist.getTags", session, "artist", artist);
    if (!result.isSuccessful())
      return Collections.emptyList();
    DomElement element = result.getContentElement();
    Collection<String> tags = new ArrayList<String>();
    for (DomElement domElement : element.getChildren("tag")) {
      tags.add(domElement.getChildText("name"));
    }
    return tags;
  }
View Full Code Here

   */
  public static Artist getCorrection(String artist, String apiKey) {
    Result result = Caller.getInstance().call("artist.getCorrection", apiKey, "artist", artist);
    if (!result.isSuccessful())
      return null;
    DomElement correctionElement = result.getContentElement().getChild("correction");
    if (correctionElement == null)
      return new Artist(artist, null);
    DomElement artistElem = correctionElement.getChild("artist");
    return FACTORY.createItemFromElement(artistElem);
  }
View Full Code Here

      // match for similar artists response
      if (element.hasChild("match")) {
        artist.similarityMatch = Float.parseFloat(element.getChildText("match"));
      }
      // similar artists
      DomElement similar = element.getChild("similar");
      if (similar != null) {
        Collection<DomElement> children = similar.getChildren("artist");
        for (DomElement child : children) {
          artist.similar.add(createItemFromElement(child));
        }
      }
      return artist;
View Full Code Here

    String authToken = md5(username + password);
    Map<String, String> params = map("api_key", apiKey, "username", username, "authToken", authToken);
    String sig = createSignature("auth.getMobileSession", params, secret);
    Result result = Caller.getInstance()
        .call("auth.getMobileSession", apiKey, "username", username, "authToken", authToken, "api_sig", sig);
    DomElement element = result.getContentElement();
    return Session.sessionFromElement(element, apiKey, secret);
  }
View Full Code Here

        t.reach = Integer.parseInt(element.getChildText("reach"));
      if (element.hasChild("streamable"))
        t.streamable = StringUtilities.convertToBoolean(element.getChildText("streamable"));

      // wiki
      DomElement wiki = element.getChild("wiki");
      if (wiki != null) {
        String publishedText = wiki.getChildText("published");
        try {
          t.wikiLastChanged = DATE_FORMAT.parse(publishedText);
        } catch (ParseException e) {
          // try parsing it with current locale
          try {
            DateFormat clFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss ZZZZ", Locale.getDefault());
            t.wikiLastChanged = clFormat.parse(publishedText);
          } catch (ParseException e2) {
            // cannot parse date, wrong locale. wait for last.fm to fix.
          }
        }
        t.wikiSummary = wiki.getChildText("summary");
        t.wikiText = wiki.getChildText("content");
      }
      return t;
    }
View Full Code Here

  public static ComparisonResult compare(InputType type1, String value1, InputType type2, String value2, String apiKey) {
    Result result = Caller.getInstance().call("tasteometer.compare", apiKey, "type1", type1.name().toLowerCase(), "type2",
            type2.name().toLowerCase(), "value1", value1, "value2", value2);
    if (!result.isSuccessful())
      return null;
    DomElement element = result.getContentElement();
    DomElement re = element.getChild("result");
    float score = Float.parseFloat(re.getChildText("score"));
    List<Artist> artists = new ArrayList<Artist>();
    for (DomElement domElement : re.getChild("artists").getChildren("artist")) {
      artists.add(ResponseBuilder.buildItem(domElement, Artist.class));
    }
    return new ComparisonResult(score, artists);
  }
View Full Code Here

      params.put("lang", locale.getLanguage());
    }
    Result result = Caller.getInstance().call("radio.tune", session, params);
    if (!result.isSuccessful())
      return null;
    DomElement root = result.getContentElement();
    Radio radio = new Radio(session);
    radio.type = root.getChildText("type");
    radio.stationName = root.getChildText("name");
    radio.stationUrl = root.getChildText("url");
    radio.supportsDiscovery = "1".equals(root.getChildText("type"));
    return radio;
  }
View Full Code Here

TOP

Related Classes of de.umass.xml.DomElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.