Package org.jsoup.nodes

Examples of org.jsoup.nodes.Element


      Elements rows = sheetRows.get(sheetNum);
      if(rowNum>=0&&rowNum<=rows.size()){
        List<Elements> tds = sheetRowCells.get(sheetNum);
        Elements cells = tds.get(rowNum);
        if(colNum>=0&&colNum<cells.size()){
          Element cell = cells.get(colNum);
          if(cell.hasAttr("formula")){
            String formula = cell.attr("formula");
            if(formula!=null){
              if(formula.startsWith("=")){
                formula = formula.substring(1);
              }
            }
            HashSet<String> es = new HashSet<String>();
            es.add(String.format("%d,%d,%d", sheetNum,rowNum,colNum));
              ANTLRStringStream input = new ANTLRStringStream(formula);
                ExcelFormulaLexer lexer = new ExcelFormulaLexer(input);
                CommonTokenStream tokens = new CommonTokenStream(lexer);
                ExcelFormulaParser parser = new ExcelFormulaParser(tokens);
                Object result = null;
                CommonTree t  = (CommonTree) parser.expressions().getTree();
                System.out.println(t.toStringTree());
                CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);
                ExcelFormulaJavaTree evaluator = new ExcelFormulaJavaTree(nodes,this,es,sheetNum,true);
                result = evaluator.expr();
                if(result!=null){
                  cell.text(result.toString());
                }else{
//                  cell.text("");
                }
                return result;
          }else{
            return cell.text();
          }
         
        }else{
          throw new ExcelException("not valid column number:"+colNum);
        }
View Full Code Here


        if(position.sColNum>=0&&position.eColNum<cells.size()){
          List<Element> result = new ArrayList<Element>();
          for(int i=position.sRowNum;i<=position.eRowNum;i++){
            Elements currentRow = tds.get(i);
            for(int j=position.sColNum;j<=position.eColNum;j++){
              Element ele = currentRow.get(j);
              result.add(ele);
            }
          }
          return result;
        }
View Full Code Here

  public HTMLExcelBridge(Elements _sheets){
//    Document doc = Jsoup.parseBodyFragment(html);
//    sheets = doc.select("table");
    sheets = _sheets;
    for(int i=0;i<sheets.size();i++){
      Element sheet = sheets.get(i);
      if(sheet.hasAttr("title")){
        name2Sheet.put(sheet.attr("title"), sheet);
        name2SheetIndex.put(sheet.attr("title"), i);
        index2SheetName.put(i, sheet.attr("title"));
      }else{
        name2Sheet.put("Spread Sheet"+i, sheet);
        name2SheetIndex.put("Spread Sheet"+i, i);
        index2SheetName.put(i, "Spread Sheet"+i);
      }
      Elements rows = sheet.select("tr");
      sheetRows.add(rows);
      List<Elements> sheetRowCell = new ArrayList<Elements>();
      for(int j=0;j<rows.size();j++){
        Element row = rows.get(j);
        Elements cells = row.select("td");
        sheetRowCell.add(cells);
      }
      sheetRowCells.add(sheetRowCell);
    }
  }
View Full Code Here

    assertTrue(doc!=null);
   
   
    Elements sheets = doc.select("table");
    for(int si=0;si<sheets.size();si++){
      Element sheet = sheets.get(si);
      Elements rows = sheet.select("tbody tr");
      for(int ri=0;ri<rows.size();ri++){
        Element row = rows.get(ri);
        Elements cells = row.select("td");
        for(int ci=0;ci<cells.size();ci++){
          Element cell = cells.get(ci);
//          System.out.println(cell.toString());
          if(!org.apache.commons.lang.StringUtils.isBlank(cell.text())){
            if(cell.hasAttr("formula")){
              System.out.printf("%d %d %d (Formula[%s]) %s\n",si,ri,ci,cell.attr("formula"),cell.text());
            }else{
              System.out.printf("%d %d %d (Normal ) %s\n",si,ri,ci,cell.text());
            }
           
          }
         
        }
View Full Code Here

    Document doc = null;
    try {
      doc = Jsoup.parse(new File(getDefaultLogPath() + ".html"), "UTF-8");
    } catch (IOException e) {
    }
    Element body = doc.select("body").first();
    if (session == 0) {
      session = System.currentTimeMillis();
      body.appendElement("br");
      Element sess = new Element(Tag.valueOf("div"), "", new Attributes());
      sess.addClass("session");
      sess.attr("id", String.valueOf(session));
      sess.append("Session started on " + new java.util.Date());
      body.appendChild(sess);
      body.appendElement("br");
      if (s.equals("")) {
        saveLogFile(doc);
        return;
      }
    }
    Element cursession = doc.select("#" + session).first();
    if (cursession == null)
      return;

    Element timestamp = new Element(Tag.valueOf("span"), "",
        new Attributes());
    timestamp.addClass("timestamp");
    if (!s.equals(""))
      timestamp.append(new java.util.Date().toString());

    String userNick = s.trim().split(" ")[0];

    if (s.startsWith("<" + this.getChannelName() + ">")
        || userNick.contains(".") || s.startsWith("<SYSTEM>")) {
      Element system = new Element(Tag.valueOf("div"), "",
          new Attributes());
      system.addClass("system");

      Element systemmsg = new Element(Tag.valueOf("span"), "",
          new Attributes());
      systemmsg.addClass("system-msg");
      systemmsg.append(s.replaceAll("<", "&lt;"));

      system.appendChild(timestamp);
      system.appendChild(systemmsg);

      body.appendChild(system);

    } else {
      // TODO use default user timestamp format
      // TODO format links and quicklinks in html log
      Element message = new Element(Tag.valueOf("div"), "",
          new Attributes());
      message.addClass("message" + (alternateMessage ? "-alt" : ""));

      Element nick = new Element(Tag.valueOf("span"), "",
          new Attributes());
      nick.addClass("nick"
          + (userNick.contains(getBot().getNick()) ? "-me" : ""));
      nick.append(userNick.replaceAll("<", "&lt;"));

      message.appendChild(timestamp);
      message.appendChild(nick);
      message.append(Message.parseForLinks(s.substring(userNick.length()))
          + " ");
View Full Code Here

  }

  private TeamData extractTeam(Element span) {
    try {
      TeamData team = new TeamData();
      Element teamAElem = span.previousElementSibling();
      team.setName(teamAElem.textNodes().get(0).text());
      Element table = span.parent().nextElementSibling();
      Elements rows = table.select("tbody > tr");
      team.setRiders(new ArrayList<String>());
      for (int i = 0; i < rows.size(); i++) {
        Element riderAElem = rows.get(i).select("td:eq(1) > a").get(0);
        team.getRiders().add(riderAElem.textNodes().get(0).text());
      }
      return team;
    } catch (Exception e) {
      e.printStackTrace();
      return null;
View Full Code Here

    List<EventSource> eventSources = new ArrayList<EventSource>();

    while (eventsDivsIter.hasNext()) {
      EventSource eventSource = null;

      Element eventDiv = eventsDivsIter.next();
      if (eventDiv.select("div.teams").size() != 0) {
        // league event
        String homeTeam = extractTeam(eventDiv, "div.teams div.home a");
        String awayTeam = extractTeam(eventDiv, "div.teams div.away a");
        String eventUri = extractTeamEventUri(eventDiv);
        if (homeTeam != null && awayTeam != null && eventUri != null) {
          eventSource = new EventSource();
          eventSource.setEventName(homeTeam + " - " + awayTeam);
          eventSource.setEventUri("www.sportowefakty.pl" + eventUri);
        }
      } else if (eventDiv.select("div.single").size() != 0) {
        // single event
        Element a = eventDiv.select("div.single a").get(0);
        String eventName = a.text();
        String eventUri = a.attr("href");
        if (eventName != null && eventUri != null) {
          eventSource = new EventSource();
          eventSource.setEventName(eventName);
          eventSource.setEventUri("www.sportowefakty.pl" + eventUri);
        }
View Full Code Here

  private Date extractEventDate(Element eventDiv) {
    Elements lis = eventDiv.select("ul.additional li");
    Iterator<Element> liIter = lis.iterator();
    while (liIter.hasNext()) {
      Element li = liIter.next();
      String text = li.text();
      if (StringUtils.isNotBlank(text)) {

        Matcher matcher = pattern.matcher(text);
        if (matcher.matches()) {
View Full Code Here

    return null;
  }

  private String extractTeam(Element eventDiv, String select) {
    try {
      Element teamA = eventDiv.select(select).get(0);
      String text = teamA.text();
      if (StringUtils.isNotBlank(text)) {
        return text.trim();
      } else {
        return null;
      }
View Full Code Here

    }
  }

  private String extractTeamEventUri(Element eventDiv) {
    try {
      Element teamA = eventDiv.select("div.teams div.home a").get(0);
      String href = teamA.attr("href");
      if (StringUtils.isNotBlank(href)) {
        return href.trim();
      } else {
        return null;
      }
View Full Code Here

TOP

Related Classes of org.jsoup.nodes.Element

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.