Example usage for java.lang String contains

List of usage examples for java.lang String contains

Introduction

In this page you can find the example usage for java.lang String contains.

Prototype

public boolean contains(CharSequence s) 

Source Link

Document

Returns true if and only if this string contains the specified sequence of char values.

Usage

From source file:GoogleImages.java

public static void main(String[] args) throws InterruptedException {
    String searchTerm = "s woman"; // term to search for (use spaces to separate terms)
    int offset = 40; // we can only 20 results at a time - use this to offset and get more!
    String fileSize = "50mp"; // specify file size in mexapixels (S/M/L not figured out yet)
    String source = null; // string to save raw HTML source code

    // format spaces in URL to avoid problems
    searchTerm = searchTerm.replaceAll(" ", "%20");

    // get Google image search HTML source code; mostly built from PhyloWidget example:
    // http://code.google.com/p/phylowidget/source/browse/trunk/PhyloWidget/src/org/phylowidget/render/images/ImageSearcher.java
    int offset2 = 0;
    Set urlsss = new HashSet<String>();
    while (offset2 < 600) {
        try {//from w w  w  .j a va  2s .  c  o m
            URL query = new URL("https://www.google.ru/search?start=" + offset2
                    + "&q=angry+woman&newwindow=1&client=opera&hs=bPE&source=lnms&tbm=isch&sa=X&ved=0ahUKEwiAgcKozIfNAhWoHJoKHSb_AUoQ_AUIBygB&biw=1517&bih=731&dpr=0.9#imgrc=G_1tH3YOPcc8KM%3A");
            HttpURLConnection urlc = (HttpURLConnection) query.openConnection(); // start connection...
            urlc.setInstanceFollowRedirects(true);
            urlc.setRequestProperty("User-Agent", "");
            urlc.connect();
            BufferedReader in = new BufferedReader(new InputStreamReader(urlc.getInputStream())); // stream in HTTP source to file
            StringBuffer response = new StringBuffer();
            char[] buffer = new char[1024];
            while (true) {
                int charsRead = in.read(buffer);
                if (charsRead == -1) {
                    break;
                }
                response.append(buffer, 0, charsRead);
            }
            in.close(); // close input stream (also closes network connection)
            source = response.toString();
        } // any problems connecting? let us know
        catch (Exception e) {
            e.printStackTrace();
        }

        // print full source code (for debugging)
        // println(source);
        // extract image URLs only, starting with 'imgurl'
        if (source != null) {
            //                System.out.println(source);
            int c = StringUtils.countMatches(source, "http://www.vmir.su");
            System.out.println(c);
            int index = source.indexOf("src=");
            System.out.println(source.subSequence(index, index + 200));
            while (index >= 0) {
                System.out.println(index);
                index = source.indexOf("src=", index + 1);
                if (index == -1) {
                    break;
                }
                String rr = source.substring(index,
                        index + 200 > source.length() ? source.length() : index + 200);

                if (rr.contains("\"")) {
                    rr = rr.substring(5, rr.indexOf("\"", 5));
                }
                System.out.println(rr);
                urlsss.add(rr);
            }
        }
        offset2 += 20;
        Thread.sleep(1000);
        System.out.println("off set = " + offset2);

    }

    System.out.println(urlsss);
    urlsss.forEach(new Consumer<String>() {

        public void accept(String s) {
            try {
                saveImage(s, "C:\\Users\\Java\\Desktop\\ang\\" + UUID.randomUUID().toString() + ".jpg");
            } catch (IOException ex) {
                Logger.getLogger(GoogleImages.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
    //            String[][] m = matchAll(source, "img height=\"\\d+\" src=\"([^\"]+)\"");

    // older regex, no longer working but left for posterity
    // built partially from: http://www.mkyong.com/regular-expressions/how-to-validate-image-file-extension-with-regular-expression
    // String[][] m = matchAll(source, "imgurl=(.*?\\.(?i)(jpg|jpeg|png|gif|bmp|tif|tiff))");    // (?i) means case-insensitive
    //            for (int i = 0; i < m.length; i++) {                                                          // iterate all results of the match
    //                println(i + ":\t" + m[i][1]);                                                         // print (or store them)**
    //            }
}

From source file:ktdiedrich.imagek.SegmentationCMD.java

/**
 * @author ktdiedrich@gmail.com/*  w  ww  .j  ava2s .c  om*/
 * @param ags:  [file path] [Median filter size] [imageId]
 * Command line segmentation
 * @throws org.apache.commons.cli.ParseException 
 */
public static void main(String[] args) throws org.apache.commons.cli.ParseException {
    int imageIds[] = null;
    int medianFilterSize = 0;
    float seed = Extractor3D.SEED_HIST_THRES;
    String paths[] = null;

    Options options = new Options();
    options.addOption("p", true, "path name to file including filename");
    options.addOption("m", true, "median filter size, m*2+1");
    options.addOption("i", true, "image ID");
    options.addOption("f", true, "Image ID from");
    options.addOption("t", true, "Image ID to, (inclusive)");
    options.addOption("s", true, "Seed threshold default " + seed);
    CommandLineParser parser = new PosixParser();
    CommandLine cmd = parser.parse(options, args);

    if (cmd.hasOption("s")) {
        seed = Float.parseFloat(cmd.getOptionValue("s"));
    }
    if (cmd.hasOption("i")) {
        imageIds = new int[1];
        imageIds[0] = Integer.parseInt(cmd.getOptionValue("i"));
        paths = new String[1];
        paths[0] = getImageIdPath(imageIds[0]);
        // TODO get path to image ID from database and properties file. 
    }
    if (cmd.hasOption("f") && cmd.hasOption("t")) {
        int from = Integer.parseInt(cmd.getOptionValue("f"));
        int to = Integer.parseInt(cmd.getOptionValue("t"));
        int range = to - from + 1;
        paths = new String[range];
        imageIds = new int[range];
        for (int i = 0, imId = from; i < range; i++, imId++) {
            imageIds[i] = imId;
            paths[i] = getImageIdPath(imId);
        }
    }
    if (paths == null && cmd.hasOption("p")) {
        paths = new String[1];
        paths[0] = cmd.getOptionValue("p");
    }
    if (cmd.hasOption("m")) {
        medianFilterSize = Integer.parseInt(cmd.getOptionValue("m"));
    }

    // System.out.println("ImageID: "+imageId+" Path: "+paths+" Median filter: "+medianFilterSize);
    if (paths != null) {
        int i = 0;
        for (String path : paths) {
            String p[] = parseDirectoryFileName(path);
            String dirPath = p[0];
            ImagePlus segImage = segment(path, medianFilterSize, imageIds[i], seed);
            String title = segImage.getShortTitle();
            if (title.contains(File.separator))
                ;
            {
                title = parseDirectoryFileName(title)[1];
            }
            String outputPath = null;
            if (!dirPath.endsWith(File.separator))
                dirPath = dirPath + File.separator;
            outputPath = dirPath + title + ".zip";

            FileSaver fs = new FileSaver(segImage);
            fs.saveAsZip(outputPath);
            System.out.println("Saved: " + outputPath);
            ImagePlus mipYim = MIP.createShortMIP(segImage, MIP.Y_AXIS);
            fs = new FileSaver(mipYim);
            title = mipYim.getShortTitle();
            if (title.contains(File.separator))
                ;
            {
                title = parseDirectoryFileName(title)[1];
            }
            outputPath = dirPath + title + ".png";
            fs.saveAsPng(outputPath);
            System.out.println("Saved: " + outputPath + "\n");
            i++;
        }
    }
}

From source file:de.mpg.escidoc.services.edoc.BatchUpdate.java

/**
 * @param args/*  w  ww.j a v  a2  s .com*/
 */
public static void main(String[] args) throws Exception {
    CORESERVICES_URL = PropertyReader.getProperty("escidoc.framework_access.framework.url");

    String userHandle = AdminHelper.loginUser("import_user", "");

    logger.info("Querying core-services...");
    HttpClient httpClient = new HttpClient();
    String filter = "<param><filter name=\"http://escidoc.de/core/01/structural-relations/context\">"
            + IMPORT_CONTEXT
            + "</filter><order-by>http://escidoc.de/core/01/properties/creation-date</order-by><limit>0</limit></param>";

    logger.info("Filter: " + filter);

    PostMethod postMethod = new PostMethod(CORESERVICES_URL + "/ir/items/filter");

    postMethod.setRequestBody(filter);

    ProxyHelper.executeMethod(httpClient, postMethod);

    //        GetMethod getMethod = new GetMethod(CORESERVICES_URL + "/ir/item/escidoc:100220");
    //        getMethod.setRequestHeader("Cookie", "escidocCookie=" + userHandle)ProxyHelper.executeMethod(httpClient, getMethod)hod(httpClient, getMethod);

    String response = postMethod.getResponseBodyAsString();
    logger.info("...done!");

    System.out.println(response);

    while (response.contains("<escidocItem:item")) {

        int startPos = response.indexOf("<escidocItem:item");
        int endPos = response.indexOf("</escidocItem:item>");

        String item = response.substring(startPos, endPos + 19);

        response = response.substring(endPos + 19);

        startPos = item.indexOf("xlink:href=\"");
        endPos = item.indexOf("\"", startPos + 12);

        String objId = item.substring(startPos + 12, endPos);

        System.out.print(objId);

        if (item.contains("escidoc:22019")) {
            item = item.replaceAll("escidoc:22019", "escidoc:55222");

            PutMethod putMethod = new PutMethod(CORESERVICES_URL + objId);

            putMethod.setRequestHeader("Cookie", "escidocCookie=" + userHandle);
            putMethod.setRequestEntity(new StringRequestEntity(item));
            ProxyHelper.executeMethod(httpClient, putMethod);

            String result = putMethod.getResponseBodyAsString();

            //System.out.println(item);

            startPos = result.indexOf("last-modification-date=\"");
            endPos = result.indexOf("\"", startPos + 24);
            String modDate = result.substring(startPos + 24, endPos);
            //System.out.println("modDate: " + modDate);
            String param = "<param last-modification-date=\"" + modDate
                    + "\"><url>http://pubman.mpdl.mpg.de/pubman/item/" + objId.substring(4) + "</url></param>";
            postMethod = new PostMethod(CORESERVICES_URL + objId + "/assign-version-pid");
            postMethod.setRequestHeader("Cookie", "escidocCookie=" + userHandle);
            postMethod.setRequestEntity(new StringRequestEntity(param));
            ProxyHelper.executeMethod(httpClient, postMethod);
            result = postMethod.getResponseBodyAsString();
            //System.out.println("Result: " + result);

            startPos = result.indexOf("last-modification-date=\"");
            endPos = result.indexOf("\"", startPos + 24);
            modDate = result.substring(startPos + 24, endPos);
            //System.out.println("modDate: " + modDate);
            param = "<param last-modification-date=\"" + modDate
                    + "\"><comment>Batch repair of organizational unit identifier</comment></param>";
            postMethod = new PostMethod(CORESERVICES_URL + objId + "/submit");
            postMethod.setRequestHeader("Cookie", "escidocCookie=" + userHandle);
            postMethod.setRequestEntity(new StringRequestEntity(param));
            ProxyHelper.executeMethod(httpClient, postMethod);
            result = postMethod.getResponseBodyAsString();
            //System.out.println("Result: " + result);

            startPos = result.indexOf("last-modification-date=\"");
            endPos = result.indexOf("\"", startPos + 24);
            modDate = result.substring(startPos + 24, endPos);
            //System.out.println("modDate: " + modDate);
            param = "<param last-modification-date=\"" + modDate
                    + "\"><comment>Batch repair of organizational unit identifier</comment></param>";
            postMethod = new PostMethod(CORESERVICES_URL + objId + "/release");
            postMethod.setRequestHeader("Cookie", "escidocCookie=" + userHandle);
            postMethod.setRequestEntity(new StringRequestEntity(param));
            ProxyHelper.executeMethod(httpClient, postMethod);
            result = postMethod.getResponseBodyAsString();
            //System.out.println("Result: " + result);
            System.out.println("...changed");
        } else {
            System.out.println("...not affected");
        }
    }

}

From source file:com.jwm123.loggly.reporter.AppLauncher.java

public static void main(String args[]) throws Exception {
    try {/*from  w w  w.  j  av  a  2 s  .  c om*/
        CommandLine cl = parseCLI(args);
        try {
            config = new Configuration();
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("ERROR: Failed to read in persisted configuration.");
        }
        if (cl.hasOption("h")) {

            HelpFormatter help = new HelpFormatter();
            String jarName = AppLauncher.class.getProtectionDomain().getCodeSource().getLocation().getFile();
            if (jarName.contains("/")) {
                jarName = jarName.substring(jarName.lastIndexOf("/") + 1);
            }
            help.printHelp("java -jar " + jarName + " [options]", opts);
        }
        if (cl.hasOption("c")) {
            config.update();
        }
        if (cl.hasOption("q")) {
            Client client = new Client(config);
            client.setQuery(cl.getOptionValue("q"));
            if (cl.hasOption("from")) {
                client.setFrom(cl.getOptionValue("from"));
            }
            if (cl.hasOption("to")) {
                client.setTo(cl.getOptionValue("to"));
            }
            List<Map<String, Object>> report = client.getReport();

            if (report != null) {
                List<Map<String, String>> reportContent = new ArrayList<Map<String, String>>();
                ReportGenerator generator = null;
                if (cl.hasOption("file")) {
                    generator = new ReportGenerator(new File(cl.getOptionValue("file")));
                }
                byte reportFile[] = null;

                if (cl.hasOption("g")) {
                    System.out.println("Search results: " + report.size());
                    Set<Object> values = new TreeSet<Object>();
                    Map<Object, Integer> counts = new HashMap<Object, Integer>();
                    for (String groupBy : cl.getOptionValues("g")) {
                        for (Map<String, Object> result : report) {
                            if (mapContains(result, groupBy)) {
                                Object value = mapGet(result, groupBy);
                                values.add(value);
                                if (counts.containsKey(value)) {
                                    counts.put(value, counts.get(value) + 1);
                                } else {
                                    counts.put(value, 1);
                                }
                            }
                        }
                        System.out.println("For key: " + groupBy);
                        for (Object value : values) {
                            System.out.println("  " + value + ": " + counts.get(value));
                        }
                    }
                    if (cl.hasOption("file")) {
                        Map<String, String> reportAddition = new LinkedHashMap<String, String>();
                        reportAddition.put("Month", MONTH_FORMAT.format(new Date()));
                        reportContent.add(reportAddition);
                        for (Object value : values) {
                            reportAddition = new LinkedHashMap<String, String>();
                            reportAddition.put(value.toString(), "" + counts.get(value));
                            reportContent.add(reportAddition);
                        }
                        reportAddition = new LinkedHashMap<String, String>();
                        reportAddition.put("Total", "" + report.size());
                        reportContent.add(reportAddition);
                    }
                } else {
                    System.out.println("The Search [" + cl.getOptionValue("q") + "] yielded " + report.size()
                            + " results.");
                    if (cl.hasOption("file")) {
                        Map<String, String> reportAddition = new LinkedHashMap<String, String>();
                        reportAddition.put("Month", MONTH_FORMAT.format(new Date()));
                        reportContent.add(reportAddition);
                        reportAddition = new LinkedHashMap<String, String>();
                        reportAddition.put("Count", "" + report.size());
                        reportContent.add(reportAddition);
                    }
                }
                if (cl.hasOption("file")) {
                    reportFile = generator.build(reportContent);
                    File reportFileObj = new File(cl.getOptionValue("file"));
                    FileUtils.writeByteArrayToFile(reportFileObj, reportFile);
                    if (cl.hasOption("e")) {
                        ReportMailer mailer = new ReportMailer(config, cl.getOptionValues("e"),
                                cl.getOptionValue("s"), reportFileObj.getName(), reportFile);
                        mailer.send();
                    }
                }
            }
        }

    } catch (IllegalArgumentException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
}

From source file:com.github.jknack.handlebars.server.HbsServer.java

public static void main(final String[] args) throws Exception {
    Options arguments = new Options();
    CmdLineParser parser = new CmdLineParser(arguments);
    try {/* w  ww .  j a v a  2 s  .  c o  m*/
        parser.parseArgument(args);
        run(arguments);
    } catch (CmdLineException e) {
        System.err.println(e.getMessage());
        String os = System.getProperty("os.name").toLowerCase();
        System.err.println("Usage:");
        String program = "java -jar handlebars-proto-${version}.jar";
        if (os.contains("win")) {
            program = "handlebars";
        }
        System.err.println("  " + program + " [-option value]");
        System.err.println("Options:");
        parser.printUsage(System.err);
    }
}

From source file:org.apache.flink.benchmark.Runner.java

public static void main(String[] args) throws Exception {
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    env.getConfig().enableObjectReuse();
    env.getConfig().disableSysoutLogging();

    ParameterTool parameters = ParameterTool.fromArgs(args);

    if (!(parameters.has("p") && parameters.has("types") && parameters.has("algorithms"))) {
        printUsage();//  w  w w  .  j  a v a2  s.  co  m
        System.exit(-1);
    }

    int parallelism = parameters.getInt("p");
    env.setParallelism(parallelism);

    Set<IdType> types = new HashSet<>();

    if (parameters.get("types").equals("all")) {
        types.add(IdType.INT);
        types.add(IdType.LONG);
        types.add(IdType.STRING);
    } else {
        for (String type : parameters.get("types").split(",")) {
            if (type.toLowerCase().equals("int")) {
                types.add(IdType.INT);
            } else if (type.toLowerCase().equals("long")) {
                types.add(IdType.LONG);
            } else if (type.toLowerCase().equals("string")) {
                types.add(IdType.STRING);
            } else {
                printUsage();
                throw new RuntimeException("Unknown type: " + type);
            }
        }
    }

    Queue<RunnerWithScore> queue = new PriorityQueue<>();

    if (parameters.get("algorithms").equals("all")) {
        for (Map.Entry<String, Class> entry : AVAILABLE_ALGORITHMS.entrySet()) {
            for (IdType type : types) {
                AlgorithmRunner runner = (AlgorithmRunner) entry.getValue().newInstance();
                runner.initialize(type, SAMPLES, parallelism);
                runner.warmup(env);
                queue.add(new RunnerWithScore(runner, 1.0));
            }
        }
    } else {
        for (String algorithm : parameters.get("algorithms").split(",")) {
            double ratio = 1.0;
            if (algorithm.contains("=")) {
                String[] split = algorithm.split("=");
                algorithm = split[0];
                ratio = Double.parseDouble(split[1]);
            }

            if (AVAILABLE_ALGORITHMS.containsKey(algorithm.toLowerCase())) {
                Class clazz = AVAILABLE_ALGORITHMS.get(algorithm.toLowerCase());

                for (IdType type : types) {
                    AlgorithmRunner runner = (AlgorithmRunner) clazz.newInstance();
                    runner.initialize(type, SAMPLES, parallelism);
                    runner.warmup(env);
                    queue.add(new RunnerWithScore(runner, ratio));
                }
            } else {
                printUsage();
                throw new RuntimeException("Unknown algorithm: " + algorithm);
            }
        }
    }

    JsonFactory factory = new JsonFactory();

    while (queue.size() > 0) {
        RunnerWithScore current = queue.poll();
        AlgorithmRunner runner = current.getRunner();

        StringWriter writer = new StringWriter();
        JsonGenerator gen = factory.createGenerator(writer);
        gen.writeStartObject();
        gen.writeStringField("algorithm", runner.getClass().getSimpleName());

        boolean running = true;

        while (running) {
            try {
                runner.run(env, gen);
                running = false;
            } catch (ProgramInvocationException e) {
                // only suppress job cancellations
                if (!(e.getCause() instanceof JobCancellationException)) {
                    throw e;
                }
            }
        }

        JobExecutionResult result = env.getLastJobExecutionResult();

        long runtime_ms = result.getNetRuntime();
        gen.writeNumberField("runtime_ms", runtime_ms);
        current.credit(runtime_ms);

        if (!runner.finished()) {
            queue.add(current);
        }

        gen.writeObjectFieldStart("accumulators");
        for (Map.Entry<String, Object> accumulatorResult : result.getAllAccumulatorResults().entrySet()) {
            gen.writeStringField(accumulatorResult.getKey(), accumulatorResult.getValue().toString());
        }
        gen.writeEndObject();

        gen.writeEndObject();
        gen.close();
        System.out.println(writer.toString());
    }
}

From source file:isc_415_practica_1.ISC_415_Practica_1.java

/**
 * @param args the command line arguments
 *//*from  w ww .j av a  2  s.c om*/
public static void main(String[] args) {
    String urlString;
    Scanner input = new Scanner(System.in);
    Document doc;

    try {
        urlString = input.next();
        if (urlString.equals("servlet")) {
            urlString = "http://localhost:8084/ISC_415_Practica1_Servlet/client";
        }
        urlString = urlString.contains("http://") || urlString.contains("https://") ? urlString
                : "http://" + urlString;
        doc = Jsoup.connect(urlString).get();
    } catch (Exception ex) {
        System.out.println("El URL ingresado no es valido.");
        return;
    }

    ArrayList<NameValuePair> formInputParams;
    formInputParams = new ArrayList<>();
    String[] plainTextDoc = new TextNode(doc.html(), "").getWholeText().split("\n");
    System.out.println(String.format("Nmero de lineas del documento: %d", plainTextDoc.length));
    System.out.println(String.format("Nmero de p tags: %d", doc.select("p").size()));
    System.out.println(String.format("Nmero de img tags: %d", doc.select("img").size()));
    System.out.println(String.format("Nmero de form tags: %d", doc.select("form").size()));

    Integer index = 1;

    ArrayList<NameValuePair> urlParameters = new ArrayList<>();
    for (Element e : doc.select("form")) {
        System.out.println(String.format("Form %d: Nmero de Input tags %d", index, e.select("input").size()));
        System.out.println(e.select("input"));

        for (Element formInput : e.select("input")) {
            if (formInput.attr("id") != null && formInput.attr("id") != "") {
                urlParameters.add(new BasicNameValuePair(formInput.attr("id"), "PRACTICA1"));
            } else if (formInput.attr("name") != null && formInput.attr("name") != "") {
                urlParameters.add(new BasicNameValuePair(formInput.attr("name"), "PRACTICA1"));
            }
        }

        index++;
    }

    if (!urlParameters.isEmpty()) {
        try {
            CloseableHttpClient httpclient = HttpClients.createDefault();
            UrlEncodedFormEntity entity = new UrlEncodedFormEntity(urlParameters, Consts.UTF_8);
            HttpPost httpPost = new HttpPost(urlString);
            httpPost.setHeader("User-Agent", USER_AGENT);
            httpPost.setEntity(entity);
            HttpResponse response = httpclient.execute(httpPost);
            System.out.println(response.getStatusLine());
        } catch (IOException ex) {
            Logger.getLogger(ISC_415_Practica_1.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

}

From source file:at.gv.egiz.pdfas.cli.test.SignaturProfileTest.java

public static void main(String[] args) {
    String user_home = System.getProperty("user.home");
    String pdfas_dir = user_home + File.separator + ".pdfas";
    PdfAs pdfas = PdfAsFactory.createPdfAs(new File(pdfas_dir));
    try {/*from   w  ww  .  ja  v a 2s .c  o m*/
        Configuration config = pdfas.getConfiguration();
        ISettings settings = (ISettings) config;
        List<String> signatureProfiles = new ArrayList<String>();

        List<String> signaturePDFAProfiles = new ArrayList<String>();

        Iterator<String> itKeys = settings.getFirstLevelKeys("sig_obj.types.").iterator();
        while (itKeys.hasNext()) {
            String key = itKeys.next();
            String profile = key.substring("sig_obj.types.".length());
            System.out.println("[" + profile + "]: " + settings.getValue(key));
            if (settings.getValue(key).equals("on")) {
                signatureProfiles.add(profile);
                if (profile.contains("PDFA")) {
                    signaturePDFAProfiles.add(profile);
                }
            }
        }

        byte[] input = IOUtils.toByteArray(new FileInputStream(sourcePDF));

        IPlainSigner signer = new PAdESSignerKeystore(KS_FILE, KS_ALIAS, KS_PASS, KS_KEY_PASS, KS_TYPE);

        Iterator<String> itProfiles = signatureProfiles.iterator();
        while (itProfiles.hasNext()) {
            String profile = itProfiles.next();
            System.out.println("Testing " + profile);

            DataSource source = new ByteArrayDataSource(input);

            FileOutputStream fos = new FileOutputStream(targetFolder + profile + ".pdf");
            SignParameter signParameter = PdfAsFactory.createSignParameter(config, source, fos);

            signParameter.setPlainSigner(signer);
            signParameter.setSignatureProfileId(profile);

            SignResult result = pdfas.sign(signParameter);

            fos.close();
        }

        byte[] inputPDFA = IOUtils.toByteArray(new FileInputStream(sourcePDFA));

        Iterator<String> itPDFAProfiles = signaturePDFAProfiles.iterator();
        while (itPDFAProfiles.hasNext()) {
            String profile = itPDFAProfiles.next();
            System.out.println("Testing " + profile);

            DataSource source = new ByteArrayDataSource(inputPDFA);
            FileOutputStream fos = new FileOutputStream(targetFolder + "PDFA_" + profile + ".pdf");
            SignParameter signParameter = PdfAsFactory.createSignParameter(config, source, fos);

            signParameter.setPlainSigner(signer);
            signParameter.setSignatureProfileId(profile);

            SignResult result = pdfas.sign(signParameter);

            fos.close();
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
}

From source file:module.entities.NameFinder.RegexNameFinder.java

/**
 * @param args the command line arguments
 *///  w ww .ja v  a 2s.co m
public static void main(String[] args) throws SQLException, IOException {

    if (args.length == 1) {
        Config.configFile = args[0];
    }
    long lStartTime = System.currentTimeMillis();
    Timestamp startTime = new Timestamp(lStartTime);
    System.out.println("Regex Name Finder process started at: " + startTime);
    DB.initPostgres();
    regexerId = DB.LogRegexFinder(lStartTime);
    initLexicons();
    JSONObject obj = new JSONObject();
    TreeMap<Integer, String> consultations = DB.getDemocracitConsultationBody();
    Document doc;
    int count = 0;
    TreeMap<Integer, String> consFoundNames = new TreeMap<>();
    TreeMap<Integer, String> consFoundRoles = new TreeMap<>();
    for (int consId : consultations.keySet()) {
        String consBody = consultations.get(consId);
        String signName = "", roleName = "";
        doc = Jsoup.parse(consBody);
        Elements allPars = new Elements();
        Elements paragraphs = doc.select("p");
        for (Element par : paragraphs) {
            if (par.html().contains("<br>")) {
                String out = "<p>" + par.html().replaceAll("<br>", "</p><p>") + "</p>";
                Document internal_doc = Jsoup.parse(out);
                Elements subparagraphs = internal_doc.select("p");
                allPars.addAll(subparagraphs);
            } else {
                allPars.add(par);
            }
            //                System.out.println(formatedText);
        }
        String signature = getSignatureFromParagraphs(allPars);
        //            System.out.println(signature);
        if (signature.contains("#")) {
            String[] sign_tokens = signature.split("#");
            signName = sign_tokens[0];
            if (sign_tokens.length > 1) {
                roleName = sign_tokens[1];
            }
            consFoundNames.put(consId, signName.trim());
            consFoundRoles.put(consId, roleName.trim());
            count++;
        } else {
            System.err.println("--" + consId);
        }
        //           
    }
    DB.insertDemocracitConsultationMinister(consFoundNames, consFoundRoles);

    TreeMap<Integer, String> consultationsCompletedText = DB.getDemocracitCompletedConsultationBody();
    Document doc2;
    TreeMap<Integer, String> complConsFoundNames = new TreeMap<>();
    int count2 = 0;
    for (int consId : consultationsCompletedText.keySet()) {
        String consBody = consultationsCompletedText.get(consId);
        String signName = "", roleName = "";
        doc2 = Jsoup.parse(consBody);
        //            if (doc.text().contains("<br>")) {
        //                doc.text().replaceAll("(<[Bb][Rr]>)+", "<p>");
        //            }
        Elements allPars = new Elements();
        Elements paragraphs = doc2.select("p");
        for (Element par : paragraphs) {

            if (par.html().contains("<br>")) {
                String out = "<p>" + par.html().replaceAll("<br>", "</p><p>") + "</p>";
                Document internal_doc = Jsoup.parse(out);
                Elements subparagraphs = internal_doc.select("p");
                allPars.addAll(subparagraphs);
            } else {
                allPars.add(par);
            }
        }
        String signature = getSignatureFromParagraphs(allPars);
        if (signature.contains("#")) {
            String[] sign_tokens = signature.split("#");
            signName = sign_tokens[0];
            if (sign_tokens.length > 1) {
                roleName = sign_tokens[1];
            }
            consFoundNames.put(consId, signName.trim());
            consFoundRoles.put(consId, roleName.trim());
            //                System.out.println(consId);
            //                System.out.println(signName.trim());
            //                System.out.println("***************");
            count2++;
        } else {
            System.err.println("++" + consId);
        }
    }
    DB.insertDemocracitConsultationMinister(complConsFoundNames, consFoundRoles);
    long lEndTime = System.currentTimeMillis();
    System.out.println("Regex Name Finder process finished at: " + startTime);
    obj.put("message", "Regex Name Finder finished with no errors");
    obj.put("details", "");
    DB.UpdateLogRegexFinder(lEndTime, regexerId, obj);
    DB.close();
}

From source file:org.kuali.student.git.importer.ConvertBuildTagBranchesToGitTags.java

/**
 * @param args//  w  w  w .j  a v  a 2  s . c  o  m
 */
public static void main(String[] args) {

    if (args.length < 3 || args.length > 6) {
        System.err.println("USAGE: <git repository> <bare> <ref mode> [<ref prefix> <username> <password>]");
        System.err.println("\t<bare> : 0 (false) or 1 (true)");
        System.err.println("\t<ref mode> : local or name of remote");
        System.err.println("\t<ref prefix> : refs/heads (default) or say refs/remotes/origin (test clone)");
        System.exit(-1);
    }

    boolean bare = false;

    if (args[1].trim().equals("1")) {
        bare = true;
    }

    String remoteName = args[2].trim();

    String refPrefix = Constants.R_HEADS;

    if (args.length == 4)
        refPrefix = args[3].trim();

    String userName = null;
    String password = null;

    if (args.length == 5)
        userName = args[4].trim();

    if (args.length == 6)
        password = args[5].trim();

    try {

        Repository repo = GitRepositoryUtils.buildFileRepository(new File(args[0]).getAbsoluteFile(), false,
                bare);

        Git git = new Git(repo);

        ObjectInserter objectInserter = repo.newObjectInserter();

        Collection<Ref> repositoryHeads = repo.getRefDatabase().getRefs(refPrefix).values();

        RevWalk rw = new RevWalk(repo);

        Map<String, ObjectId> tagNameToTagId = new HashMap<>();

        Map<String, Ref> tagNameToRef = new HashMap<>();

        for (Ref ref : repositoryHeads) {

            String branchName = ref.getName().substring(refPrefix.length() + 1);

            if (branchName.contains("tag") && branchName.contains("builds")) {

                String branchParts[] = branchName.split("_");

                int buildsIndex = ArrayUtils.indexOf(branchParts, "builds");

                String moduleName = StringUtils.join(branchParts, "_", buildsIndex + 1, branchParts.length);

                RevCommit commit = rw.parseCommit(ref.getObjectId());

                ObjectId tag = GitRefUtils.insertTag(moduleName, commit, objectInserter);

                tagNameToTagId.put(moduleName, tag);

                tagNameToRef.put(moduleName, ref);

            }

        }

        BatchRefUpdate batch = repo.getRefDatabase().newBatchUpdate();

        List<RefSpec> branchesToDelete = new ArrayList<>();

        for (Entry<String, ObjectId> entry : tagNameToTagId.entrySet()) {

            String tagName = entry.getKey();

            // create the reference to the tag object
            batch.addCommand(
                    new ReceiveCommand(null, entry.getValue(), Constants.R_TAGS + tagName, Type.CREATE));

            // delete the original branch object

            Ref branch = tagNameToRef.get(entry.getKey());

            if (remoteName.equals("local")) {

                batch.addCommand(new ReceiveCommand(branch.getObjectId(), null, branch.getName(), Type.DELETE));

            } else {
                String adjustedBranchName = branch.getName().substring(refPrefix.length() + 1);

                branchesToDelete.add(new RefSpec(":" + Constants.R_HEADS + adjustedBranchName));
            }

        }

        // create the tags
        batch.execute(rw, new TextProgressMonitor());

        if (!remoteName.equals("local")) {
            // push the tag to the remote right now
            PushCommand pushCommand = git.push().setRemote(remoteName).setPushTags()
                    .setProgressMonitor(new TextProgressMonitor());

            if (userName != null)
                pushCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(userName, password));

            Iterable<PushResult> results = pushCommand.call();

            for (PushResult pushResult : results) {

                if (!pushResult.equals(Result.NEW)) {
                    log.warn("failed to push tag " + pushResult.getMessages());
                }
            }

            // delete the branches from the remote
            results = git.push().setRemote(remoteName).setRefSpecs(branchesToDelete)
                    .setProgressMonitor(new TextProgressMonitor()).call();

            log.info("");

        }

        //         Result result = GitRefUtils.createTagReference(repo, moduleName, tag);
        //         
        //         if (!result.equals(Result.NEW)) {
        //            log.warn("failed to create tag {} for branch {}", moduleName, branchName);
        //            continue;
        //         }
        //         
        //         if (deleteMode) {
        //         result = GitRefUtils.deleteRef(repo, ref);
        //   
        //         if (!result.equals(Result.NEW)) {
        //            log.warn("failed to delete branch {}", branchName);
        //            continue;
        //         }

        objectInserter.release();

        rw.release();

    } catch (Exception e) {

        log.error("unexpected Exception ", e);
    }
}