Пример #1
0
  /**
   * Handles POST requests for /
   *
   * @param apiEntry the object with form data about entry point.
   * @param result BindingResult with data about validation of input data.
   * @return JSP page which will be shown.
   */
  @RequestMapping(value = "/", method = RequestMethod.POST)
  public String doCheckAPI(ApiEntry apiEntry, BindingResult result) {
    if (result.hasErrors()) {
      return JSP;
    }
    if (!apiEntry.getUrl().startsWith("http://") && !apiEntry.getUrl().startsWith("https://")) {
      apiEntry.setUrl("http://" + apiEntry.getUrl());
    }
    if (apiEntry.getUrl().length() < 10) {
      apiEntry.setMessage("Invalid URL");
      return JSP;
    }

    createTree(apiEntry);
    if (HttpValidator.responseOk(apiEntry)
        && apiEntry.getResourceNodes().getDescendants().size() > 0) {
      validateTree(apiEntry);
      generateViewOfQuestionnaires(apiEntry);
      generateViewOfResources(apiEntry);
      generateViewOfTree(apiEntry);
      return JSPOkResponse;
    } else {
      return JSPBadResponse;
    }
  }
Пример #2
0
  /**
   * Writes the View of APIs resource tree for specified resourceNode and its descendants.
   *
   * @param resourceNode for which the view is written.
   * @param baseUrl Used for shortening the URI id's of resources and limiting API scope.
   * @param maxSiblings limits number of children for one resource.
   * @param sb StringBuilder in which the view is written.
   */
  private void writeResourceNodeTreeView(
      ResourceNode resourceNode, String baseUrl, int maxSiblings, StringBuilder sb) {
    String temp;
    sb.append("<li>");
    temp = resourceNode.getCurrentResource().getUrl().replaceFirst(baseUrl, "");
    if (temp.length() == 0) {
      temp = "/";
    }

    sb.append(temp);

    sb.append(
        " <a class=\"right\" href=\"#\" onclick=\"toggleVisibility(document.getElementById(\'"
            + HttpValidator.toSafeId(resourceNode.getCurrentResource().getUrl())
            + "\')); return false\" > more info</a> ");

    if (resourceNode.getViolationMessages().size() > 0) {
      for (String violationKey : resourceNode.getViolationMessages().keySet()) {
        String messagesDisp = "";
        for (String vilationMessages :
            resourceNode.getViolationMessages().get(violationKey).getMessages()) {
          messagesDisp = messagesDisp + ", " + vilationMessages;
        }
        if (messagesDisp.startsWith(", ")) {
          messagesDisp = messagesDisp.substring(2);
        }
        sb.append(
            " <img src=\"../redDot.gif\" alt=\" x \" title=\""
                + violationKey
                + ": "
                + messagesDisp
                + "\" height=\"13\" width=\"13\" /> ");
      }
    }

    if (resourceNode.getNonViolationMessages().size() > 0) {
      for (String violationKey : resourceNode.getNonViolationMessages().keySet()) {
        String messagesDisp = "";
        for (String vilationMessages :
            resourceNode.getNonViolationMessages().get(violationKey).getMessages()) {
          messagesDisp = messagesDisp + ", " + vilationMessages;
        }
        if (messagesDisp.startsWith(", ")) {
          messagesDisp = messagesDisp.substring(2);
        }
        sb.append(
            " <img class=\"right\" src=\"../orangeDot.gif\" alt=\" ? \" title=\""
                + violationKey
                + ": "
                + messagesDisp
                + "\" height=\"13\" width=\"13\" /> ");
      }
    }

    if (resourceNode.getDescendants().size() > 0) {
      sb.append("\n<ul>\n");
      try {
        for (ResourceNode rs : resourceNode.getDescendants().subList(0, maxSiblings)) {
          writeResourceNodeTreeView(rs, baseUrl, maxSiblings, sb);
        }
        int overSize = resourceNode.getDescendants().size() - maxSiblings;
        if (overSize > 0) {
          sb.append("<li>...and " + overSize + " more.</li>");
        }
      } catch (java.lang.IndexOutOfBoundsException e) {
        for (ResourceNode rs : resourceNode.getDescendants()) {
          writeResourceNodeTreeView(rs, baseUrl, maxSiblings, sb);
        }
      }
      sb.append("</ul>\n");
    }

    sb.append("</li>");
    sb.append("\n");
  }