Esempio n. 1
0
 public void compile() {
   if (!compiled) {
     createOutputDirStructure();
     compileScreenShot();
     compileXML();
   }
 }
Esempio n. 2
0
  public void compileScreenShot() {
    createOutputDirStructure();
    if (!screenshotcompiled) {
      try {
        int travDiviser = 100;
        BufferedImage shot = ResourceHelper.getImageResource(googleScreenShot);
        int shotWidth = shot.getWidth();
        int shotHeight = shot.getHeight();
        int travXUnit = Math.max(shotWidth / travDiviser, 1);
        int travYUnit = Math.max(shotHeight / travDiviser, 1);
        Color bg =
            new Color(
                Integer.parseInt(
                    ResourceHelper.getGoogleProperty(Constants.KEY_GOOGLE_BACKGROUND_COLOR_RED)),
                Integer.parseInt(
                    ResourceHelper.getGoogleProperty(Constants.KEY_GOOGLE_BACKGROUND_COLOR_GREEN)),
                Integer.parseInt(
                    ResourceHelper.getGoogleProperty(Constants.KEY_GOOGLE_BACKGROUND_COLOR_BLUE)));
        Color col;
        ArrayList<Integer> topList = new ArrayList<>();
        ArrayList<Integer> btmList = new ArrayList<>();
        boolean lastLineMatched = true;
        for1:
        for (int y = 0; y < shotHeight; y++) {
          for2:
          for (int x = 0; x < shotWidth; x += travXUnit) {
            col = new Color(shot.getRGB(x, y));
            if (!col.equals(bg)) {
              if (lastLineMatched) {
                topList.add(y);
                lastLineMatched = false;
              }
              continue for1;
            }
          }
          if (!lastLineMatched) {
            btmList.add(y - 1);
            lastLineMatched = true;
          }
        }

        Rectangle rect = null;
        boolean newRectInserted = false;
        ArrayList<GrabbedImagePosition> grabbedImagePoss = new ArrayList<>();
        int colnum, sno = 0;
        loop1:
        for (int i = 0; i < topList.size(); i++) {
          lastLineMatched = true;
          int maxTop = topList.get(i);
          int maxBtm = btmList.get(i);
          travYUnit = Math.max((maxBtm - maxTop) / travDiviser, 1);
          colnum = 0;
          loop2:
          for (int x = 0; x < shotWidth; x++) {
            loop3:
            for (int y = maxTop; y <= maxBtm; y += travYUnit) {
              col = new Color(shot.getRGB(x, y));
              if (!col.equals(bg)) {
                if (lastLineMatched) {
                  newRectInserted = false;
                  rect = new Rectangle(x, maxTop, 0, maxBtm - maxTop + 1);
                  lastLineMatched = false;
                }
                continue loop2;
              }
            }
            if (!lastLineMatched) {
              rect.width = x - rect.x;
              GrabbedImagePosition gip = new GrabbedImagePosition(sno++);
              gip.setBounds(rect);
              gip.setRownumber(i);
              gip.setColnumber(colnum++);
              grabbedImagePoss.add(gip);
              lastLineMatched = true;
              newRectInserted = true;
            }
          }
          if (!newRectInserted) {
            rect.width = shotWidth - rect.x;
            GrabbedImagePosition gip = new GrabbedImagePosition(sno++);
            gip.setBounds(rect);
            gip.setRownumber(i);
            gip.setColnumber(colnum++);
            grabbedImagePoss.add(gip);
            newRectInserted = true;
          }
        }

        int maxY, maxX;
        loop1:
        for (GrabbedImagePosition gip : grabbedImagePoss) {
          rect = gip.getBounds();
          travXUnit = Math.max(rect.width / travDiviser, 1);
          lastLineMatched = true;
          maxY = rect.y + rect.height;
          maxX = rect.x + rect.width;
          loop2:
          for (int y = rect.y; y < maxY; y++) {
            loop3:
            for (int x = rect.x; x < maxX; x += travXUnit) {
              col = new Color(shot.getRGB(x, y));
              if (!col.equals(bg)) {
                if (lastLineMatched) {
                  rect.y = y;
                  lastLineMatched = false;
                }
                continue loop2;
              }
            }
            if (!lastLineMatched) {
              rect.height = y - rect.y;
              lastLineMatched = true;
            }
          }
        }
        setGrabbedImagePositions(grabbedImagePoss);
        screenshotcompiled = true;
      } catch (Exception ex) {
        ResourceHelper.errLog("Compiler > compileScreenShot() > Error %s", ex);
      }
    }
  }
Esempio n. 3
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);
      }
    }
  }