Package com.jbidwatcher.util.xml

Examples of com.jbidwatcher.util.xml.XMLElement


        JConfig.setConfiguration("savefile", canonicalFName);
      }
    }

    try {
      XMLElement xmlFile = new XMLElement(true);

      InputStreamReader isr = new InputStreamReader(new FileInputStream(canonicalFName));

      xmlFile.parseFromReader(isr);

      AuctionServerManager.getInstance().fromXML(xmlFile);
    } catch(IOException e) {
      JConfig.log().handleException("Error loading XML file with auctions: " + canonicalFName, e);
    }
View Full Code Here


    m_tokenIndex = 0;
    m_contentIndex = 0;
  }

  public Map<String, String> extractMicroformat() {
    XMLElement xe = new XMLElement();
    String currentProperty = null;
    Map<String, String> rval = new HashMap<String, String>();
    htmlToken tok;
    int balance = 0;

    String currentContent = null;
    while((tok = nextToken()) != null) {
      int type = tok.getTokenType();

      if(currentProperty != null) {
        if(type == htmlToken.HTML_TAG) balance++;
        if(type == htmlToken.HTML_ENDTAG) {
          balance--;
          if(balance == 0) {
            if(rval.get(currentProperty) == null || rval.get(currentProperty).length() == 0 || currentContent.length() != 0) {
              rval.put(currentProperty, currentContent);
            }
            currentProperty = null;
          }
        }
      }

      if(type == htmlToken.HTML_TAG || type == htmlToken.HTML_SINGLETAG) {
        if(tok.getToken().startsWith("!")) continue;

        try {
          xe.reset();
          xe.parseString("<" + tok.getToken() + "/>");
        } catch(XMLParseException xpe) {
          JConfig.log().logVerboseDebug("eBay's HTML still sucks.");
          continue;
        }
        String itemprop = xe.getProperty("itemprop");
        if(itemprop != null) {
          String content = xe.getProperty("content");
          if (content != null) {
            if(rval.get(itemprop) == null || rval.get(itemprop).length() == 0 || content.length() != 0) {
              rval.put(itemprop, content);
            }
          } else {
            currentProperty = itemprop;
            currentContent = "";
            balance = 1;
          }
        } else if(xe.getTagName().equals("meta")) {
          String property = xe.getProperty("property");
          if(property != null && property.startsWith("og:")) {
            itemprop = property.substring(3);
            String content = xe.getProperty("content");
            if (rval.get(itemprop) == null || rval.get(itemprop).length() == 0 || content.length() != 0) {
              rval.put(itemprop, content);
            }
          }
        }
View Full Code Here

    public static final String FORM_PASSWORD = "password";
    private static final String FORM_HIDDEN = "hidden";
    private static final String FORM_RADIO = "radio";

    public Form(String initialTag) {
      formTag = new XMLElement();
      formTag.parseString('<' + initialTag + "/>");

      mAllInputs = new ArrayList<XMLInterface>();

      if (do_uber_debug) JConfig.log().logDebug("Name: " + formTag.getProperty("name", "(unnamed)"));
View Full Code Here

    public String getFormData() throws UnsupportedEncodingException {
      Iterator<XMLInterface> it = mAllInputs.iterator();
      StringBuffer rval = new StringBuffer("");
      String seperator = "";
      while(it.hasNext()) {
        XMLElement curInput = (XMLElement)it.next();

        if(do_uber_debug) JConfig.log().logDebug("Type == " + curInput.getProperty("type", "text"));
        if (rval.length() != 0) {
          seperator = "&";
        }

        String type = curInput.getProperty("type", "text");
        String name = curInput.getProperty("name", "");

        if(type.equals("text") || type.equalsIgnoreCase(FORM_HIDDEN) || type.equals(FORM_PASSWORD)) {
          //  Need to URL-Encode 'value'...
          rval.append(seperator).append(name).append('=').append(URLEncoder.encode(curInput.getProperty(FORM_VALUE, ""), "UTF-8"));
        } else if(type.equals(FORM_CHECKBOX) || type.equals(FORM_RADIO)) {
          if(curInput.getProperty("checked") != null) {
            rval.append(seperator).append(name).append('=').append(URLEncoder.encode(curInput.getProperty(FORM_VALUE, "on"), "UTF-8"));
          }
        } else if(type.equals(FORM_SUBMIT)) {
          if(name.length() != 0) {
            String value = curInput.getProperty(FORM_VALUE, "Submit");
            if (!value.equalsIgnoreCase("cancel")) {
              rval.append(seperator).append(name).append('=').append(URLEncoder.encode(value, "UTF-8"));
            }
          }
        }
View Full Code Here

      }
      return defValue;
    }

    public void addInput(String newTag) {
      XMLElement inputTag = new XMLElement();

      try {
        inputTag.parseString('<' + newTag + "/>");
      } catch (XMLParseException e) {
        if(XMLElement.rejectingBadHTML()) throw e;
        JConfig.log().handleException("Bad input tag", e);
        return;
      }
      String inputType = inputTag.getProperty("type", "text").toLowerCase();
      if(inputTag.getTagName().equals("button")) {
        XMLElement tempTag = new XMLElement();
        String name = createProperty("name", inputTag, "");
        String value= createProperty("value", inputTag, "");
        String type = createProperty("type", inputTag, "button");
        tempTag.parseString("<input " + type + name + value + "/>");
        inputType = tempTag.getProperty("type");
        inputTag = tempTag;
      }

      boolean showInputs = JConfig.queryConfiguration("debug.showInputs", "false").equals("true");
View Full Code Here

    if(sInstance == null) sInstance = new MyJBidwatcher();
    return sInstance;
  }

  public void postXML(String queue, XMLSerialize ae) {
    XMLElement xmlWrapper = new XMLElement("message");
    XMLElement user = new XMLElement("user");
    XMLElement access_key = new XMLElement("key");
    user.setContents(JConfig.queryConfiguration("my.jbidwatcher.id"));
    access_key.setContents(JConfig.queryConfiguration("my.jbidwatcher.key"));
    xmlWrapper.addChild(user);
    xmlWrapper.addChild(access_key);
    xmlWrapper.addChild(ae.toXML());
    String aucXML = xmlWrapper.toString();
View Full Code Here

  }

  private void uploadAuctionHTML(AuctionEntry ae, String uploadType) {
    if(canUploadHTML()) {
      String s3Result = sendFile(JConfig.getContentFile(ae.getIdentifier()), url(ITEM_UPLOAD_URL), JConfig.queryConfiguration("my.jbidwatcher.id"), ae.getLastStatus());
      XMLElement root = new XMLElement(uploadType);
      XMLElement s3Key = new XMLElement("s3");
      s3Key.setContents(s3Result);
      root.addChild(ae.toXML());
      postXML(mReportQueueURL, root);
      My status = My.findByIdentifier(ae.getIdentifier());
      String identifier = ae.getIdentifier();
      if (status == null) status = new My(identifier);
View Full Code Here

      //  If we've already submitted a snipe for this listing, don't send it again.
      My status = My.findByIdentifier(identifier);
      if (status != null && ae.getSnipeAmount().equals(status.getMonetary("snipe_amount"))) return;
      if (status == null) status = new My(identifier);

      XMLElement gixen = generateGixenXML(identifier, cancel, ae);
      if (gixen == null) return;
      postXML(mGixenQueueURL, gixen);
      if (cancel) {
        status.setDate("snipe_submitted_at", null);
        status.setMonetary("snipe_amount", null);
View Full Code Here

      status.saveDB();
    }
  }

  private static XMLElement generateGixenXML(String identifier, boolean cancel, AuctionEntry ae) {
    XMLElement gixen = new XMLElement(cancel ? "cancelsnipe" : "snipe");
    gixen.setProperty("AUCTION", identifier);

    if (!cancel) {
      String bid = ae.getSnipeAmount().getValueString();
      gixen.setProperty("AMOUNT", bid);
    }

    XMLElement userInfo = new XMLElement("credentials");
    String user = JConfig.queryConfiguration(ae.getServer().getName() + ".user");
    String password = JConfig.queryConfiguration(ae.getServer().getName() + ".password");
    if(user == null || password == null) {
      JConfig.log().logMessage("Failed to submit snipe to Gixen; one or both of username and password are not set.");
      return null;
    }
    userInfo.setProperty("user", user);
    userInfo.setProperty("password", Base64.encodeString(password));
    userInfo.setEmpty();
    gixen.addChild(userInfo);
    return gixen;
  }
View Full Code Here

    if(username == null || password == null) return false;
    if (username.length() == 0 || password.length() == 0) return false;
    StringBuffer sb = getRawAccountXML(username, password);
    if(sb == null) return false;

    XMLElement xml = new XMLElement();
    xml.parseString(sb.toString());
    XMLInterface sync = xml.getChild("syncq");
    XMLInterface snipe = xml.getChild("snipeq");
    XMLInterface expires = xml.getChild("expiry");
    XMLInterface listingsRemaining = xml.getChild("listings");
    XMLInterface categoriesRemaining = xml.getChild("categories");
    XMLInterface reporting = xml.getChild("reportq");
    XMLInterface snipesListen = xml.getChild("snipes");
    XMLInterface ssl = xml.getChild("ssl");
    XMLInterface uploadHTML = xml.getChild("uploadhtml");
    XMLInterface serverParser = xml.getChild("parser");
    XMLInterface gixen = xml.getChild("gixen");

    checkExpiration(expires);

    JConfig.setConfiguration("my.jbidwatcher.allow.listings", listingsRemaining.getContents());
    JConfig.setConfiguration("my.jbidwatcher.allow.categories", categoriesRemaining.getContents());
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.