Ejemplo n.º 1
0
 private void resetGidSerial() {
   GrabbedImageData gid;
   for (int i = 0; i < grabbedImageData.size(); i++) {
     gid = grabbedImageData.get(i);
     if (gid != null) {
       gid.setSerialnumber(i);
     }
   }
 }
Ejemplo n.º 2
0
  public void compileXML() {
    createOutputDirStructure();
    if (!xmlcompiled) {
      Pattern pass1 = Pattern.compile("\\<div.*?\\>");
      Pattern pass2 = Pattern.compile("^\\<.*(?=data\\-ri).*\\>$");
      Pattern pass3 = Pattern.compile("\\<a.*?\\>");
      Pattern hrefPat = Pattern.compile("(?<=href\\=\\\").*?(?=\\\".*\\>)");
      Pattern dataRowPat = Pattern.compile("(?<=data\\-row\\=\\\").*?(?=\\\")");
      Pattern dataRiPat = Pattern.compile("(?<=data\\-ri\\=\\\").*?(?=\\\")");
      Pattern imgurlPat = Pattern.compile("(?<=\\?imgurl\\=).*?(?=\\&amp\\;)");
      Pattern imgwPat = Pattern.compile("(?<=\\&amp\\;w=).*?(?=\\&amp\\;)");
      Pattern imghPat = Pattern.compile("(?<=\\&amp\\;h=).*?(?=\\&amp\\;)");
      Pattern tagMeta =
          Pattern.compile(
              "(?<=\\<div\\s{1,10}class\\=\\\"rg_meta\\\"\\>" + "\\s{0,10})\\{.*\\}(?=\\</div\\>)");
      Pattern metaName = Pattern.compile("(?<=((\\{|\\,)\\\"fn\\\"\\s?:\\s?\\\")).*?(?=\\\")");
      Pattern metaPara = Pattern.compile("(?<=((\\{|\\,)\\\"pt\\\"\\s?:\\s?\\\")).*?(?=\\\")");
      Pattern metaSide = Pattern.compile("(?<=((\\{|\\,)\\\"s\\\"\\s?:\\s?\\\")).*?(?=\\\")");

      Matcher mat1, mat2, mat3;
      try (Scanner sc = new Scanner(new FileInputStream(googleXML))) {
        while (sc.hasNextLine()) {
          ArrayList<Match> lineMatches = new ArrayList<>();
          String mainline = sc.nextLine();
          mat1 = pass1.matcher(mainline);
          while (mat1.find()) {
            String divline = mat1.group();
            mat2 = pass2.matcher(divline);
            if (mat2.find()) {
              lineMatches.add(new Match(divline, mat1.start(), mat1.end()));
            }
          }
          String tagALineEx, tagALine;
          int size = lineMatches.size();
          for (int i = 0; i < size; i++) {
            Match match = lineMatches.get(i);
            tagALineEx =
                mainline.substring(
                    match.divend,
                    i + 1 == size ? mainline.length() : lineMatches.get(i + 1).divstart);
            mat3 = pass3.matcher(tagALineEx);
            if (mat3.find()) {
              tagALine = mat3.group();
              mat1 = hrefPat.matcher(tagALine);
              if (mat1.find()) {
                match.tagahref = mat1.group();
              }
            }
            mat2 = tagMeta.matcher(tagALineEx);
            if (mat2.find()) {
              match.tagmeta = mat2.group();
            }
          }

          GrabbedImageData gid;
          for (Match match : lineMatches) {
            gid = new GrabbedImageData();
            mat1 = dataRowPat.matcher(match.tagdiv);
            if (mat1.find()) {
              gid.setRownumber(Integer.parseInt(mat1.group()));
            }
            mat1 = dataRiPat.matcher(match.tagdiv);
            if (mat1.find()) {
              gid.setSerialnumber(Integer.parseInt(mat1.group()));
            }
            mat1 = imgurlPat.matcher(match.tagahref);
            if (mat1.find()) {
              gid.setUrl(mat1.group());
            }
            mat1 = imgwPat.matcher(match.tagahref);
            if (mat1.find()) {
              gid.setWidth(Integer.parseInt(mat1.group()));
            }
            mat1 = imghPat.matcher(match.tagahref);
            if (mat1.find()) {
              gid.setHeight(Integer.parseInt(mat1.group()));
            }
            mat1 = metaName.matcher(match.tagmeta);
            if (mat1.find()) {
              gid.setFileName(mat1.group());
            }
            mat1 = metaPara.matcher(match.tagmeta);
            if (mat1.find()) {
              gid.setHeading(mat1.group());
            }
            mat1 = metaSide.matcher(match.tagmeta);
            if (mat1.find()) {
              gid.setSideData(mat1.group());
            }
            grabbedImageData.add(gid);
          }
        }
        xmlcompiled = true;
      } catch (FileNotFoundException ex) {
        ResourceHelper.errLog("Compiler > compileXML() > Error : %s", ex);
      }
    }
  }