Example usage for org.xml.sax XMLReader setErrorHandler

List of usage examples for org.xml.sax XMLReader setErrorHandler

Introduction

In this page you can find the example usage for org.xml.sax XMLReader setErrorHandler.

Prototype

public void setErrorHandler(ErrorHandler handler);

Source Link

Document

Allow an application to register an error event handler.

Usage

From source file:net.sf.firemox.xml.XmlParser.java

/**
 * Parse InputStream.//  w w w.j  a  v a 2s . c  o m
 * 
 * @param in
 *          the document source.
 * @return the node of document.
 * @throws IOException
 *           error while opening the stream.
 * @throws SAXException
 *           error while parsing.
 */
public synchronized Node parse(InputStream in) throws IOException, SAXException {
    Handler handler = new Handler();
    XMLReader reader = parser.getXMLReader();
    reader.setContentHandler(handler);
    reader.setErrorHandler(handler);
    reader.setEntityResolver(handler);
    parser.parse(new InputSource(in), handler);
    if (handler.error != null) {
        throw handler.error;
    }
    Node doc = (Node) handler.top.get(0);
    handler.clear();
    return doc;
}

From source file:SAXTreeValidator.java

/**
 * <p>This handles building the Swing UI tree.</p>
 *
 * @param treeModel Swing component to build upon.
 * @param base tree node to build on./*from  w  w  w .j a  va 2  s. co m*/
 * @param xmlURI URI to build XML document from.
 * @throws <code>IOException</code> - when reading the XML URI fails.
 * @throws <code>SAXException</code> - when errors in parsing occur.
 */
public void buildTree(DefaultTreeModel treeModel, DefaultMutableTreeNode base, String xmlURI)
        throws IOException, SAXException {

    // Create instances needed for parsing
    XMLReader reader = XMLReaderFactory.createXMLReader(vendorParserClass);
    ContentHandler jTreeContentHandler = new JValidatorContentHandler(treeModel, base);
    ErrorHandler jTreeErrorHandler = new JValidatorErrorHandler();

    // Register content handler
    reader.setContentHandler(jTreeContentHandler);

    // Register error handler
    reader.setErrorHandler(jTreeErrorHandler);

    // Turn on validation
    reader.setFeature("http://xml.org/sax/features/validation", true);
    reader.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);

    // Parse
    InputSource inputSource = new InputSource(xmlURI);
    reader.parse(inputSource);
}

From source file:hu.sztaki.lpds.pgportal.services.dspace.LNIclient.java

/**
 * Completes the two-part operation started by startPut(), by
 * collecting status of the PUT operation and converting the
 * WebDAV URI of the newly-created resource back to a Handle,
 * which it returns.//from www  .ja v a 2s  .c o  m
 * <p>
 * Any failure results in an exception.
 *
 * @return Handle of the newly-created DSpace resource.
 */
public String finishPut() throws InterruptedException, IOException, SAXException, SAXNotRecognizedException,
        ParserConfigurationException {
    if (lastPutThread != null) {
        lastPutThread.join();
        lastPutThread = null;
    }

    Header loc = lastPut.getResponseHeader("Location");
    lastStatus = lastPut.getStatusCode();
    if (lastStatus < 100 || lastStatus >= 400)
        throw new IOException("PUT returned status = " + lastStatus + "; text=" + lastPut.getStatusText());

    lastPut = null;
    if (loc != null) {
        String newURL = loc.getValue();

        // do a quick PROPFIND to get the handle
        PropfindMethod pf = new PropfindMethod(newURL, propfindBody);
        pf.setDoAuthentication(true);
        client.executeMethod(pf);

        int pfStatus = pf.getStatusCode();
        if (pfStatus < 200 || pfStatus >= 300)
            throw new IOException(
                    "finishPut.propfind got status = " + pfStatus + "; text=" + pf.getStatusText());

        // Maybe move all this crap to within Propfind class??
        // so it can get the inputstream directly?
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();
        PropfindHandler handler = new PropfindHandler();

        // XXX FIXME: should turn off validation here explicitly, but
        //  it seems to be off by default.
        xr.setFeature("http://xml.org/sax/features/namespaces", true);
        xr.setContentHandler(handler);
        xr.setErrorHandler(handler);
        xr.parse(new InputSource(pf.getResponseBodyAsStream()));

        return handler.handle;
    } else
        throw new IOException("PUT response was missing a Location: header.");
}

From source file:Counter.java

/** Main program entry point. */
public static void main(String argv[]) {

    // is there anything to do?
    if (argv.length == 0) {
        printUsage();/* w  w w. j a v  a 2 s .  co m*/
        System.exit(1);
    }

    // variables
    Counter counter = new Counter();
    PrintWriter out = new PrintWriter(System.out);
    XMLReader parser = null;
    int repetition = DEFAULT_REPETITION;
    boolean namespaces = DEFAULT_NAMESPACES;
    boolean namespacePrefixes = DEFAULT_NAMESPACE_PREFIXES;
    boolean validation = DEFAULT_VALIDATION;
    boolean schemaValidation = DEFAULT_SCHEMA_VALIDATION;
    boolean schemaFullChecking = DEFAULT_SCHEMA_FULL_CHECKING;
    boolean honourAllSchemaLocations = DEFAULT_HONOUR_ALL_SCHEMA_LOCATIONS;
    boolean validateAnnotations = DEFAULT_VALIDATE_ANNOTATIONS;
    boolean dynamicValidation = DEFAULT_DYNAMIC_VALIDATION;
    boolean xincludeProcessing = DEFAULT_XINCLUDE;
    boolean xincludeFixupBaseURIs = DEFAULT_XINCLUDE_FIXUP_BASE_URIS;
    boolean xincludeFixupLanguage = DEFAULT_XINCLUDE_FIXUP_LANGUAGE;
    boolean memoryUsage = DEFAULT_MEMORY_USAGE;
    boolean tagginess = DEFAULT_TAGGINESS;

    // process arguments
    for (int i = 0; i < argv.length; i++) {
        String arg = argv[i];
        if (arg.startsWith("-")) {
            String option = arg.substring(1);
            if (option.equals("p")) {
                // get parser name
                if (++i == argv.length) {
                    System.err.println("error: Missing argument to -p option.");
                    continue;
                }
                String parserName = argv[i];

                // create parser
                try {
                    parser = XMLReaderFactory.createXMLReader(parserName);
                } catch (Exception e) {
                    try {
                        Parser sax1Parser = ParserFactory.makeParser(parserName);
                        parser = new ParserAdapter(sax1Parser);
                        System.err.println("warning: Features and properties not supported on SAX1 parsers.");
                    } catch (Exception ex) {
                        parser = null;
                        System.err.println("error: Unable to instantiate parser (" + parserName + ")");
                    }
                }
                continue;
            }
            if (option.equals("x")) {
                if (++i == argv.length) {
                    System.err.println("error: Missing argument to -x option.");
                    continue;
                }
                String number = argv[i];
                try {
                    int value = Integer.parseInt(number);
                    if (value < 1) {
                        System.err.println("error: Repetition must be at least 1.");
                        continue;
                    }
                    repetition = value;
                } catch (NumberFormatException e) {
                    System.err.println("error: invalid number (" + number + ").");
                }
                continue;
            }
            if (option.equalsIgnoreCase("n")) {
                namespaces = option.equals("n");
                continue;
            }
            if (option.equalsIgnoreCase("np")) {
                namespacePrefixes = option.equals("np");
                continue;
            }
            if (option.equalsIgnoreCase("v")) {
                validation = option.equals("v");
                continue;
            }
            if (option.equalsIgnoreCase("s")) {
                schemaValidation = option.equals("s");
                continue;
            }
            if (option.equalsIgnoreCase("f")) {
                schemaFullChecking = option.equals("f");
                continue;
            }
            if (option.equalsIgnoreCase("hs")) {
                honourAllSchemaLocations = option.equals("hs");
                continue;
            }
            if (option.equalsIgnoreCase("va")) {
                validateAnnotations = option.equals("va");
                continue;
            }
            if (option.equalsIgnoreCase("dv")) {
                dynamicValidation = option.equals("dv");
                continue;
            }
            if (option.equalsIgnoreCase("xi")) {
                xincludeProcessing = option.equals("xi");
                continue;
            }
            if (option.equalsIgnoreCase("xb")) {
                xincludeFixupBaseURIs = option.equals("xb");
                continue;
            }
            if (option.equalsIgnoreCase("xl")) {
                xincludeFixupLanguage = option.equals("xl");
                continue;
            }
            if (option.equalsIgnoreCase("m")) {
                memoryUsage = option.equals("m");
                continue;
            }
            if (option.equalsIgnoreCase("t")) {
                tagginess = option.equals("t");
                continue;
            }
            if (option.equals("-rem")) {
                if (++i == argv.length) {
                    System.err.println("error: Missing argument to -# option.");
                    continue;
                }
                System.out.print("# ");
                System.out.println(argv[i]);
                continue;
            }
            if (option.equals("h")) {
                printUsage();
                continue;
            }
            System.err.println("error: unknown option (" + option + ").");
            continue;
        }

        // use default parser?
        if (parser == null) {

            // create parser
            try {
                parser = XMLReaderFactory.createXMLReader(DEFAULT_PARSER_NAME);
            } catch (Exception e) {
                System.err.println("error: Unable to instantiate parser (" + DEFAULT_PARSER_NAME + ")");
                continue;
            }
        }

        // set parser features
        try {
            parser.setFeature(NAMESPACES_FEATURE_ID, namespaces);
        } catch (SAXException e) {
            System.err.println("warning: Parser does not support feature (" + NAMESPACES_FEATURE_ID + ")");
        }
        try {
            parser.setFeature(NAMESPACE_PREFIXES_FEATURE_ID, namespacePrefixes);
        } catch (SAXException e) {
            System.err.println(
                    "warning: Parser does not support feature (" + NAMESPACE_PREFIXES_FEATURE_ID + ")");
        }
        try {
            parser.setFeature(VALIDATION_FEATURE_ID, validation);
        } catch (SAXException e) {
            System.err.println("warning: Parser does not support feature (" + VALIDATION_FEATURE_ID + ")");
        }
        try {
            parser.setFeature(SCHEMA_VALIDATION_FEATURE_ID, schemaValidation);
        } catch (SAXNotRecognizedException e) {
            System.err.println(
                    "warning: Parser does not recognize feature (" + SCHEMA_VALIDATION_FEATURE_ID + ")");

        } catch (SAXNotSupportedException e) {
            System.err
                    .println("warning: Parser does not support feature (" + SCHEMA_VALIDATION_FEATURE_ID + ")");
        }
        try {
            parser.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, schemaFullChecking);
        } catch (SAXNotRecognizedException e) {
            System.err.println(
                    "warning: Parser does not recognize feature (" + SCHEMA_FULL_CHECKING_FEATURE_ID + ")");

        } catch (SAXNotSupportedException e) {
            System.err.println(
                    "warning: Parser does not support feature (" + SCHEMA_FULL_CHECKING_FEATURE_ID + ")");
        }
        try {
            parser.setFeature(HONOUR_ALL_SCHEMA_LOCATIONS_ID, honourAllSchemaLocations);
        } catch (SAXNotRecognizedException e) {
            System.err.println(
                    "warning: Parser does not recognize feature (" + HONOUR_ALL_SCHEMA_LOCATIONS_ID + ")");
        } catch (SAXNotSupportedException e) {
            System.err.println(
                    "warning: Parser does not support feature (" + HONOUR_ALL_SCHEMA_LOCATIONS_ID + ")");
        }
        try {
            parser.setFeature(VALIDATE_ANNOTATIONS_ID, validateAnnotations);
        } catch (SAXNotRecognizedException e) {
            System.err.println("warning: Parser does not recognize feature (" + VALIDATE_ANNOTATIONS_ID + ")");

        } catch (SAXNotSupportedException e) {
            System.err.println("warning: Parser does not support feature (" + VALIDATE_ANNOTATIONS_ID + ")");
        }
        try {
            parser.setFeature(DYNAMIC_VALIDATION_FEATURE_ID, dynamicValidation);
        } catch (SAXNotRecognizedException e) {
            System.err.println(
                    "warning: Parser does not recognize feature (" + DYNAMIC_VALIDATION_FEATURE_ID + ")");

        } catch (SAXNotSupportedException e) {
            System.err.println(
                    "warning: Parser does not support feature (" + DYNAMIC_VALIDATION_FEATURE_ID + ")");
        }
        try {
            parser.setFeature(XINCLUDE_FEATURE_ID, xincludeProcessing);
        } catch (SAXNotRecognizedException e) {
            System.err.println("warning: Parser does not recognize feature (" + XINCLUDE_FEATURE_ID + ")");

        } catch (SAXNotSupportedException e) {
            System.err.println("warning: Parser does not support feature (" + XINCLUDE_FEATURE_ID + ")");
        }
        try {
            parser.setFeature(XINCLUDE_FIXUP_BASE_URIS_FEATURE_ID, xincludeFixupBaseURIs);
        } catch (SAXNotRecognizedException e) {
            System.err.println(
                    "warning: Parser does not recognize feature (" + XINCLUDE_FIXUP_BASE_URIS_FEATURE_ID + ")");

        } catch (SAXNotSupportedException e) {
            System.err.println(
                    "warning: Parser does not support feature (" + XINCLUDE_FIXUP_BASE_URIS_FEATURE_ID + ")");
        }
        try {
            parser.setFeature(XINCLUDE_FIXUP_LANGUAGE_FEATURE_ID, xincludeFixupLanguage);
        } catch (SAXNotRecognizedException e) {
            System.err.println(
                    "warning: Parser does not recognize feature (" + XINCLUDE_FIXUP_LANGUAGE_FEATURE_ID + ")");

        } catch (SAXNotSupportedException e) {
            System.err.println(
                    "warning: Parser does not support feature (" + XINCLUDE_FIXUP_LANGUAGE_FEATURE_ID + ")");
        }

        // parse file
        parser.setContentHandler(counter);
        parser.setErrorHandler(counter);
        try {
            long timeBefore = System.currentTimeMillis();
            long memoryBefore = Runtime.getRuntime().freeMemory();
            for (int j = 0; j < repetition; j++) {
                parser.parse(arg);
            }
            long memoryAfter = Runtime.getRuntime().freeMemory();
            long timeAfter = System.currentTimeMillis();

            long time = timeAfter - timeBefore;
            long memory = memoryUsage ? memoryBefore - memoryAfter : Long.MIN_VALUE;
            counter.printResults(out, arg, time, memory, tagginess, repetition);
        } catch (SAXParseException e) {
            // ignore
        } catch (Exception e) {
            System.err.println("error: Parse error occurred - " + e.getMessage());
            Exception se = e;
            if (e instanceof SAXException) {
                se = ((SAXException) e).getException();
            }
            if (se != null)
                se.printStackTrace(System.err);
            else
                e.printStackTrace(System.err);

        }
    }

}

From source file:org.esco.grouper.parsing.SGSParsingUtil.java

/**
 * Starts the parsing process./* ww  w. ja  v a 2 s . co  m*/
 * @throws SAXException If there is an error during the parsing (invalid group defintion for instance).
 * @throws IOException  If there is an IO error.
 */
public void parse() throws IOException, SAXException {

    XMLReader saxReader = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
    saxReader.setFeature("http://xml.org/sax/features/validation", true);
    saxReader.setContentHandler(this);
    saxReader.setErrorHandler(this);
    saxReader.setEntityResolver(this);
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("---------------------------------");
        LOGGER.info("Parsing definition file: ");
        LOGGER.info(definitionsFileURI);
        LOGGER.info("---------------------------------");
    }
    InputStream iStream = getClass().getClassLoader().getResourceAsStream(definitionsFileURI);

    if (iStream == null) {
        LOGGER.fatal("Unable to load (from classpath) file: " + definitionsFileURI + ".");
    }

    //final InputSource is =
    saxReader.parse(new InputSource(iStream));

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("---------------------------------");
        LOGGER.info("Definition file parsed.");
        LOGGER.info("---------------------------------");
    }
}

From source file:com.cloudhopper.sxmp.SxmpParser.java

/**
public Node parse(InputSource source) throws IOException, SAXException {
//        _dtd=null;//w  ww.  jav  a  2  s  .c om
Handler handler = new Handler();
XMLReader reader = _parser.getXMLReader();
reader.setContentHandler(handler);
reader.setErrorHandler(handler);
reader.setEntityResolver(handler);
if (logger.isDebugEnabled())
    logger.debug("parsing: sid=" + source.getSystemId() + ",pid=" + source.getPublicId());
_parser.parse(source, handler);
if (handler.error != null)
    throw handler.error;
Node root = (Node)handler.root;
handler.reset();
return root;
}
        
public synchronized Node parse(String xml) throws IOException, SAXException {
ByteArrayInputStream is = new ByteArrayInputStream(xml.getBytes());
return parse(is);
}
        
public synchronized Node parse(File file) throws IOException, SAXException {
return parse(new InputSource(file.toURI().toURL().toString()));
}
        
public synchronized Node parse(InputStream in) throws IOException, SAXException {
//_dtd=null;
Handler handler = new Handler();
XMLReader reader = _parser.getXMLReader();
reader.setContentHandler(handler);
reader.setErrorHandler(handler);
reader.setEntityResolver(handler);
_parser.parse(new InputSource(in), handler);
if (handler.error != null)
    throw handler.error;
Node root = (Node)handler.root;
handler.reset();
return root;
}
 */

public Operation parse(InputStream in)
        throws SxmpParsingException, IOException, SAXException, ParserConfigurationException {
    // create a new SAX parser
    SAXParserFactory factory = SAXParserFactory.newInstance();
    //factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);

    SAXParser parser = factory.newSAXParser();
    //_parser.getXMLReader().setFeature("http://xml.org/sax/features/validation", validating);
    parser.getXMLReader().setFeature("http://xml.org/sax/features/namespaces", true);
    parser.getXMLReader().setFeature("http://xml.org/sax/features/namespace-prefixes", true);
    parser.getXMLReader().setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true);

    //_dtd=null;
    Handler handler = new Handler();
    XMLReader reader = parser.getXMLReader();
    reader.setContentHandler(handler);
    reader.setErrorHandler(handler);
    reader.setEntityResolver(handler);

    // try parsing (may throw an SxmpParsingException in the handler)
    try {
        parser.parse(new InputSource(in), handler);
    } catch (com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException e) {
        throw new SxmpParsingException(SxmpErrorCode.INVALID_XML, "XML encoding mismatch", null);
    }

    // check if there was an error
    if (handler.error != null) {
        throw handler.error;
    }

    // check to see if an operation was actually parsed
    if (handler.getOperation() == null) {
        throw new SxmpParsingException(SxmpErrorCode.MISSING_REQUIRED_ELEMENT,
                "The operation type [" + handler.operationType.getValue() + "] requires a request element",
                new PartialOperation(handler.operationType));
    }

    // if we got here, an operation was parsed -- now we need to validate it
    // to make sure that it has all required elements
    try {
        handler.getOperation().validate();
    } catch (SxmpErrorException e) {
        throw new SxmpParsingException(e.getErrorCode(), e.getErrorMessage(), handler.getOperation());
    }

    return handler.getOperation();
}

From source file:edu.lternet.pasta.dml.dataquery.DataquerySpecification.java

/**
 * Set up the SAX parser for reading the XML serialized query
 *//*ww w . j ava2s  . co m*/
private XMLReader initializeParser() {
    XMLReader parser = null;

    // Set up the SAX document handlers for parsing
    try {

        // Get an instance of the parser
        parser = XMLReaderFactory.createXMLReader(parserName);

        // Set the ContentHandler to this instance
        parser.setContentHandler(this);

        // Set the error Handler to this instance
        parser.setErrorHandler(this);

    } catch (Exception e) {
        System.err.println("Error in QuerySpcecification.initializeParser " + e.toString());
    }

    return parser;
}

From source file:de.uzk.hki.da.sb.Cli.java

/**
 * Copies the files listed in a SIP list to a single directory
 * //from   w  w w .j a  v  a  2 s  .  c o  m
 * @param fileListFile The SIP list file
 * @return The path to the directory containing the files
 */
private String copySipListContentToFolder(File sipListFile) {

    CliProgressManager progressManager = new CliProgressManager();

    String tempFolderName = getTempFolderName();

    XMLReader xmlReader = null;
    SAXParserFactory spf = SAXParserFactory.newInstance();
    try {
        xmlReader = spf.newSAXParser().getXMLReader();
    } catch (Exception e) {
        logger.log("ERROR: Failed to create SAX parser", e);
        System.out.println("Fehler beim Einlesen der SIP-Liste: SAX-Parser konnte nicht erstellt werden.");
        return "";
    }
    xmlReader.setErrorHandler(new ErrorHandler() {

        @Override
        public void error(SAXParseException e) throws SAXException {
            throw new SAXException("Beim Einlesen der SIP-Liste ist ein Fehler aufgetreten.", e);
        }

        @Override
        public void fatalError(SAXParseException e) throws SAXException {
            throw new SAXException("Beim Einlesen der SIP-Liste ist ein schwerer Fehler aufgetreten.", e);
        }

        @Override
        public void warning(SAXParseException e) throws SAXException {
            logger.log("WARNING: Warning while parsing siplist", e);
            System.out.println("\nWarnung:\n" + e.getMessage());
        }
    });

    InputStream inputStream;
    try {
        inputStream = new FileInputStream(sipListFile);

        Reader reader = new InputStreamReader(inputStream, "UTF-8");
        Builder parser = new Builder(xmlReader);
        Document doc = parser.build(reader);
        reader.close();

        Element root = doc.getRootElement();
        Elements sipElements = root.getChildElements("sip");

        long files = 0;
        for (int i = 0; i < sipElements.size(); i++) {
            Elements fileElements = sipElements.get(i).getChildElements("file");
            if (fileElements != null)
                files += fileElements.size();
        }
        progressManager.setTotalSize(files);

        for (int i = 0; i < sipElements.size(); i++) {
            Element sipElement = sipElements.get(i);
            String sipName = sipElement.getAttributeValue("name");

            File tempDirectory = new File(tempFolderName + File.separator + sipName);
            if (tempDirectory.exists()) {
                FileUtils.deleteQuietly(new File(tempFolderName));
                System.out.println("\nDie SIP-Liste enthlt mehrere SIPs mit dem Namen " + sipName + ". "
                        + "Bitte vergeben Sie fr jedes SIP einen eigenen Namen.");
                return "";
            }
            tempDirectory.mkdirs();

            Elements fileElements = sipElement.getChildElements("file");

            for (int j = 0; j < fileElements.size(); j++) {
                Element fileElement = fileElements.get(j);
                String filepath = fileElement.getValue();

                File file = new File(filepath);
                if (!file.exists()) {
                    logger.log("ERROR: File " + file.getAbsolutePath() + " is referenced in siplist, "
                            + "but does not exist");
                    System.out.println("\nDie in der SIP-Liste angegebene Datei " + file.getAbsolutePath()
                            + " existiert nicht.");
                    FileUtils.deleteQuietly(new File(tempFolderName));
                    return "";
                }

                try {
                    if (file.isDirectory())
                        FileUtils.copyDirectoryToDirectory(file, tempDirectory);
                    else
                        FileUtils.copyFileToDirectory(file, tempDirectory);
                    progressManager.copyFilesFromListProgress();
                } catch (IOException e) {
                    logger.log("ERROR: Failed to copy file " + file.getAbsolutePath() + " to folder "
                            + tempDirectory.getAbsolutePath(), e);
                    System.out.println("\nDie in der SIP-Liste angegebene Datei " + file.getAbsolutePath()
                            + " konnte nicht kopiert werden.");
                    FileUtils.deleteQuietly(new File(tempFolderName));
                    return "";
                }
            }
        }
    } catch (Exception e) {
        logger.log("ERROR: Failed to read siplist " + sipListFile.getAbsolutePath(), e);
        System.out.println("\nBeim Lesen der SIP-Liste ist ein Fehler aufgetreten. ");
        return "";
    }

    return (new File(tempFolderName).getAbsolutePath());
}

From source file:de.uzk.hki.da.cli.Cli.java

/**
 * Copies the files listed in a SIP list to a single directory
 * //from  w  w  w  .  j a  v a2 s. c o m
 * @param fileListFile The SIP list file
 * @return The path to the directory containing the files
 */
private String copySipListContentToFolder(File sipListFile) {

    CliProgressManager progressManager = new CliProgressManager();

    String tempFolderName = getTempFolderName();

    XMLReader xmlReader = null;
    SAXParserFactory spf = SAXParserFactory.newInstance();
    try {
        xmlReader = spf.newSAXParser().getXMLReader();
    } catch (Exception e) {
        logger.error("Failed to create SAX parser", e);
        System.out.println("Fehler beim Einlesen der SIP-Liste: SAX-Parser konnte nicht erstellt werden.");
        return "";
    }
    xmlReader.setErrorHandler(new ErrorHandler() {

        @Override
        public void error(SAXParseException e) throws SAXException {
            throw new SAXException("Beim Einlesen der SIP-Liste ist ein Fehler aufgetreten.", e);
        }

        @Override
        public void fatalError(SAXParseException e) throws SAXException {
            throw new SAXException("Beim Einlesen der SIP-Liste ist ein schwerer Fehler aufgetreten.", e);
        }

        @Override
        public void warning(SAXParseException e) throws SAXException {
            logger.warn("Warning while parsing siplist", e);
            System.out.println("\nWarnung:\n" + e.getMessage());
        }
    });

    InputStream inputStream;
    try {
        inputStream = new FileInputStream(sipListFile);

        Reader reader = new InputStreamReader(inputStream, "UTF-8");
        Builder parser = new Builder(xmlReader);
        Document doc = parser.build(reader);
        reader.close();

        Element root = doc.getRootElement();
        Elements sipElements = root.getChildElements("sip");

        long files = 0;
        for (int i = 0; i < sipElements.size(); i++) {
            Elements fileElements = sipElements.get(i).getChildElements("file");
            if (fileElements != null)
                files += fileElements.size();
        }
        progressManager.setTotalSize(files);

        for (int i = 0; i < sipElements.size(); i++) {
            Element sipElement = sipElements.get(i);
            String sipName = sipElement.getAttributeValue("name");

            File tempDirectory = new File(tempFolderName + File.separator + sipName);
            if (tempDirectory.exists()) {
                FolderUtils.deleteQuietlySafe(new File(tempFolderName));
                System.out.println("\nDie SIP-Liste enthlt mehrere SIPs mit dem Namen " + sipName + ". "
                        + "Bitte vergeben Sie fr jedes SIP einen eigenen Namen.");
                return "";
            }
            tempDirectory.mkdirs();

            Elements fileElements = sipElement.getChildElements("file");

            for (int j = 0; j < fileElements.size(); j++) {
                Element fileElement = fileElements.get(j);
                String filepath = fileElement.getValue();

                File file = new File(filepath);
                if (!file.exists()) {
                    logger.error("File " + file.getAbsolutePath() + " is referenced in siplist, "
                            + "but does not exist");
                    System.out.println("\nDie in der SIP-Liste angegebene Datei " + file.getAbsolutePath()
                            + " existiert nicht.");
                    FolderUtils.deleteQuietlySafe(new File(tempFolderName));
                    return "";
                }

                try {
                    if (file.isDirectory())
                        FileUtils.copyDirectoryToDirectory(file, tempDirectory);
                    else
                        FileUtils.copyFileToDirectory(file, tempDirectory);
                    progressManager.copyFilesFromListProgress();
                } catch (IOException e) {
                    logger.error("Failed to copy file " + file.getAbsolutePath() + " to folder "
                            + tempDirectory.getAbsolutePath(), e);
                    System.out.println("\nDie in der SIP-Liste angegebene Datei " + file.getAbsolutePath()
                            + " konnte nicht kopiert werden.");
                    FolderUtils.deleteQuietlySafe(new File(tempFolderName));
                    return "";
                }
            }
        }
    } catch (Exception e) {
        logger.error("Failed to read siplist " + sipListFile.getAbsolutePath(), e);
        System.out.println("\nBeim Lesen der SIP-Liste ist ein Fehler aufgetreten. ");
        return "";
    }

    return (new File(tempFolderName).getAbsolutePath());
}