Example usage for java.io File isAbsolute

List of usage examples for java.io File isAbsolute

Introduction

In this page you can find the example usage for java.io File isAbsolute.

Prototype

public boolean isAbsolute() 

Source Link

Document

Tests whether this abstract pathname is absolute.

Usage

From source file:com.cyberway.issue.crawler.admin.CrawlJob.java

/**
 * Returns the absolute path of the specified log.
 * Note: If crawl has not begun, this file may not exist.
 * @param log/*  ww w. ja v  a2  s. c  o m*/
 * @return the absolute path for the specified log.
 * @throws AttributeNotFoundException
 * @throws ReflectionException
 * @throws MBeanException
 */
public String getLogPath(String log) throws AttributeNotFoundException, MBeanException, ReflectionException {
    String logsPath = (String) settingsHandler.getOrder().getAttribute(CrawlOrder.ATTR_LOGS_PATH);
    CrawlOrder order = settingsHandler.getOrder();
    String diskPath = (String) order.getAttribute(null, CrawlOrder.ATTR_DISK_PATH);
    File disk = settingsHandler.getPathRelativeToWorkingDirectory(diskPath);
    File f = new File(logsPath, log);
    if (!f.isAbsolute()) {
        f = new File(disk.getPath(), f.getPath());
    }
    return f.getAbsolutePath();
}

From source file:org.energy_home.jemma.ah.internal.hac.lib.HacService.java

/**
 * Load HAC configuration. It is useful to describe the algorithm used to
 * instantiate the virtual appliances trough virtual appliances factory
 * services Each <va></va> section contains the properties of the virtual
 * appliance that the section represents. The load procedure stores all
 * these properties and tries to match them in an already installed bundles
 * or to download them on demand./*from  w ww  .ja v a 2s  .  c om*/
 * 
 * The procedure for doing that is identical to the Device Attachment
 * Algorithm described in the "Device Access Specification v1.1" The
 * HacService implements the DeviceLocator interface but doesn't register
 * it.
 * 
 * 
 * 1. If a DRIVER_ID property is present, the algorithm tries to locate an
 * already registered IApplianceType service exposing the same DERVICE_ID
 * property. If such an IApplianceType service is not found, an attempt to
 * download the maching driver bundle. If the
 * 
 * 
 * @param configName
 *            Filename. The filename must not include the .xml extension
 * 
 * @param storageArea
 *            If this parameter is true the configuration file is got from
 *            the r/w data area reserved to the bundle
 * 
 * @return true if the configuration has been read and applied correctly. In
 *         case of errors returns false
 */

protected boolean loadConfiguration(String configName, boolean storageArea) {
    synchronized (lockHacService) {
        File configFile;
        InputStream stream = null;

        if (configName == null) {
            configName = "defaultconfig";
            storageArea = true;
        }

        LOG.debug("try to load '" + configName + "'");

        try {
            if (storageArea) {
                String configFilename = SCENARIOS_PATH + configName + ".xml";
                if (getProperty("org.energy_home.jemma.ah.updatepatch", enableUpdatePatch)) {
                    patched = PatchUpdateBug.patchUpdateBugOnHacLib(bc, configFilename);
                }
                configFile = bc.getDataFile(configFilename);
                LOG.debug("storage area is " + configFile);
                stream = new FileInputStream(configFile);
            } else {
                File f = new File(configName);
                if (f.isAbsolute()) {
                    stream = new FileInputStream(configName);
                } else {
                    String configFilename = SCENARIOS_PATH + configName + ".xml";
                    URL url = bc.getBundle().getEntry(configFilename);
                    if (url == null) {
                        LOG.debug("unable to open file " + configFilename);
                        return false;
                    }
                    stream = url.openStream();
                }
            }
        } catch (FileNotFoundException e) {
            LOG.warn("no saved configuration '" + configName + "'", e);
            return false;
        } catch (IOException e) {
            LOG.warn("unable to open file " + configName, e);
            return false;
        }

        categories.clear();

        try {
            factory.setNamespaceAware(true);
            factory.setValidating(false);

            DocumentBuilder parser = factory.newDocumentBuilder();
            Document doc = parser.parse(new InputSource(stream));

            // parses the configuration file and updates the current
            // configuration present in memory
            traverseConfigurationTree(doc);
        } catch (IOException e) {
            LOG.warn(e.getMessage(), e);
            return false;
        } catch (SAXException e) {
            LOG.warn(e.getMessage(), e);
            return false;
        } catch (Exception e) {
            LOG.warn(e.getMessage(), e);
            return false;
        }

        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
                LOG.warn(e.getMessage(), e);
                return false;
            }
        }

        if (patched && (getProperty("it.telecomitalia.ah.updatepatch", enableUpdatePatch))) {
            PatchUpdateBug.moveFactoryConfigurations(configAdmin, LocationsService.FACTORY_PID);
        }

        LOG.debug("loaded successfully the previously saved configuration");
        return true;
    }
}

From source file:org.eclipse.birt.report.utility.ParameterAccessor.java

/**
 * Check if the given file path is a universal path, it could be either an
 * absolute file path or a valid url path. This will check for both local
 * file path and global url path like "http://", "jndi://", etc.
 * //  w w  w  . j  a va2 s  .  c o  m
 * @param fileName
 * @return
 */
public static boolean isUniversalPath(String fileName) {
    if (fileName == null) {
        return false;
    }

    File f = new File(fileName);

    if (f.isAbsolute()) {
        return true;
    }

    try {
        new URL(fileName);
        return true;
    } catch (MalformedURLException e) {
    }

    return false;
}

From source file:catalina.core.StandardServer.java

/**
 * Write the configuration information for this entire <code>Server</code>
 * out to the server.xml configuration file.
 *
 * @exception InstanceNotFoundException if the managed resource object
 *  cannot be found/*from  w  w w. j  a v a2  s  .  com*/
 * @exception MBeanException if the initializer of the object throws
 *  an exception, or persistence is not supported
 * @exception RuntimeOperationsException if an exception is reported
 *  by the persistence mechanism
 */
public synchronized void store() throws Exception {

    // Calculate file objects for the old and new configuration files.
    String configFile = "conf/server.xml"; // FIXME - configurable?
    File configOld = new File(configFile);
    if (!configOld.isAbsolute()) {
        configOld = new File(System.getProperty("catalina.base"), configFile);
    }
    File configNew = new File(configFile + ".new");
    if (!configNew.isAbsolute()) {
        configNew = new File(System.getProperty("catalina.base"), configFile + ".new");
    }
    String ts = (new Timestamp(System.currentTimeMillis())).toString();
    //        yyyy-mm-dd hh:mm:ss
    //        0123456789012345678
    StringBuffer sb = new StringBuffer(".");
    sb.append(ts.substring(0, 10));
    sb.append('.');
    sb.append(ts.substring(11, 13));
    sb.append('-');
    sb.append(ts.substring(14, 16));
    sb.append('-');
    sb.append(ts.substring(17, 19));
    File configSave = new File(configFile + sb.toString());
    if (!configSave.isAbsolute()) {
        configSave = new File(System.getProperty("catalina.base"), configFile + sb.toString());
    }

    // Open an output writer for the new configuration file
    PrintWriter writer = null;
    try {
        writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(configNew), "UTF8"));
    } catch (IOException e) {
        if (writer != null) {
            try {
                writer.close();
            } catch (Throwable t) {
                ;
            }
        }
        throw (e);
    }

    // Store the state of this Server MBean
    // (which will recursively store everything
    try {
        storeServer(writer, 0, this);
    } catch (Exception e) {
        if (writer != null) {
            try {
                writer.close();
            } catch (Throwable t) {
                ;
            }
        }
        throw (e);
    }

    // Flush and close the output file
    try {
        writer.flush();
    } catch (Exception e) {
        throw (e);
    }
    try {
        writer.close();
    } catch (Exception e) {
        throw (e);
    }

    // Shuffle old->save and new->old
    if (configOld.renameTo(configSave)) {
        if (configNew.renameTo(configOld)) {
            return;
        } else {
            configSave.renameTo(configOld);
            throw new IOException(
                    "Cannot rename " + configNew.getAbsolutePath() + " to " + configOld.getAbsolutePath());
        }
    } else {
        throw new IOException(
                "Cannot rename " + configOld.getAbsolutePath() + " to " + configSave.getAbsolutePath());
    }

}

From source file:org.eclipse.birt.report.utility.ParameterAccessor.java

/**
 * If set isWorkingFolderAccessOnly as true, check the file if exist in
 * working folder.//  w ww .ja  v  a 2 s  . c o m
 * 
 * @param filePath
 * @return boolean
 */

public static boolean isValidFilePath(HttpServletRequest request, String filePath) {
    if (filePath == null)
        return false;

    // check and aply url report path policy
    if (!POLICY_ALL.equalsIgnoreCase(urlReportPathPolicy)) {
        File f = new File(filePath);

        if (!f.isAbsolute()) {
            try {
                URL url = new URL(filePath);

                if (POLICY_DOMAIN.equalsIgnoreCase(urlReportPathPolicy)) {
                    String dm = request.getServerName();

                    if (!dm.equals(url.getHost())) {
                        return false;
                    }
                } else {
                    return false;
                }
            } catch (MalformedURLException e) {
                // ignore
            }
        }
    }

    if (isWorkingFolderAccessOnly) {
        // TODO check non-file path case

        File docFile = new File(filePath);
        if (!docFile.isAbsolute()) {
            if (filePath.indexOf("..") != -1) //$NON-NLS-1$
                return false;

            return true;
        }

        File docFolder = new File(workingFolder);
        if (docFolder.isAbsolute()) {
            String absolutePath = docFile.getAbsolutePath();
            String docFolderPath = docFolder.getAbsolutePath();

            // if OS is windows, ignore the case sensitive.
            if (isWindowsPlatform()) {
                absolutePath = absolutePath.toLowerCase();
                docFolderPath = docFolderPath.toLowerCase();
            }

            return absolutePath.startsWith(docFolderPath);
        } else {
            // if workingFolder is relative path, return false.
            return false;
        }
    }

    return true;
}

From source file:com.cyberway.issue.crawler.admin.CrawlJob.java

/**
 * A constructor for reloading jobs from disk. Jobs (not profiles) have
 * their data written to persistent storage in the file system. This method
 * is used to load the job from such storage. This is done by the
 * <code>CrawlJobHandler</code>.
 * <p>//from  w w w .java 2 s.co  m
 * Proper structure of a job file (TODO: Maybe one day make this an XML file)
 * Line 1. UID <br>
 * Line 2. Job name (string) <br>
 * Line 3. Job status (string) <br>
 * Line 4. is job read only (true/false) <br>
 * Line 5. is job running (true/false) <br>
 * Line 6. job priority (int) <br>
 * Line 7. number of journal entries <br>
 * Line 8. setting file (with path) <br>
 * Line 9. statistics tracker file (with path) <br>
 * Line 10-?. error message (String, empty for null), can be many lines <br>
 * @param jobFile
 *            a file containing information about the job to load.
 * @param errorHandler The crawl jobs settings error handler.
 *            null means none is set
 * @throws InvalidJobFileException
 *            if the specified file does not refer to a valid job file.
 * @throws IOException
 *            if io operations fail
 */
protected CrawlJob(final File jobFile, final CrawlJobErrorHandler errorHandler)
        throws InvalidJobFileException, IOException {
    this(null, null, null, errorHandler, PRIORITY_AVERAGE, null, null, false, true);
    this.jobDir = jobFile.getParentFile();

    // Check for corrupt job.state files (can be corrupt if we crash).
    if (jobFile.length() == 0) {
        throw new InvalidJobFileException(jobFile.getCanonicalPath() + " is corrupt (length is zero)");
    }

    // Open file. Read data and set up class variables accordingly...
    BufferedReader jobReader = new BufferedReader(new FileReader(jobFile), 4096);
    // UID
    this.UID = jobReader.readLine();
    // name
    this.name = jobReader.readLine();
    // status
    this.status = jobReader.readLine();
    if (status.equals(STATUS_ABORTED) == false && status.equals(STATUS_CREATED) == false
            && status.equals(STATUS_DELETED) == false && status.equals(STATUS_FINISHED) == false
            && status.equals(STATUS_FINISHED_ABNORMAL) == false
            && status.equals(STATUS_FINISHED_DATA_LIMIT) == false
            && status.equals(STATUS_FINISHED_DOCUMENT_LIMIT) == false
            && status.equals(STATUS_FINISHED_TIME_LIMIT) == false
            && status.equals(STATUS_MISCONFIGURED) == false && status.equals(STATUS_PAUSED) == false
            && status.equals(STATUS_CHECKPOINTING) == false && status.equals(STATUS_PENDING) == false
            && status.equals(STATUS_RUNNING) == false && status.equals(STATUS_WAITING_FOR_PAUSE) == false
            && status.equals(STATUS_PREPARING) == false) {
        // status is invalid. Must be one of the above
        throw new InvalidJobFileException("Status (line 3) in job file " + "is not valid: '" + status + "'");
    }
    // isReadOnly
    String tmp = jobReader.readLine();
    if (tmp.equals("true")) {
        isReadOnly = true;
    } else if (tmp.equals("false")) {
        isReadOnly = false;
    } else {
        throw new InvalidJobFileException("isReadOnly (line 4) in job" + " file '" + jobFile.getAbsolutePath()
                + "' is not " + "valid: '" + tmp + "'");
    }
    // isRunning
    tmp = jobReader.readLine();
    if (tmp.equals("true")) {
        this.isRunning = true;
    } else if (tmp.equals("false")) {
        this.isRunning = false;
    } else {
        throw new InvalidJobFileException("isRunning (line 5) in job " + "file '" + jobFile.getAbsolutePath()
                + "' is not valid: " + "'" + tmp + "'");
    }
    // priority
    tmp = jobReader.readLine();
    try {
        this.priority = Integer.parseInt(tmp);
    } catch (NumberFormatException e) {
        throw new InvalidJobFileException("priority (line 5) in job " + "file '" + jobFile.getAbsolutePath()
                + "' is not valid: " + "'" + tmp + "'");
    }
    // numberOfJournalEntries
    tmp = jobReader.readLine();
    try {
        this.numberOfJournalEntries = Integer.parseInt(tmp);
    } catch (NumberFormatException e) {
        throw new InvalidJobFileException("numberOfJournalEntries " + "(line 5) in job file '"
                + jobFile.getAbsolutePath() + "' is not valid: " + "'" + tmp + "'");
    }
    // settingsHandler
    tmp = jobReader.readLine();
    try {
        File f = new File(tmp);
        this.settingsHandler = new XMLSettingsHandler((f.isAbsolute()) ? f : new File(jobDir, f.getName()));
        if (this.errorHandler != null) {
            this.settingsHandler.registerValueErrorHandler(errorHandler);
        }
        this.settingsHandler.initialize();
    } catch (InvalidAttributeValueException e1) {
        throw new InvalidJobFileException("Problem reading from settings " + "file (" + tmp
                + ") specified in job file '" + jobFile.getAbsolutePath() + "'\n" + e1.getMessage());
    }
    // Statistics tracker.
    jobReader.readLine();
    // errorMessage
    // TODO: Multilines
    tmp = jobReader.readLine();
    errorMessage = "";
    while (tmp != null) {
        errorMessage += tmp + '\n';
        tmp = jobReader.readLine();
    }
    if (errorMessage.length() == 0) {
        // Empty error message should be null
        errorMessage = null;
    }
    // TODO: Load stattrack if needed.

    // TODO: This should be inside a finally block.
    jobReader.close();
}

From source file:it.geosolutions.geobatch.catalog.file.DataDirHandler.java

/**
 * Try to retrieve the info about where the requested property dir is located.
 *
 * @param propertyName a property name referring to a string containing a path
 *
 * @return a valid dir or null./*from   www .  ja  va 2  s .  c  o m*/
 *
 * @throws NullPointerException
 * @throws IllegalStateException
 */
protected File retrieveConfiguredDir(String propertyName) throws NullPointerException, IllegalStateException {
    File ret = null;

    //        try {
    String prop = System.getProperty(propertyName);
    if (prop != null) {
        ret = new File(prop);
        if (LOGGER.isErrorEnabled()) {
            LOGGER.error(propertyName + " read from property");
        }
    } else {
        prop = System.getenv(propertyName);
        if (prop != null) {
            ret = new File(prop);
            if (LOGGER.isErrorEnabled()) {
                LOGGER.error(propertyName + " read from environment var");
            }
        } else {
            if (this.applicationContext instanceof WebApplicationContext) {
                final WebApplicationContext wContext = (WebApplicationContext) applicationContext;
                final ServletContext servletContext = wContext.getServletContext();
                String rootDir = servletContext.getInitParameter(propertyName);
                if (rootDir != null) {
                    ret = new File(rootDir);
                    if (LOGGER.isErrorEnabled()) {
                        LOGGER.error(propertyName + " read from servlet init param");
                    }
                }
            }
        }
    }
    //        } catch (SecurityException e) {
    //            // gobble exception
    //            if ( LOGGER.isInfoEnabled() ) {
    //                LOGGER.info(e.getLocalizedMessage(), e);
    //            }
    //        }

    if (ret == null) {
        return null;
    }

    if (!ret.exists()) {
        throw new IllegalStateException(
                "Could not initialize " + propertyName + ": The provided path does not exists (" + ret + ")");
    }

    if (!ret.isDirectory() || !ret.canRead()) {
        throw new IllegalStateException("Could not initialize " + propertyName
                + ": The provided path is not a readable directory (" + ret + ")");
    }

    if (!ret.isAbsolute())
        LOGGER.warn("The configured " + propertyName + " is not absolute: " + ret);

    return ret;
}

From source file:org.apache.catalina.manager.HTMLManagerServlet.java

/**
 * Process a POST request for the specified resource.
 *
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet-specified error occurs
 *//*  w w w . jav a2 s  .com*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    // Identify the request parameters that we need
    String command = request.getPathInfo();

    if (command == null || !command.equals("/upload")) {
        doGet(request, response);
        return;
    }

    // Prepare our output writer to generate the response message
    response.setContentType("text/html; charset=" + Constants.CHARSET);

    String message = "";

    // Create a new file upload handler
    DiskFileUpload upload = new DiskFileUpload();

    // Get the tempdir
    File tempdir = (File) getServletContext().getAttribute("javax.servlet.context.tempdir");
    // Set upload parameters
    upload.setSizeMax(-1);
    upload.setRepositoryPath(tempdir.getCanonicalPath());

    // Parse the request
    String basename = null;
    File appBaseDir = null;
    String war = null;
    FileItem warUpload = null;
    try {
        List items = upload.parseRequest(request);

        // Process the uploaded fields
        Iterator iter = items.iterator();
        while (iter.hasNext()) {
            FileItem item = (FileItem) iter.next();

            if (!item.isFormField()) {
                if (item.getFieldName().equals("deployWar") && warUpload == null) {
                    warUpload = item;
                } else {
                    item.delete();
                }
            }
        }
        while (true) {
            if (warUpload == null) {
                message = sm.getString("htmlManagerServlet.deployUploadNoFile");
                break;
            }
            war = warUpload.getName();
            if (!war.toLowerCase().endsWith(".war")) {
                message = sm.getString("htmlManagerServlet.deployUploadNotWar", war);
                break;
            }
            // Get the filename if uploaded name includes a path
            if (war.lastIndexOf('\\') >= 0) {
                war = war.substring(war.lastIndexOf('\\') + 1);
            }
            if (war.lastIndexOf('/') >= 0) {
                war = war.substring(war.lastIndexOf('/') + 1);
            }
            // Identify the appBase of the owning Host of this Context
            // (if any)
            String appBase = null;
            appBase = ((Host) context.getParent()).getAppBase();
            appBaseDir = new File(appBase);
            if (!appBaseDir.isAbsolute()) {
                appBaseDir = new File(System.getProperty("catalina.base"), appBase);
            }
            basename = war.substring(0, war.indexOf(".war"));
            File file = new File(appBaseDir, war);
            if (file.exists()) {
                message = sm.getString("htmlManagerServlet.deployUploadWarExists", war);
                break;
            }
            warUpload.write(file);
            try {
                URL url = file.toURL();
                war = url.toString();
                war = "jar:" + war + "!/";
            } catch (MalformedURLException e) {
                file.delete();
                throw e;
            }
            break;
        }
    } catch (Exception e) {
        message = sm.getString("htmlManagerServlet.deployUploadFail", e.getMessage());
        log(message, e);
    } finally {
        if (warUpload != null) {
            warUpload.delete();
        }
        warUpload = null;
    }

    // Extract the nested context deployment file (if any)
    File localWar = new File(appBaseDir, basename + ".war");
    File localXml = new File(configBase, basename + ".xml");
    try {
        extractXml(localWar, localXml);
    } catch (IOException e) {
        log("managerServlet.extract[" + localWar + "]", e);
        return;
    }
    String config = null;
    try {
        if (localXml.exists()) {
            URL url = localXml.toURL();
            config = url.toString();
        }
    } catch (MalformedURLException e) {
        throw e;
    }

    // If there were no errors, deploy the WAR
    if (message.length() == 0) {
        message = deployInternal(config, null, war);
    }

    list(request, response, message);
}

From source file:json_to_xml_1.java

public int execute(String args[]) throws ProgramTerminationException {
    this.getInfoMessages().clear();

    if (args.length < 2) {
        throw constructTermination("messageArgumentsMissing", null,
                getI10nString("messageArgumentsMissingUsage") + "\n\tjson_to_xml_1 "
                        + getI10nString("messageParameterList") + "\n");
    }/*w  w w  .ja  v a  2  s  .  c  o m*/

    File resultInfoFile = new File(args[1]);

    try {
        resultInfoFile = resultInfoFile.getCanonicalFile();
    } catch (SecurityException ex) {
        throw constructTermination("messageResultInfoFileCantGetCanonicalPath", ex, null,
                resultInfoFile.getAbsolutePath());
    } catch (IOException ex) {
        throw constructTermination("messageResultInfoFileCantGetCanonicalPath", ex, null,
                resultInfoFile.getAbsolutePath());
    }

    if (resultInfoFile.exists() == true) {
        if (resultInfoFile.isFile() == true) {
            if (resultInfoFile.canWrite() != true) {
                throw constructTermination("messageResultInfoFileIsntWritable", null, null,
                        resultInfoFile.getAbsolutePath());
            }
        } else {
            throw constructTermination("messageResultInfoPathIsntAFile", null, null,
                    resultInfoFile.getAbsolutePath());
        }
    }

    json_to_xml_1.resultInfoFile = resultInfoFile;

    File jobFile = new File(args[0]);

    try {
        jobFile = jobFile.getCanonicalFile();
    } catch (SecurityException ex) {
        throw constructTermination("messageJobFileCantGetCanonicalPath", ex, null, jobFile.getAbsolutePath());
    } catch (IOException ex) {
        throw constructTermination("messageJobFileCantGetCanonicalPath", ex, null, jobFile.getAbsolutePath());
    }

    if (jobFile.exists() != true) {
        throw constructTermination("messageJobFileDoesntExist", null, null, jobFile.getAbsolutePath());
    }

    if (jobFile.isFile() != true) {
        throw constructTermination("messageJobPathIsntAFile", null, null, jobFile.getAbsolutePath());
    }

    if (jobFile.canRead() != true) {
        throw constructTermination("messageJobFileIsntReadable", null, null, jobFile.getAbsolutePath());
    }

    System.out.println("json_to_xml_1: " + getI10nStringFormatted("messageCallDetails",
            jobFile.getAbsolutePath(), resultInfoFile.getAbsolutePath()));

    File inputFile = null;
    File outputFile = null;

    try {
        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
        InputStream in = new FileInputStream(jobFile);
        XMLEventReader eventReader = inputFactory.createXMLEventReader(in);

        while (eventReader.hasNext() == true) {
            XMLEvent event = eventReader.nextEvent();

            if (event.isStartElement() == true) {
                String tagName = event.asStartElement().getName().getLocalPart();

                if (tagName.equals("json-input-file") == true) {
                    StartElement inputFileElement = event.asStartElement();
                    Attribute pathAttribute = inputFileElement.getAttributeByName(new QName("path"));

                    if (pathAttribute == null) {
                        throw constructTermination("messageJobFileEntryIsMissingAnAttribute", null, null,
                                jobFile.getAbsolutePath(), tagName, "path");
                    }

                    String inputFilePath = pathAttribute.getValue();

                    if (inputFilePath.isEmpty() == true) {
                        throw constructTermination("messageJobFileAttributeValueIsEmpty", null, null,
                                jobFile.getAbsolutePath(), tagName, "path");
                    }

                    inputFile = new File(inputFilePath);

                    if (inputFile.isAbsolute() != true) {
                        inputFile = new File(
                                jobFile.getAbsoluteFile().getParent() + File.separator + inputFilePath);
                    }

                    try {
                        inputFile = inputFile.getCanonicalFile();
                    } catch (SecurityException ex) {
                        throw constructTermination("messageInputFileCantGetCanonicalPath", ex, null,
                                new File(inputFilePath).getAbsolutePath(), jobFile.getAbsolutePath());
                    } catch (IOException ex) {
                        throw constructTermination("messageInputFileCantGetCanonicalPath", ex, null,
                                new File(inputFilePath).getAbsolutePath(), jobFile.getAbsolutePath());
                    }

                    if (inputFile.exists() != true) {
                        throw constructTermination("messageInputFileDoesntExist", null, null,
                                inputFile.getAbsolutePath(), jobFile.getAbsolutePath());
                    }

                    if (inputFile.isFile() != true) {
                        throw constructTermination("messageInputPathIsntAFile", null, null,
                                inputFile.getAbsolutePath(), jobFile.getAbsolutePath());
                    }

                    if (inputFile.canRead() != true) {
                        throw constructTermination("messageInputFileIsntReadable", null, null,
                                inputFile.getAbsolutePath(), jobFile.getAbsolutePath());
                    }
                } else if (tagName.equals("xml-output-file") == true) {
                    StartElement outputFileElement = event.asStartElement();
                    Attribute pathAttribute = outputFileElement.getAttributeByName(new QName("path"));

                    if (pathAttribute == null) {
                        throw constructTermination("messageJobFileEntryIsMissingAnAttribute", null, null,
                                jobFile.getAbsolutePath(), tagName, "path");
                    }

                    String outputFilePath = pathAttribute.getValue();

                    if (outputFilePath.isEmpty() == true) {
                        throw constructTermination("messageJobFileAttributeValueIsEmpty", null, null,
                                jobFile.getAbsolutePath(), tagName, "path");
                    }

                    outputFile = new File(outputFilePath);

                    if (outputFile.isAbsolute() != true) {
                        outputFile = new File(
                                jobFile.getAbsoluteFile().getParent() + File.separator + outputFilePath);
                    }

                    try {
                        outputFile = outputFile.getCanonicalFile();
                    } catch (SecurityException ex) {
                        throw constructTermination("messageOutputFileCantGetCanonicalPath", ex, null,
                                new File(outputFilePath).getAbsolutePath(), jobFile.getAbsolutePath());
                    } catch (IOException ex) {
                        throw constructTermination("messageOutputFileCantGetCanonicalPath", ex, null,
                                new File(outputFilePath).getAbsolutePath(), jobFile.getAbsolutePath());
                    }

                    if (outputFile.exists() == true) {
                        if (outputFile.isFile() == true) {
                            if (outputFile.canWrite() != true) {
                                throw constructTermination("messageOutputFileIsntWritable", null, null,
                                        outputFile.getAbsolutePath());
                            }
                        } else {
                            throw constructTermination("messageOutputPathIsntAFile", null, null,
                                    outputFile.getAbsolutePath());
                        }
                    }
                }
            }
        }
    } catch (XMLStreamException ex) {
        throw constructTermination("messageJobFileErrorWhileReading", ex, null, jobFile.getAbsolutePath());
    } catch (SecurityException ex) {
        throw constructTermination("messageJobFileErrorWhileReading", ex, null, jobFile.getAbsolutePath());
    } catch (IOException ex) {
        throw constructTermination("messageJobFileErrorWhileReading", ex, null, jobFile.getAbsolutePath());
    }

    if (inputFile == null) {
        throw constructTermination("messageJobFileNoInputFile", null, null, jobFile.getAbsolutePath());
    }

    if (outputFile == null) {
        throw constructTermination("messageJobFileNoOutputFile", null, null, jobFile.getAbsolutePath());
    }

    StringBuilder stringBuilder = new StringBuilder();

    try {
        JSONObject json = new JSONObject(new JSONTokener(new BufferedReader(new FileReader(inputFile))));

        stringBuilder.append(XML.toString(json));
    } catch (Exception ex) {
        throw constructTermination("messageConversionError", ex, null, inputFile.getAbsolutePath());
    }

    try {
        BufferedWriter writer = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8"));

        writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        writer.write(
                "<!-- This file was created by json_to_xml_1, which is free software licensed under the GNU Affero General Public License 3 or any later version (see https://github.com/publishing-systems/digital_publishing_workflow_tools/ and http://www.publishing-systems.org). -->\n");
        writer.write(stringBuilder.toString());

        writer.flush();
        writer.close();
    } catch (FileNotFoundException ex) {
        throw constructTermination("messageOutputFileWritingError", ex, null, outputFile.getAbsolutePath());
    } catch (UnsupportedEncodingException ex) {
        throw constructTermination("messageOutputFileWritingError", ex, null, outputFile.getAbsolutePath());
    } catch (IOException ex) {
        throw constructTermination("messageOutputFileWritingError", ex, null, outputFile.getAbsolutePath());
    }

    return 0;
}