Package de.umass.xml

Examples of de.umass.xml.DomElement


   * @param entry An entry
   * @param element XML source element
   */
  protected static void loadStandardInfo(MusicEntry entry, DomElement element) {
    // playcount & listeners
    DomElement statsChild = element.getChild("stats");
    String playcountString;
    String userPlaycountString;
    String listenersString;
    if (statsChild != null) {
      playcountString = statsChild.getChildText("playcount");
      userPlaycountString = statsChild.getChildText("userplaycount");
      listenersString = statsChild.getChildText("listeners");
    } else {
      playcountString = element.getChildText("playcount");
      userPlaycountString = element.getChildText("userplaycount");
      listenersString = element.getChildText("listeners");
    }
    if (element.hasChild("id")) {
      entry.id = element.getChildText("id");
    }
    // percentagechange in getHype() responses
    if (element.hasChild("percentagechange")) {
      entry.percentageChange = Integer.parseInt(element.getChildText("percentagechange"));
    }
    int playcount = playcountString == null || playcountString.length() == 0 ? -1 : Integer
        .parseInt(playcountString);
    int userPlaycount = userPlaycountString == null || userPlaycountString.length() == 0 ? -1 : Integer
        .parseInt(userPlaycountString);
    int listeners = listenersString == null || listenersString.length() == 0 ? -1 : Integer
        .parseInt(listenersString);
    // streamable
    String s = element.getChildText("streamable");
    boolean streamable = s != null && s.length() != 0 && Integer.parseInt(s) == 1;
    // copy
    entry.name = element.getChildText("name");
    entry.url = element.getChildText("url");
    entry.mbid = element.getChildText("mbid");
    entry.playcount = playcount;
    entry.userPlaycount = userPlaycount;
    entry.listeners = listeners;
    entry.streamable = streamable;
    // tags
    DomElement tags = element.getChild("tags");
    if (tags == null)
      tags = element.getChild("toptags");
    if (tags != null) {
      for (DomElement tage : tags.getChildren("tag")) {
        entry.tags.add(tage.getChildText("name"));
      }
    }
    // wiki
    DomElement wiki = element.getChild("bio");
    if (wiki == null)
      wiki = element.getChild("wiki");
    if (wiki != null) {
      String publishedText = wiki.getChildText("published");
      try {
        entry.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());
          entry.wikiLastChanged = clFormat.parse(publishedText);
        } catch (ParseException e2) {
          // cannot parse date, wrong locale. wait for last.fm to fix.
        }
      }
      entry.wikiSummary = wiki.getChildText("summary");
      entry.wikiText = wiki.getChildText("content");
    }
    // images
    ImageHolder.loadImages(entry, element);
  }
View Full Code Here


      try {
        i.dateAdded = DATE_ADDED_FORMAT.parse(element.getChildText("dateadded"));
      } catch (ParseException e1) {
        e1.printStackTrace();
      }
      DomElement owner = element.getChild("owner");
      if (owner != null)
        i.owner = owner.getChildText("name");
      DomElement votes = element.getChild("votes");
      if (votes != null) {
        i.thumbsUp = Integer.parseInt(votes.getChildText("thumbsup"));
        i.thumbsDown = Integer.parseInt(votes.getChildText("thumbsdown"));
      }
      DomElement sizes = element.getChild("sizes");
      for (DomElement image : sizes.getChildren("size")) {
        // code copied from ImageHolder.loadImages
        String attribute = image.getAttribute("name");
        ImageSize size;
        if (attribute == null)
          size = ImageSize.MEDIUM; // workaround for image responses without size attr.
View Full Code Here

    params.put("venue", venue);
    MapUtilities.nullSafePut(params, "country", country);
    Result result = Caller.getInstance().call("venue.search", apiKey, params);
    if (!result.isSuccessful())
      return Collections.emptyList();
    DomElement child = result.getContentElement().getChild("venuematches");
    return ResponseBuilder.buildCollection(child, Venue.class);
  }
View Full Code Here

      venue.name = element.getChildText("name");
      venue.url = element.getChildText("url");
      venue.phonenumber = element.getChildText("phonenumber");
      venue.website = element.getChildText("website");
      ImageHolder.loadImages(venue, element);
      DomElement l = element.getChild("location");
      venue.city = l.getChildText("city");
      venue.country = l.getChildText("country");
      venue.street = l.getChildText("street");
      venue.postal = l.getChildText("postalcode");
      venue.timezone = l.getChildText("timezone");
      DomElement p = l.getChild("geo:point");
      if (p.getChildText("geo:lat").length() != 0) { // some venues don't have geo information applied
        venue.latitude = Float.parseFloat(p.getChildText("geo:lat"));
        venue.longitude = Float.parseFloat(p.getChildText("geo:long"));
      }
      return venue;
    }
View Full Code Here

    params.put("limit", String.valueOf(limit));
    MapUtilities.nullSafePut(params, "artist", artist);
    Result result = Caller.getInstance().call("track.search", apiKey, params);
    if(!result.isSuccessful())
      return Collections.emptyList();
    DomElement element = result.getContentElement();
    DomElement matches = element.getChild("trackmatches");
    return ResponseBuilder.buildCollection(matches, Track.class);
  }
View Full Code Here

   * @param session A Session instance
   * @return a list of tags
   */
  public static Collection<String> getTags(String artist, String track, Session session) {
    Result result = Caller.getInstance().call("track.getTags", session, "artist", artist, "track", track);
    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

    }
    MapUtilities.nullSafePut(params, "username", username);
    Result result = Caller.getInstance().call("track.getInfo", apiKey, params);
    if (!result.isSuccessful())
      return null;
    DomElement content = result.getContentElement();
    DomElement album = content.getChild("album");
    Track track = FACTORY.createItemFromElement(content);
    if (album != null) {
      String pos = album.getAttribute("position");
      if ((pos != null) && pos.length() != 0) {
        track.position = Integer.parseInt(pos);
      }
      track.album = album.getChildText("title");
      track.albumMbid = album.getChildText("mbid");
      ImageHolder.loadImages(track, album);
    }
    return track;
  }
View Full Code Here

    }
    params.put("country", country);
    Result result = Caller.getInstance().call("track.getBuylinks", apiKey, params);
    if (!result.isSuccessful())
      return Collections.emptyList();
    DomElement element = result.getContentElement();
    DomElement physicals = element.getChild("physicals");
    DomElement downloads = element.getChild("downloads");
    Collection<BuyLink> links = new ArrayList<BuyLink>();
    for (DomElement e : physicals.getChildren("affiliation")) {
      links.add(BuyLink.linkFromElement(BuyLink.StoreType.PHYSICAl, e));
    }
    for (DomElement e : downloads.getChildren("affiliation")) {
      links.add(BuyLink.linkFromElement(BuyLink.StoreType.DIGITAL, e));
    }
    return links;
  }
View Full Code Here

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

    if (!result.isSuccessful()) {
      // if result failed then we have no extra information
      ScrobbleResult scrobbleResult = new ScrobbleResult(result);
      scrobbleResults.add(scrobbleResult);
    } else {
      DomElement element = result.getContentElement();
      if (scrobbleResultType == ScrobbleResultType.NOW_PLAYING) {
        ScrobbleResult scrobbleResult = new ScrobbleResult(result);
        parseIntoScrobbleResult(element, scrobbleResult);
        scrobbleResults.add(scrobbleResult);
      } else if (scrobbleResultType == ScrobbleResultType.SINGLE_SCROBBLE) {
        ScrobbleResult scrobbleResult = new ScrobbleResult(result);
        parseIntoScrobbleResult(element.getChild("scrobble"), scrobbleResult);
        scrobbleResults.add(scrobbleResult);
      } else if (scrobbleResultType == ScrobbleResultType.MULTIPLE_SCROBBLES) {
        for (DomElement scrobbleElement : element.getChildren("scrobble")) {
          ScrobbleResult scrobbleResult = new ScrobbleResult(result);
          parseIntoScrobbleResult(scrobbleElement, scrobbleResult);
          scrobbleResults.add(scrobbleResult);
        }
      }
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.