Package com.jbidwatcher.util.xml

Examples of com.jbidwatcher.util.xml.XMLElement


   * @return An XMLElement containing as children, all of the key
   * values associated with this auction entry.
   */
  @SuppressWarnings({"FeatureEnvy"})
  public XMLElement toXML(boolean includeEvents) {
    XMLElement xmlResult = new XMLElement("auction");

    xmlResult.setProperty("id", getIdentifier());
    AuctionInfo ai = findByIdOrIdentifier(getAuctionId(), getIdentifier());
    xmlResult.addChild(ai.toXML());

    if(isBidOn()) {
      XMLElement xbid = new XMLElement("bid");
      xbid.setEmpty();
      xbid.setProperty("quantity", Integer.toString(getBidQuantity()));
      xbid.setProperty("currency", getBid().fullCurrencyName());
      xbid.setProperty("price", Double.toString(getBid().getValue()));
      if(mBidAt != 0) {
        xbid.setProperty("when", Long.toString(mBidAt));
      }
      xmlResult.addChild(xbid);
    }

    if(isSniped()) {
      XMLElement xsnipe = new XMLElement("snipe");
      xsnipe.setEmpty();
      xsnipe.setProperty("quantity", Integer.toString(getSnipe().getQuantity()));
      xsnipe.setProperty("currency", getSnipe().getAmount().fullCurrencyName());
      xsnipe.setProperty("price", Double.toString(getSnipe().getAmount().getValue()));
      xsnipe.setProperty("secondsprior", Long.toString(mSnipeAt));
      xmlResult.addChild(xsnipe);
    }

//    if(isMultiSniped()) xmlResult.addChild(getMultiSnipe().toXML());

    if(isComplete()) addStatusXML(xmlResult, "complete");
    if(isInvalid()) addStatusXML(xmlResult, "invalid");
    if(isDeleted()) addStatusXML(xmlResult, "deleted");
    if(isWinning()) addStatusXML(xmlResult, "winning");

    if(getComment() != null) {
      XMLElement xcomment = new XMLElement("comment");
      xcomment.setContents(getComment());
      xmlResult.addChild(xcomment);
    }

    if(getCategory() != null) {
      XMLElement xcategory = new XMLElement("category");
      xcategory.setContents(getCategory());
      xcategory.setProperty("sticky", isSticky() ?"true":"false");
      xmlResult.addChild(xcategory);
    }

    if(getShipping() != null) {
      XMLElement xshipping = new XMLElement("shipping");
      xshipping.setEmpty();
      xshipping.setProperty("currency", getShipping().fullCurrencyName());
      xshipping.setProperty("price", Double.toString(getShipping().getValue()));
      xmlResult.addChild(xshipping);
    }

    if(includeEvents && mEntryEvents != null) {
      XMLElement xlog = mEntryEvents.toXML();
      if (xlog != null) {
        xmlResult.addChild(xlog);
      }
    }
    return xmlResult;
View Full Code Here


  public void loadFromString(StringBuffer sb, String packageName) {
    if(sb == null || packageName == null) {
      //noinspection ThrowableInstanceNeverThrown
      JConfig.log().handleException("loadFromString Failed with a null pointer!", new Exception("Updater got incorrect XML file."));
    } else {
      XMLElement xmlUpdate = new XMLElement(true);

      xmlUpdate.parseString(sb.toString());
      if (xmlUpdate.getTagName().equalsIgnoreCase(packageName)) {
        fromXML(xmlUpdate);
      } else {
        throw new XMLParseException(xmlUpdate.getTagName(), "Updater got incorrect XML file.");
      }
    }
  }
View Full Code Here

    Currency value = getMonetary(name, currencyType);
    return addCurrencyChild(parent, name, value);
  }

  protected XMLElement addCurrencyChild(XMLElement parent, String name, Currency value) {
    XMLElement xadd = null;
    if (value != null && !value.isNull()) {
      xadd = new XMLElement(name);
      xadd.setProperty("currency", value.fullCurrencyName());
      xadd.setProperty("price", Double.toString(value.getValue()));
      xadd.setEmpty();
      parent.addChild(xadd);
    }

    return xadd;
  }
View Full Code Here

    return xadd;
  }

  protected XMLInterface addStringChild(XMLElement parent, String name) {
    String value = getString(name);
    XMLElement xadd = null;
    if (value != null && value.length() != 0) {
      xadd = new XMLElement(name);
      xadd.setContents(getString(name));
      parent.addChild(xadd);
    }

    return xadd;
  }
View Full Code Here

    return xadd;
  }

  protected XMLElement addBooleanChild(XMLElement parent, String name) {
    boolean value = getBoolean(name);
    XMLElement xadd = null;
    if (value) {
      xadd = new XMLElement(name);
      xadd.setEmpty();
      parent.addChild(xadd);
    }

    return xadd;
  }
View Full Code Here

  }

  private void retrieveAndVerifyAuctions(List<String> params) {
    if(params.size() == 0) return;
    try {
      XMLElement auctionList = new XMLElement("auctions");
      for (String id : params) {
        XMLElement xmlized = mEbay.create(id).toXML();
        if (xmlized != null) auctionList.addChild(xmlized);
      }
      System.out.println(auctionList.toString());
    } catch(Exception dumpMe) {
      JConfig.log().handleException("Failure during serialization or deserialization of an auction", dumpMe);
View Full Code Here

    try {
      String category = URLDecoder.decode(categoryName, "UTF-8");
      Category tab = Category.findFirstByName(category);
      List<AuctionEntry> auctions = AuctionEntry.findAllBy("category_id", tab.get("id"));
      XMLElement xauctions = new XMLElement("auctions");
      for(AuctionEntry ae : auctions) {
        XMLElement child = ae.toXML();
        if(ae.getThumbnail() != null) {
          XMLElement thumbnail = new XMLElement("thumbnail");
          thumbnail.setContents(serviceURL + "/" + ae.getIdentifier() + ".jpg");
          child.addChild(thumbnail);
        }
        XMLElement url = new XMLElement("url");
        url.setContents(ae.getBrowseableURL());
        child.addChild(url);
        xauctions.addChild(child);
      }
      StringBuffer sb = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
      sb.append("<!DOCTYPE auctions [\n" +
View Full Code Here

   * I'd like to abstract this, and make it work with arbitrary
   * streams, so that we could send an XML file of auctions over a
   * network to sync between JBidwatcher instances.
   */
  public void loadAuctions() {
    XMLElement xmlFile = new XMLElement(true);
    String loadFile = JConfig.queryConfiguration("savefile", "auctions.xml");
    String oldLoad = loadFile;

    loadFile = Path.getCanonicalFile(loadFile, "jbidwatcher", true);
    if(!loadFile.equals(oldLoad)) {
View Full Code Here

    xmlFile.parseFromReader(isr);
    MQFactory.getConcrete("splash").enqueue("SET " + MAX_PERCENT);

    String formatVersion = xmlFile.getProperty("FORMAT", "0101");
    XMLElement auctionsXML = xmlFile.getChild("auctions");
    JConfig.setConfiguration("savefile.format", formatVersion);
    //  set the width of the splash progress bar based on the number
    //  of auctions that will be loaded!
    if (auctionsXML == null) {
      throw new XMLParseException(xmlFile.getTagName(), "AuctionsManager requires an <auctions> tag!");
    }
    String auctionQuantity = auctionsXML.getProperty("COUNT", null);

    int auctionTotal = 0;
    if(auctionQuantity != null) {
      auctionTotal = Integer.parseInt(auctionQuantity);
      MQFactory.getConcrete("splash").enqueue("SET 0");
View Full Code Here

   * a remote node to update it with our auctions and snipes.
   *
   * @return - the filename if it successfully saved, null if an error occurred.
   */
  public String saveAuctions() {
    XMLElement auctionsData = AuctionServerManager.getInstance().toXML();
    String oldSave = JConfig.queryConfiguration("savefile", "auctions.xml");
    String saveFilename = Path.getCanonicalFile(JConfig.queryConfiguration("savefile", "auctions.xml"), "jbidwatcher", false);
    String newSave=saveFilename;

    //  If there's no data to save, then pretend we did it.
View Full Code Here

TOP

Related Classes of com.jbidwatcher.util.xml.XMLElement

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.