private static Collection<Node> extractImageNodes(Element aInContent) {
    Collection<Node> lImageNodes = new LinkedList<>();

    Elements lImageElements = aInContent.getElementsByTag("img");
    if (!lImageElements.isEmpty()) {
      int i = 0;
      for (Element lImageElement : lImageElements) {
        i++;
        if (lImageElement.hasClass("float-left")) {
          if (!lImageElement.hasClass("alignleft")) {
            lImageElement.addClass("alignleft");
          }
        } else if (lImageElement.hasClass("float-right")) {
          if (!lImageElement.hasClass("alignright")) {
            lImageElement.addClass("alignright");
          }
        }

        if (i > 1) {
          lImageElement.removeAttr("width");
          lImageElement.removeAttr("height");
        }

        Node lThisNode = toNode(lImageElement);
        lImageNodes.add(lThisNode.clone());
      }
    }

    return lImageNodes;
  }
Example #2
0
 private String getUpdatedFileContent(List<Vacancy> vacancies) {
   Document document = null;
   try {
     document = getDocument();
     document.html();
     Element template = document.select("[class=vacancy template]").first();
     Element templateCopy = template.clone();
     templateCopy.removeAttr("style");
     templateCopy.removeAttr("class");
     templateCopy.addClass("vacancy");
     document.select("tr[class=vacancy]").remove();
     for (Vacancy vacancy : vacancies) {
       Element thisVacancyElement = templateCopy.clone();
       thisVacancyElement.select("[class=city]").first().text(vacancy.getCity());
       thisVacancyElement.select("[class=companyName]").first().text(vacancy.getCompanyName());
       thisVacancyElement.select("[class=salary]").first().text(vacancy.getSalary());
       thisVacancyElement
           .select("[class=title]")
           .select("a[href]")
           .first()
           .text(vacancy.getTitle());
       thisVacancyElement
           .select("[class=title]")
           .select("a[href]")
           .first()
           .attr("href", vacancy.getUrl());
       document.select("[class=vacancy template]").first().before(thisVacancyElement.outerHtml());
     }
   } catch (IOException e) {
     e.printStackTrace();
     System.out.println("Some exception occurred");
   }
   return document.html();
 }
Example #3
0
  @Test
  public void testClassUpdates() {
    Document doc = Jsoup.parse("<div class='mellow yellow'></div>");
    Element div = doc.select("div").first();

    div.addClass("green");
    assertEquals("mellow yellow green", div.className());
    div.removeClass("red"); // noop
    div.removeClass("yellow");
    assertEquals("mellow green", div.className());
    div.toggleClass("green").toggleClass("red");
    assertEquals("mellow red", div.className());
  }