Ejemplo n.º 1
0
  public Integer getImageNr() {
    Integer url = -1;
    try {
      ElementIterator it = new ElementIterator(this.htmlDoc);
      Element element;
      while ((element = it.next()) != null) {
        // <div id="picture">
        Element elementIdAnswers = getChildElementByTagName(element, Tag.IMG, null);
        if (elementIdAnswers != null) {
          Map<String, String> foundAtrib = this.getAtributes(elementIdAnswers, questionReadAtrib);
          String href = foundAtrib.get("a");
          if (href != null) {
            href = clearHref(href);
            url = CommonS.strToInteger(href);
            break;
          }
        }
      }

    } catch (Exception ex) {
      logger.error("Save page: " + CommonS.saveStringList(buff));
    }

    // if (url < 1){
    //	HtmlPrinter hp = new HtmlPrinter(this.htmlDoc);
    //	CommonS.out("Save page: "+ CommonS.saveStringList(buff));
    //	CommonS.stopThread(" Picture Href not found ! ");
    // }

    return url;
  }
Ejemplo n.º 2
0
  public Question getQuestion() throws Exception {
    Question question = new Question();
    try {
      ElementIterator it = new ElementIterator(this.htmlDoc);
      Element element;
      while ((element = it.next()) != null) {

        // <div id="question">
        Element elementQuestion = getChildElementByTagName(element, Tag.DIV, srcIdQuest);
        if (elementQuestion != null) {
          // <div class="question"> text . . .
          Element elementQuestionText =
              getChildElementByTagName(elementQuestion, Tag.DIV, srcClassQuest);
          if (elementQuestionText != null)
            question.setQuestionText(getElementText(elementQuestionText));
          // <input id="question" type="hidden" value="32384"
          // name="question">.
          Element elementQuestionInput =
              getChildElementByTagName(elementQuestion, Tag.IMPLIED, null /* searchQusetion */);
          if (elementQuestionInput != null) {
            Element elementQuestionInput2 =
                getChildElementByTagName(elementQuestionInput, Tag.INPUT, srcIdQuest);
            if (elementQuestionInput2 != null) {
              Map<String, String> foundAtrib =
                  this.getAtributes(elementQuestionInput2, questionReadAtrib);
              String str = foundAtrib.get("value");
              Integer sk = CommonS.strToInteger(str);
              question.setQuestionCsddId(sk);
            }
          }
        }
      }
    } catch (Exception e) {
      logger.error("", e);
      CommonS.stopThread(e);
    }
    if (!question.isQuestionOk()) {
      logger.error("question not found ! ");
      logger.error("Save page: " + CommonS.saveStringList(buff));
      throw new MyCustException("Ending thread");
      // CommonS.stopThread();
    }

    return question;
  }
Ejemplo n.º 3
0
  public Integer getCorrectAnswer() throws MyCustException {
    Integer csddIdInt = 0;
    try {
      ElementIterator it = new ElementIterator(this.htmlDoc);
      Element element;
      while ((element = it.next()) != null) {
        // <div id="answers">
        Element elementIdAnswers = getChildElementByTagName(element, Tag.DIV, srcIdAnswers);
        if (elementIdAnswers != null) {
          // <div>
          Element elementDiv = getChildElementByTagName(elementIdAnswers, Tag.DIV, null);
          if (elementDiv != null) {
            // <div class= 'answer right'>
            Element elementAnswerRight =
                getChildElementByTagName(elementDiv, Tag.DIV, srcAnswerRight);
            if (elementAnswerRight != null) {
              Element elementClassAnswerInp =
                  getChildElementByTagName(elementAnswerRight, Tag.IMPLIED, null);
              if (elementClassAnswerInp != null) {
                Element elementClassAnswerInp2 =
                    getChildElementByTagName(elementClassAnswerInp, Tag.INPUT, srcNameAnswer);
                if (elementClassAnswerInp2 != null) {
                  Map<String, String> foundAtrib =
                      this.getAtributes(elementClassAnswerInp2, questionReadAtrib);
                  String csddId = foundAtrib.get("id");
                  csddId = clearAnswer(csddId);
                  csddIdInt = CommonS.strToInteger(csddId);
                }
              }
            }
          }
        }
      }

    } catch (Exception ex) {
      logger.error("Save page: " + CommonS.saveStringList(buff));
    }
    if (csddIdInt == 0) {
      logger.info("Save page: " + CommonS.saveStringList(buff));
      CommonS.stopThread("CorrectAnswer not found !");
    }

    return csddIdInt;
  }
Ejemplo n.º 4
0
  public Map<Integer, Integer> getAnswerIds() throws MyCustException {
    Map<Integer, Integer> answers = new HashMap<Integer, Integer>();
    try {
      ElementIterator it = new ElementIterator(this.htmlDoc);
      Element element;
      while ((element = it.next()) != null) {
        // <div id="navi">
        Element elementIdNav = getChildElementByTagName(element, Tag.DIV, srcIdNavi);
        if (elementIdNav != null) {
          // <div id ='change1'>
          Element elementIdChange1 = getChildElementByTagName(elementIdNav, Tag.DIV, srcIdChange1);
          if (elementIdChange1 != null) {
            // <div id ='change2'>
            Element elementIdChange2 =
                getChildElementByTagName(elementIdChange1, Tag.DIV, srcIdChange2);
            if (elementIdChange2 != null) {
              // <div id ='question_xxxxx'>
              List<Element> elementIdQuestions =
                  getChildElementsByTagName(elementIdChange2, Tag.DIV, null);
              if (elementIdQuestions.size() != 0) {
                for (int index = 1; index < elementIdQuestions.size(); index++) {
                  Element elemntid = elementIdQuestions.get(index);
                  Map<String, String> rez = getAtributes(elemntid, allAnswers);
                  String str = clearQuestion(rez.get("id"));
                  Integer sk = CommonS.strToInteger(str);
                  answers.put(index, sk);
                }
              }
            }
          }
        }
      } // end while
    } catch (Exception e) {
      logger.error("Save page: " + CommonS.saveStringList(buff));
      CommonS.stopThread(e);
    }

    if ((answers.size() == 0) || (answers.size() != TCaseCont.QUESTION_COUNT)) {
      CommonS.stopThread(" short answerList not corect ! ");
    }

    return answers;
  }
Ejemplo n.º 5
0
  /**
   * @return List<Answer> - order is important!
   * @throws MyCustException
   */
  public List<Answer> getAnswers() throws MyCustException {
    List<Answer> answers = new ArrayList<Answer>();

    try {
      ElementIterator it = new ElementIterator(this.htmlDoc);
      Element element;
      while ((element = it.next()) != null) {
        // <div class="answer"
        List<Element> elementAnswers = getChildElementsByTagName(element, Tag.DIV, srcClassAnswer);
        if (elementAnswers.size() != 0)
          for (Element elementAnswer : elementAnswers) {
            // <input id="answer55667" type="radio" value="55667"
            // name="answer">
            Element elementAnswerInput =
                getChildElementByTagName(elementAnswer, Tag.IMPLIED, null /* searchQusetion */);
            if (elementAnswerInput != null) {
              Element elementAnswerInput2 =
                  getChildElementByTagName(elementAnswerInput, Tag.INPUT, srcNameAnswer);
              if (elementAnswerInput2 != null) {
                Map<String, String> foundAtrib =
                    getAtributes(elementAnswerInput2, questionReadAtrib);
                String csddIdText = foundAtrib.get("value");
                Integer csddId = CommonS.strToInteger(csddIdText);
                String questionText = getElementText(elementAnswer);
                answers.add(new Answer(csddId, questionText));
              }
            }
          }
      }
    } catch (Exception e) {
      logger.error("", e);
      CommonS.stopThread(e);
    }
    if (answers.size() == 0) {
      logger.info("Save page: " + CommonS.saveStringList(buff));
      CommonS.stopThread("Answers not found ! ");
    }
    return answers;
  }