public void corrector() { compile(); int max = Math.min(grabbedImageData.size(), grabbedImagePositions.size()); GrabbedImageData gid = null; GrabbedImagePosition gip = null; for (int i = 0; i < max; i++) { for (GrabbedImageData g : grabbedImageData) { if (g != null && g.getSerialnumber() == i) { gid = g; break; } } for (GrabbedImagePosition g : grabbedImagePositions) { if (g != null && g.getSerialnumber() == i) { gip = g; } } if (gid == null || gip == null) { System.out.printf("Error : i = %d, gid = %s, gip = %s", i, gid, gip); } else if (gid.getRownumber() != gip.getRownumber()) { grabbedImagePositions.remove(gip); resetGipSerial(); } } }
private void resetGidSerial() { GrabbedImageData gid; for (int i = 0; i < grabbedImageData.size(); i++) { gid = grabbedImageData.get(i); if (gid != null) { gid.setSerialnumber(i); } } }
public void createClones() { compile(); File dir = new File( getCompileOutputCurrentDir(), ResourceHelper.getGoogleProperty(Constants.KEY_COMPILED_OUTPUT_CLONE_DIR_NAME)); if (dir.mkdirs()) { BufferedImage shot = ResourceHelper.getImageResource(googleScreenShot); Image img; Rectangle rect; File file; String fname; for (GrabbedImagePosition gip : getGrabbedImagePositions()) { GrabbedImageData gid = null; for (GrabbedImageData g : grabbedImageData) { if (g.getSerialnumber() == gip.getSerialnumber()) { gid = g; } } try { rect = gip.getBounds(); img = shot.getSubimage(rect.x, rect.y, rect.width, rect.height); fname = null; file = null; if (gid != null) { fname = gid.getFileName(); if (fname.matches(".+\\..{3,}")) { file = new File(dir, fname); } } try { if (file == null || !file.createNewFile()) { file = new File( dir, String.format( "Clone%d info invalid or not found.png", gip.getSerialnumber())); } } catch (IOException exx) { file = new File( dir, String.format("Clone%d invalid name found.png", gip.getSerialnumber())); } ImageIO.write((RenderedImage) img, "png", file); } catch (Exception ex) { ResourceHelper.errLog("Compiler > createClones() > Error : %s", ex); } } } else { ResourceHelper.errLog("Compiler > createClone() > Unable to create clone"); } }
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\\=).*?(?=\\&\\;)"); Pattern imgwPat = Pattern.compile("(?<=\\&\\;w=).*?(?=\\&\\;)"); Pattern imghPat = Pattern.compile("(?<=\\&\\;h=).*?(?=\\&\\;)"); 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); } } }