Ejemplo n.º 1
0
    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;
    }
 public String GetInnerTextByXpath(String html, String xpath) throws Exception {
   HtmlCleaner hc = new HtmlCleaner();
   TagNode tn = hc.clean(html);
   Object[] objarr = null;
   objarr = tn.evaluateXPath(xpath);
   TagNode newNode = (TagNode) objarr[0];
   return newNode.getText().toString();
 }
Ejemplo n.º 3
0
 private String getMensagemErro(String html) {
   TagNode root = new HtmlCleaner().clean(html);
   String idSpanMensagemErro = context.getString(R.string.janusmob_span_erro_id);
   TagNode[] tags = root.getElementsByName("span", true);
   for (TagNode node : tags) {
     if (idSpanMensagemErro.equals(node.getAttributeByName("id"))) {
       return node.getText().toString();
     }
   }
   return context.getString(R.string.janusmob_mensagem_erro_login);
 }
Ejemplo n.º 4
0
    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;
    }
Ejemplo n.º 5
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);
      }
    }
  }
Ejemplo n.º 6
0
  public static ArrayList<String> dobi_opis(TagNode node, String XPathExpression) {
    ArrayList<String> Temp = new ArrayList<String>();
    TagNode description_node = null;
    NodeList nodes;
    try {

      //			description_node = (TagNode) node.evaluateXPath(XPathExpression)[0];
      for (int x = 0; x < node.evaluateXPath(XPathExpression).length; x++) {
        description_node = (TagNode) node.evaluateXPath(XPathExpression)[x];
        //
        //	System.out.println(description_node.getText()+"\n"+"---------------------------------------");
        Temp.add(description_node.getText().toString());
      }
    } catch (XPatherException e) {
      e.printStackTrace();
    }
    return Temp;
    //
    //	System.out.println(description_node.getText()+"\n"+"---------------------------------------");
  }
  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;
  }