Example usage for org.xml.sax SAXParseException getMessage

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

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Return a detail message for this exception.

Usage

From source file:net.i2cat.netconf.transport.TransportContentParser.java

@Override
public void error(SAXParseException e) throws SAXException {
    // super.error(e);
    log.warn(e.getMessage());
}

From source file:com.itude.mobile.mobbl.core.model.parser.MBXmlDocumentParser.java

@Override
public void error(SAXParseException e) throws SAXException {

    String message = "Error parsing document " + _definition.getName() + " at line " + e.getLineNumber()
            + " column " + e.getColumnNumber() + ": " + e.getMessage();

    throw new MBParseErrorException(message);
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.util.QCliveXMLSchemaValidator.java

protected Boolean validateSchema(final List<Source> schemaSourceList, final Document document,
        final File xmlFile, final QcContext context) throws SAXException, IOException {

    final SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    // instantiate the schema
    Schema schema = factory.newSchema(schemaSourceList.toArray(new Source[] {}));
    // now validate the file against the schema
    // note: supposedly there is a way to just let the XML document figure
    // out its own schema based on what is referred to, but
    // I could not get that to work, which is why I am looking for the
    // schema in the attribute

    final DOMSource source = new DOMSource(document);
    final Validator validator = schema.newValidator();

    // wow this looks dumb, but isValid has to be final to be accessed from
    // within an inner class
    // and this was IDEA's solution to the problem: make it an array and set
    // the first element of the array
    final boolean[] isValid = new boolean[] { true };

    // add error handler that will add validation errors and warnings
    // directly to the QcContext object
    validator.setErrorHandler(new ErrorHandler() {
        public void warning(final SAXParseException exception) {
            context.addWarning(new StringBuilder().append(xmlFile.getName()).append(": ")
                    .append(exception.getMessage()).toString());
        }//from   w  w  w. j a  va2 s. c om

        public void error(final SAXParseException exception) {
            context.addError(MessageFormat.format(MessagePropertyType.XML_FILE_PROCESSING_ERROR,
                    xmlFile.getName(), new StringBuilder().append(xmlFile.getName()).append(": ")
                            .append(exception.getMessage()).toString()));
            isValid[0] = false;
        }

        public void fatalError(final SAXParseException exception) throws SAXException {
            context.getArchive().setDeployStatus(Archive.STATUS_INVALID);
            throw exception;
        }
    });
    validator.validate(source);
    return isValid[0];
}

From source file:net.i2cat.netconf.transport.TransportContentParser.java

@Override
public void fatalError(SAXParseException e) throws SAXException {
    // TODO Auto-generated method stub
    // super.fatalError(e);
    log.warn(e.getMessage());
}

From source file:kmlvalidator.KmlValidatorServlet.java

/**
 * Handles POST requests for the servlet.
 *//*from w  ww .j a v a 2  s  .  c  om*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
    // Our response is always JSON.
    response.setContentType("application/json");

    // Create the JSON response objects to be filled in later.
    JSONObject responseObj = new JSONObject();
    JSONArray responseErrors = new JSONArray();

    try {
        // Load XSD files here. Note that the Java runtime should be caching
        // these files.
        Object[] schemas = {
                new URL("http://schemas.opengis.net/kml/2.2.0/atom-author-link.xsd").openConnection()
                        .getInputStream(),
                new URL("http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd").openConnection().getInputStream(),
                new URL("http://code.google.com/apis/kml/schema/kml22gx.xsd").openConnection()
                        .getInputStream() };

        // Create a SAX parser factory (not a DOM parser, we don't need the
        // overhead) and set it to validate and be namespace aware, for
        // we want to validate against multiple XSDs.
        SAXParserFactory parserFactory = SAXParserFactory.newInstance();
        parserFactory.setValidating(true);
        parserFactory.setNamespaceAware(true);

        // Create a SAX parser and prepare for XSD validation.
        SAXParser parser = parserFactory.newSAXParser();
        parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
        parser.setProperty(JAXP_SCHEMA_SOURCE, schemas);

        // Create a parser handler to trap errors during parse.
        KmlValidatorParserHandler parserHandler = new KmlValidatorParserHandler();

        // Parse the KML and send all errors to our handler.
        parser.parse(request.getInputStream(), parserHandler);

        // Check our handler for validation results.
        if (parserHandler.getErrors().size() > 0) {
            // There were errors, enumerate through them and create JSON objects
            // for each one.
            for (KmlValidationError e : parserHandler.getErrors()) {
                JSONObject error = new JSONObject();

                switch (e.getType()) {
                case KmlValidationError.VALIDATION_WARNING:
                    error.put("type", "warning");
                    break;

                case KmlValidationError.VALIDATION_ERROR:
                    error.put("type", "error");
                    break;

                case KmlValidationError.VALIDATION_FATAL_ERROR:
                    error.put("type", "fatal_error");
                    break;

                default:
                    error.put("type", "fatal_error");
                }

                // fill in parse exception details
                SAXParseException innerException = e.getInnerException();
                error.put("message", innerException.getMessage());

                if (innerException.getLineNumber() >= 0)
                    error.put("line", innerException.getLineNumber());

                if (innerException.getColumnNumber() >= 0)
                    error.put("column", innerException.getColumnNumber());

                // add this error to the list
                responseErrors.add(error);
            }

            // The KML wasn't valid.
            responseObj.put("status", "invalid");
        } else {
            // The KML is valid against the XSDs.
            responseObj.put("status", "valid");
        }
    } catch (SAXException e) {
        // We should never get here due to regular parse errors. This error
        // must've been thrown by the schema factory.
        responseObj.put("status", "internal_error");

        JSONObject error = new JSONObject();
        error.put("type", "fatal_error");
        error.put("message", "Internal error: " + e.getMessage());
        responseErrors.add(error);

    } catch (ParserConfigurationException e) {
        // Internal error at this point.
        responseObj.put("status", "internal_error");

        JSONObject error = new JSONObject();
        error.put("type", "fatal_error");
        error.put("message", "Internal parse error.");
        responseErrors.add(error);
    }

    // If there were errors, add them to the final response JSON object.
    if (responseErrors.size() > 0) {
        responseObj.put("errors", responseErrors);
    }

    // output the JSON object as the HTTP response and append a newline for
    // prettiness
    response.getWriter().print(responseObj);
    response.getWriter().println();
}

From source file:org.wikipedia.vlsergey.secretary.utils.DefaultErrorHandler.java

protected StringBuffer getText(SAXParseException exc, String type) {
    StringBuffer errorMessage = new StringBuffer();
    if (exc.getSystemId() != null) {
        errorMessage.append("[");
        errorMessage.append(exc.getSystemId());
        errorMessage.append("] ");
    }/*from  ww w .  j  av a  2  s . c o m*/
    errorMessage.append("XML ");
    errorMessage.append(type);
    errorMessage.append(": ");
    errorMessage.append(exc.getMessage());

    // String around = XMLTools.getSourceTextAround(exc);
    // if (around != null) {
    // errorMessage.append(":\n");
    // errorMessage.append(around);
    // errorMessage.append("\n");
    // }
    return errorMessage;
}

From source file:gov.nih.nci.caadapter.ui.mapping.sdtm.SDTMMapFileTransformer.java

public SDTMMapFileTransformer(String mapFileName, String csvFileName, AbstractMainFrame _callingFrame,
        String saveSDTMPath) throws Exception {
    mainFrame = _callingFrame;//from  ww w  . j  a  va2 s  .c o m
    _saveSDTMPath = saveSDTMPath;
    _csvFileName = csvFileName;
    // create a complete list before
    ParseSDTMXMLFile _parseSDTMFile = new ParseSDTMXMLFile(getDefineXMlName(mapFileName));
    ArrayList<String> _retArray = _parseSDTMFile.getSDTMStructure();
    // LinkedList defineXMLList = new LinkedList();
    for (int k = 0; k < 18; k++) {
        if (_retArray.get(k).startsWith("KEY")) {
            // EmptyStringTokenizer _str = new EmptyStringTokenizer(_retArray.get(k),",");
        } else {
            EmptyStringTokenizer _str = new EmptyStringTokenizer(_retArray.get(k), ",");
            String _tmpStr = _str.getTokenAt(1).toString();
            defineXMLList.add(_tmpStr.substring(0, _tmpStr.indexOf("&")));
            // pNode.add(new DefaultTargetTreeNode(new SDTMMetadata(_str.getTokenAt(1),_str.getTokenAt(2), _str.getTokenAt(3), _str.getTokenAt(4))));
        }
    }
    SDTM_CSVReader _csvData = new SDTM_CSVReader();
    _csvData.readCSVFile(csvFileName);
    _csvDataFromFile = _csvData.get_CSVData();
    try {
        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
        Document doc = docBuilder.parse(new File(mapFileName));
        //System.out.println("Root element of the doc is " + doc.getDocumentElement().getNodeName());
        NodeList linkNodeList = doc.getElementsByTagName("link");
        int totalPersons = linkNodeList.getLength();
        //System.out.println("Total no of links are : " + totalPersons);
        //System.out.println(defineXMLList.toString());
        for (int s = 0; s < linkNodeList.getLength(); s++) {
            Node node = linkNodeList.item(s);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                Element firstPersonElement = (Element) node;
                NodeList targetNode = firstPersonElement.getElementsByTagName("target");
                Element targetName = (Element) targetNode.item(0);
                NodeList textLNList = targetName.getChildNodes();
                String _targetName = ((Node) textLNList.item(0)).getNodeValue().trim();
                EmptyStringTokenizer _tmpEmp = new EmptyStringTokenizer(_targetName.toString(), "\\");
                String finalTargetName = _tmpEmp.getTokenAt(_tmpEmp.countTokens() - 1);
                NodeList sourceNode = firstPersonElement.getElementsByTagName("source");
                Element sourceName = (Element) sourceNode.item(0);
                NodeList textFNList = sourceName.getChildNodes();
                String _srcNodeVal = ((Node) textFNList.item(0)).getNodeValue().trim();
                EmptyStringTokenizer _str = new EmptyStringTokenizer(_srcNodeVal, "\\");
                String _tmp = _str.getTokenAt(_str.countTokens() - 2);
                String sourceNodeValue = _str.getTokenAt(_str.countTokens() - 1);
                // _mappedData.put(finalTargetName, _tmp+"%"+sourceNodeValue);
                StringBuffer _sBuf = new StringBuffer();
                if (_mappedData.get(_tmp) == null) {
                    _sBuf.append(sourceNodeValue + "?" + finalTargetName);
                    _mappedData.put(_tmp, _sBuf);
                } else {
                    StringBuffer _tBuf = (StringBuffer) _mappedData.get(_tmp);
                    _tBuf.append("," + sourceNodeValue + "?" + finalTargetName);
                    _mappedData.put(_tmp, _tBuf);
                }
            } // end of if clause
        } // end of for loop with s var
        System.out.println(_mappedData);
        System.out.println(_csvDataFromFile);
        BeginTransformation();
    } catch (SAXParseException err) {
        System.out.println("** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId());
        System.out.println(" " + err.getMessage());
    } catch (SAXException e) {
        Exception x = e.getException();
        ((x == null) ? e : x).printStackTrace();
    } catch (Throwable t) {
        // JOptionPane.showMessageDialog(mainFrame, "SDTM Record File created successfully");
        t.printStackTrace();
    }
    JOptionPane.showMessageDialog(mainFrame, "SDTM Record File " + _saveSDTMPath + " created successfully");
    // System.exit (0);
}

From source file:ch.entwine.weblounge.common.impl.content.AbstractResourceReaderImpl.java

/**
 * The parser encountered problems while parsing. The error is printed out and
 * the parsing process is stopped./*from w  w w. j  av a 2s .c  o m*/
 * 
 * @param e
 *          information about the error
 */
@Override
public void error(SAXParseException e) {
    logger.warn("Error while reading {}: {}", resource, e.getMessage());
}

From source file:ch.entwine.weblounge.common.impl.content.AbstractResourceReaderImpl.java

/**
 * The parser encountered problems while parsing. The warning is printed out
 * but the parsing process continues./*  w  w  w . ja  va  2s  .  co m*/
 * 
 * @param e
 *          information about the warning
 */
@Override
public void warning(SAXParseException e) {
    logger.warn("Warning while reading {}: {}", resource, e.getMessage());
}

From source file:ch.entwine.weblounge.common.impl.content.AbstractResourceReaderImpl.java

/**
 * The parser encountered problems while parsing. The fatal error is printed
 * out and the parsing process is stopped.
 * /*w  w  w  . j  av a 2  s.  co m*/
 * @param e
 *          information about the error
 */
@Override
public void fatalError(SAXParseException e) {
    logger.warn("Fatal error while reading {}: {}", resource, e.getMessage());
}