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.pentaho.di.trans.steps.ivwloader.IngresVectorwiseLoader.java

public boolean execute(IngresVectorwiseLoaderMeta meta) throws KettleException {
    Runtime rt = Runtime.getRuntime();

    try {/*from   w ww.  j  av  a2  s. c  om*/
        // 1) Create the FIFO file using the "mkfifo" command...
        // Make sure to log all the possible output, also from STDERR
        //
        data.fifoFilename = environmentSubstitute(meta.getFifoFileName());

        File fifoFile = new File(data.fifoFilename);
        if (!fifoFile.exists()) {
            // MKFIFO!
            //
            String mkFifoCmd = "mkfifo -m 666 [" + data.fifoFilename + "]";
            String[] args = new String[] { "mkfifo", "-m", "666", data.fifoFilename }; // handle spaces and permissions all
                                                                                       // at once.
            logDetailed("Creating FIFO file using this command : " + mkFifoCmd);
            Process mkFifoProcess = rt.exec(args);
            StreamLogger errorLogger = new StreamLogger(log, mkFifoProcess.getErrorStream(), "mkFifoError");
            StreamLogger outputLogger = new StreamLogger(log, mkFifoProcess.getInputStream(), "mkFifoOuptut");
            new Thread(errorLogger).start();
            new Thread(outputLogger).start();
            int result = mkFifoProcess.waitFor();
            if (result != 0) {
                throw new Exception("Return code " + result + " received from statement : " + mkFifoCmd);
            }

            // String chmodCmd = "chmod 666 " + data.fifoFilename;
            // logDetailed("Setting FIFO file permissings using this command : " + chmodCmd);
            // Process chmodProcess = rt.exec(chmodCmd);
            // errorLogger = new StreamLogger(log, chmodProcess.getErrorStream(), "chmodError");
            // outputLogger = new StreamLogger(log, chmodProcess.getInputStream(), "chmodOuptut");
            // new Thread(errorLogger).start();
            // new Thread(outputLogger).start();
            // result = chmodProcess.waitFor();
            // if (result != 0) {
            // throw new Exception("Return code " + result + " received from statement : " + chmodCmd);
            // }
        }

        // 2) Execute the Ingres "sql" command...
        //

        String cmd = createCommandLine(meta);

        try {
            // masquerading the password for log
            if (meta.isUseDynamicVNode()) {
                logDetailed("Executing command: " + cmd.substring(0, cmd.indexOf("[")) + "[username,password]"
                        + cmd.substring(cmd.indexOf("]") + 1));
            } else {
                logDetailed("Executing command: " + cmd);
            }
            data.sqlProcess = rt.exec(cmd);

            // any error message?
            //
            data.errorLogger = new StreamLogger(log, data.sqlProcess.getErrorStream(), "ERR_SQL", true);

            // any output?
            data.outputLogger = new StreamLogger(log, data.sqlProcess.getInputStream(), "OUT_SQL");

            // Where do we send the data to? --> To STDIN of the sql process
            //
            data.sqlOutputStream = data.sqlProcess.getOutputStream();

            // kick them off
            new Thread(data.errorLogger).start();
            Thread outputLoggerThread = new Thread(data.outputLogger);
            outputLoggerThread.start();

            vwLoadMonitor = new VWloadMonitor(data.sqlProcess, data.outputLogger, outputLoggerThread);
            vwLoadMonitorThread = new Thread(vwLoadMonitor);
            vwLoadMonitorThread.start();

        } catch (Exception ex) {
            throw new KettleException("Error while executing psql : " + cmd, ex);
        }

        logDetailed("Connected to VectorWise with the 'sql' command.");

        // OK, from here on, we need to feed in the COPY command followed by the
        // data into the pgOutputStream
        //
        String loadCommand = createLoadCommand();
        logDetailed("Executing command: " + loadCommand);
        data.sqlRunner = new SqlRunner(data, loadCommand);
        data.sqlRunner.start();

        logDetailed("LOAD TABLE command started");

        // Open a new fifo output stream, buffered.
        //
        openFifoFile();

        logDetailed("Fifo stream opened");

        // Wait until it all hooks up in the FIFO
        //
        waitForAConnection();

        logDetailed("Ready to start bulk loading!");
    } catch (Exception ex) {
        throw new KettleException(ex);
    }

    return true;
}

From source file:com.bibisco.servlet.BibiscoServlet.java

public void openUrlExternalBrowser(HttpServletRequest pRequest, HttpServletResponse pResponse)
        throws IOException {
    mLog.debug("Start openUrlExternalBrowser(HttpServletRequest, HttpServletResponse)");

    String lStrUrl = pRequest.getParameter("url");
    mLog.debug("url= ", lStrUrl);

    if (Desktop.isDesktopSupported()) {
        Desktop desktop = Desktop.getDesktop();
        try {/*from  w  w  w.  ja v  a2s  . c o  m*/
            desktop.browse(new URI(lStrUrl));
        } catch (Exception e) {
            mLog.error(e);
            throw new BibiscoException(e, BibiscoException.IO_EXCEPTION);
        }
    } else {
        Runtime runtime = Runtime.getRuntime();
        try {
            runtime.exec("xdg-open " + lStrUrl);
        } catch (Exception e) {
            mLog.error(e);
            throw new BibiscoException(e, BibiscoException.IO_EXCEPTION);
        }
    }

    pResponse.setContentType("text/html; charset=UTF-8");
    Writer lWriter = pResponse.getWriter();
    lWriter.write("ok");

    mLog.debug("End openUrlExternalBrowser(HttpServletRequest, HttpServletResponse)");
}

From source file:org.pentaho.di.trans.steps.luciddbbulkloader.LucidDBBulkLoader.java

public boolean execute(LucidDBBulkLoaderMeta meta, boolean wait) throws KettleException {
    Runtime rt = Runtime.getRuntime();

    try {/*from ww w . j a v a  2 s .  com*/
        String tableName = environmentSubstitute(meta.getTableName());

        // 1) Set up the FIFO folder, create the directory and path to it...
        //
        String fifoVfsDirectory = environmentSubstitute(meta.getFifoDirectory());
        FileObject directory = KettleVFS.getFileObject(fifoVfsDirectory, getTransMeta());
        directory.createFolder();
        String fifoDirectory = KettleVFS.getFilename(directory);

        // 2) Create the FIFO file using the "mkfifo" command...
        // Make sure to log all the possible output, also from STDERR
        //
        data.fifoFilename = KettleVFS.getFilename(directory) + Const.FILE_SEPARATOR + tableName + ".csv";
        data.bcpFilename = KettleVFS.getFilename(directory) + Const.FILE_SEPARATOR + tableName + ".bcp";

        File fifoFile = new File(data.fifoFilename);
        if (!fifoFile.exists()) {
            String mkFifoCmd = "mkfifo " + data.fifoFilename + "";
            logBasic("Creating FIFO file using this command : " + mkFifoCmd);
            Process mkFifoProcess = rt.exec(mkFifoCmd);
            StreamLogger errorLogger = new StreamLogger(log, mkFifoProcess.getErrorStream(), "mkFifoError");
            StreamLogger outputLogger = new StreamLogger(log, mkFifoProcess.getInputStream(), "mkFifoOuptut");
            new Thread(errorLogger).start();
            new Thread(outputLogger).start();
            int result = mkFifoProcess.waitFor();
            if (result != 0) {
                throw new Exception("Return code " + result + " received from statement : " + mkFifoCmd);
            }
        }

        // 3) Make a connection to LucidDB for sending SQL commands
        // (Also, we need a clear cache for getting up-to-date target metadata)
        DBCache.getInstance().clear(meta.getDatabaseMeta().getName());
        if (meta.getDatabaseMeta() == null) {
            logError(BaseMessages.getString(PKG, "LuciDBBulkLoader.Init.ConnectionMissing", getStepname()));
            return false;
        }
        data.db = new Database(this, meta.getDatabaseMeta());
        data.db.shareVariablesWith(this);
        // Connect to the database
        if (getTransMeta().isUsingUniqueConnections()) {
            synchronized (getTrans()) {
                data.db.connect(getTrans().getTransactionId(), getPartitionID());
            }
        } else {
            data.db.connect(getPartitionID());
        }

        logBasic("Connected to LucidDB");

        // 4) Now we are ready to create the LucidDB FIFO server that will handle the actual bulk loading.
        //
        String fifoServerStatement = "";
        fifoServerStatement += "create or replace server " + meta.getFifoServerName() + Const.CR;
        fifoServerStatement += "foreign data wrapper sys_file_wrapper" + Const.CR;
        fifoServerStatement += "options (" + Const.CR;
        fifoServerStatement += "directory '" + fifoDirectory + "'," + Const.CR;
        fifoServerStatement += "file_extension 'csv'," + Const.CR;
        fifoServerStatement += "with_header 'no'," + Const.CR;
        fifoServerStatement += "num_rows_scan '0'," + Const.CR;
        fifoServerStatement += "lenient 'no');" + Const.CR;

        logBasic("Creating LucidDB fifo_server with the following command: " + fifoServerStatement);
        data.db.execStatements(fifoServerStatement);

        // 5) Set the error limit in the LucidDB session
        // REVIEW jvs 13-Dec-2008: is this guaranteed to retain the same
        // connection?
        String errorMaxStatement = "";
        errorMaxStatement += "alter session set \"errorMax\" = " + meta.getMaxErrors() + ";" + Const.CR;
        logBasic("Setting error limit in LucidDB session with the following command: " + errorMaxStatement);
        data.db.execStatements(errorMaxStatement);

        // 6) Now we also need to create a bulk loader file .bcp
        //
        createBulkLoadConfigFile(data.bcpFilename);

        // 7) execute the actual load command!
        // This will actually block until the load is done in the
        // separate execution thread; see notes in executeLoadCommand
        // on why it's important for this to occur BEFORE
        // opening our end of the FIFO.
        //
        executeLoadCommand(tableName);

        // 8) We have to write rows to the FIFO file later on.
        data.fifoStream = new BufferedOutputStream(new FileOutputStream(fifoFile));
    } catch (Exception ex) {
        throw new KettleException(ex);
    }

    return true;
}

From source file:org.klco.email2html.OutputWriter.java

/**
 * Writes the attachment contained in the body part to a file.
 * //from   w  w w  .j  a  v a 2  s  .com
 * @param containingMessage
 *            the message this body part is contained within
 * @param part
 *            the part containing the attachment
 * @return the file that was created/written to
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 * @throws MessagingException
 *             the messaging exception
 */
public boolean writeAttachment(EmailMessage containingMessage, Part part)
        throws IOException, MessagingException {
    log.trace("writeAttachment");

    File attachmentFolder;
    File attachmentFile;
    InputStream in = null;
    OutputStream out = null;
    try {

        attachmentFolder = new File(outputDir.getAbsolutePath() + File.separator + config.getImagesSubDir()
                + File.separator + FILE_DATE_FORMAT.format(containingMessage.getSentDate()));
        if (!attachmentFolder.exists()) {
            log.debug("Creating attachment folder");
            attachmentFolder.mkdirs();
        }

        attachmentFile = new File(attachmentFolder, part.getFileName());
        log.debug("Writing attachment file: {}", attachmentFile.getAbsolutePath());
        if (!attachmentFile.exists()) {
            attachmentFile.createNewFile();
        }

        in = new BufferedInputStream(part.getInputStream());
        out = new BufferedOutputStream(new FileOutputStream(attachmentFile));

        log.debug("Downloading attachment");
        CRC32 checksum = new CRC32();
        for (int b = in.read(); b != -1; b = in.read()) {
            checksum.update(b);
            out.write(b);
        }

        if (this.excludeDuplicates) {
            log.debug("Computing checksum");
            long value = checksum.getValue();
            if (this.attachmentChecksums.contains(value)) {
                log.info("Skipping duplicate attachment: {}", part.getFileName());
                attachmentFile.delete();
                return false;
            } else {
                attachmentChecksums.add(value);
            }
        }

        log.debug("Attachement saved");
    } finally {
        IOUtils.closeQuietly(out);
        IOUtils.closeQuietly(in);
    }

    if (part.getContentType().toLowerCase().startsWith("image")) {
        log.debug("Creating renditions");
        String contentType = part.getContentType().substring(0, part.getContentType().indexOf(";"));
        log.debug("Creating renditions of type: " + contentType);

        for (Rendition rendition : renditions) {
            File renditionFile = new File(attachmentFolder, rendition.getName() + "-" + part.getFileName());
            try {
                if (!renditionFile.exists()) {
                    renditionFile.createNewFile();
                }
                log.debug("Creating rendition file: {}", renditionFile.getAbsolutePath());
                createRendition(attachmentFile, renditionFile, rendition);
                log.debug("Rendition created");
            } catch (OutOfMemoryError oome) {
                Runtime rt = Runtime.getRuntime();
                rt.gc();
                log.warn("Ran out of memory creating rendition: " + rendition, oome);

                log.warn("Free Memory: {}", rt.freeMemory());
                log.warn("Max Memory: {}", rt.maxMemory());
                log.warn("Total Memory: {}", rt.totalMemory());

                String[] command = null;
                if (rendition.getFill()) {
                    command = new String[] { "convert", attachmentFile.getAbsolutePath(), "-resize",
                            (rendition.getHeight() * 2) + "x", "-resize",
                            "'x" + (rendition.getHeight() * 2) + "<'", "-resize", "50%", "-gravity", "center",
                            "-crop", rendition.getHeight() + "x" + rendition.getWidth() + "+0+0", "+repage",
                            renditionFile.getAbsolutePath() };
                } else {
                    command = new String[] { "convert", attachmentFile.getAbsolutePath(), "-resize",
                            rendition.getHeight() + "x" + rendition.getWidth(),
                            renditionFile.getAbsolutePath() };

                }
                log.debug("Trying to resize with ImageMagick: " + StringUtils.join(command, " "));

                rt.exec(command);
            } catch (Exception t) {
                log.warn("Exception creating rendition: " + rendition, t);
            }
        }
    }
    return true;
}

From source file:com.flexive.shared.FxSharedUtils.java

/**
 * Execute a command on the operating system
 *
 * @param command   name of the command//from  w ww.  j  a va2  s  .  c  o m
 * @param arguments arguments to pass to the command (one argument per String!)
 * @return result
 */

public static ProcessResult executeCommand(String command, String... arguments) {
    Runtime r = Runtime.getRuntime();
    String[] cmd = new String[arguments.length + (WINDOWS ? 3 : 1)];
    if (WINDOWS) {
        //have to run a shell on windows
        cmd[0] = "cmd";
        cmd[1] = "/c";
    }

    cmd[WINDOWS ? 2 : 0] = command;
    System.arraycopy(arguments, 0, cmd, (WINDOWS ? 3 : 1), arguments.length);
    StringBuilder cmdline = new StringBuilder(200);
    cmdline.append(command);
    for (String argument : arguments)
        cmdline.append(" ").append(argument);
    Process p = null;
    AsyncStreamBuffer out = null;
    AsyncStreamBuffer err = null;
    try {
        p = r.exec(cmd);
        //            p = r.exec(cmdline);
        out = new AsyncStreamBuffer(p.getInputStream());
        err = new AsyncStreamBuffer(p.getErrorStream());
        out.start();
        err.start();
        p.waitFor();
        while (out.isAlive())
            Thread.sleep(10);
        while (err.isAlive())
            Thread.sleep(10);
    } catch (Exception e) {
        String error = e.getMessage();
        if (err != null && err.getResult() != null && err.getResult().trim().length() > 0)
            error = error + "(" + err.getResult() + ")";
        return new ProcessResult(cmdline.toString(), (p == null ? -1 : p.exitValue()),
                (out == null ? "" : out.getResult()), error);
    } finally {
        if (p != null) {
            try {
                p.getInputStream().close();
            } catch (Exception e1) {
                //bad luck
            }
            try {
                p.getErrorStream().close();
            } catch (Exception e1) {
                //bad luck
            }
            try {
                p.getOutputStream().close();
            } catch (Exception e1) {
                //bad luck
            }
        }
    }
    return new ProcessResult(cmdline.toString(), p.exitValue(), out.getResult(), err.getResult());
}

From source file:com.ah.be.common.NmsUtil.java

/**
 * <p>//from  www.j  av a2 s.  c  o m
 * Check if the port specified is occupied by some certain process/socket in
 * the current system.
 * </p>
 *
 * @param port
 *            the number of port to be checked for.
 * @return <tt>true</tt> if the port given is occupied by a certain
 *         process/socket, <tt>false</tt> otherwise.
 * @throws IOException If an I/O error occurs.
 * @throws InterruptedException if the current thread is interrupted by another thread while it is waiting for the result.
 */
public static boolean checkPortOccupancy(int port) throws IOException, InterruptedException {
    boolean occupied = false;
    String cmdForWindows = "netstat -ano|findstr \":" + port + "\\>\"";
    String cmdForLinux = "netstat -anp|grep \":" + port + " \"";
    String os = System.getProperty("os.name");
    String[] cmdArray = os.toLowerCase().contains("windows") ? new String[] { "cmd.exe", "/C", cmdForWindows }
            : new String[] { "bash", "-c", cmdForLinux };
    Runtime runtime = Runtime.getRuntime();
    Process proc = null;
    BufferedReader reader = null;
    log.info("checkPortOccupancy",
            "Executing netstat cmd: " + cmdArray[0] + " " + cmdArray[1] + " " + cmdArray[2]);

    try {
        proc = runtime.exec(cmdArray);
        int exitValue = proc.waitFor();
        log.info("checkPortOccupancy",
                "Netstat cmd was executed and exit value related to the process was " + exitValue);

        if (exitValue == 0) {
            InputStream input = proc.getInputStream();

            if (input != null) {
                reader = new BufferedReader(new InputStreamReader(input));
                String readLine = reader.readLine();
                occupied = readLine != null;
            }
        }
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException ioe) {
                log.error("checkPortOccupancy", "I/O Error in closing BufferedReader", ioe);
            }
        }

        if (proc != null) {
            proc.destroy();
        }
    }

    return occupied;
}

From source file:com.ah.be.common.NmsUtil.java

public static List<Integer> checkUsingPorts() throws IOException {
    String cmdForWindows = "netstat -ano";
    String cmdForLinux = "netstat -anp";
    String os = System.getProperty("os.name");
    String[] cmdArray = os.toLowerCase().contains("windows") ? new String[] { "cmd.exe", "/C", cmdForWindows }
            : new String[] { "bash", "-c", cmdForLinux };
    Runtime runtime = Runtime.getRuntime();
    Process proc = null;//  w  w w  .  j ava  2  s.  com
    BufferedReader reader = null;
    log.info("checkUsingPorts",
            "Executing netstat cmd: " + cmdArray[0] + " " + cmdArray[1] + " " + cmdArray[2]);

    try {
        proc = runtime.exec(cmdArray);
        InputStream in = proc.getInputStream();

        if (in == null) {
            throw new IOException("Could not get the input stream from Process when executing " + cmdArray[0]
                    + " " + cmdArray[1] + " " + cmdArray[2]);
        }

        reader = new BufferedReader(new InputStreamReader(in));
        List<Integer> usingPorts = new ArrayList<Integer>();
        String rawLine;

        while ((rawLine = reader.readLine()) != null) {
            rawLine = rawLine.trim().toUpperCase();

            if (rawLine.startsWith("TCP") || rawLine.startsWith("UDP")) {
                for (StringTokenizer token = new StringTokenizer(rawLine, " "); token.hasMoreTokens();) {
                    String field = token.nextToken();

                    // The string token firstly containing the character of ":" is the "Local Address"
                    // field and the sub-string behind the last ":" is the port number being used.
                    int lastColonIndex = field.lastIndexOf(":");

                    if (lastColonIndex != -1) {
                        String strPort = null;

                        try {
                            strPort = field.substring(lastColonIndex + 1);
                            int usingPort = Integer.parseInt(strPort);

                            if (!usingPorts.contains(usingPort)) {
                                usingPorts.add(usingPort);
                            }
                        } catch (NumberFormatException nfe) {
                            log.error("checkUsingPorts", strPort + " is not a numeric.", nfe);
                        }

                        break;
                    }
                }
            }
        }

        Collections.sort(usingPorts);

        return usingPorts;
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException ioe) {
                log.error("checkUsingPorts", "I/O Error in closing BufferedReader", ioe);
            }
        }

        if (proc != null) {
            proc.destroy();
        }
    }
}

From source file:es.bsc.servicess.ide.PackagingUtils.java

private static void preInstrumentOrchestration(String runtime, String orchClass, List<String> methods,
        IFolder classes, List<Dependency> depLibraries, IProgressMonitor myProgressMonitor)
        throws CoreException {
    Runtime rt = Runtime.getRuntime();
    if (runtime != null && orchClass != null && methods != null && methods.size() > 0) {
        String classpath = new String();
        for (Dependency d : depLibraries) {
            if (d.getType().equalsIgnoreCase(ProjectMetadata.JAR_DEP_TYPE)
                    || d.getType().equalsIgnoreCase(ProjectMetadata.CLASS_FOLDER_DEP_TYPE))
                classpath = classpath.concat(":" + d.getLocation());
        }//from  w  w  w . j  a  va  2s.  c o  m
        boolean first = true;
        String methodsString = new String();
        for (String m : methods) {
            if (first) {
                methodsString = methodsString.concat(m);
                first = false;
            } else
                methodsString = methodsString.concat(" " + m);
        }
        String command = new String(runtime + "/../scripts/pre_instrument.sh "
                + classes.getLocation().toOSString() + classpath + " " + runtime + "/.." + " "
                + classes.getLocation().toOSString() + " " + orchClass + " " + methodsString);
        log.debug("Command to exec: " + command);
        Process ps;
        try {
            ps = rt.exec(command);
            BufferedReader stdInput = new BufferedReader(new InputStreamReader(ps.getInputStream()));

            BufferedReader stdError = new BufferedReader(new InputStreamReader(ps.getErrorStream()));
            String s = null;
            // read the output from the command
            log.debug("Here is the standard output of the command:\n");
            while ((s = stdInput.readLine()) != null) {
                log.debug(s);
            }

            // read any errors from the attempted command
            log.debug("Here is the standard error of the command (if any):\n");
            while ((s = stdError.readLine()) != null) {
                log.debug(s);
            }

            // if (ps.exitValue() != 0){
            if (ps.waitFor() != 0) {
                throw (new CoreException(
                        new Status(IStatus.ERROR, Activator.PLUGIN_ID, "metadata info not found")));
            }
        } catch (IOException e) {
            CoreException ce = new CoreException(
                    new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
            ce.setStackTrace(e.getStackTrace());
            throw (ce);
        } catch (InterruptedException e) {
            CoreException ce = new CoreException(
                    new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
            ce.setStackTrace(e.getStackTrace());
            throw (ce);
        }
    } else {
        throw (new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "metadata info not found")));
    }
}

From source file:org.kisti.edison.science.service.impl.ScienceAppLocalServiceImpl.java

/****
 * Execute a given command//from w w w  .j av  a  2 s  . c  o  m
 * @param command a given command
 * @return install message
 * @throws IOException 
 * @throws InterruptedException 
 */
private void executeCommand(String command) throws SystemException, IOException, InterruptedException {
    String[] commandAndArgs = new String[] { "/bin/sh", "-c", command };
    //System.out.println(commandAndArgs);
    // Get Runtime instance.
    String report = "";
    Runtime runTime = Runtime.getRuntime();
    // Declare a process.
    Process process = null;
    // Let's execute the command.
    process = runTime.exec(commandAndArgs);
    // Get any input stream.
    InputStream instd = process.getInputStream();
    // Let's get it through buffered reader.
    BufferedReader buf_reader = new BufferedReader(new InputStreamReader(instd));
    String temp = "";
    // System.out.println("new line executed command: " + command);
    while ((temp = buf_reader.readLine()) != null) {
        // System.out.println("temp: " + temp);
        report += temp + "\n";
    }
    // Let's close buffered reader
    buf_reader.close();

    // Get any error stream.
    InputStream stderr = process.getErrorStream();
    // Let's get it through buffered reader.
    BufferedReader buf_err_reader = new BufferedReader(new InputStreamReader(stderr));
    // Initialize a temporary variable.
    temp = "";
    // Until there's no more error message,
    while ((temp = buf_err_reader.readLine()) != null) {
        // Append a current error message to the error message
        // container.
        report += temp + "\n";
    }
    // Close buffered error reader.
    buf_err_reader.close();
    // Let's wait p0 for completion.
    process.waitFor();
}

From source file:ch.kostceco.tools.kostval.validation.modulejp2.impl.ValidationAvalidationAModuleImpl.java

@Override
public boolean validate(File valDatei, File directoryOfLogfile) throws ValidationAjp2validationException {

    // Start mit der Erkennung

    // Eine JP2 Datei (.jp2) muss mit ....jP ...ftypjp2
    // [0000000c6a5020200d0a870a] beginnen
    if (valDatei.isDirectory()) {
        getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2)
                + getTextResourceService().getText(ERROR_XML_A_JP2_ISDIRECTORY));
        return false;
    } else if ((valDatei.getAbsolutePath().toLowerCase().endsWith(".jp2"))) {

        FileReader fr = null;/*w  w w  . j a  va  2s  .c o m*/

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

            // wobei hier nur die ersten 10 Zeichen der Datei ausgelesen werden
            // 1 00 010203
            // 2 0c 04
            // 3 6a 05
            // 4 50 06
            // 5 20 0708
            // 6 0d 09
            // 7 0a 10

            // Hex 00 in Char umwandeln
            String str1 = "00";
            int i1 = Integer.parseInt(str1, 16);
            char c1 = (char) i1;
            // Hex 0c in Char umwandeln
            String str2 = "0c";
            int i2 = Integer.parseInt(str2, 16);
            char c2 = (char) i2;
            // Hex 6a in Char umwandeln
            String str3 = "6a";
            int i3 = Integer.parseInt(str3, 16);
            char c3 = (char) i3;
            // Hex 50 in Char umwandeln
            String str4 = "50";
            int i4 = Integer.parseInt(str4, 16);
            char c4 = (char) i4;
            // Hex 20 in Char umwandeln
            String str5 = "20";
            int i5 = Integer.parseInt(str5, 16);
            char c5 = (char) i5;
            // Hex 0d in Char umwandeln
            String str6 = "0d";
            int i6 = Integer.parseInt(str6, 16);
            char c6 = (char) i6;
            // Hex 0a in Char umwandeln
            String str7 = "0a";
            int i7 = Integer.parseInt(str7, 16);
            char c7 = (char) i7;

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

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

            if (Arrays.equals(charArray1, charArray2)) {
                /* hchstwahrscheinlich ein JP2 da es mit 0000000c6a5020200d0a respektive ....jP ..
                 * beginnt */
            } else {
                // TODO: Droid-Erkennung, damit Details ausgegeben werden knnen
                String nameOfSignature = getConfigurationService().getPathToDroidSignatureFile();
                if (nameOfSignature == null) {
                    getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2)
                            + 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_JP2)
                            + 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_JP2)
                            + 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_JP2)
                        + getTextResourceService().getText(ERROR_XML_A_JP2_INCORRECTFILE, puid));
                return false;
            }
        } catch (Exception e) {
            getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2)
                    + getTextResourceService().getText(ERROR_XML_A_JP2_INCORRECTFILE));
            return false;
        }
    } else {
        // die Datei endet nicht mit jp2 -> Fehler
        getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2)
                + getTextResourceService().getText(ERROR_XML_A_JP2_INCORRECTFILEENDING));
        return false;
    }
    // Ende der Erkennung

    boolean isValid = false;

    // TODO: Erledigt - Initialisierung Jpylyzer -> existiert Jpylyzer?
    String pathToJpylyzerExe = "resources" + File.separator + "jpylyzer" + File.separator + "jpylyzer.exe";

    File fJpylyzerExe = new File(pathToJpylyzerExe);
    if (!fJpylyzerExe.exists()) {
        getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2)
                + getTextResourceService().getText(ERROR_XML_A_JP2_JPYLYZER_MISSING));
    }

    pathToJpylyzerExe = "\"" + pathToJpylyzerExe + "\"";

    try {
        File report;
        Document doc = null;

        try {
            // jpylyzer-Befehl: pathToJpylyzerExe valDatei > valDatei.jpylyzer-log.xml
            String outputPath = directoryOfLogfile.getAbsolutePath();
            String outputName = File.separator + valDatei.getName() + ".jpylyzer-log.xml";
            String pathToJpylyzerReport = outputPath + outputName;
            File output = new File(pathToJpylyzerReport);
            Runtime rt = Runtime.getRuntime();
            Process proc = null;

            try {
                report = output;

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

                /* Das redirect Zeichen verunmglicht eine direkte eingabe. mit dem geschachtellten Befehl
                 * gehts: cmd /c\"urspruenlicher Befehl\" */
                String command = "cmd /c \"" + pathToJpylyzerExe + " \"" + valDatei.getAbsolutePath()
                        + "\" > \"" + output.getAbsolutePath() + "\"\"";
                proc = rt.exec(command.toString().split(" "));
                // .split(" ") ist notwendig wenn in einem Pfad ein Doppelleerschlag vorhanden ist!

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

            } catch (Exception e) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2)
                        + getTextResourceService().getText(ERROR_XML_A_JP2_SERVICEFAILED, e.getMessage()));
                return false;
            } finally {
                if (proc != null) {
                    closeQuietly(proc.getOutputStream());
                    closeQuietly(proc.getInputStream());
                    closeQuietly(proc.getErrorStream());
                }
            }
            if (report.exists()) {
                // alles io
            } else {
                // Datei nicht angelegt...
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2)
                        + getTextResourceService().getText(ERROR_XML_A_JP2_NOREPORT));
                return false;
            }

            // Ende Jpylyzer direkt auszulsen

            // TODO: Erledigt - Ergebnis auslesen

            BufferedInputStream bis = new BufferedInputStream(new FileInputStream(pathToJpylyzerReport));
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            doc = db.parse(bis);
            doc.normalize();

            NodeList nodeLstI = doc.getElementsByTagName("isValidJP2");

            // Node isValidJP2 enthlt im TextNode das Resultat TextNode ist ein ChildNode
            for (int s = 0; s < nodeLstI.getLength(); s++) {
                Node resultNode = nodeLstI.item(s);
                StringBuffer buf = new StringBuffer();
                NodeList children = resultNode.getChildNodes();
                for (int i = 0; i < children.getLength(); i++) {
                    Node textChild = children.item(i);
                    if (textChild.getNodeType() != Node.TEXT_NODE) {
                        continue;
                    }
                    buf.append(textChild.getNodeValue());
                }
                String result = buf.toString();

                // Das Resultat ist False oder True
                if (result.equalsIgnoreCase("True")) {
                    // valid
                    isValid = true;
                } else {
                    // invalide
                    getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2)
                            + getTextResourceService().getText(ERROR_XML_A_JP2_JPYLYZER_FAIL));
                    isValid = false;
                }
            }

        } catch (Exception e) {
            getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2)
                    + getTextResourceService().getText(ERROR_XML_UNKNOWN, e.getMessage()));
            return false;
        }
        // TODO: Erledigt: Fehler Auswertung

        if (!isValid) {
            // Invalide JP2-Datei
            int isignatureBox = 0;
            int ifileTypeBox = 0;
            int iimageHeaderBox = 0;
            int ibitsPerComponentBox = 0;
            int icolourSpecificationBox = 0;
            int ipaletteBox = 0;
            int icomponentMappingBox = 0;
            int ichannelDefinitionBox = 0;
            int iresolutionBox = 0;
            int itileParts = 0;
            int isiz = 0;
            int icod = 0;
            int iqcd = 0;
            int icoc = 0;
            int icom = 0;
            int iqcc = 0;
            int irgn = 0;
            int ipoc = 0;
            int iplm = 0;
            int ippm = 0;
            int itlm = 0;
            int icrg = 0;
            int iplt = 0;
            int ippt = 0;
            int ixmlBox = 0;
            int iuuidBox = 0;
            int iuuidInfoBox = 0;
            int iunknownBox = 0;
            int icontainsImageHeaderBox = 0;
            int icontainsColourSpecificationBox = 0;
            int icontainsBitsPerComponentBox = 0;
            int ifirstJP2HeaderBoxIsImageHeaderBox = 0;
            int inoMoreThanOneImageHeaderBox = 0;
            int inoMoreThanOneBitsPerComponentBox = 0;
            int inoMoreThanOnePaletteBox = 0;
            int inoMoreThanOneComponentMappingBox = 0;
            int inoMoreThanOneChannelDefinitionBox = 0;
            int inoMoreThanOneResolutionBox = 0;
            int icolourSpecificationBoxesAreContiguous = 0;
            int ipaletteAndComponentMappingBoxesOnlyTogether = 0;

            int icodestreamStartsWithSOCMarker = 0;
            int ifoundSIZMarker = 0;
            int ifoundCODMarker = 0;
            int ifoundQCDMarker = 0;
            int iquantizationConsistentWithLevels = 0;
            int ifoundExpectedNumberOfTiles = 0;
            int ifoundExpectedNumberOfTileParts = 0;
            int ifoundEOCMarker = 0;

            NodeList nodeLstTest = doc.getElementsByTagName("tests");

            // Node test enthlt alle invaliden tests
            for (int s = 0; s < nodeLstTest.getLength(); s++) {
                Node testNode = nodeLstTest.item(s);
                NodeList children = testNode.getChildNodes();
                for (int i = 0; i < children.getLength(); i++) {
                    Node textChild = children.item(i);
                    if (textChild.getNodeType() == Node.ELEMENT_NODE) {
                        if (textChild.getNodeName().equals("signatureBox")) {
                            isignatureBox = isignatureBox + 1;
                        } else if (textChild.getNodeName().equals("fileTypeBox")) {
                            ifileTypeBox = ifileTypeBox + 1;
                        } else if (textChild.getNodeName().equals("jp2HeaderBox")) {
                            NodeList childrenII = textChild.getChildNodes();
                            for (int j = 0; j < childrenII.getLength(); j++) {
                                Node textChildII = childrenII.item(j);
                                if (textChildII.getNodeType() == Node.ELEMENT_NODE) {
                                    if (textChildII.getNodeName().equals("imageHeaderBox")) {
                                        iimageHeaderBox = iimageHeaderBox + 1;
                                    } else if (textChildII.getNodeName().equals("bitsPerComponentBox")) {
                                        ibitsPerComponentBox = ibitsPerComponentBox + 1;
                                    } else if (textChildII.getNodeName().equals("colourSpecificationBox")) {
                                        icolourSpecificationBox = icolourSpecificationBox + 1;
                                    } else if (textChildII.getNodeName().equals("paletteBox")) {
                                        ipaletteBox = ipaletteBox + 1;
                                    } else if (textChildII.getNodeName().equals("componentMappingBox")) {
                                        icomponentMappingBox = icomponentMappingBox + 1;
                                    } else if (textChildII.getNodeName().equals("channelDefinitionBox")) {
                                        ichannelDefinitionBox = ichannelDefinitionBox + 1;
                                    } else if (textChildII.getNodeName().equals("resolutionBox")) {
                                        iresolutionBox = iresolutionBox + 1;
                                    } else if (textChildII.getNodeName().equals("containsImageHeaderBox")) {
                                        icontainsImageHeaderBox = icontainsImageHeaderBox + 1;
                                    } else if (textChildII.getNodeName()
                                            .equals("containsColourSpecificationBox")) {
                                        icontainsColourSpecificationBox = icontainsColourSpecificationBox + 1;
                                    } else if (textChildII.getNodeName()
                                            .equals("containsBitsPerComponentBox")) {
                                        icontainsBitsPerComponentBox = icontainsBitsPerComponentBox + 1;
                                    } else if (textChildII.getNodeName()
                                            .equals("firstJP2HeaderBoxIsImageHeaderBox")) {
                                        ifirstJP2HeaderBoxIsImageHeaderBox = ifirstJP2HeaderBoxIsImageHeaderBox
                                                + 1;
                                    } else if (textChildII.getNodeName()
                                            .equals("noMoreThanOneImageHeaderBox")) {
                                        inoMoreThanOneImageHeaderBox = inoMoreThanOneImageHeaderBox + 1;
                                    } else if (textChildII.getNodeName()
                                            .equals("noMoreThanOneBitsPerComponentBox")) {
                                        inoMoreThanOneBitsPerComponentBox = inoMoreThanOneBitsPerComponentBox
                                                + 1;
                                    } else if (textChildII.getNodeName().equals("noMoreThanOnePaletteBox")) {
                                        inoMoreThanOnePaletteBox = inoMoreThanOnePaletteBox + 1;
                                    } else if (textChildII.getNodeName()
                                            .equals("noMoreThanOneComponentMappingBox")) {
                                        inoMoreThanOneComponentMappingBox = inoMoreThanOneComponentMappingBox
                                                + 1;
                                    } else if (textChildII.getNodeName()
                                            .equals("noMoreThanOneChannelDefinitionBox")) {
                                        inoMoreThanOneChannelDefinitionBox = inoMoreThanOneChannelDefinitionBox
                                                + 1;
                                    } else if (textChildII.getNodeName().equals("noMoreThanOneResolutionBox")) {
                                        inoMoreThanOneResolutionBox = inoMoreThanOneResolutionBox + 1;
                                    } else if (textChildII.getNodeName()
                                            .equals("colourSpecificationBoxesAreContiguous")) {
                                        icolourSpecificationBoxesAreContiguous = icolourSpecificationBoxesAreContiguous
                                                + 1;
                                    } else if (textChildII.getNodeName()
                                            .equals("paletteAndComponentMappingBoxesOnlyTogether")) {
                                        ipaletteAndComponentMappingBoxesOnlyTogether = ipaletteAndComponentMappingBoxesOnlyTogether
                                                + 1;
                                    }
                                }
                                continue;
                            }
                        } else if (textChild.getNodeName().equals("contiguousCodestreamBox")) {
                            NodeList childrenIII = textChild.getChildNodes();
                            for (int k = 0; k < childrenIII.getLength(); k++) {
                                Node textChildIII = childrenIII.item(k);
                                if (textChildIII.getNodeType() == Node.ELEMENT_NODE) {
                                    if (textChildIII.getNodeName().equals("tileParts")) {
                                        itileParts = itileParts + 1;
                                    } else if (textChildIII.getNodeName().equals("siz")) {
                                        isiz = isiz + 1;
                                    } else if (textChildIII.getNodeName().equals("cod")) {
                                        icod = icod + 1;
                                    } else if (textChildIII.getNodeName().equals("qcd")) {
                                        iqcd = iqcd + 1;
                                    } else if (textChildIII.getNodeName().equals("coc")) {
                                        icoc = icoc + 1;
                                    } else if (textChildIII.getNodeName().equals("com")) {
                                        icom = icom + 1;
                                    } else if (textChildIII.getNodeName().equals("qcc")) {
                                        iqcc = iqcc + 1;
                                    } else if (textChildIII.getNodeName().equals("rgn")) {
                                        irgn = irgn + 1;
                                    } else if (textChildIII.getNodeName().equals("poc")) {
                                        ipoc = ipoc + 1;
                                    } else if (textChildIII.getNodeName().equals("plm")) {
                                        iplm = iplm + 1;
                                    } else if (textChildIII.getNodeName().equals("ppm")) {
                                        ippm = ippm + 1;
                                    } else if (textChildIII.getNodeName().equals("tlm")) {
                                        itlm = itlm + 1;
                                    } else if (textChildIII.getNodeName().equals("crg")) {
                                        icrg = icrg + 1;
                                    } else if (textChildIII.getNodeName().equals("plt")) {
                                        iplt = iplt + 1;
                                    } else if (textChildIII.getNodeName().equals("ppt")) {
                                        ippt = ippt + 1;
                                    } else if (textChildIII.getNodeName()
                                            .equals("codestreamStartsWithSOCMarker")) {
                                        icodestreamStartsWithSOCMarker = icodestreamStartsWithSOCMarker + 1;
                                    } else if (textChildIII.getNodeName().equals("foundSIZMarker")) {
                                        ifoundSIZMarker = ifoundSIZMarker + 1;
                                    } else if (textChildIII.getNodeName().equals("foundCODMarker")) {
                                        ifoundCODMarker = ifoundCODMarker + 1;
                                    } else if (textChildIII.getNodeName().equals("foundQCDMarker")) {
                                        ifoundQCDMarker = ifoundQCDMarker + 1;
                                    } else if (textChildIII.getNodeName()
                                            .equals("quantizationConsistentWithLevels")) {
                                        iquantizationConsistentWithLevels = iquantizationConsistentWithLevels
                                                + 1;
                                    } else if (textChildIII.getNodeName()
                                            .equals("foundExpectedNumberOfTiles")) {
                                        ifoundExpectedNumberOfTiles = ifoundExpectedNumberOfTiles + 1;
                                    } else if (textChildIII.getNodeName()
                                            .equals("foundExpectedNumberOfTileParts")) {
                                        ifoundExpectedNumberOfTileParts = ifoundExpectedNumberOfTileParts + 1;
                                    } else if (textChildIII.getNodeName().equals("foundEOCMarker")) {
                                        ifoundEOCMarker = ifoundEOCMarker + 1;
                                    }
                                }
                                continue;
                            }
                        } else if (textChild.getNodeName().equals("xmlBox")) {
                            ixmlBox = ixmlBox + 1;
                        } else if (textChild.getNodeName().equals("uuidBox")) {
                            iuuidBox = iuuidBox + 1;
                        } else if (textChild.getNodeName().equals("uuidInfoBox")) {
                            iuuidInfoBox = iuuidInfoBox + 1;
                        } else if (textChild.getNodeName().equals("unknownBox")) {
                            iunknownBox = iunknownBox + 1;
                        }
                    }
                    continue;
                }
                continue;
            }

            if (isignatureBox >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2)
                        + getTextResourceService().getText(ERROR_XML_A_JP2_SIGNATURE));
            }
            if (ifileTypeBox >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2)
                        + getTextResourceService().getText(ERROR_XML_A_JP2_FILETYPE));
            }
            if (iimageHeaderBox >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2)
                        + getTextResourceService().getText(ERROR_XML_B_JP2_IMAGE));
            }
            if (ibitsPerComponentBox >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2)
                        + getTextResourceService().getText(ERROR_XML_B_JP2_BITSPC));
            }
            if (icolourSpecificationBox >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2)
                        + getTextResourceService().getText(ERROR_XML_B_JP2_COLOUR));
            }
            if (ipaletteBox >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2)
                        + getTextResourceService().getText(ERROR_XML_B_JP2_PALETTE));
            }
            if (icomponentMappingBox >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2)
                        + getTextResourceService().getText(ERROR_XML_B_JP2_MAPPING));
            }
            if (ichannelDefinitionBox >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2)
                        + getTextResourceService().getText(ERROR_XML_B_JP2_CHANNEL));
            }
            if (iresolutionBox >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2)
                        + getTextResourceService().getText(ERROR_XML_B_JP2_RESOLUTION));
            }

            if (icontainsImageHeaderBox >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2)
                        + getTextResourceService().getText(ERROR_XML_B_JP2_NOIHB));
            }
            if (icontainsColourSpecificationBox >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2)
                        + getTextResourceService().getText(ERROR_XML_B_JP2_NOCSB));
            }
            if (icontainsBitsPerComponentBox >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2)
                        + getTextResourceService().getText(ERROR_XML_B_JP2_NBPCB));
            }
            if (ifirstJP2HeaderBoxIsImageHeaderBox >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2)
                        + getTextResourceService().getText(ERROR_XML_B_JP2_IHBNF));
            }
            if (inoMoreThanOneImageHeaderBox >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2)
                        + getTextResourceService().getText(ERROR_XML_B_JP2_IHBMO));
            }
            if (inoMoreThanOneBitsPerComponentBox >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2)
                        + getTextResourceService().getText(ERROR_XML_B_JP2_OBPCMO));
            }
            if (inoMoreThanOnePaletteBox >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2)
                        + getTextResourceService().getText(ERROR_XML_B_JP2_OPBMO));
            }
            if (inoMoreThanOneComponentMappingBox >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2)
                        + getTextResourceService().getText(ERROR_XML_B_JP2_CMBMO));
            }
            if (inoMoreThanOneChannelDefinitionBox >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2)
                        + getTextResourceService().getText(ERROR_XML_B_JP2_CDBMO));
            }
            if (inoMoreThanOneResolutionBox >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2)
                        + getTextResourceService().getText(ERROR_XML_B_JP2_RBMO));
            }
            if (icolourSpecificationBoxesAreContiguous >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2)
                        + getTextResourceService().getText(ERROR_XML_B_JP2_CSBNC));
            }
            if (ipaletteAndComponentMappingBoxesOnlyTogether >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2)
                        + getTextResourceService().getText(ERROR_XML_B_JP2_PACMB));
            }

            if (icodestreamStartsWithSOCMarker >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2)
                        + getTextResourceService().getText(ERROR_XML_C_JP2_SOC));
            }
            if (ifoundSIZMarker >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2)
                        + getTextResourceService().getText(ERROR_XML_C_JP2_FSIZ));
            }
            if (ifoundCODMarker >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2)
                        + getTextResourceService().getText(ERROR_XML_C_JP2_FCOD));
            }
            if (ifoundQCDMarker >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2)
                        + getTextResourceService().getText(ERROR_XML_C_JP2_FQCD));
            }
            if (iquantizationConsistentWithLevels >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2)
                        + getTextResourceService().getText(ERROR_XML_C_JP2_PQCD));
            }
            if (ifoundExpectedNumberOfTiles >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2)
                        + getTextResourceService().getText(ERROR_XML_C_JP2_NOTILES));
            }
            if (ifoundExpectedNumberOfTileParts >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2)
                        + getTextResourceService().getText(ERROR_XML_C_JP2_NOTILESPART));
            }
            if (ifoundEOCMarker >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2)
                        + getTextResourceService().getText(ERROR_XML_C_JP2_EOC));
            }

            if (itileParts >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2)
                        + getTextResourceService().getText(ERROR_XML_C_JP2_TILEPARTS));
            }
            if (isiz >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2)
                        + getTextResourceService().getText(ERROR_XML_C_JP2_SIZ));
            }
            if (icod >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2)
                        + getTextResourceService().getText(ERROR_XML_C_JP2_COD));
            }
            if (iqcd >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2)
                        + getTextResourceService().getText(ERROR_XML_C_JP2_QCD));
            }
            if (icom >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2)
                        + getTextResourceService().getText(ERROR_XML_C_JP2_COM));
            }
            if (icoc >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2)
                        + getTextResourceService().getText(ERROR_XML_C_JP2_COC));
            }
            if (irgn >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2)
                        + getTextResourceService().getText(ERROR_XML_C_JP2_RGN));
            }
            if (iqcc >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2)
                        + getTextResourceService().getText(ERROR_XML_C_JP2_QCC));
            }
            if (ipoc >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2)
                        + getTextResourceService().getText(ERROR_XML_C_JP2_POC));
            }
            if (iplm >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2)
                        + getTextResourceService().getText(ERROR_XML_C_JP2_PLM));
            }
            if (ippm >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2)
                        + getTextResourceService().getText(ERROR_XML_C_JP2_PPM));
            }
            if (itlm >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2)
                        + getTextResourceService().getText(ERROR_XML_C_JP2_TLM));
            }
            if (icrg >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2)
                        + getTextResourceService().getText(ERROR_XML_C_JP2_CRG));
            }
            if (iplt >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2)
                        + getTextResourceService().getText(ERROR_XML_C_JP2_PLT));
            }
            if (ippt >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2)
                        + getTextResourceService().getText(ERROR_XML_C_JP2_PPT));
            }

            if (ixmlBox >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_D_JP2)
                        + getTextResourceService().getText(ERROR_XML_D_JP2_XML));
            }
            if (iuuidBox >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_D_JP2)
                        + getTextResourceService().getText(ERROR_XML_D_JP2_UUID));
            }
            if (iuuidInfoBox >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_D_JP2)
                        + getTextResourceService().getText(ERROR_XML_D_JP2_UUIDINFO));
            }
            if (iunknownBox >= 1) {
                getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_D_JP2)
                        + getTextResourceService().getText(ERROR_XML_D_JP2_UNKNOWN));
            }
        }

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