private boolean recuperaDadosAluno(String html) {
      HtmlCleaner cleaner = new HtmlCleaner();
      TagNode root = cleaner.clean(html);

      String table_name = context.getString(R.string.janusmob_table_ficha_aluno_id);

      TagNode table = null;
      for (TagNode node : root.getElementsByName("table", true)) {
        if (table_name.equals(node.getAttributeByName("id"))) {
          table = node;
          break;
        }
      }

      if (table == null) {
        return false;
      }

      String attribute_class_name = context.getString(R.string.janusmob_attribute_td_class_name);
      List<Campo> l = new LinkedList<Campo>();
      TagNode nodeValor = null;
      for (TagNode nodeCampo : table.getElementsByName("td", true)) {
        if (attribute_class_name.equals(nodeCampo.getAttributeByName("class"))) {
          nodeValor = nodeCampo.getParent().getElementsByName("td", false)[1];
          l.add(
              new Campo(
                  nodeCampo.getText().toString().split(":")[0],
                  nodeValor.getText().toString().trim().replaceAll("\"", "")));
        }
      }

      dbAdapter.setCampos(l);

      return true;
    }
Esempio n. 2
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);
    }
  }
    private boolean recuperaDadosPessoais(String html) {
      HtmlCleaner cleaner = new HtmlCleaner();
      TagNode root = cleaner.clean(html);

      String table_name = context.getString(R.string.janusmob_table_dados_aluno_id);

      TagNode table = null;
      for (TagNode node : root.getElementsByName("table", true)) {
        if (table_name.equals(node.getAttributeByName("id"))) {
          table = node;
          break;
        }
      }

      if (table == null) {
        return false;
      }

      String attribute_class_name = context.getString(R.string.janusmob_attribute_class_name);
      String campo_nusp = context.getString(R.string.janusmob_campo_nusp);
      String campo_nome = context.getString(R.string.janusmob_campo_nome);
      String campo_email = context.getString(R.string.janusmob_campo_email);
      String campo_cpf = context.getString(R.string.janusmob_campo_cpf);
      Usuario usuario = new Usuario();
      for (TagNode node : table.getElementsByName("span", true)) {
        if (attribute_class_name.equals(node.getAttributeByName("class"))) {
          TagNode parent = node.getParent();
          parent.removeChild(node);
          if (node.getText().toString().trim().equals(campo_nusp)) {
            usuario.setNusp(parent.getText().toString().trim());
          } else if (node.getText().toString().trim().equals(campo_nome)) {
            usuario.setNome(parent.getText().toString().trim());
          } else if (node.getText().toString().trim().equals(campo_email)) {
            usuario.setEmail(parent.getText().toString().trim());
          } else if (node.getText().toString().trim().equals(campo_cpf)) {
            usuario.setCpf(parent.getText().toString().trim());
          }
        }
      }

      if (lembrarSenha) {
        usuario.setSenha(senha);
      } else {
        usuario.setSenha(null);
      }

      dbAdapter.setUsuario(usuario);

      return true;
    }
  public static ArrayList<ContentValues> parsePosts(
      TagNode aThread,
      int aThreadId,
      int unreadIndex,
      int opId,
      AwfulPreferences prefs,
      int startIndex) {
    ArrayList<ContentValues> result = new ArrayList<ContentValues>();
    boolean lastReadFound = false;
    int index = startIndex;
    String update_time = new Timestamp(System.currentTimeMillis()).toString();
    Log.v(TAG, "Update time: " + update_time);
    try {
      if (!Constants.isICS()
          || !prefs.inlineYoutube) { // skipping youtube support for now, it kinda sucks.
        aThread = convertVideos(aThread);
      }
      TagNode[] postNodes = aThread.getElementsByAttValue("class", "post", true, true);

      for (TagNode node : postNodes) {
        // fyad status, to prevent processing postbody twice if we are in fyad
        ContentValues post = new ContentValues();
        post.put(THREAD_ID, aThreadId);

        // We'll just reuse the array of objects rather than create
        // a ton of them
        int id = Integer.parseInt(node.getAttributeByName("id").replaceAll("post", ""));
        post.put(ID, id);
        post.put(AwfulProvider.UPDATED_TIMESTAMP, update_time);
        post.put(POST_INDEX, index);
        if (index > unreadIndex) {
          post.put(PREVIOUSLY_READ, 0);
          lastReadFound = true;
        } else {
          post.put(PREVIOUSLY_READ, 1);
        }
        index++;
        post.put(IS_MOD, 0);
        post.put(IS_ADMIN, 0);
        TagNode[] postContent = node.getElementsHavingAttribute("class", true);
        for (TagNode pc : postContent) {
          if (pc.getAttributeByName("class").contains("author")) {
            post.put(USERNAME, pc.getText().toString().trim());
          }

          if (pc.getAttributeByName("class").contains("role-mod")) {
            post.put(IS_MOD, 1);
          }

          if (pc.getAttributeByName("class").contains("role-admin")) {
            post.put(IS_ADMIN, 1);
          }

          if (pc.getAttributeByName("class").equalsIgnoreCase("title")
              && pc.getChildTags().length > 0) {
            TagNode[] avatar = pc.getElementsByName("img", true);

            if (avatar.length > 0) {
              post.put(AVATAR, avatar[0].getAttributeByName("src"));
            }
            post.put(AVATAR_TEXT, pc.getText().toString().trim());
          }

          if (pc.getAttributeByName("class").equalsIgnoreCase("postbody")
              || pc.getAttributeByName("class").contains("complete_shit")) {
            TagNode[] images = pc.getElementsByName("img", true);

            for (TagNode img : images) {
              // don't alter video mock buttons
              if ((img.hasAttribute("class")
                  && img.getAttributeByName("class").contains("videoPlayButton"))) {
                continue;
              }
              boolean dontLink = false;
              TagNode parent = img.getParent();
              String src = img.getAttributeByName("src");

              if ((parent != null && parent.getName().equals("a"))
                  || (img.hasAttribute("class")
                      && img.getAttributeByName("class")
                          .contains("nolink"))) { // image is linked, don't override
                dontLink = true;
              }
              if (src.contains(".gif")) {
                img.setAttribute(
                    "class",
                    (img.hasAttribute("class") ? img.getAttributeByName("class") + " " : "")
                        + "gif");
              }

              if (img.hasAttribute("title")) {
                if (!prefs.showSmilies) { // kill all emotes
                  String name = img.getAttributeByName("title");
                  img.setName("p");
                  img.addChild(new ContentNode(name));
                }
              } else {
                if (!lastReadFound && prefs.hideOldImages || !prefs.imagesEnabled) {
                  if (!dontLink) {
                    img.setName("a");
                    img.setAttribute("href", src);
                    img.addChild(new ContentNode(src));
                  } else {
                    img.setName("p");
                    img.addChild(new ContentNode(src));
                  }
                } else {
                  if (!dontLink) {
                    img.setName("a");
                    img.setAttribute("href", src);
                    TagNode newimg = new TagNode("img");
                    if (!prefs.imgurThumbnails.equals("d") && src.contains("i.imgur.com")) {
                      int lastSlash = src.lastIndexOf('/');
                      if (src.length() - lastSlash <= 9) {
                        int pos = src.length() - 4;
                        src = src.substring(0, pos) + prefs.imgurThumbnails + src.substring(pos);
                      }
                    }
                    newimg.setAttribute("src", src);
                    img.addChild(newimg);
                  }
                }
              }
            }

            StringBuffer fixedContent = new StringBuffer();
            Matcher fixCharMatch = fixCharacters_regex.matcher(NetworkUtils.getAsString(pc));

            while (fixCharMatch.find()) {
              fixCharMatch.appendReplacement(fixedContent, "");
            }

            fixCharMatch.appendTail(fixedContent);
            post.put(CONTENT, fixedContent.toString());
          }

          if (pc.getAttributeByName("class").equalsIgnoreCase("postdate")) {
            post.put(
                DATE,
                NetworkUtils.unencodeHtml(pc.getText().toString())
                    .replaceAll("[^\\w\\s:,]", "")
                    .trim());
          }

          if (pc.getAttributeByName("class").equalsIgnoreCase("profilelinks")) {
            TagNode[] links = pc.getElementsHavingAttribute("href", true);

            if (links.length > 0) {
              String href = links[0].getAttributeByName("href").trim();
              String userId = href.substring(href.lastIndexOf("rid=") + 4);

              post.put(USER_ID, userId);

              if (Integer.toString(opId).equals(userId)) { // ugh
                post.put(IS_OP, 1);
              } else {
                post.put(IS_OP, 0);
              }
            }
          }
          if (pc.getAttributeByName("class").equalsIgnoreCase("editedby")
              && pc.getChildTags().length > 0) {
            post.put(EDITED, "<i>" + pc.getChildTags()[0].getText().toString() + "</i>");
          }
        }
        TagNode[] editImgs = node.getElementsByAttValue("alt", "Edit", true, true);

        if (editImgs.length > 0) {
          post.put(EDITABLE, 1);
        } else {
          post.put(EDITABLE, 0);
        }
        result.add(post);
      }

      Log.i(
          TAG,
          Integer.toString(postNodes.length) + " posts found, " + result.size() + " posts parsed.");
    } catch (Exception e) {
      e.printStackTrace();
    }

    return result;
  }