Example usage for java.lang Runtime exec

List of usage examples for java.lang Runtime exec

Introduction

In this page you can find the example usage for java.lang Runtime exec.

Prototype

public Process exec(String cmdarray[]) throws IOException 

Source Link

Document

Executes the specified command and arguments in a separate process.

Usage

From source file:org.ecoinformatics.seek.R.RExpression.java

private void _exec() throws IllegalActionException {
    Runtime runtime = Runtime.getRuntime();
    String[] commandArray;/* www  .  jav  a 2 s  .  c  o m*/

    String osName = System.getProperty("os.name");
    if (osName.equals("Windows NT") || osName.equals("Windows XP") || osName.equals("Windows 2000")) {
        // checkRLocation is commented out for now since it slows down the
        // first execution of a
        // workflow with an RExpression actor too much (>= 30 sec for a
        // 'cold' machine)
        _checkRLocation();
        commandArray = new String[6];
        commandArray[0] = "cmd.exe";
        commandArray[1] = "/C";
        commandArray[2] = RdotExe;
        commandArray[3] = "--silent";
        commandArray[4] = restoreString;
        commandArray[5] = saveString;
    } else if (osName.equals("Windows 95")) {
        _checkRLocation();
        commandArray = new String[6];
        commandArray[0] = "command.com";
        commandArray[1] = "/C";
        commandArray[2] = RdotExe;
        commandArray[3] = "--silent";
        commandArray[4] = restoreString;
        commandArray[5] = saveString;
    } else {
        commandArray = new String[4];
        commandArray[0] = RdotExe;
        commandArray[1] = "--silent";
        commandArray[2] = restoreString;
        commandArray[3] = saveString;
    }

    // log.debug("commandArray :"+commandArray);
    try {
        // log.debug("ready to create _process!");
        _process = runtime.exec(commandArray);
        log.debug("Process :" + _process);
    } catch (Exception e) {
        log.error("Problem with creating process in RExpression!");
    }
    // log.debug("Ready to create threads");
    // Create two threads to read from the subprocess.
    _outputGobbler = new _StreamReaderThread(_process.getInputStream(),
            "Exec Stdout Gobbler-" + _streamReaderThreadCount++, this);
    _errorGobbler = new _StreamReaderThread(_process.getErrorStream(),
            "Exec Stderr Gobbler-" + _streamReaderThreadCount++, this);
    _errorGobbler.start();
    _outputGobbler.start();

    if (_streamReaderThreadCount > 1000) {
        // Avoid overflow in the thread count.
        _streamReaderThreadCount = 0;
    }

    OutputStreamWriter inputStreamWriter = new OutputStreamWriter(_process.getOutputStream());
    _inputBufferedWriter = new BufferedWriter(inputStreamWriter);

}

From source file:ch.kostceco.tools.kostval.validation.modulepdfa.impl.ValidationAvalidationAiModuleImpl.java

@Override
public boolean validate(File valDatei, File directoryOfLogfile) throws ValidationApdfvalidationException {
    @SuppressWarnings("unused")
    boolean valid = false;

    // Version & Level herausfinden
    String pdfa1 = getConfigurationService().pdfa1();
    String pdfa2 = getConfigurationService().pdfa2();

    Integer pdfaVer1 = 0;//from ww w  .ja va 2s .  c o  m
    Integer pdfaVer2 = 0;

    /* Nicht vergessen in "src/main/resources/config/applicationContext-services.xml" beim
     * entsprechenden Modul die property anzugeben: <property name="configurationService"
     * ref="configurationService" /> */

    // Vorbereitung fr eine allfllige Festhaltung bei unterschiedlichen Validierungsresultaten in
    // einer PDF_Diagnosedatei
    File pdfDia = null;
    String pdfDiaPath = getConfigurationService().getPathToDiagnose();

    try {
        pdfDia = new File(pdfDiaPath + File.separator + "PDF-Diagnosedaten.kost-val.xml");
        if (!pdfDia.exists()) {
            pdfDia.createNewFile();
            PrintWriter output;
            BufferedWriter buffer;
            FileWriter fileWriter;
            fileWriter = new FileWriter(pdfDia);
            buffer = new BufferedWriter(fileWriter);
            output = new PrintWriter(buffer);
            try {
                output.print(getTextResourceService().getText(MESSAGE_XML_DIAHEADER) + "\n");
                output.print(getTextResourceService().getText(MESSAGE_XML_DIAEND));
            } finally {
                output.close();
                buffer.close();
                fileWriter.close();
            }
        }
        File xslDiaOrig = new File("resources" + File.separator + "kost-val_PDFdia.xsl");
        File xslDiaCopy = new File(pdfDiaPath + File.separator + "kost-val_PDFdia.xsl");
        if (!xslDiaCopy.exists()) {
            Util.copyFile(xslDiaOrig, xslDiaCopy);
        }
    } catch (IOException e) {
        getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_PDFA)
                + getTextResourceService().getText(ERROR_XML_UNKNOWN, e.getMessage()));
    }

    /* Neu soll die Validierung mit PDFTron konfigurier bar sein Mgliche Werte 1A, 1B und no sowie
     * 2A, 2B, 2U und no Da Archive beide Versionen erlauben knnen sind es 2 config eintrge Es
     * gibt mehre Mglichkeiten das PDF in der gewnschten Version zu testen - Unterscheidung anhand
     * DROID --> braucht viel Zeit auch mit KaD_Signaturefile - Unterscheidung anhand PDF/A-Eintrag
     * wie Droid aber selber programmiert --> ist viel schneller */
    if (pdfa2.equals("2A") || pdfa2.equals("2B") || pdfa2.equals("2U")) {
        // gltiger Konfigurationseintrag und V2 erlaubt
        pdfaVer2 = 2;
    } else {
        // v2 nicht erlaubt oder falscher eintrag
        pdfa2 = "no";
    }
    if (pdfa1.equals("1A") || pdfa1.equals("1B")) {
        // gltiger Konfigurationseintrag und V1 erlaubt
        pdfaVer1 = 1;
    } else {
        // v1 nicht erlaubt oder falscher eintrag
        pdfa1 = "no";
    }
    if (pdfa1 == "no" && pdfa2 == "no") {
        // keine Validierung mglich. keine PDFA-Versionen konfiguriert
        getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_PDFA)
                + getTextResourceService().getText(ERROR_XML_A_PDFA_NOCONFIG));
        valid = false;
        return false;
    }

    String level = "no";
    // Richtiges Level definieren
    if (pdfaVer1 != 1) {
        // Level 1 nicht erlaubt --> Level 2
        level = pdfa2;
    } else if (pdfaVer2 != 2) {
        // Level 2 nicht erlaubt --> Level 1
        level = pdfa1;
    } else {
        try {
            // Beide sind mglich --> Level je nach File auswhlen
            pdfaVer1 = 0;
            pdfaVer2 = 0;
            BufferedReader in = new BufferedReader(new FileReader(valDatei));
            String line;
            while ((line = in.readLine()) != null) {
                // hufige Partangaben: pdfaid:part>1< pdfaid:part='1' pdfaid:part="1"
                if (line.contains("pdfaid:part")) {
                    // pdfaid:part
                    if (line.contains("pdfaid:part>1<")) {
                        level = pdfa1;
                        pdfaVer1 = 1;
                    } else if (line.contains("pdfaid:part='1'")) {
                        level = pdfa1;
                        pdfaVer1 = 1;
                    } else if (line.contains("pdfaid:part=\"1\"")) {
                        level = pdfa1;
                        pdfaVer1 = 1;
                    } else if (line.contains("pdfaid:part>2<")) {
                        level = pdfa2;
                        pdfaVer2 = 2;
                    } else if (line.contains("pdfaid:part='2'")) {
                        level = pdfa2;
                        pdfaVer2 = 2;
                    } else if (line.contains("pdfaid:part=\"2\"")) {
                        level = pdfa2;
                        pdfaVer2 = 2;
                    } else if (line.contains("pdfaid:part") && line.contains("1")) {
                        // PDFA-Version = 1
                        level = pdfa1;
                        pdfaVer1 = 1;
                    } else if (line.contains("pdfaid:part") && line.contains("2")) {
                        // PDFA-Version = 2
                        level = pdfa2;
                        pdfaVer2 = 2;
                    }
                }
                if (pdfaVer1 == 0 && pdfaVer2 == 0) {
                    // der Part wurde nicht gefunden --> Level 2
                    level = pdfa2;
                }
            }
        } catch (Throwable e) {
            getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_PDFA)
                    + getTextResourceService().getText(ERROR_XML_UNKNOWN, e.getMessage()));
        }
    }
    getMessageService().logError(getTextResourceService().getText(MESSAGE_PDFAVALIDATION_VL, level));

    // Start mit der Erkennung

    // Eine PDF Datei (.pdf / .pdfa) muss mit %PDF [25504446] beginnen
    if (valDatei.isDirectory()) {
        getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_PDFA)
                + getTextResourceService().getText(ERROR_XML_A_PDFA_ISDIRECTORY));
        return false;
    } else if ((valDatei.getAbsolutePath().toLowerCase().endsWith(".pdf")
            || valDatei.getAbsolutePath().toLowerCase().endsWith(".pdfa"))) {

        FileReader fr = null;

        try {
            fr = new FileReader(valDatei);
            BufferedReader read = new BufferedReader(fr);

            // Hex 25 in Char umwandeln
            String str1 = "25";
            int i1 = Integer.parseInt(str1, 16);
            char c1 = (char) i1;
            // Hex 50 in Char umwandeln
            String str2 = "50";
            int i2 = Integer.parseInt(str2, 16);
            char c2 = (char) i2;
            // Hex 44 in Char umwandeln
            String str3 = "44";
            int i3 = Integer.parseInt(str3, 16);
            char c3 = (char) i3;
            // Hex 46 in Char umwandeln
            String str4 = "46";
            int i4 = Integer.parseInt(str4, 16);
            char c4 = (char) i4;

            // auslesen der ersten 4 Zeichen der Datei
            int length;
            int i;
            char[] buffer = new char[4];
            length = read.read(buffer);
            for (i = 0; i != length; i++)
                ;

            // die beiden charArrays (soll und ist) mit einander vergleichen IST = c1c2c3c4
            char[] charArray1 = buffer;
            char[] charArray2 = new char[] { c1, c2, c3, c4 };

            if (Arrays.equals(charArray1, charArray2)) {
                // hchstwahrscheinlich ein PDF da es mit 25504446 respektive %PDF beginnt
                valid = true;
            } else {
                // Droid-Erkennung, damit Details ausgegeben werden knnen
                String nameOfSignature = getConfigurationService().getPathToDroidSignatureFile();
                if (nameOfSignature == null) {
                    getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_PDFA)
                            + getTextResourceService().getText(MESSAGE_XML_CONFIGURATION_ERROR_NO_SIGNATURE));
                    return false;
                }
                // existiert die SignatureFile am angebenen Ort?
                File fnameOfSignature = new File(nameOfSignature);
                if (!fnameOfSignature.exists()) {
                    getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_PDFA)
                            + getTextResourceService().getText(MESSAGE_XML_CA_DROID));
                    return false;
                }

                Droid droid = null;
                try {
                    /* kleiner Hack, weil die Droid libraries irgendwo ein System.out drin haben, welche den
                     * Output stren Util.switchOffConsole() als Kommentar markieren wenn man die
                     * Fehlermeldung erhalten mchte */
                    Util.switchOffConsole();
                    droid = new Droid();

                    droid.readSignatureFile(nameOfSignature);

                } catch (Exception e) {
                    getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_PDFA)
                            + getTextResourceService().getText(ERROR_XML_CANNOT_INITIALIZE_DROID));
                    return false;
                } finally {
                    Util.switchOnConsole();
                }
                File file = valDatei;
                String puid = "";
                IdentificationFile ifile = droid.identify(file.getAbsolutePath());
                for (int x = 0; x < ifile.getNumHits(); x++) {
                    FileFormatHit ffh = ifile.getHit(x);
                    FileFormat ff = ffh.getFileFormat();
                    puid = ff.getPUID();
                }
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_PDFA)
                        + getTextResourceService().getText(ERROR_XML_A_PDFA_INCORRECTFILE, puid));
                return false;
            }
        } catch (Exception e) {
            getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_PDFA)
                    + getTextResourceService().getText(ERROR_XML_A_PDFA_INCORRECTFILE));
            return false;
        }
    } else {
        // die Datei endet nicht mit pdf oder pdfa -> Fehler
        getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_PDFA)
                + getTextResourceService().getText(ERROR_XML_A_PDFA_INCORRECTFILEENDING));
        return false;
    }
    // Ende der Erkennung

    boolean isValid = false;
    boolean dual = false;

    // Initialisierung PDFTron -> berprfen der Angaben: existiert die PdftronExe am angebenen Ort?
    String pathToPdftronExe = getConfigurationService().getPathToPdftronExe();
    String producerFirstValidator = getConfigurationService().firstValidator();
    String dualValidation = getConfigurationService().dualValidation();

    /* Nicht vergessen in "src/main/resources/config/applicationContext-services.xml" beim
     * entsprechenden Modul die property anzugeben: <property name="configurationService"
     * ref="configurationService" /> */

    if (dualValidation.contentEquals("dual")) {
        // Duale Validierung gewnscht
        dual = true;
    }
    if (!producerFirstValidator.contentEquals("PDFTron")) {
        // nicht der Validator von PDFTron --> PDFTools wird verwendet
        producerFirstValidator = "PDFTools";
    }

    File fPdftronExe = new File(pathToPdftronExe);
    if (!fPdftronExe.exists() || !fPdftronExe.getName().equals("pdfa.exe")) {
        // Keine Duale Validierung mglich
        if (dualValidation.contentEquals("dual") || producerFirstValidator.contentEquals("PDFTron")) {
            getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_PDFA)
                    + getTextResourceService().getText(ERROR_XML_PDFTRON_MISSING));
            dual = false;
            producerFirstValidator = "PDFTools";
        }
    }

    pathToPdftronExe = "\"" + pathToPdftronExe + "\"";

    String pdfTools = "";
    String pdfTron = "";
    String newPdfDiaTxt = "";

    try {
        int iCategory = 999999999;
        // Create object
        PdfValidatorAPI docPdf = new PdfValidatorAPI();

        // TODO: Erledigt Start mit PDFTron
        if (producerFirstValidator.contentEquals("PDFTron")) {
            // zuerst mit PDFTron und danach ggf mit PDFTools
            File report;
            Document doc = null;

            try {

                // Pfad zum Programm Pdftron
                File pdftronExe = new File(pathToPdftronExe);
                File output = directoryOfLogfile;
                String pathToPdftronOutput = output.getAbsolutePath();
                StringBuffer command = new StringBuffer(pdftronExe + " ");
                command.append("-l " + level);
                command.append(" -o ");
                command.append("\"");
                command.append(output.getAbsolutePath());
                command.append("\"");
                command.append(" ");
                command.append("\"");
                command.append(valDatei.getAbsolutePath());
                command.append("\"");

                Process proc = null;
                Runtime rt = null;

                try {
                    /* Der Name des generierten Reports lautet per default report.xml und es scheint keine
                     * Mglichkeit zu geben, dies zu bersteuern. */
                    report = new File(pathToPdftronOutput, "report.xml");

                    // falls das File bereits existiert, z.B. von einem vorhergehenden Durchlauf, lschen
                    // wir es
                    if (report.exists()) {
                        report.delete();
                    }

                    Util.switchOffConsole();

                    rt = Runtime.getRuntime();
                    proc = rt.exec(command.toString().split(" "));
                    // .split(" ") ist notwendig wenn in einem Pfad ein Doppelleerschlag vorhanden ist!

                    // Fehleroutput holen
                    StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");

                    // Output holen
                    StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT");

                    // Threads starten
                    errorGobbler.start();
                    outputGobbler.start();

                    // Warte, bis wget fertig ist
                    proc.waitFor();

                    Util.switchOnConsole();
                } catch (Exception e) {
                    getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_PDFA)
                            + getTextResourceService().getText(ERROR_XML_A_PDFA_SERVICEFAILED, e.getMessage()));
                    return false;
                } finally {
                    if (proc != null) {
                        closeQuietly(proc.getOutputStream());
                        closeQuietly(proc.getInputStream());
                        closeQuietly(proc.getErrorStream());
                    }
                }
                // Ende PDFTRON direkt auszulsen

                String pathToPdftronReport = report.getAbsolutePath();
                BufferedInputStream bis = new BufferedInputStream(new FileInputStream(pathToPdftronReport));
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                DocumentBuilder db = dbf.newDocumentBuilder();
                doc = db.parse(bis);
                doc.normalize();

                Integer passCount = new Integer(0);
                NodeList nodeLstI = doc.getElementsByTagName("Pass");

                // Valide pdfa-Dokumente enthalten "<Validation> <Pass FileName..." Anzahl pass = anzahl
                // Valider pdfa
                for (int s = 0; s < nodeLstI.getLength(); s++) {
                    passCount = passCount + 1;
                    // Valide PDFA-Datei Module A-J sind Valid
                    isValid = true;
                }

                if (passCount == 0) {
                    if (dual) {
                        // Duale Validierung mit PDFTools

                        if (docPdf.open(valDatei.getAbsolutePath(), "", NativeLibrary.COMPLIANCE.ePDFUnk)) {
                            // PDF Konnte geffnet werden
                            docPdf.setStopOnError(true);
                            docPdf.setReportingLevel(1);
                        } else {
                            docPdf.setStopOnError(true);
                            docPdf.setReportingLevel(1);
                            if (docPdf.getErrorCode() == NativeLibrary.ERRORCODE.PDF_E_PASSWORD) {
                                getMessageService().logError(getTextResourceService()
                                        .getText(MESSAGE_XML_MODUL_A_PDFA)
                                        + getTextResourceService().getText(ERROR_XML_A_PDFTOOLS_ENCRYPTED));
                                return false;
                            } else {
                                getMessageService().logError(getTextResourceService()
                                        .getText(MESSAGE_XML_MODUL_A_PDFA)
                                        + getTextResourceService().getText(ERROR_XML_A_PDFTOOLS_DAMAGED));
                                return false;
                            }
                        }

                        /* ePDFA1a 5122 ePDFA1b 5121 ePDFA2a 5891 ePDFA2b 5889 ePDFA2u 5890 */
                        if (level.contentEquals("1A")) {
                            if (docPdf.open(valDatei.getAbsolutePath(), "", 5122)) {
                                docPdf.validate();
                            }
                        } else if (level.contentEquals("1B")) {
                            if (docPdf.open(valDatei.getAbsolutePath(), "", 5121)) {
                                docPdf.validate();
                            }
                        } else if (level.contentEquals("2A")) {
                            if (docPdf.open(valDatei.getAbsolutePath(), "", 5891)) {
                                docPdf.validate();
                            }
                        } else if (level.contentEquals("2B")) {
                            if (docPdf.open(valDatei.getAbsolutePath(), "", 5889)) {
                                docPdf.validate();
                            }
                        } else if (level.contentEquals("2U")) {
                            if (docPdf.open(valDatei.getAbsolutePath(), "", 5890)) {
                                docPdf.validate();
                            }
                        } else {
                            // Validierung nach 2b
                            level = "2B";
                            if (docPdf.open(valDatei.getAbsolutePath(), "", 5889)) {
                                docPdf.validate();
                            }
                        }

                        // Error Category
                        iCategory = docPdf.getCategories();
                        /* die Zahl kann auch eine Summe von Kategorien sein z.B. 6144=2048+4096 ->
                         * getCategoryText gibt nur die erste Kategorie heraus (z.B. 2048) */

                        int success = 0;

                        /* ErrorCode kann ungleich Null sein, wenn es nur eine Information zu einer nicht
                         * einhaltung einer Empfehlung gefunden wurde.
                         * 
                         * Entsprechend wird der ErrorCode ignoriert. */

                        PdfError err = docPdf.getFirstError();
                        PdfError err1 = docPdf.getFirstError();

                        @SuppressWarnings("unused")
                        int iError = 0;
                        while (err != null) {
                            iError = err1.getErrorCode();
                            success = success + 1;
                            // Get next error
                            err = docPdf.getNextError();
                        }

                        if (success == 0 && iCategory == 0) {
                            // valide
                            isValid = true;

                            // Diskrepanz => PDF-Diagnosedaten ErrorCodes von PDFTron holen
                            NodeList nodeLst = doc.getElementsByTagName("Error");
                            String errorCodes = "";
                            for (int s = 0; s < nodeLst.getLength(); s++) {
                                Node dateiNode = nodeLst.item(s);
                                NamedNodeMap nodeMap = dateiNode.getAttributes();
                                Node errorNode = nodeMap.getNamedItem("Code");
                                String errorCode = errorNode.getNodeValue();
                                errorCodes = errorCodes + "  " + errorCode;
                            }

                            pdfTools = "<PDFTools><iCategory>0</iCategory><iError>0</iError></PDFTools>";
                            pdfTron = "<PDFTron><Code>" + errorCodes + "</Code></PDFTron>";
                            newPdfDiaTxt = "<Validation><ValFile>" + valDatei.getAbsolutePath()
                                    + "</ValFile><PdfaVL>" + level + "</PdfaVL>" + pdfTools + pdfTron
                                    + "</Validation>\n" + getTextResourceService().getText(MESSAGE_XML_DIAEND);
                            Util.pdfDia(newPdfDiaTxt, pdfDia);
                            Util.amp(pdfDia);

                        } else {
                            // invalid
                            isValid = false;
                        }
                    } else {
                        // keine duale Validierung -> invalid
                        isValid = false;
                    }
                }

            } catch (Exception e) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_PDFA)
                        + getTextResourceService().getText(ERROR_XML_UNKNOWN, e.getMessage()));
                return false;
            }
        } else {
            // TODO: Erledigt Start mit PDFTools
            // zuerst mit PDFTools und danach ggf mit PDFTron

            if (docPdf.open(valDatei.getAbsolutePath(), "", NativeLibrary.COMPLIANCE.ePDFUnk)) {
                // PDF Konnte geffnet werden
            } else {
                if (docPdf.getErrorCode() == NativeLibrary.ERRORCODE.PDF_E_PASSWORD) {
                    getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_PDFA)
                            + getTextResourceService().getText(ERROR_XML_A_PDFTOOLS_ENCRYPTED));
                    return false;
                } else {
                    getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_PDFA)
                            + getTextResourceService().getText(ERROR_XML_A_PDFTOOLS_DAMAGED));
                    return false;
                }
            }

            /* ePDFA1a 5122 ePDFA1b 5121 ePDFA2a 5891 ePDFA2b 5889 ePDFA2u 5890 */
            if (level.contentEquals("1A")) {
                if (docPdf.open(valDatei.getAbsolutePath(), "", 5122)) {
                    docPdf.validate();
                }
            } else if (level.contentEquals("1B")) {
                if (docPdf.open(valDatei.getAbsolutePath(), "", 5121)) {
                    docPdf.validate();
                }
            } else if (level.contentEquals("2A")) {
                if (docPdf.open(valDatei.getAbsolutePath(), "", 5891)) {
                    docPdf.validate();
                }
            } else if (level.contentEquals("2B")) {
                if (docPdf.open(valDatei.getAbsolutePath(), "", 5889)) {
                    docPdf.validate();
                }
            } else if (level.contentEquals("2U")) {
                if (docPdf.open(valDatei.getAbsolutePath(), "", 5890)) {
                    docPdf.validate();
                }
            } else {
                // Validierung nach 2b
                level = "2B";
                if (docPdf.open(valDatei.getAbsolutePath(), "", 5889)) {
                    docPdf.validate();
                }
            }

            docPdf.setStopOnError(false);
            docPdf.setReportingLevel(2);

            // Error Category
            iCategory = docPdf.getCategories();
            /* die Zahl kann auch eine Summe von Kategorien sein z.B. 6144=2048+4096 -> getCategoryText
             * gibt nur die erste Kategorie heraus (z.B. 2048) */

            int success = 0;

            PdfError err = docPdf.getFirstError();
            PdfError err1 = docPdf.getFirstError();

            int iError = 0;
            while (err != null) {
                iError = err1.getErrorCode();
                success = success + 1;
                // Get next error
                err = docPdf.getNextError();
            }

            if (success == 0 && iCategory == 0) {
                // valide
                isValid = true;
            } else {
                if (dual) {
                    // duale Validierung
                    File report;
                    Document doc = null;

                    try {
                        // Pfad zum Programm Pdftron
                        File pdftronExe = new File(pathToPdftronExe);
                        File output = directoryOfLogfile;
                        String pathToPdftronOutput = output.getAbsolutePath();
                        StringBuffer command = new StringBuffer(pdftronExe + " ");
                        command.append("-l " + level);
                        command.append(" -o ");
                        command.append("\"");
                        command.append(output.getAbsolutePath());
                        command.append("\"");
                        command.append(" ");
                        command.append("\"");
                        command.append(valDatei.getAbsolutePath());
                        command.append("\"");

                        Process proc = null;
                        Runtime rt = null;

                        try {
                            /* Der Name des generierten Reports lautet per default report.xml und es scheint
                             * keine Mglichkeit zu geben, dies zu bersteuern. */
                            report = new File(pathToPdftronOutput, "report.xml");

                            // falls das File bereits existiert, z.B. von einemvorhergehenden Durchlauf, lschen
                            // wir es
                            if (report.exists()) {
                                report.delete();
                            }

                            Util.switchOffConsole();

                            rt = Runtime.getRuntime();
                            proc = rt.exec(command.toString().split(" "));
                            // .split(" ") ist notwendig wenn in einem Pfad ein Doppelleerschlag vorhanden ist!

                            // Fehleroutput holen
                            StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");

                            // Output holen
                            StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT");

                            // Threads starten
                            errorGobbler.start();
                            outputGobbler.start();

                            // Warte, bis wget fertig ist
                            proc.waitFor();

                            Util.switchOnConsole();
                        } catch (Exception e) {
                            getMessageService()
                                    .logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_PDFA)
                                            + getTextResourceService().getText(ERROR_XML_A_PDFA_SERVICEFAILED,
                                                    e.getMessage()));
                            return false;
                        } finally {
                            if (proc != null) {
                                closeQuietly(proc.getOutputStream());
                                closeQuietly(proc.getInputStream());
                                closeQuietly(proc.getErrorStream());
                            }
                        }
                        // Ende PDFTRON direkt auszulsen

                        String pathToPdftronReport = report.getAbsolutePath();
                        BufferedInputStream bis = new BufferedInputStream(
                                new FileInputStream(pathToPdftronReport));
                        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                        DocumentBuilder db = dbf.newDocumentBuilder();
                        doc = db.parse(bis);
                        doc.normalize();

                        Integer passCount = new Integer(0);
                        NodeList nodeLstI = doc.getElementsByTagName("Pass");

                        // Valide pdfa-Dokumente enthalten "<Validation> <Pass FileName..." Anzahl pass =
                        // anzahl Valider pdfa
                        for (int s = 0; s < nodeLstI.getLength(); s++) {
                            passCount = passCount + 1;
                            // Valide PDFA-Datei Module A-J sind Valid
                            isValid = true;

                            // Diskrepanz => PDF-Diagnosedaten
                            pdfTools = "<PDFTools><iCategory>" + iCategory + "</iCategory><iError>" + iError
                                    + "</iError></PDFTools>";
                            pdfTron = "<PDFTron><Code>Pass</Code></PDFTron>";
                            newPdfDiaTxt = "<Validation><ValFile>" + valDatei.getAbsolutePath()
                                    + "</ValFile><PdfaVL>" + level + "</PdfaVL>" + pdfTools + pdfTron
                                    + "</Validation>\n" + getTextResourceService().getText(MESSAGE_XML_DIAEND);
                            Util.pdfDia(newPdfDiaTxt, pdfDia);
                            Util.amp(pdfDia);

                        }
                        if (passCount == 0) {
                            // Invalide PDFA-Datei (doppelt besttigt)
                            isValid = false;
                        }

                    } catch (Exception e) {
                        getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_PDFA)
                                + getTextResourceService().getText(ERROR_XML_A_PDFA_SERVICEFAILED,
                                        e.getMessage()));
                        return false;
                    }
                } else {
                    // keine duale Validierung -> invalid
                    isValid = false;
                }
            }
        }

        // TODO: Erledigt: Fehler Auswertung

        if (!isValid) {
            // Invalide PDFA-Datei

            boolean exponent0 = false;
            boolean exponent1 = false;
            boolean exponent2 = false;
            boolean exponent3 = false;
            boolean exponent4 = false;
            boolean exponent5 = false;
            boolean exponent6 = false;
            boolean exponent7 = false;
            boolean exponent8 = false;
            boolean exponent9 = false;
            boolean exponent10 = false;
            boolean exponent11 = false;
            boolean exponent12 = false;
            boolean exponent13 = false;
            boolean exponent14 = false;
            boolean exponent15 = false;
            boolean exponent16 = false;
            boolean exponent17 = false;
            boolean exponent18 = false;

            int iExp0 = (int) Math.pow(2, 0);
            int iExp1 = (int) Math.pow(2, 1);
            int iExp2 = (int) Math.pow(2, 2);
            int iExp3 = (int) Math.pow(2, 3);
            int iExp4 = (int) Math.pow(2, 4);
            int iExp5 = (int) Math.pow(2, 5);
            int iExp6 = (int) Math.pow(2, 6);
            int iExp7 = (int) Math.pow(2, 7);
            int iExp8 = (int) Math.pow(2, 8);
            int iExp9 = (int) Math.pow(2, 9);
            int iExp10 = (int) Math.pow(2, 10);
            int iExp11 = (int) Math.pow(2, 11);
            int iExp12 = (int) Math.pow(2, 12);
            int iExp13 = (int) Math.pow(2, 13);
            int iExp14 = (int) Math.pow(2, 14);
            int iExp15 = (int) Math.pow(2, 15);
            int iExp16 = (int) Math.pow(2, 16);
            int iExp17 = (int) Math.pow(2, 17);
            int iExp18 = (int) Math.pow(2, 18);

            if (producerFirstValidator.contentEquals("PDFTools") || dual) {
                // Invalide Kategorien von PDF-Tools
                if (iCategory >= iExp18) {
                    exponent18 = true;
                    iCategory = iCategory - iExp18;
                }
                if (iCategory >= iExp17) {
                    exponent17 = true;
                    iCategory = iCategory - iExp17;
                }
                if (iCategory >= iExp16) {
                    exponent16 = true;
                    iCategory = iCategory - iExp16;
                }
                if (iCategory >= iExp15) {
                    exponent15 = true;
                    iCategory = iCategory - iExp15;
                }
                if (iCategory >= iExp14) {
                    exponent14 = true;
                    iCategory = iCategory - iExp14;
                }
                if (iCategory >= iExp13) {
                    exponent13 = true;
                    iCategory = iCategory - iExp13;
                }
                if (iCategory >= iExp12) {
                    exponent12 = true;
                    iCategory = iCategory - iExp12;
                }
                if (iCategory >= iExp11) {
                    exponent11 = true;
                    iCategory = iCategory - iExp11;
                }
                if (iCategory >= iExp10) {
                    exponent10 = true;
                    iCategory = iCategory - iExp10;
                }
                if (iCategory >= iExp9) {
                    exponent9 = true;
                    iCategory = iCategory - iExp9;
                }
                if (iCategory >= iExp8) {
                    exponent8 = true;
                    iCategory = iCategory - iExp8;
                }
                if (iCategory >= iExp7) {
                    exponent7 = true;
                    iCategory = iCategory - iExp7;
                }
                if (iCategory >= iExp6) {
                    exponent6 = true;
                    iCategory = iCategory - iExp6;
                }
                if (iCategory >= iExp5) {
                    exponent5 = true;
                    iCategory = iCategory - iExp5;
                }
                if (iCategory >= iExp4) {
                    exponent4 = true;
                    iCategory = iCategory - iExp4;
                }
                if (iCategory >= iExp3) {
                    exponent3 = true;
                    iCategory = iCategory - iExp3;
                }
                if (iCategory >= iExp2) {
                    exponent2 = true;
                    iCategory = iCategory - iExp2;
                }
                if (iCategory >= iExp1) {
                    exponent1 = true;
                    iCategory = iCategory - iExp1;
                }
                if (iCategory >= iExp0) {
                    exponent0 = true;
                    iCategory = iCategory - iExp0;
                }
            } else {
                iCategory = 0;
            }

            File report = new File(directoryOfLogfile.getAbsolutePath(), "report.xml");
            Document doc = null;

            if (producerFirstValidator.contentEquals("PDFTron") || dual) {
                // aus dem Output von Pdftron die Fehlercodes extrahieren und bersetzen

                String pathToPdftronReport = report.getAbsolutePath();
                BufferedInputStream bis = new BufferedInputStream(new FileInputStream(pathToPdftronReport));
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                DocumentBuilder db = dbf.newDocumentBuilder();
                doc = db.parse(bis);
                doc.normalize();

                // Bsp. fr einen Error Code: <Error Code="e_PDFA173" die erste Ziffer nach e_PDFA ist der
                // Error Code.
            }
            /** Modul A **/
            if (exponent1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_PDFA)
                        + getTextResourceService().getText(ERROR_XML_AI_1, "iCategory_1"));
            }
            if (exponent2) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_PDFA)
                        + getTextResourceService().getText(ERROR_XML_AI_2, "iCategory_2"));
            }
            if (producerFirstValidator.contentEquals("PDFTron") || dual) {
                // aus dem Output von Pdftron die Fehlercodes extrahieren und bersetzen

                String errorDigitA = "Fehler";

                NodeList nodeLst = doc.getElementsByTagName("Error");
                /* Bsp. fr einen Error Code: <Error Code="e_PDFA173" die erste Ziffer nach e_PDFA ist der
                 * Error Code. */
                for (int s = 0; s < nodeLst.getLength(); s++) {
                    Node dateiNode = nodeLst.item(s);
                    NamedNodeMap nodeMap = dateiNode.getAttributes();
                    Node errorNode = nodeMap.getNamedItem("Code");
                    String errorCode = errorNode.getNodeValue();
                    String errorCodeMsg = "error.xml.ai." + errorCode.substring(2);
                    Node errorNodeM = nodeMap.getNamedItem("Message");
                    String errorMessage = errorNodeM.getNodeValue();
                    errorDigitA = errorCode.substring(6, 7);

                    // der Error Code kann auch "Unknown" sein, dieser wird in den Code "0" bersetzt
                    if (errorDigitA.equals("U")) {
                        errorDigitA = "0";
                    }
                    if (errorDigitA.equals("n")) {
                        errorDigitA = "0";
                    }
                    try {
                        if (errorDigitA.equals("0")) {

                            // Allgemeiner Fehler -> A
                            isValid = false;
                            getMessageService()
                                    .logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_PDFA)
                                            + getTextResourceService().getText(errorCodeMsg, errorCode));
                        }
                    } catch (Exception e) {
                        getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_PDFA)
                                + getTextResourceService().getText(ERROR_XML_AI_TRANSLATE, errorCode,
                                        errorMessage));
                    }
                }
                if (errorDigitA.equals("Fehler")) {
                    // Fehler bei der Initialisierung Passierte bei einem Leerschlag im Namen
                    isValid = false;
                    getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_PDFA)
                            + getTextResourceService().getText(ERROR_XML_A_PDFA_INIT));
                    return false;
                }
            }

            /** Modul B **/
            if (exponent0) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_PDFA)
                        + getTextResourceService().getText(ERROR_XML_AI_0, "iCategory_0"));
            }
            if (exponent7) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_PDFA)
                        + getTextResourceService().getText(ERROR_XML_AI_7, "iCategory_7"));
            }
            if (exponent18) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_PDFA)
                        + getTextResourceService().getText(ERROR_XML_AI_18, "iCategory_18"));
            }
            if (producerFirstValidator.contentEquals("PDFTron") || dual) {
                // Analog Modul A
                NodeList nodeLst = doc.getElementsByTagName("Error");
                for (int s = 0; s < nodeLst.getLength(); s++) {
                    Node dateiNode = nodeLst.item(s);
                    NamedNodeMap nodeMap = dateiNode.getAttributes();
                    Node errorNode = nodeMap.getNamedItem("Code");
                    String errorCode = errorNode.getNodeValue();
                    String errorCodeMsg = "error.xml.ai." + errorCode.substring(2);
                    Node errorNodeM = nodeMap.getNamedItem("Message");
                    String errorMessage = errorNodeM.getNodeValue();
                    String errorDigit = errorCode.substring(6, 7);
                    try {
                        if (errorDigit.equals("1")) {
                            // Struktur Fehler -> B
                            isValid = false;
                            getMessageService()
                                    .logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_PDFA)
                                            + getTextResourceService().getText(errorCodeMsg, errorCode));
                        }
                    } catch (Exception e) {
                        getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_PDFA)
                                + getTextResourceService().getText(ERROR_XML_AI_TRANSLATE, errorCode,
                                        errorMessage));
                    }
                }
            }

            /** Modul C **/
            if (exponent3) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_PDFA)
                        + getTextResourceService().getText(ERROR_XML_AI_3, "iCategory_3"));
            }
            if (exponent4) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_PDFA)
                        + getTextResourceService().getText(ERROR_XML_AI_4, "iCategory_4"));
            }
            if (exponent5) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_PDFA)
                        + getTextResourceService().getText(ERROR_XML_AI_5, "iCategory_5"));
            }
            if (exponent6) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_PDFA)
                        + getTextResourceService().getText(ERROR_XML_AI_6, "iCategory_6"));
            }
            if (producerFirstValidator.contentEquals("PDFTron") || dual) {
                // Analog Modul A
                NodeList nodeLst = doc.getElementsByTagName("Error");
                for (int s = 0; s < nodeLst.getLength(); s++) {
                    Node dateiNode = nodeLst.item(s);
                    NamedNodeMap nodeMap = dateiNode.getAttributes();
                    Node errorNode = nodeMap.getNamedItem("Code");
                    String errorCode = errorNode.getNodeValue();
                    String errorCodeMsg = "error.xml.ai." + errorCode.substring(2);
                    Node errorNodeM = nodeMap.getNamedItem("Message");
                    String errorMessage = errorNodeM.getNodeValue();
                    String errorDigit = errorCode.substring(6, 7);
                    try {
                        if (errorDigit.equals("2")) {
                            // Grafik Fehler -> C
                            isValid = false;
                            getMessageService()
                                    .logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_PDFA)
                                            + getTextResourceService().getText(errorCodeMsg, errorCode));
                        }
                    } catch (Exception e) {
                        getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_PDFA)
                                + getTextResourceService().getText(ERROR_XML_AI_TRANSLATE, errorCode,
                                        errorMessage));
                    }
                }
            }
            /** Modul D **/
            if (exponent8) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_D_PDFA)
                        + getTextResourceService().getText(ERROR_XML_AI_8, "iCategory_8"));
            }
            if (exponent9) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_D_PDFA)
                        + getTextResourceService().getText(ERROR_XML_AI_9, "iCategory_9"));
            }
            if (producerFirstValidator.contentEquals("PDFTron") || dual) {
                // Analog Modul A
                NodeList nodeLst = doc.getElementsByTagName("Error");
                for (int s = 0; s < nodeLst.getLength(); s++) {
                    Node dateiNode = nodeLst.item(s);
                    NamedNodeMap nodeMap = dateiNode.getAttributes();
                    Node errorNode = nodeMap.getNamedItem("Code");
                    String errorCode = errorNode.getNodeValue();
                    String errorCodeMsg = "error.xml.ai." + errorCode.substring(2);
                    Node errorNodeM = nodeMap.getNamedItem("Message");
                    String errorMessage = errorNodeM.getNodeValue();
                    String errorDigit = errorCode.substring(6, 7);
                    try {
                        if (errorDigit.equals("3")) {
                            // Schrift Fehler -> D
                            isValid = false;
                            getMessageService()
                                    .logError(getTextResourceService().getText(MESSAGE_XML_MODUL_D_PDFA)
                                            + getTextResourceService().getText(errorCodeMsg, errorCode));
                        }
                    } catch (Exception e) {
                        getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_D_PDFA)
                                + getTextResourceService().getText(ERROR_XML_AI_TRANSLATE, errorCode,
                                        errorMessage));
                    }
                }
            }
            /** Modul E **/
            if (exponent10) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_E_PDFA)
                        + getTextResourceService().getText(ERROR_XML_AI_10, "iCategory_10"));
            }
            if (producerFirstValidator.contentEquals("PDFTron") || dual) {
                // Analog Modul A
                NodeList nodeLst = doc.getElementsByTagName("Error");
                for (int s = 0; s < nodeLst.getLength(); s++) {
                    Node dateiNode = nodeLst.item(s);
                    NamedNodeMap nodeMap = dateiNode.getAttributes();
                    Node errorNode = nodeMap.getNamedItem("Code");
                    String errorCode = errorNode.getNodeValue();
                    String errorCodeMsg = "error.xml.ai." + errorCode.substring(2);
                    Node errorNodeM = nodeMap.getNamedItem("Message");
                    String errorMessage = errorNodeM.getNodeValue();
                    String errorDigit = errorCode.substring(6, 7);
                    try {
                        if (errorDigit.equals("4")) {
                            // Transparenz Fehler -> E
                            isValid = false;
                            getMessageService()
                                    .logError(getTextResourceService().getText(MESSAGE_XML_MODUL_E_PDFA)
                                            + getTextResourceService().getText(errorCodeMsg, errorCode));
                        }
                    } catch (Exception e) {
                        getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_E_PDFA)
                                + getTextResourceService().getText(ERROR_XML_AI_TRANSLATE, errorCode,
                                        errorMessage));
                    }
                }
            }
            /** Modul F **/
            if (exponent11) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_F_PDFA)
                        + getTextResourceService().getText(ERROR_XML_AI_11, "iCategory_11"));
            }
            if (exponent12) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_F_PDFA)
                        + getTextResourceService().getText(ERROR_XML_AI_12, "iCategory_12"));
            }
            if (exponent13) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_F_PDFA)
                        + getTextResourceService().getText(ERROR_XML_AI_13, "iCategory_13"));
            }
            if (exponent14) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_F_PDFA)
                        + getTextResourceService().getText(ERROR_XML_AI_14, "iCategory_14"));
            }
            if (producerFirstValidator.contentEquals("PDFTron") || dual) {
                // Analog Modul A
                NodeList nodeLst = doc.getElementsByTagName("Error");
                for (int s = 0; s < nodeLst.getLength(); s++) {
                    Node dateiNode = nodeLst.item(s);
                    NamedNodeMap nodeMap = dateiNode.getAttributes();
                    Node errorNode = nodeMap.getNamedItem("Code");
                    String errorCode = errorNode.getNodeValue();
                    String errorCodeMsg = "error.xml.ai." + errorCode.substring(2);
                    Node errorNodeM = nodeMap.getNamedItem("Message");
                    String errorMessage = errorNodeM.getNodeValue();
                    String errorDigit = errorCode.substring(6, 7);
                    try {
                        if (errorDigit.equals("5")) {
                            // Annotations Fehler -> F
                            isValid = false;
                            getMessageService()
                                    .logError(getTextResourceService().getText(MESSAGE_XML_MODUL_F_PDFA)
                                            + getTextResourceService().getText(errorCodeMsg, errorCode));
                        }
                    } catch (Exception e) {
                        getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_F_PDFA)
                                + getTextResourceService().getText(ERROR_XML_AI_TRANSLATE, errorCode,
                                        errorMessage));
                    }
                }
            }
            /** Modul G **/
            if (exponent15) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_G_PDFA)
                        + getTextResourceService().getText(ERROR_XML_AI_15, "iCategory_15"));
            }
            if (producerFirstValidator.contentEquals("PDFTron") || dual) {
                // Analog Modul A
                NodeList nodeLst = doc.getElementsByTagName("Error");
                for (int s = 0; s < nodeLst.getLength(); s++) {
                    Node dateiNode = nodeLst.item(s);
                    NamedNodeMap nodeMap = dateiNode.getAttributes();
                    Node errorNode = nodeMap.getNamedItem("Code");
                    String errorCode = errorNode.getNodeValue();
                    String errorCodeMsg = "error.xml.ai." + errorCode.substring(2);
                    Node errorNodeM = nodeMap.getNamedItem("Message");
                    String errorMessage = errorNodeM.getNodeValue();
                    String errorDigit = errorCode.substring(6, 7);
                    try {
                        if (errorDigit.equals("6")) {
                            // Aktions Fehler -> G
                            isValid = false;
                            getMessageService()
                                    .logError(getTextResourceService().getText(MESSAGE_XML_MODUL_G_PDFA)
                                            + getTextResourceService().getText(errorCodeMsg, errorCode));
                        }
                        // neu sind die Interaktionen (J) bei den Aktionen (G)
                        if (errorDigit.equals("9")) {
                            // Interaktions Fehler -> J
                            isValid = false;
                            getMessageService()
                                    .logError(getTextResourceService().getText(MESSAGE_XML_MODUL_G_PDFA)
                                            + getTextResourceService().getText(errorCodeMsg, errorCode));
                        }
                    } catch (Exception e) {
                        getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_G_PDFA)
                                + getTextResourceService().getText(ERROR_XML_AI_TRANSLATE, errorCode,
                                        errorMessage));
                    }
                }
            }
            /** Modul H **/
            if (exponent16) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_H_PDFA)
                        + getTextResourceService().getText(ERROR_XML_AI_16, "iCategory_16"));
            }
            if (producerFirstValidator.contentEquals("PDFTron") || dual) {
                // Analog Modul A
                NodeList nodeLst = doc.getElementsByTagName("Error");
                for (int s = 0; s < nodeLst.getLength(); s++) {
                    Node dateiNode = nodeLst.item(s);
                    NamedNodeMap nodeMap = dateiNode.getAttributes();
                    Node errorNode = nodeMap.getNamedItem("Code");
                    String errorCode = errorNode.getNodeValue();
                    String errorCodeMsg = "error.xml.ai." + errorCode.substring(2);
                    Node errorNodeM = nodeMap.getNamedItem("Message");
                    String errorMessage = errorNodeM.getNodeValue();
                    String errorDigit = errorCode.substring(6, 7);
                    try {
                        if (errorDigit.equals("7")) {
                            // Metadaten Fehler -> H
                            isValid = false;
                            getMessageService()
                                    .logError(getTextResourceService().getText(MESSAGE_XML_MODUL_H_PDFA)
                                            + getTextResourceService().getText(errorCodeMsg, errorCode));
                        }
                    } catch (Exception e) {
                        getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_H_PDFA)
                                + getTextResourceService().getText(ERROR_XML_AI_TRANSLATE, errorCode,
                                        errorMessage));
                    }
                }
            }
            /** Modul I **/
            if (exponent17) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_I_PDFA)
                        + getTextResourceService().getText(ERROR_XML_AI_17, "iCategory_17"));
            }
            if (producerFirstValidator.contentEquals("PDFTron") || dual) {
                // Analog Modul A
                NodeList nodeLst = doc.getElementsByTagName("Error");
                for (int s = 0; s < nodeLst.getLength(); s++) {
                    Node dateiNode = nodeLst.item(s);
                    NamedNodeMap nodeMap = dateiNode.getAttributes();
                    Node errorNode = nodeMap.getNamedItem("Code");
                    String errorCode = errorNode.getNodeValue();
                    String errorCodeMsg = "error.xml.ai." + errorCode.substring(2);
                    Node errorNodeM = nodeMap.getNamedItem("Message");
                    String errorMessage = errorNodeM.getNodeValue();
                    String errorDigit = errorCode.substring(6, 7);
                    try {
                        if (errorDigit.equals("8")) {
                            // Zugnglichkeit Fehler -> I
                            isValid = false;
                            getMessageService()
                                    .logError(getTextResourceService().getText(MESSAGE_XML_MODUL_I_PDFA)
                                            + getTextResourceService().getText(errorCodeMsg, errorCode));
                        }
                    } catch (Exception e) {
                        getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_I_PDFA)
                                + getTextResourceService().getText(ERROR_XML_AI_TRANSLATE, errorCode,
                                        errorMessage));
                    }
                }
            }
            /** Modul J **/
            // neu sind die Interaktionen (J) bei den Aktionen (G)

            docPdf.close();

            // Destroy the object
            docPdf.destroyObject();

        }
    } catch (Exception e) {
        getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_PDFA)
                + getTextResourceService().getText(ERROR_XML_UNKNOWN, e.getMessage()));
    }
    return isValid;
}

From source file:io.hops.hopsworks.common.project.ProjectController.java

private void killYarnJobs(Project project) {
    List<Jobs> running = jobFacade.getRunningJobs(project);
    if (running != null && !running.isEmpty()) {
        Runtime rt = Runtime.getRuntime();
        for (Jobs job : running) {
            //Get the appId of the running app
            List<Execution> jobExecs = execFacade.findForJob(job);
            //Sort descending based on jobId because therie might be two
            // jobs with the same name and we want the latest
            Collections.sort(jobExecs, new Comparator<Execution>() {
                @Override//from ww w  .j  a v a  2  s .c o  m
                public int compare(Execution lhs, Execution rhs) {
                    return lhs.getId() > rhs.getId() ? -1 : (lhs.getId() < rhs.getId()) ? 1 : 0;
                }
            });
            try {
                rt.exec(settings.getHadoopSymbolicLinkDir() + "/bin/yarn application -kill "
                        + jobExecs.get(0).getAppId());
            } catch (IOException ex) {
                Logger.getLogger(ProjectController.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

From source file:de.unibi.techfak.bibiserv.BiBiTools.java

/**
 * chmodDir() sets perms of a dir as defined in bibiprops.
 *
 * @return boolean true if successfully exec of chmod is succesful, doesnt
 * matter if changed or not, false on failure
 *//* ww  w. j  a  va 2  s .com*/
private boolean chmodDir(File dir) {
    Runtime runtime = Runtime.getRuntime();
    try {
        String chmodCmd = properties.getProperty("chmod.bin") + " " + properties.getProperty("chmod.param")
                + " " + dir.toString();
        Process process = runtime.exec(chmodCmd);
        if (process.waitFor() != 0) {
            log.error("could not chmod '" + chmodCmd + "'!\n "
                    + i2s(new InputStreamReader(process.getErrorStream())));

            process.getErrorStream().close();
            return false;
        }

        log.debug("chmod for dir '" + dir.toString() + "' done: " + dir.toString());
    } catch (InterruptedException e) {
        log.error("could not chmod dir '" + dir.toString() + "' : " + e.getMessage());
        return false;
    } catch (IOException e) {
        log.error("could not chmod dir '" + dir.toString() + "' : " + e.getMessage());
        return false;
    }

    return true;
}

From source file:io.hops.hopsworks.common.project.ProjectController.java

/**
 * Deletes a member from a project/*from  w w w  .j  a v a2  s .  co m*/
 *
 * @param project
 * @param email
 * @param toRemoveEmail
 */
public void removeMemberFromTeam(Project project, String email, String toRemoveEmail)
        throws UserException, ProjectException, ServiceException, IOException, CAException {
    Users userToBeRemoved = userFacade.findByEmail(toRemoveEmail);
    if (userToBeRemoved == null) {
        throw new UserException(RESTCodes.UserErrorCode.USER_WAS_NOT_FOUND, Level.FINE, "user: " + email);
    }
    ProjectTeam projectTeam = projectTeamFacade.findProjectTeam(project, userToBeRemoved);
    if (projectTeam == null) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.TEAM_MEMBER_NOT_FOUND, Level.FINE,
                "project: " + project + ", user: " + email);
    }
    projectTeamFacade.removeProjectTeam(project, userToBeRemoved);
    Users user = userFacade.findByEmail(email);
    String hdfsUser = hdfsUsersController.getHdfsUserName(project, userToBeRemoved);

    YarnClientWrapper yarnClientWrapper = ycs.getYarnClientSuper(settings.getConfiguration());
    YarnClient client = yarnClientWrapper.getYarnClient();
    try {
        Set<String> hdfsUsers = new HashSet<>();
        hdfsUsers.add(hdfsUser);
        List<ApplicationReport> projectsApps = client.getApplications(null, hdfsUsers, null,
                EnumSet.of(YarnApplicationState.ACCEPTED, YarnApplicationState.NEW,
                        YarnApplicationState.NEW_SAVING, YarnApplicationState.RUNNING,
                        YarnApplicationState.SUBMITTED));
        //kill jupyter for this user
        jupyterProcessFacade.stopCleanly(hdfsUser);
        if (settings.isPythonKernelEnabled()) {
            jupyterProcessFacade.removePythonKernelForProjectUser(hdfsUser);
        }

        //kill running TB if any
        tensorBoardController.cleanup(project, user);

        //kill all jobs run by this user.
        //kill jobs
        List<Jobs> running = jobFacade.getRunningJobs(project, hdfsUser);
        if (running != null && !running.isEmpty()) {
            Runtime rt = Runtime.getRuntime();
            for (Jobs job : running) {
                //Get the appId of the running app
                List<Execution> jobExecs = execFacade.findForJob(job);
                //Sort descending based on jobId because there might be two 
                // jobs with the same name and we want the latest
                Collections.sort(jobExecs, new Comparator<Execution>() {
                    @Override
                    public int compare(Execution lhs, Execution rhs) {
                        return lhs.getId() > rhs.getId() ? -1 : (lhs.getId() < rhs.getId()) ? 1 : 0;
                    }
                });
                try {
                    rt.exec(settings.getHadoopSymbolicLinkDir() + "/bin/yarn application -kill "
                            + jobExecs.get(0).getAppId());
                } catch (IOException ex) {
                    Logger.getLogger(ProjectController.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        //wait that log aggregation for the jobs finish
        for (ApplicationReport appReport : projectsApps) {
            FinalApplicationStatus finalState = appReport.getFinalApplicationStatus();
            while (finalState.equals(FinalApplicationStatus.UNDEFINED)) {
                client.killApplication(appReport.getApplicationId());
                appReport = client.getApplicationReport(appReport.getApplicationId());
                finalState = appReport.getFinalApplicationStatus();
            }
            LogAggregationStatus logAggregationState = appReport.getLogAggregationStatus();
            while (!YarnLogUtil.isFinal(logAggregationState)) {
                Thread.sleep(500);
                appReport = client.getApplicationReport(appReport.getApplicationId());
                logAggregationState = appReport.getLogAggregationStatus();
            }
        }
    } catch (YarnException | IOException | InterruptedException e) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.KILL_MEMBER_JOBS, Level.SEVERE,
                "project: " + project + ", user: " + userToBeRemoved, e.getMessage(), e);
    } finally {
        ycs.closeYarnClient(yarnClientWrapper);
    }

    kafkaController.removeProjectMemberFromTopics(project, userToBeRemoved);

    logActivity(ActivityFacade.REMOVED_MEMBER + toRemoveEmail, ActivityFacade.FLAG_PROJECT, user, project);

    certificateMaterializer.forceRemoveLocalMaterial(userToBeRemoved.getUsername(), project.getName(), null,
            false);
    certificatesController.deleteUserSpecificCertificates(project, userToBeRemoved);
}

From source file:edu.harvard.iq.dvn.core.web.ExploreDataPage.java

private File generateImageString(String size, String width, String orientation, String rotate, String inStr)
        throws IOException {
    // let's attempt to generate the Text image:
    int exitValue = 0;
    File file = File.createTempFile("imageString", "tmp");

    // TODO: hard-coded pathname for the ImageMagick "convert"!
    // - L.A.//  w  w  w.ja v  a 2 s.  c  o  m

    if (new File("/usr/bin/convert").exists()) {

        String ImageMagickCmd[] = new String[15];

        ImageMagickCmd[0] = "/usr/bin/convert";
        ImageMagickCmd[1] = "-background";
        ImageMagickCmd[2] = "white";
        ImageMagickCmd[3] = "-font";
        ImageMagickCmd[4] = "Helvetica";
        ImageMagickCmd[5] = "-pointsize";
        ImageMagickCmd[6] = size;
        ImageMagickCmd[7] = "-gravity";
        ImageMagickCmd[8] = orientation;
        ImageMagickCmd[9] = "-rotate";
        ImageMagickCmd[10] = rotate;
        ImageMagickCmd[11] = "-size";
        ImageMagickCmd[12] = width;
        ImageMagickCmd[13] = "caption:" + inStr;
        ImageMagickCmd[14] = "png:" + file.getAbsolutePath();

        try {
            Runtime runtime = Runtime.getRuntime();
            Process process = runtime.exec(ImageMagickCmd);
            exitValue = process.waitFor();
        } catch (Exception e) {
            exitValue = 1;
        }

        if (exitValue == 0) {
            return file;
        }

        return file;
    }

    return null;
}

From source file:com.loy.MainFrame.java

@SuppressWarnings("rawtypes")
public void init() {

    String src = "ee.png";
    try {//from   w w  w  .jav a 2s.co m
        ClassPathResource classPathResource = new ClassPathResource(src);
        image = ImageIO.read(classPathResource.getURL());
        this.setIconImage(image);
    } catch (IOException e) {
    }

    menu = new JMenu("LOG CONSOLE");
    this.jmenuBar = new JMenuBar();
    this.jmenuBar.add(menu);

    panel = new JPanel(new BorderLayout());
    this.add(panel);

    ClassPathResource classPathResource = new ClassPathResource("application.yml");
    Yaml yaml = new Yaml();
    Map result = null;
    try {
        result = (Map) yaml.load(classPathResource.getInputStream());
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    String platformStr = result.get("platform").toString();
    String version = result.get("version").toString();
    String jvmOption = result.get("jvmOption").toString();
    @SuppressWarnings("unchecked")
    List<String> projects = (List<String>) result.get("projects");
    platform = Platform.valueOf(platformStr);
    final Runtime runtime = Runtime.getRuntime();
    File pidsForder = new File("./pids");
    if (!pidsForder.exists()) {
        pidsForder.mkdir();
    } else {
        File[] files = pidsForder.listFiles();
        if (files != null) {
            for (File f : files) {
                f.deleteOnExit();
                String pidStr = f.getName();
                try {
                    Long pid = new Long(pidStr);
                    if (Processes.isProcessRunning(platform, pid)) {
                        if (Platform.Windows == platform) {
                            Processes.tryKillProcess(null, platform, new NullProcessor(), pid);
                        } else {
                            Processes.killProcess(null, platform, new NullProcessor(), pid);
                        }

                    }
                } catch (Exception ex) {
                }
            }
        }
    }

    File currentForder = new File("");
    String rootPath = currentForder.getAbsolutePath();
    rootPath = rootPath.replace(File.separator + "build" + File.separator + "libs", "");
    rootPath = rootPath.replace(File.separator + "e-example-ms-start-w", "");

    for (String value : projects) {
        String path = value;
        String[] values = value.split("/");
        value = values[values.length - 1];
        String appName = value;
        value = rootPath + "/" + path + "/build/libs/" + value + "-" + version + ".jar";

        JMenuItem menuItem = new JMenuItem(appName);
        JTextArea textArea = new JTextArea();
        textArea.setVisible(true);
        textArea.setLineWrap(true);
        textArea.setWrapStyleWord(true);
        textArea.setAutoscrolls(true);
        JScrollPane scorll = new JScrollPane(textArea);
        this.textSreaMap.put(appName, scorll);
        EComposite ecomposite = new EComposite();
        ecomposite.setCommand(value);
        ecomposite.setTextArea(textArea);
        composites.put(appName, ecomposite);
        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Collection<JScrollPane> values = textSreaMap.values();
                for (JScrollPane t : values) {
                    t.setVisible(false);
                }
                String actions = e.getActionCommand();
                JScrollPane textArea = textSreaMap.get(actions);
                if (textArea != null) {
                    textArea.setVisible(true);
                    panel.removeAll();
                    panel.add(textArea);
                    panel.repaint();
                    panel.validate();
                    self.repaint();
                    self.validate();
                }
            }
        });
        menu.add(menuItem);
    }

    new Thread(new Runnable() {
        @Override
        public void run() {
            int size = composites.keySet().size();
            int index = 1;
            for (String appName : composites.keySet()) {
                EComposite composite = composites.get(appName);
                try {

                    Process process = runtime.exec(
                            "java " + jvmOption + " -Dfile.encoding=UTF-8 -jar " + composite.getCommand());
                    Long pid = Processes.processId(process);
                    pids.add(pid);
                    File pidsFile = new File("./pids", pid.toString());
                    pidsFile.createNewFile();

                    new WriteLogThread(process.getInputStream(), composite.getTextArea()).start();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                synchronized (lock) {
                    try {
                        if (index < size) {
                            lock.wait();
                        } else {
                            index++;
                        }

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }).start();

}

From source file:patientmanagerv1.HomeController.java

public void launchSpeechRecognition() {
    Runtime rt = Runtime.getRuntime();
    try {//from  w  ww. j a  va  2 s.c  om
        //Process process = rt.exec("control panel");
        //Process process2 = rt.exec("cmd.exe");
        Process process = rt.exec("Control Panel");

        try {
            process.wait(2500);
        } catch (Exception e) {
        }

        Process process3 = rt.exec("notepad");

        //Process process4 = rt.exec("Speech Recognition");

    } catch (Exception e) {
        //    System.out.println(e);
    }

    try {
        Audio audio = Audio.getInstance();
        InputStream sound = audio.getAudio("Type 'speech' into the control panel search bar.",
                Language.ENGLISH);
        audio.play(sound);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null,
                "Type 'Speech' into the control panel search bar. It will guide you through how to use Windows 7 Native Dictation");
    }

}

From source file:talonetl.getproperties_0_2.getProperties.java

public void tRunJob_1Process(final java.util.Map<String, Object> globalMap) throws TalendException {
    globalMap.put("tRunJob_1_SUBPROCESS_STATE", 0);

    final boolean execStat = this.execStat;

    String iterateId = "";
    int iterateLoop = 0;
    String currentComponent = "";

    try {/*from  w ww .j  a  v  a 2 s  .co  m*/

        String currentMethodName = new Exception().getStackTrace()[0].getMethodName();
        boolean resumeIt = currentMethodName.equals(resumeEntryMethodName);
        if (resumeEntryMethodName == null || resumeIt || globalResumeTicket) {// start
            // the
            // resume
            globalResumeTicket = true;

            /**
             * [tRunJob_1 begin ] start
             */

            ok_Hash.put("tRunJob_1", false);
            start_Hash.put("tRunJob_1", System.currentTimeMillis());
            currentComponent = "tRunJob_1";

            int tos_count_tRunJob_1 = 0;
            class DealChildJobLibrary_tRunJob_1 {

                public String replaceJarPathsFromCrcMap(String originalClassPathLine) throws Exception {
                    String classPathLine = "";
                    String crcMapPath = new java.io.File("../crcMap").getCanonicalPath();
                    if (isNeedAddLibsPath(crcMapPath)) {
                        java.util.Map<String, String> crcMap = null;
                        java.io.ObjectInputStream ois = new ObjectInputStream(
                                new java.io.FileInputStream(crcMapPath));
                        crcMap = (java.util.Map<String, String>) ois.readObject();
                        ois.close();
                        classPathLine = addLibsPath(originalClassPathLine, crcMap);
                    } else {
                        classPathLine = originalClassPathLine;
                    }
                    return classPathLine;
                }

                private boolean isNeedAddLibsPath(String crcMapPath) {
                    if (!(new java.io.File(crcMapPath).exists())) {// when
                        // not
                        // use
                        // cache
                        return false;
                    }
                    return true;
                }

                private String addLibsPath(String line, java.util.Map<String, String> crcMap) {
                    for (java.util.Map.Entry<String, String> entry : crcMap.entrySet()) {
                        line = adaptLibPaths(line, entry);
                    }
                    return line;
                }

                private String adaptLibPaths(String line, java.util.Map.Entry<String, String> entry) {
                    String jarName = entry.getValue();
                    String crc = entry.getKey();
                    String libStringFinder = "../lib/" + jarName;
                    if (line.contains(libStringFinder)) {
                        line = line.replace(libStringFinder, "../../../cache/lib/" + crc + "/" + jarName);
                    } else if (line.contains(":$ROOT_PATH/" + jarName + ":")) {
                        line = line.replace(":$ROOT_PATH/" + jarName + ":",
                                ":$ROOT_PATH/../../../cache/lib/" + crc + "/" + jarName + ":");
                    } else if (line.contains(";" + jarName + ";")) {
                        line = line.replace(";" + jarName + ";",
                                ";../../../cache/lib/" + crc + "/" + jarName + ";");
                    }
                    return line;
                }

            }
            DealChildJobLibrary_tRunJob_1 dealChildJobLibrary_tRunJob_1 = new DealChildJobLibrary_tRunJob_1();

            /**
             * [tRunJob_1 begin ] stop
             */
            /**
             * [tRunJob_1 main ] start
             */

            currentComponent = "tRunJob_1";

            java.util.List<String> paraList_tRunJob_1 = new java.util.ArrayList<String>();
            String osName_tRunJob_1 = System.getProperty("os.name");
            if (osName_tRunJob_1 != null && osName_tRunJob_1.toLowerCase().startsWith("win")) {

                paraList_tRunJob_1.add("java");

                paraList_tRunJob_1.add("-Xms256M");

                paraList_tRunJob_1.add("-Xmx1024M");

                paraList_tRunJob_1.add("-cp");

                paraList_tRunJob_1.add(dealChildJobLibrary_tRunJob_1.replaceJarPathsFromCrcMap(
                        "../lib/advancedPersistentLookupLib-1.0.jar;../lib/commons-codec-1.3.jar;../lib/commons-collections-3.2.jar;../lib/commons-httpclient-3.0.1.jar;../lib/commons-logging-1.1.jar;../lib/dom4j-1.6.1.jar;../lib/jboss-serialization.jar;../lib/jcifs-1.3.0.jar;../lib/log4j-1.2.15.jar;../lib/mysql-connector-java-5.1.22-bin.jar;../lib/TalendSAX.jar;../lib/trove.jar;../lib/systemRoutines.jar;../lib/userRoutines.jar;.;getpropfinacials_0_1.jar;getpropfinacials_0_1.jar;loadfinacialdata_0_1.jar;"));

                paraList_tRunJob_1.add("talonetl.getpropfinacials_0_1.getPropFinacials");

                paraList_tRunJob_1.add("--father_pid=" + pid);

                paraList_tRunJob_1.add("--root_pid=" + rootPid);

                paraList_tRunJob_1.add("--father_node=tRunJob_1");

                paraList_tRunJob_1.add("--context=Default");

                paraList_tRunJob_1.add("%*");

            } else {

                paraList_tRunJob_1.add("java");

                paraList_tRunJob_1.add("-Xms256M");

                paraList_tRunJob_1.add("-Xmx1024M");

                paraList_tRunJob_1.add("-cp");

                paraList_tRunJob_1.add(dealChildJobLibrary_tRunJob_1.replaceJarPathsFromCrcMap(
                        "$ROOT_PATH/../lib/advancedPersistentLookupLib-1.0.jar:$ROOT_PATH/../lib/commons-codec-1.3.jar:$ROOT_PATH/../lib/commons-collections-3.2.jar:$ROOT_PATH/../lib/commons-httpclient-3.0.1.jar:$ROOT_PATH/../lib/commons-logging-1.1.jar:$ROOT_PATH/../lib/dom4j-1.6.1.jar:$ROOT_PATH/../lib/jboss-serialization.jar:$ROOT_PATH/../lib/jcifs-1.3.0.jar:$ROOT_PATH/../lib/log4j-1.2.15.jar:$ROOT_PATH/../lib/mysql-connector-java-5.1.22-bin.jar:$ROOT_PATH/../lib/TalendSAX.jar:$ROOT_PATH/../lib/trove.jar:$ROOT_PATH:$ROOT_PATH/../lib/systemRoutines.jar:$ROOT_PATH/../lib/userRoutines.jar::.:$ROOT_PATH/getpropfinacials_0_1.jar:$ROOT_PATH/getpropfinacials_0_1.jar:$ROOT_PATH/loadfinacialdata_0_1.jar:")
                        .replace("$ROOT_PATH", System.getProperty("user.dir")));

                paraList_tRunJob_1.add("talonetl.getpropfinacials_0_1.getPropFinacials");

                paraList_tRunJob_1.add("--father_pid=" + pid);

                paraList_tRunJob_1.add("--root_pid=" + rootPid);

                paraList_tRunJob_1.add("--father_node=tRunJob_1");

                paraList_tRunJob_1.add("--context=Default");

                paraList_tRunJob_1.add("$@");

            }

            // for feature:10589
            paraList_tRunJob_1.add("--stat_port=" + null);

            if (resuming_logs_dir_path != null) {
                paraList_tRunJob_1.add("--resuming_logs_dir_path=" + resuming_logs_dir_path);
            }
            String childResumePath_tRunJob_1 = ResumeUtil.getChildJobCheckPointPath(resuming_checkpoint_path);
            String tRunJobName_tRunJob_1 = ResumeUtil.getRighttRunJob(resuming_checkpoint_path);
            if ("tRunJob_1".equals(tRunJobName_tRunJob_1) && childResumePath_tRunJob_1 != null) {
                paraList_tRunJob_1.add("--resuming_checkpoint_path="
                        + ResumeUtil.getChildJobCheckPointPath(resuming_checkpoint_path));
            }
            paraList_tRunJob_1.add("--parent_part_launcher=JOB:" + jobName + "/NODE:tRunJob_1");

            java.util.Map<String, Object> parentContextMap_tRunJob_1 = new java.util.HashMap<String, Object>();

            context.synchronizeContext();
            java.util.Enumeration<?> propertyNames_tRunJob_1 = context.propertyNames();
            while (propertyNames_tRunJob_1.hasMoreElements()) {
                String key_tRunJob_1 = (String) propertyNames_tRunJob_1.nextElement();
                Object value_tRunJob_1 = (Object) context.get(key_tRunJob_1);
                paraList_tRunJob_1.add("--context_param " + key_tRunJob_1 + "=" + value_tRunJob_1);
            }

            parentContextMap_tRunJob_1.put("propertySourceUri", context.propertySourceUri);
            parentContextMap_tRunJob_1.put("cusomterName", context.cusomterName);

            Object obj_tRunJob_1 = null;

            Runtime runtime_tRunJob_1 = Runtime.getRuntime();
            final Process ps_tRunJob_1;
            ps_tRunJob_1 = runtime_tRunJob_1
                    .exec((String[]) paraList_tRunJob_1.toArray(new String[paraList_tRunJob_1.size()]));

            Thread normal_tRunJob_1 = new Thread() {
                public void run() {
                    try {
                        java.io.BufferedReader reader = new java.io.BufferedReader(
                                new java.io.InputStreamReader(ps_tRunJob_1.getInputStream()));
                        String line = "";
                        try {
                            while ((line = reader.readLine()) != null) {
                                System.out.println(line);
                            }
                        } finally {
                            reader.close();
                        }
                    } catch (java.io.IOException ioe) {
                        ioe.printStackTrace();
                    }
                }
            };
            normal_tRunJob_1.start();

            final StringBuffer errorMsg_tRunJob_1 = new StringBuffer();
            Thread error_tRunJob_1 = new Thread() {
                public void run() {
                    try {
                        java.io.BufferedReader reader = new java.io.BufferedReader(
                                new java.io.InputStreamReader(ps_tRunJob_1.getErrorStream()));
                        String line = "";
                        try {
                            while ((line = reader.readLine()) != null) {
                                errorMsg_tRunJob_1.append(line).append("\n");
                            }
                        } finally {
                            reader.close();
                        }
                    } catch (java.io.IOException ioe) {
                        ioe.printStackTrace();
                    }
                }
            };
            error_tRunJob_1.start();

            // 0 indicates normal termination
            int result_tRunJob_1 = ps_tRunJob_1.waitFor();
            normal_tRunJob_1.join(10000);
            error_tRunJob_1.join(10000);

            globalMap.put("tRunJob_1_CHILD_RETURN_CODE", result_tRunJob_1);
            if (result_tRunJob_1 != 0) {
                globalMap.put("tRunJob_1_CHILD_EXCEPTION_STACKTRACE", errorMsg_tRunJob_1.toString());

                throw new RuntimeException("Child job return " + result_tRunJob_1
                        + ". It doesn't terminate normally.\n" + errorMsg_tRunJob_1.toString());

            }

            tos_count_tRunJob_1++;

            /**
             * [tRunJob_1 main ] stop
             */
            /**
             * [tRunJob_1 end ] start
             */

            currentComponent = "tRunJob_1";

            ok_Hash.put("tRunJob_1", true);
            end_Hash.put("tRunJob_1", System.currentTimeMillis());

            /**
             * [tRunJob_1 end ] stop
             */

        } // end the resume

    } catch (Exception e) {

        throw new TalendException(e, currentComponent, globalMap);

    } catch (java.lang.Error error) {

        throw new java.lang.Error(error);

    }

    globalMap.put("tRunJob_1_SUBPROCESS_STATE", 1);
}

From source file:talonetl.getproperties_0_3.getProperties.java

public void tRunJob_2Process(final java.util.Map<String, Object> globalMap) throws TalendException {
    globalMap.put("tRunJob_2_SUBPROCESS_STATE", 0);

    final boolean execStat = this.execStat;

    String iterateId = "";
    int iterateLoop = 0;
    String currentComponent = "";

    try {//from  w ww.  j  ava2  s  .  com

        String currentMethodName = new Exception().getStackTrace()[0].getMethodName();
        boolean resumeIt = currentMethodName.equals(resumeEntryMethodName);
        if (resumeEntryMethodName == null || resumeIt || globalResumeTicket) {// start
            // the
            // resume
            globalResumeTicket = true;

            /**
             * [tRunJob_2 begin ] start
             */

            ok_Hash.put("tRunJob_2", false);
            start_Hash.put("tRunJob_2", System.currentTimeMillis());
            currentComponent = "tRunJob_2";

            int tos_count_tRunJob_2 = 0;
            class DealChildJobLibrary_tRunJob_2 {

                public String replaceJarPathsFromCrcMap(String originalClassPathLine) throws Exception {
                    String classPathLine = "";
                    String crcMapPath = new java.io.File("../crcMap").getCanonicalPath();
                    if (isNeedAddLibsPath(crcMapPath)) {
                        java.util.Map<String, String> crcMap = null;
                        java.io.ObjectInputStream ois = new ObjectInputStream(
                                new java.io.FileInputStream(crcMapPath));
                        crcMap = (java.util.Map<String, String>) ois.readObject();
                        ois.close();
                        classPathLine = addLibsPath(originalClassPathLine, crcMap);
                    } else {
                        classPathLine = originalClassPathLine;
                    }
                    return classPathLine;
                }

                private boolean isNeedAddLibsPath(String crcMapPath) {
                    if (!(new java.io.File(crcMapPath).exists())) {// when
                        // not
                        // use
                        // cache
                        return false;
                    }
                    return true;
                }

                private String addLibsPath(String line, java.util.Map<String, String> crcMap) {
                    for (java.util.Map.Entry<String, String> entry : crcMap.entrySet()) {
                        line = adaptLibPaths(line, entry);
                    }
                    return line;
                }

                private String adaptLibPaths(String line, java.util.Map.Entry<String, String> entry) {
                    String jarName = entry.getValue();
                    String crc = entry.getKey();
                    String libStringFinder = "../lib/" + jarName;
                    if (line.contains(libStringFinder)) {
                        line = line.replace(libStringFinder, "../../../cache/lib/" + crc + "/" + jarName);
                    } else if (line.contains(":$ROOT_PATH/" + jarName + ":")) {
                        line = line.replace(":$ROOT_PATH/" + jarName + ":",
                                ":$ROOT_PATH/../../../cache/lib/" + crc + "/" + jarName + ":");
                    } else if (line.contains(";" + jarName + ";")) {
                        line = line.replace(";" + jarName + ";",
                                ";../../../cache/lib/" + crc + "/" + jarName + ";");
                    }
                    return line;
                }

            }
            DealChildJobLibrary_tRunJob_2 dealChildJobLibrary_tRunJob_2 = new DealChildJobLibrary_tRunJob_2();

            /**
             * [tRunJob_2 begin ] stop
             */
            /**
             * [tRunJob_2 main ] start
             */

            currentComponent = "tRunJob_2";

            java.util.List<String> paraList_tRunJob_2 = new java.util.ArrayList<String>();
            String osName_tRunJob_2 = System.getProperty("os.name");
            if (osName_tRunJob_2 != null && osName_tRunJob_2.toLowerCase().startsWith("win")) {

                paraList_tRunJob_2.add("java");

                paraList_tRunJob_2.add("-Xms256M");

                paraList_tRunJob_2.add("-Xmx1024M");

                paraList_tRunJob_2.add("-cp");

                paraList_tRunJob_2.add(dealChildJobLibrary_tRunJob_2.replaceJarPathsFromCrcMap(
                        "../lib/advancedPersistentLookupLib-1.0.jar;../lib/commons-codec-1.3.jar;../lib/commons-collections-3.2.jar;../lib/commons-httpclient-3.0.1.jar;../lib/commons-logging-1.1.jar;../lib/dom4j-1.6.1.jar;../lib/jboss-serialization.jar;../lib/jcifs-1.3.0.jar;../lib/log4j-1.2.15.jar;../lib/mysql-connector-java-5.1.22-bin.jar;../lib/TalendSAX.jar;../lib/trove.jar;../lib/systemRoutines.jar;../lib/userRoutines.jar;.;loadpropertyimages_0_1.jar;getpropfinacials_0_1.jar;loadfinacialdata_0_1.jar;loadpropertyimages_0_1.jar;"));

                paraList_tRunJob_2.add("talonetl.loadpropertyimages_0_1.loadPropertyImages");

                paraList_tRunJob_2.add("--father_pid=" + pid);

                paraList_tRunJob_2.add("--root_pid=" + rootPid);

                paraList_tRunJob_2.add("--father_node=tRunJob_2");

                paraList_tRunJob_2.add("--context=Default");

                paraList_tRunJob_2.add("%*");

            } else {

                paraList_tRunJob_2.add("java");

                paraList_tRunJob_2.add("-Xms256M");

                paraList_tRunJob_2.add("-Xmx1024M");

                paraList_tRunJob_2.add("-cp");

                paraList_tRunJob_2.add(dealChildJobLibrary_tRunJob_2.replaceJarPathsFromCrcMap(
                        "$ROOT_PATH/../lib/advancedPersistentLookupLib-1.0.jar:$ROOT_PATH/../lib/commons-codec-1.3.jar:$ROOT_PATH/../lib/commons-collections-3.2.jar:$ROOT_PATH/../lib/commons-httpclient-3.0.1.jar:$ROOT_PATH/../lib/commons-logging-1.1.jar:$ROOT_PATH/../lib/dom4j-1.6.1.jar:$ROOT_PATH/../lib/jboss-serialization.jar:$ROOT_PATH/../lib/jcifs-1.3.0.jar:$ROOT_PATH/../lib/log4j-1.2.15.jar:$ROOT_PATH/../lib/mysql-connector-java-5.1.22-bin.jar:$ROOT_PATH/../lib/TalendSAX.jar:$ROOT_PATH/../lib/trove.jar:$ROOT_PATH:$ROOT_PATH/../lib/systemRoutines.jar:$ROOT_PATH/../lib/userRoutines.jar::.:$ROOT_PATH/loadpropertyimages_0_1.jar:$ROOT_PATH/getpropfinacials_0_1.jar:$ROOT_PATH/loadfinacialdata_0_1.jar:$ROOT_PATH/loadpropertyimages_0_1.jar:")
                        .replace("$ROOT_PATH", System.getProperty("user.dir")));

                paraList_tRunJob_2.add("talonetl.loadpropertyimages_0_1.loadPropertyImages");

                paraList_tRunJob_2.add("--father_pid=" + pid);

                paraList_tRunJob_2.add("--root_pid=" + rootPid);

                paraList_tRunJob_2.add("--father_node=tRunJob_2");

                paraList_tRunJob_2.add("--context=Default");

                paraList_tRunJob_2.add("$@");

            }

            // for feature:10589
            paraList_tRunJob_2.add("--stat_port=" + null);

            if (resuming_logs_dir_path != null) {
                paraList_tRunJob_2.add("--resuming_logs_dir_path=" + resuming_logs_dir_path);
            }
            String childResumePath_tRunJob_2 = ResumeUtil.getChildJobCheckPointPath(resuming_checkpoint_path);
            String tRunJobName_tRunJob_2 = ResumeUtil.getRighttRunJob(resuming_checkpoint_path);
            if ("tRunJob_2".equals(tRunJobName_tRunJob_2) && childResumePath_tRunJob_2 != null) {
                paraList_tRunJob_2.add("--resuming_checkpoint_path="
                        + ResumeUtil.getChildJobCheckPointPath(resuming_checkpoint_path));
            }
            paraList_tRunJob_2.add("--parent_part_launcher=JOB:" + jobName + "/NODE:tRunJob_2");

            java.util.Map<String, Object> parentContextMap_tRunJob_2 = new java.util.HashMap<String, Object>();

            context.synchronizeContext();
            java.util.Enumeration<?> propertyNames_tRunJob_2 = context.propertyNames();
            while (propertyNames_tRunJob_2.hasMoreElements()) {
                String key_tRunJob_2 = (String) propertyNames_tRunJob_2.nextElement();
                Object value_tRunJob_2 = (Object) context.get(key_tRunJob_2);
                paraList_tRunJob_2.add("--context_param " + key_tRunJob_2 + "=" + value_tRunJob_2);
            }

            parentContextMap_tRunJob_2.put("propertySourceUri", context.propertySourceUri);
            parentContextMap_tRunJob_2.put("cusomterName", context.cusomterName);

            Object obj_tRunJob_2 = null;

            obj_tRunJob_2 = context.propertySourceUri;
            paraList_tRunJob_2.add(
                    "--context_param propertySourceUri=" + RuntimeUtils.tRunJobConvertContext(obj_tRunJob_2));
            parentContextMap_tRunJob_2.put("propertySourceUri", obj_tRunJob_2);
            Runtime runtime_tRunJob_2 = Runtime.getRuntime();
            final Process ps_tRunJob_2;
            ps_tRunJob_2 = runtime_tRunJob_2
                    .exec((String[]) paraList_tRunJob_2.toArray(new String[paraList_tRunJob_2.size()]));

            Thread normal_tRunJob_2 = new Thread() {
                public void run() {
                    try {
                        java.io.BufferedReader reader = new java.io.BufferedReader(
                                new java.io.InputStreamReader(ps_tRunJob_2.getInputStream()));
                        String line = "";
                        try {
                            while ((line = reader.readLine()) != null) {
                                System.out.println(line);
                            }
                        } finally {
                            reader.close();
                        }
                    } catch (java.io.IOException ioe) {
                        ioe.printStackTrace();
                    }
                }
            };
            normal_tRunJob_2.start();

            final StringBuffer errorMsg_tRunJob_2 = new StringBuffer();
            Thread error_tRunJob_2 = new Thread() {
                public void run() {
                    try {
                        java.io.BufferedReader reader = new java.io.BufferedReader(
                                new java.io.InputStreamReader(ps_tRunJob_2.getErrorStream()));
                        String line = "";
                        try {
                            while ((line = reader.readLine()) != null) {
                                errorMsg_tRunJob_2.append(line).append("\n");
                            }
                        } finally {
                            reader.close();
                        }
                    } catch (java.io.IOException ioe) {
                        ioe.printStackTrace();
                    }
                }
            };
            error_tRunJob_2.start();

            // 0 indicates normal termination
            int result_tRunJob_2 = ps_tRunJob_2.waitFor();
            normal_tRunJob_2.join(10000);
            error_tRunJob_2.join(10000);

            globalMap.put("tRunJob_2_CHILD_RETURN_CODE", result_tRunJob_2);
            if (result_tRunJob_2 != 0) {
                globalMap.put("tRunJob_2_CHILD_EXCEPTION_STACKTRACE", errorMsg_tRunJob_2.toString());

                throw new RuntimeException("Child job return " + result_tRunJob_2
                        + ". It doesn't terminate normally.\n" + errorMsg_tRunJob_2.toString());

            }

            tos_count_tRunJob_2++;

            /**
             * [tRunJob_2 main ] stop
             */
            /**
             * [tRunJob_2 end ] start
             */

            currentComponent = "tRunJob_2";

            ok_Hash.put("tRunJob_2", true);
            end_Hash.put("tRunJob_2", System.currentTimeMillis());

            /**
             * [tRunJob_2 end ] stop
             */

        } // end the resume

    } catch (Exception e) {

        throw new TalendException(e, currentComponent, globalMap);

    } catch (java.lang.Error error) {

        throw new java.lang.Error(error);

    }

    globalMap.put("tRunJob_2_SUBPROCESS_STATE", 1);
}