Example usage for org.xml.sax SAXException getMessage

List of usage examples for org.xml.sax SAXException getMessage

Introduction

In this page you can find the example usage for org.xml.sax SAXException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Return a detail message for this exception.

Usage

From source file:edu.ucsd.xmlrpc.xmlrpc.server.XmlRpcStreamServer.java

protected void writeError(XmlRpcStreamRequestConfig pConfig, OutputStream pStream, Throwable pError)
        throws XmlRpcException {
    final Throwable error = convertThrowable(pError);
    final int code;
    final String message;
    if (error instanceof XmlRpcException) {
        XmlRpcException ex = (XmlRpcException) error;
        code = ex.code;/*from w  ww  . j a v a2  s .c  o  m*/
    } else {
        code = 0;
    }
    message = error.getMessage();
    try {
        getXmlRpcWriter(pConfig, pStream).write(pConfig, code, message, error);
    } catch (SAXException e) {
        throw new XmlRpcException("Failed to write XML-RPC response: " + e.getMessage(), e);
    }
}

From source file:com.aurel.track.exchange.docx.importer.HTMLParser.java

private void parse(ByteArrayOutputStream byteArrayOutputStream, Locale locale) {
    localizedHeading = "berschrift";//LocalizeUtil.getLocalizedTextFromApplicationResources(HEADING_KEY, locale);
    SAXParserFactory spf = SAXParserFactory.newInstance();
    Reader fileReader = null;/*w ww.j  a va  2s .c  o  m*/
    try {
        fileReader = new FileReader(new File("d:/docx/PN164_SC_Track.docx.html"));
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        LOGGER.error(ExceptionUtils.getStackTrace(e));
    }
    try {
        //get a new instance of parser
        SAXParser sp = spf.newSAXParser();
        //InputSource is=new InputSource(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
        InputSource is = new InputSource(fileReader);
        sp.parse(is, this);
    } catch (SAXException se) {
        LOGGER.error("Parsing failed with " + se.getMessage());
        if (LOGGER.isDebugEnabled()) {
            LOGGER.error(ExceptionUtils.getStackTrace(se));
        }
    } catch (ParserConfigurationException pce) {
        LOGGER.error("Parsing failed with " + pce.getMessage());
        if (LOGGER.isDebugEnabled()) {
            LOGGER.error(ExceptionUtils.getStackTrace(pce));
        }
    } catch (IOException ie) {
        LOGGER.error("Reading failed with " + ie.getMessage());
        LOGGER.error(ExceptionUtils.getStackTrace(ie));
    }
}

From source file:net.sf.joost.trax.TemplatesImpl.java

/**
 * Configures the <code>Templates</code> - initializing with a completed
 *  <code>Parser</code> object.
 * @param stxParser A <code>Parser</code>
 * @throws TransformerConfigurationException When an error occurs while
 *  initializing the <code>Templates</code>.
 *//*from w  ww  .  j a  va  2 s  .c o m*/
private void init(Parser stxParser) throws TransformerConfigurationException {

    if (DEBUG)
        log.debug("init without InputSource ");
    try {
        // check if transformerfactory is in debug mode
        boolean debugmode = ((Boolean) this.factory.getAttribute(DEBUG_FEATURE)).booleanValue();

        if (debugmode) {
            if (log != null)
                log.info("init transformer in debug mode");
            processor = new DebugProcessor(stxParser);
        } else {
            processor = new Processor(stxParser);
        }
        processor.setTransformerHandlerResolver(factory.thResolver);
        processor.setOutputURIResolver(factory.outputUriResolver);
    } catch (org.xml.sax.SAXException sE) {
        if (log != null)
            log.fatal(sE);
        throw new TransformerConfigurationException(sE.getMessage());
    } catch (java.lang.NullPointerException nE) {
        if (log != null)
            log.fatal(nE);
        throw new TransformerConfigurationException(
                "Could not found value for property javax.xml.parsers.SAXParser " + nE.getMessage());
    }
}

From source file:edu.wustl.bulkoperator.templateImport.AbstractImportBulkOperation.java

/**
 *
 * @param operationName/*from w w  w .j  av  a  2s. co  m*/
 * @param dropdownName
 * @param csvFile
 * @param xmlFile
 * @param mappingXml
 * @return
 * @throws BulkOperationException
 * @throws SQLException
 * @throws IOException
 * @throws DAOException
 */
protected Set<String> validate(String operationName, String dropdownName, String csvFile, String xmlFile,
        String mappingXml, String xsdLocation)
        throws BulkOperationException, SQLException, IOException, DAOException {
    Set<String> errorList = null;
    CsvReader csvReader = null;
    try {
        csvReader = CsvFileReader.createCsvFileReader(csvFile, true);

    } catch (Exception exp) {
        ErrorKey errorkey = ErrorKey.getErrorKey("bulk.error.incorrect.csv.file");
        throw new BulkOperationException(errorkey, exp, "");
    }
    BulkOperationMetaData bulkOperationMetaData = null;
    try {
        SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
        File schemaLocation = new File(xsdLocation);
        Schema schema = factory.newSchema(schemaLocation);
        DigesterLoader digesterLoader = DigesterLoader.newLoader(new XmlRulesModule(mappingXml));
        Digester digester = digesterLoader.newDigester();
        digester.setValidating(true);
        digester.setXMLSchema(schema);
        Validator validator = schema.newValidator();
        Source xmlFileForValidation = new StreamSource(new File(xmlFile));
        validator.validate(xmlFileForValidation);
        InputStream inputStream = new FileInputStream(xmlFile);
        bulkOperationMetaData = digester.parse(inputStream);
    } catch (SAXException e) {
        logger.debug(e.getMessage());
        ErrorKey errorkey = ErrorKey.getErrorKey("bulk.error.xml.template");
        throw new BulkOperationException(errorkey, e, e.getMessage());
    }
    Collection<BulkOperationClass> classList = bulkOperationMetaData.getBulkOperationClass();
    if (classList == null) {
        ErrorKey errorkey = ErrorKey.getErrorKey("bulk.no.templates.loaded.message");
        throw new BulkOperationException(errorkey, null, "");
    } else {
        Iterator<BulkOperationClass> iterator = classList.iterator();
        if (iterator.hasNext()) {
            BulkOperationClass bulkOperationClass = iterator.next();
            TemplateValidator templateValidator = new TemplateValidator();
            errorList = templateValidator.validateXmlAndCsv(bulkOperationClass, operationName, csvReader);
        }
    }
    return errorList;
}

From source file:fr.paris.lutece.plugins.dila.modules.solr.utils.parsers.DilaSolrPublicParser.java

/**
 * Launches the parsing on each public card
 *
 * @param fileBasePath the base path//from  w ww . ja  v a  2s  .  com
 * @param parser the SAX parser
 */
private void parseAllPublicCards(File fileBasePath, SAXParser parser) {
    if (fileBasePath.isFile()) {
        // Launches the parsing of this public card (with the current handler)
        try {
            parser.parse(fileBasePath.getAbsolutePath(), this);
        } catch (SAXException e) {
            AppLogService.error(e.getMessage(), e);
        } catch (IOException e) {
            AppLogService.error(e.getMessage(), e);
        }
    } else {
        // Processes all the files of the current directory
        File[] files = fileBasePath.listFiles();

        for (File fileCurrent : files) {
            // Launches the parsing on each public card (recursive)
            parseAllPublicCards(fileCurrent, parser);
        }
    }
}

From source file:com.aurel.track.exchange.docx.importer.HTMLParser.java

private void parse(String fileName, Locale locale) {
    //get a factory
    localizedHeading = "berschrift";//LocalizeUtil.getLocalizedTextFromApplicationResources(HEADING_KEY, locale);
    SAXParserFactory spf = SAXParserFactory.newInstance();
    try {/*  w ww.  jav  a 2s. co m*/
        //get a new instance of parser
        SAXParser sp = spf.newSAXParser();
        //spf.setValidating(true);
        XMLReader xmlReader = sp.getXMLReader();
        xmlReader.setErrorHandler(new MyErrorHandler(System.err));
        xmlReader.setContentHandler(this);
        //parse the file and also register this class for call backs
        //InputSource is=new InputSource(new StringReader(xml));
        xmlReader.parse(convertToFileURL(fileName));
    } catch (SAXException se) {
        LOGGER.error("Parsing the file " + fileName + " failed with " + se.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(se));
    } catch (ParserConfigurationException pce) {
        LOGGER.error("Parsing the file " + fileName + " failed with " + pce.getMessage());
        if (LOGGER.isDebugEnabled()) {
            LOGGER.error(ExceptionUtils.getStackTrace(pce));
        }
    } catch (IOException ie) {
        LOGGER.error("Reading the file " + fileName + " failed with " + ie.getMessage());
        LOGGER.error(ExceptionUtils.getStackTrace(ie));
    }

}

From source file:com.panet.imeta.job.entries.xsdvalidator.JobEntryXSDValidator.java

public Result execute(Result previousResult, int nr, Repository rep, Job parentJob) {
    LogWriter log = LogWriter.getInstance();
    Result result = previousResult;
    result.setResult(false);/*from  www  .  j av a  2  s  .co m*/

    String realxmlfilename = getRealxmlfilename();
    String realxsdfilename = getRealxsdfilename();

    FileObject xmlfile = null;
    FileObject xsdfile = null;

    try

    {

        if (xmlfilename != null && xsdfilename != null) {
            xmlfile = KettleVFS.getFileObject(realxmlfilename);
            xsdfile = KettleVFS.getFileObject(realxsdfilename);

            if (xmlfile.exists() && xsdfile.exists()) {

                SchemaFactory factorytXSDValidator_1 = SchemaFactory
                        .newInstance("http://www.w3.org/2001/XMLSchema");

                // Get XSD File
                File XSDFile = new File(KettleVFS.getFilename(xsdfile));
                Schema SchematXSD = factorytXSDValidator_1.newSchema(XSDFile);

                Validator XSDValidator = SchematXSD.newValidator();

                // Get XML File
                File xmlfiletXSDValidator_1 = new File(KettleVFS.getFilename(xmlfile));

                Source sourcetXSDValidator_1 = new StreamSource(xmlfiletXSDValidator_1);

                XSDValidator.validate(sourcetXSDValidator_1);

                // Everything is OK
                result.setResult(true);

            } else {

                if (!xmlfile.exists()) {
                    log.logError(toString(),
                            Messages.getString("JobEntryXSDValidator.FileDoesNotExist1.Label") + realxmlfilename
                                    + Messages.getString("JobEntryXSDValidator.FileDoesNotExist2.Label"));
                }
                if (!xsdfile.exists()) {
                    log.logError(toString(),
                            Messages.getString("JobEntryXSDValidator.FileDoesNotExist1.Label") + realxsdfilename
                                    + Messages.getString("JobEntryXSDValidator.FileDoesNotExist2.Label"));
                }
                result.setResult(false);
                result.setNrErrors(1);
            }

        } else {
            log.logError(toString(), Messages.getString("JobEntryXSDValidator.AllFilesNotNull.Label"));
            result.setResult(false);
            result.setNrErrors(1);
        }

    }

    catch (SAXException ex) {
        log.logError(toString(), "Error :" + ex.getMessage());
    } catch (Exception e) {

        log.logError(toString(),
                Messages.getString("JobEntryXSDValidator.ErrorXSDValidator.Label")
                        + Messages.getString("JobEntryXSDValidator.ErrorXML1.Label") + realxmlfilename
                        + Messages.getString("JobEntryXSDValidator.ErrorXML2.Label")
                        + Messages.getString("JobEntryXSDValidator.ErrorXSD1.Label") + realxsdfilename
                        + Messages.getString("JobEntryXSDValidator.ErrorXSD2.Label") + e.getMessage());
        result.setResult(false);
        result.setNrErrors(1);
    } finally {
        try {
            if (xmlfile != null)
                xmlfile.close();

            if (xsdfile != null)
                xsdfile.close();

        } catch (IOException e) {
        }
    }

    return result;
}

From source file:com.google.enterprise.adaptor.experimental.Sim.java

private void processMultipartPost(HttpExchange ex) throws IOException {
    InputStream inStream = ex.getRequestBody();
    String encoding = ex.getRequestHeaders().getFirst("Content-encoding");
    if (null != encoding && "gzip".equals(encoding.toLowerCase())) {
        inStream = new GZIPInputStream(inStream);
    }/*from  w  w w . j a v a 2  s .  c  om*/
    String lens = ex.getRequestHeaders().getFirst("Content-Length");
    long len = (null != lens) ? Long.parseLong(lens) : 0;
    String ct = ex.getRequestHeaders().getFirst("Content-Type");
    try {
        String xml = extractFeedFromMultipartPost(inStream, len, ct);
        processXml(xml);
        respond(ex, HttpURLConnection.HTTP_OK, "text/plain", "Success".getBytes(UTF8));
    } catch (NoXmlFound nox) {
        log.warning("failed to find xml");
        respond(ex, HttpURLConnection.HTTP_BAD_REQUEST, "text/plain", "xml beginning not found".getBytes(UTF8));
    } catch (SAXException saxe) {
        log.warning("sax error: " + saxe.getMessage());
        respond(ex, HttpURLConnection.HTTP_BAD_REQUEST, "text/plain", "sax not liking the xml".getBytes(UTF8));
    } catch (ParserConfigurationException confige) {
        log.warning("parser error: " + confige.getMessage());
        respond(ex, HttpURLConnection.HTTP_BAD_REQUEST, "text/plain", "parser error".getBytes(UTF8));
    } catch (BadFeed bad) {
        log.warning("error in feed: " + bad.getMessage());
        respond(ex, HttpURLConnection.HTTP_BAD_REQUEST, "text/plain", bad.getMessage().getBytes(UTF8));
    }
}

From source file:net.sbbi.upnp.messages.StateVariableMessage.java

/**
 * Executes the state variable query and retuns the UPNP device response, according to the UPNP specs,
 * this method could take up to 30 secs to process ( time allowed for a device to respond to a request )
 * @return a state variable response object containing the variable value
 * @throws IOException if some IOException occurs during message send and reception process
 * @throws UPNPResponseException if an UPNP error message is returned from the server
 *         or if some parsing exception occurs ( detailErrorCode = 899, detailErrorDescription = SAXException message )
 *//*from   www. ja v a  2  s. co  m*/
public StateVariableResponse service() throws IOException, UPNPResponseException {
    StateVariableResponse rtrVal = null;
    UPNPResponseException upnpEx = null;
    IOException ioEx = null;
    StringBuffer body = new StringBuffer(256);

    body.append("<?xml version=\"1.0\"?>\r\n");
    body.append("<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"");
    body.append(" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">");
    body.append("<s:Body>");
    body.append("<u:QueryStateVariable xmlns:u=\"urn:schemas-upnp-org:control-1-0\">");
    body.append("<u:varName>").append(serviceStateVar.getName()).append("</u:varName>");
    body.append("</u:QueryStateVariable>");
    body.append("</s:Body>");
    body.append("</s:Envelope>");

    if (log.isDebugEnabled())
        log.debug("POST prepared for URL " + service.getControlURL());
    URL url = new URL(service.getControlURL().toString());
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setDoInput(true);
    conn.setDoOutput(true);
    conn.setUseCaches(false);
    conn.setRequestMethod("POST");
    HttpURLConnection.setFollowRedirects(false);
    //conn.setConnectTimeout( 30000 );
    conn.setRequestProperty("HOST", url.getHost() + ":" + url.getPort());
    conn.setRequestProperty("SOAPACTION", "\"urn:schemas-upnp-org:control-1-0#QueryStateVariable\"");
    conn.setRequestProperty("CONTENT-TYPE", "text/xml; charset=\"utf-8\"");
    conn.setRequestProperty("CONTENT-LENGTH", Integer.toString(body.length()));
    OutputStream out = conn.getOutputStream();
    out.write(body.toString().getBytes());
    out.flush();
    conn.connect();
    InputStream input = null;

    if (log.isDebugEnabled())
        log.debug("executing query :\n" + body);
    try {
        input = conn.getInputStream();
    } catch (IOException ex) {
        // java can throw an exception if he error code is 500 or 404 or something else than 200
        // but the device sends 500 error message with content that is required
        // this content is accessible with the getErrorStream
        input = conn.getErrorStream();
    }

    if (input != null) {
        int response = conn.getResponseCode();
        String responseBody = getResponseBody(input);
        if (log.isDebugEnabled())
            log.debug("received response :\n" + responseBody);
        SAXParserFactory saxParFact = SAXParserFactory.newInstance();
        saxParFact.setValidating(false);
        saxParFact.setNamespaceAware(true);
        StateVariableResponseParser msgParser = new StateVariableResponseParser(serviceStateVar);
        StringReader stringReader = new StringReader(responseBody);
        InputSource src = new InputSource(stringReader);
        try {
            SAXParser parser = saxParFact.newSAXParser();
            parser.parse(src, msgParser);
        } catch (ParserConfigurationException confEx) {
            // should never happen
            // we throw a runtimeException to notify the env problem
            throw new RuntimeException(
                    "ParserConfigurationException during SAX parser creation, please check your env settings:"
                            + confEx.getMessage());
        } catch (SAXException saxEx) {
            // kind of tricky but better than nothing..
            upnpEx = new UPNPResponseException(899, saxEx.getMessage());
        } finally {
            try {
                input.close();
            } catch (IOException ex) {
                // ignoring
            }
        }
        if (upnpEx == null) {
            if (response == HttpURLConnection.HTTP_OK) {
                rtrVal = msgParser.getStateVariableResponse();
            } else if (response == HttpURLConnection.HTTP_INTERNAL_ERROR) {
                upnpEx = msgParser.getUPNPResponseException();
            } else {
                ioEx = new IOException("Unexpected server HTTP response:" + response);
            }
        }
    }
    try {
        out.close();
    } catch (IOException ex) {
        // ignore
    }
    conn.disconnect();
    if (upnpEx != null) {
        throw upnpEx;
    }
    if (rtrVal == null && ioEx == null) {
        ioEx = new IOException("Unable to receive a response from the UPNP device");
    }
    if (ioEx != null) {
        throw ioEx;
    }
    return rtrVal;
}

From source file:cz.muni.fi.mir.mathmlcanonicalization.MathMLCanonicalizer.java

/**
 * Validate the configuration against XML Schema.
 *
 * @throws ConfigException if not valid//ww  w. j a  v  a  2  s . c  o  m
 */
private void validateXMLConfiguration(InputStream xmlConfigurationStream) throws IOException, ConfigException {
    assert xmlConfigurationStream != null;
    final SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    try {
        final Schema schema = sf
                .newSchema(MathMLCanonicalizer.class.getResource(Settings.getProperty("configSchema")));

        final Validator validator = schema.newValidator();
        validator.validate(new StreamSource(xmlConfigurationStream));
    } catch (SAXException ex) {
        throw new ConfigException("configuration not valid\n" + ex.getMessage(), ex);
    }
}