Пример #1
0
  private void doProcessIncludes(TagNode html, int depth, FormFlow formFlow)
      throws IOException, FormParserException {
    if (depth < processIncludesMaxDepth) {
      @SuppressWarnings("unchecked")
      List<TagNode> includeNodes = html.getElementListByName(Constants.INCLUDE_ELEMENT, true);
      for (TagNode includeNode : includeNodes) {
        String srcAttribute = includeNode.getAttributeByName("src");
        srcAttribute = formFlow.resolveResourcePathIfRelative(srcAttribute);
        InputStream resourceAsStream = resourceLoader.getFormResourceAsStream(srcAttribute);
        if (resourceAsStream != null) {
          TagNode includeHtml = htmlCleaner.clean(resourceAsStream);
          TagNode body = includeHtml.findElementByName("body", false);
          doProcessIncludes(body, depth + 1, formFlow);

          @SuppressWarnings("unchecked")
          List<HtmlNode> bodyChildren = body.getChildren();
          Collections.reverse(bodyChildren);
          TagNode includeParent = includeNode.getParent();
          for (HtmlNode bodyChild : bodyChildren) {
            includeParent.insertChildAfter(includeNode, bodyChild);
          }
          includeParent.removeChild(includeNode);
        } else {
          throw new FormParserException("Include file not found. Path:'" + srcAttribute + "'");
        }
      }
    } else {
      throw new FormParserException(
          "Exceeded maximum nested "
              + Constants.INCLUDE_ELEMENT
              + " depth of "
              + processIncludesMaxDepth);
    }
  }
Пример #2
0
  @Override
  public void getSubtitleData(TagNode rootNode, ArrayList<Subtitle> subtitles) {
    ArrayList<TagNode> listingTags = getTagsByClass(rootNode, "li", "listing");

    if (!listingTags.isEmpty()) {
      TagNode liNode = listingTags.get(0);
      TagNode nja = (TagNode) liNode.getChildren().get(0);
      for (int i = 0; i < nja.getChildren().size(); i++) {
        TagNode titlli = (TagNode) nja.getChildren().get(i);
        TagNode namelink = (TagNode) titlli.getElementListByName("a", true).get(0);
        ArrayList<TagNode> cdTags = getTagsByClass(titlli, "span", "cd");
        ArrayList<TagNode> releaseTags = getTagsByClass(titlli, "span", "release");
        ArrayList<TagNode> fpsTags = getTagsByClass(titlli, "span", "fps");
        ArrayList<TagNode> dwTags = getTagsByClass(titlli, "a", "button");

        // naslov
        String ttitle = namelink.getText().toString();
        // broj cd-a
        String tCDNumber = "0";
        if (!cdTags.isEmpty()) {
          tCDNumber = cdTags.get(0).getText().toString().replace("CD", " ").trim();
        }
        // verzija
        String release = "N/A";
        if (!releaseTags.isEmpty()) {
          release = releaseTags.get(0).getText().toString().trim();
        }
        // fps
        String fps = "N/A";
        if (!fpsTags.isEmpty()) {
          fps =
              fpsTags
                  .get(0)
                  .getText()
                  .toString()
                  .substring(4, fpsTags.get(0).getText().toString().length())
                  .trim();
        }

        TagNode dwTagNode = dwTags.get(0);
        String dwPage = dwTagNode.getAttributeByName("href");

        Subtitle subtitle = new Subtitle(ttitle, release, dwPage);
        subtitle.setNumberOfDiscs(Integer.parseInt(tCDNumber));
        subtitle.setFps(fps);
        subtitle.setDownloadURL(dwPage);

        subtitles.add(subtitle);
      }
    }
  }
Пример #3
0
  private void recordInputFields(
      TagNode formNode, FormFlow formFlow, Document dataDocument, String docBase)
      throws XPathExpressionException, XPatherException {
    List<InputPojo> inputPojos = new ArrayList<InputPojo>();
    Map<String, InputPojo> inputPojosMap = new HashMap<String, InputPojo>();

    @SuppressWarnings("unchecked")
    List<TagNode> inputs = formNode.getElementListByName("input", true);
    @SuppressWarnings("unchecked")
    List<TagNode> selects = formNode.getElementListByName("select", true);
    inputs.addAll(selects);
    for (TagNode inputTagNode : inputs) {
      String name = inputTagNode.getAttributeByName(Constants.NAME_ATTR);
      if (name != null) {
        String type;

        if (inputTagNode.getName().equals("select")) {
          type = "select";
        } else {
          type = inputTagNode.getAttributeByName(Constants.TYPE_ATTR);
        }

        if (type != null) {

          if (!(type.equals("radio") && inputPojosMap.containsKey(name))) {

            // Collect all rf.xxx attributes
            Map<String, String> rfAttributes = new HashMap<String, String>();
            Map<String, String> attributes = inputTagNode.getAttributes();
            for (String attName : attributes.keySet()) {
              if (attName.startsWith("rf.")) {
                rfAttributes.put(attName, attributes.get(attName));
              }
            }

            InputPojo inputPojo = new InputPojo(name, type, rfAttributes);
            inputPojosMap.put(name, inputPojo);
            inputPojos.add(inputPojo);
          }

          // Push values from the dataDocument into the form html.
          String inputValue = lookupValueByFieldName(dataDocument, name, docBase);
          if (inputValue != null) {
            if (type.equals("radio")) {
              String value = inputTagNode.getAttributeByName(Constants.VALUE_ATTR);
              if (inputValue.equals(value)) {
                inputTagNode.setAttribute(Constants.CHECKED_ATTR, Constants.CHECKED_ATTR);
              }
            } else if (type.equals("checkbox")) {
              if (inputValue.equals("true")) {
                inputTagNode.setAttribute(Constants.CHECKED_ATTR, Constants.CHECKED_ATTR);
              }
            } else if (type.equals("select")) {
              Object[] nodes = inputTagNode.evaluateXPath("option[@value=\"" + inputValue + "\"]");
              if (nodes.length == 0) {
                nodes = inputTagNode.evaluateXPath("option[text()=\"" + inputValue + "\"]");
              }
              if (nodes.length > 0) {
                ((TagNode) nodes[0]).setAttribute(Constants.SELECTED_ATTR, "selected");
              }
            } else {
              inputTagNode.setAttribute("value", inputValue);
            }
          }
        } else {
          logger.debug("Input name:{} has no type attribute!", name);
        }
      }
    }
    formFlow.setCurrentInputPojos(inputPojos);
  }