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:org.apache.jackrabbit.spi2dav.RepositoryServiceImpl.java

private QValue[] getValues(InputStream response, NamePathResolver resolver, ItemId id)
        throws RepositoryException {
    try {/* w  ww.jav  a  2 s.  c  om*/
        Document doc = DomUtil.parseDocument(response);
        Element prop = DomUtil.getChildElement(doc, JcrRemotingConstants.JCR_VALUES_LN,
                ItemResourceConstants.NAMESPACE);
        if (prop == null) {
            // no jcr-values present in the response body -> apparently
            // not representation of a jcr-property
            throw new ItemNotFoundException("No property found at " + saveGetIdString(id, resolver));
        } else {
            DavProperty<?> p = DefaultDavProperty.createFromXml(prop);
            Value[] jcrVs = ValueUtil.valuesFromXml(p.getValue(), PropertyType.STRING, valueFactory);
            QValue[] qvs = new QValue[jcrVs.length];
            int type = (jcrVs.length > 0) ? jcrVs[0].getType() : PropertyType.STRING;

            for (int i = 0; i < jcrVs.length; i++) {
                if (jcrVs[i] instanceof QValueValue) {
                    qvs[i] = ((QValueValue) jcrVs[i]).getQValue();
                } else if (type == PropertyType.BINARY) {
                    qvs[i] = qValueFactory.create(jcrVs[i].getStream());
                } else {
                    qvs[i] = ValueFormat.getQValue(jcrVs[i], resolver, qValueFactory);
                }
            }
            return qvs;
        }
    } catch (SAXException e) {
        log.warn("Internal error: {}", e.getMessage());
        throw new RepositoryException(e);
    } catch (IOException e) {
        log.warn("Internal error: {}", e.getMessage());
        throw new RepositoryException(e);
    } catch (ParserConfigurationException e) {
        log.warn("Internal error: {}", e.getMessage());
        throw new RepositoryException(e);
    }
}

From source file:org.apache.jmeter.assertions.XPathAssertion.java

/**
 * Returns the result of the Assertion. Checks if the result is well-formed
 * XML, and that the XPath expression is matched (or not, as the case may
 * be)/*w  w  w.j a  v  a2s.  c om*/
 */
@Override
public AssertionResult getResult(SampleResult response) {
    // no error as default
    AssertionResult result = new AssertionResult(getName());
    result.setFailure(false);
    result.setFailureMessage("");

    byte[] responseData = null;
    Document doc = null;

    try {
        if (isScopeVariable()) {
            String inputString = getThreadContext().getVariables().get(getVariableName());
            if (!StringUtils.isEmpty(inputString)) {
                responseData = inputString.getBytes("UTF-8");
            }
        } else {
            responseData = response.getResponseData();
        }

        if (responseData == null || responseData.length == 0) {
            return result.setResultForNull();
        }

        if (log.isDebugEnabled()) {
            log.debug(new StringBuilder("Validation is set to ").append(isValidating()).toString());
            log.debug(new StringBuilder("Whitespace is set to ").append(isWhitespace()).toString());
            log.debug(new StringBuilder("Tolerant is set to ").append(isTolerant()).toString());
        }

        boolean isXML = JOrphanUtils.isXML(responseData);

        doc = XPathUtil.makeDocument(new ByteArrayInputStream(responseData), isValidating(), isWhitespace(),
                isNamespace(), isTolerant(), isQuiet(), showWarnings(), reportErrors(), isXML,
                isDownloadDTDs());
    } catch (SAXException e) {
        log.debug("Caught sax exception: " + e);
        result.setError(true);
        result.setFailureMessage(new StringBuilder("SAXException: ").append(e.getMessage()).toString());
        return result;
    } catch (IOException e) {
        log.warn("Cannot parse result content", e);
        result.setError(true);
        result.setFailureMessage(new StringBuilder("IOException: ").append(e.getMessage()).toString());
        return result;
    } catch (ParserConfigurationException e) {
        log.warn("Cannot parse result content", e);
        result.setError(true);
        result.setFailureMessage(
                new StringBuilder("ParserConfigurationException: ").append(e.getMessage()).toString());
        return result;
    } catch (TidyException e) {
        result.setError(true);
        result.setFailureMessage(e.getMessage());
        return result;
    }

    if (doc == null || doc.getDocumentElement() == null) {
        result.setError(true);
        result.setFailureMessage("Document is null, probably not parsable");
        return result;
    }
    XPathUtil.computeAssertionResult(result, doc, getXPathString(), isNegated());
    return result;
}

From source file:org.apache.maven.plugin.changes.schema.DefaultChangesSchemaValidator.java

public void loadSchema(String uriSchema) throws SchemaValidatorException {
    try {/*from   w  w  w . j av a  2  s  .  c  o m*/
        this.getSchema(uriSchema);
    } catch (SAXException e) {
        throw new SchemaValidatorException("SAXException : " + e.getMessage(), e);
    }

}

From source file:org.apache.maven.shared.release.phase.AbstractReleaseTestCase.java

protected void comparePomFiles(File expectedFile, File actualFile, boolean normalizeLineEndings)
        throws IOException {
    Reader expected = null;//from   w ww.  j  av a2 s  .  c  o m
    Reader actual = null;
    try {
        expected = ReaderFactory.newXmlReader(expectedFile);
        actual = ReaderFactory.newXmlReader(actualFile);

        StringBuffer sb = new StringBuffer("Check the transformed POM " + actualFile);
        sb.append(SystemUtils.LINE_SEPARATOR);

        final String remoteRepositoryURL = getRemoteRepositoryURL();

        XMLUnit.setNormalizeWhitespace(true);

        Diff diff = XMLUnit.compareXML(expected, actual);

        diff.overrideDifferenceListener(new DifferenceListener() {

            public void skippedComparison(Node arg0, Node arg1) {
                //do nothing
            }

            public int differenceFound(Difference difference) {
                if ("${remoterepo}".equals(difference.getControlNodeDetail().getValue())
                        && remoteRepositoryURL.equals(difference.getTestNodeDetail().getValue())) {
                    return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
                } else {
                    return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
                }
            }
        });
        diff.appendMessage(sb);

        XMLAssert.assertXMLIdentical(diff, true);
    } catch (SAXException e) {
        fail(e.getMessage());
    } finally {
        IOUtil.close(expected);
        IOUtil.close(actual);
    }
}

From source file:org.apache.ode.utils.SerializableElement.java

/**
 * De-serialization routines.//from  ww w. ja  v  a2s  .  c o  m
 *
 * @see Serializable
 */
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
    try {
        e = DOMUtils.stringToDOM((String) in.readObject());
    } catch (SAXException e) {
        __log.error("De-serialization eror", e);
        throw new IOException(e.getMessage());
    }
}

From source file:org.apache.shindig.protocol.conversion.BeanAtomConverter.java

public String convertToXml(Object obj) {
    String xmlHead = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    StringWriter outputWriter = new StringWriter();
    BeanWriter writer = new BeanWriter(outputWriter);
    IntrospectionConfiguration configuration = writer.getXMLIntrospector().getConfiguration();
    configuration.setAttributesForPrimitives(false);
    configuration.setWrapCollectionsInElement(true);

    writer.getBindingConfiguration().setMapIDs(false);
    // Print no line endings
    writer.setEndOfLine("");
    writer.setWriteEmptyElements(false);

    // Still left to do:
    //// w w  w  .  ja v a  2 s  .  c om
    // Fix map output with custom outputter:
    // for a map with {key : value, key2 : value2} we need:
    // <key>value</key> <key2>value2</key2>

    // Supress empty lists

    // Within a list the items need to be renamed - this probably means with need a .betwixt file

    String toReturn = xmlHead;
    try {
        writer.write("response", obj);
        toReturn = toReturn + outputWriter.toString();
        if (LOG.isLoggable(Level.FINEST))
            LOG.finest("XML is: " + toReturn + "\n **** \n\n");

    } catch (SAXException e) {
        LOG.log(Level.SEVERE, e.getMessage(), e);
    } catch (IOException e) {
        LOG.log(Level.SEVERE, e.getMessage(), e);
    } catch (IntrospectionException e) {
        LOG.log(Level.SEVERE, e.getMessage(), e);
    } finally {
        try {
            writer.close();
        } catch (IOException e) {
            if (LOG.isLoggable(Level.FINEST))
                LOG.log(Level.FINEST, e.getMessage(), e);
        }
    }

    return toReturn;
}

From source file:org.apache.shindig.protocol.conversion.BeanXmlConverter.java

public String convertToXml(Object obj) {
    StringWriter outputWriter = new StringWriter();
    BeanWriter writer = new BeanWriter(outputWriter);
    IntrospectionConfiguration configuration = writer.getXMLIntrospector().getConfiguration();
    configuration.setAttributesForPrimitives(false);
    configuration.setWrapCollectionsInElement(true);

    writer.getBindingConfiguration().setMapIDs(false);
    // Print no line endings
    writer.setEndOfLine("");
    writer.setWriteEmptyElements(false);

    // Still left to do:
    ///*  www. j a  v  a  2  s.c o m*/
    // Fix map output with custom outputter:
    // for a map with {key : value, key2 : value2} we need:
    // <key>value</key> <key2>value2</key2>

    // Supress empty lists

    // Within a list the items need to be renamed - this probably means with need a .betwixt file

    String toReturn = null;
    try {
        writer.write("response", obj);
        toReturn = outputWriter.toString();
        if (LOG.isLoggable(Level.FINEST))
            LOG.finest("XML is: " + toReturn + "\n **** \n\n");

    } catch (SAXException e) {
        LOG.log(Level.SEVERE, e.getMessage(), e);
    } catch (IOException e) {
        LOG.log(Level.SEVERE, e.getMessage(), e);
    } catch (IntrospectionException e) {
        LOG.log(Level.SEVERE, e.getMessage(), e);
    } finally {
        try {
            writer.close();
        } catch (IOException e) {
            if (LOG.isLoggable(Level.FINEST))
                LOG.log(Level.FINEST, e.getMessage(), e);
        }
    }

    return toReturn;
}

From source file:org.apache.shindig.social.core.util.BeanAtomConverter.java

public String convertToXml(Object obj) {
    String xmlHead = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    StringWriter outputWriter = new StringWriter();
    BeanWriter writer = new BeanWriter(outputWriter);
    IntrospectionConfiguration configuration = writer.getXMLIntrospector().getConfiguration();
    configuration.setAttributesForPrimitives(false);
    configuration.setWrapCollectionsInElement(true);

    writer.getBindingConfiguration().setMapIDs(false);
    // Print no line endings
    writer.setEndOfLine("");
    writer.setWriteEmptyElements(false);

    // Still left to do:
    ///*w w  w.ja  va2s. co m*/
    // Fix map output with custom outputter:
    // for a map with {key : value, key2 : value2} we need:
    // <key>value</key> <key2>value2</key2>

    // Supress empty lists

    // Within a list the items need to be renamed - this probably means with need a .betwixt file

    String toReturn = xmlHead;
    try {
        writer.write("response", obj);
        toReturn = toReturn + outputWriter.toString();
        if (logger.isLoggable(Level.FINEST))
            logger.finest("XML is: " + toReturn + "\n **** \n\n");

    } catch (SAXException e) {
        logger.log(Level.SEVERE, e.getMessage(), e);
    } catch (IOException e) {
        logger.log(Level.SEVERE, e.getMessage(), e);
    } catch (IntrospectionException e) {
        logger.log(Level.SEVERE, e.getMessage(), e);
    } finally {
        try {
            writer.close();
        } catch (IOException e) {
            if (logger.isLoggable(Level.FINEST))
                logger.log(Level.FINEST, e.getMessage(), e);
        }
    }

    return toReturn;
}

From source file:org.apache.shindig.social.core.util.BeanXmlConverter.java

public String convertToXml(Object obj) {
    StringWriter outputWriter = new StringWriter();
    BeanWriter writer = new BeanWriter(outputWriter);
    IntrospectionConfiguration configuration = writer.getXMLIntrospector().getConfiguration();
    configuration.setAttributesForPrimitives(false);
    configuration.setWrapCollectionsInElement(true);

    writer.getBindingConfiguration().setMapIDs(false);
    // Print no line endings
    writer.setEndOfLine("");
    writer.setWriteEmptyElements(false);

    // Still left to do:
    ///* w  w  w  . j  a va2s  . co  m*/
    // Fix map output with custom outputter:
    // for a map with {key : value, key2 : value2} we need:
    // <key>value</key> <key2>value2</key2>

    // Supress empty lists

    // Within a list the items need to be renamed - this probably means with need a .betwixt file

    String toReturn = null;
    try {
        writer.write("response", obj);
        toReturn = outputWriter.toString();
        if (logger.isLoggable(Level.FINEST))
            logger.finest("XML is: " + toReturn + "\n **** \n\n");

    } catch (SAXException e) {
        logger.log(Level.SEVERE, e.getMessage(), e);
    } catch (IOException e) {
        logger.log(Level.SEVERE, e.getMessage(), e);
    } catch (IntrospectionException e) {
        logger.log(Level.SEVERE, e.getMessage(), e);
    } finally {
        try {
            writer.close();
        } catch (IOException e) {
            if (logger.isLoggable(Level.FINEST))
                logger.log(Level.FINEST, e.getMessage(), e);
        }
    }

    return toReturn;
}

From source file:org.apache.struts.tiles.xmlDefinition.I18nFactorySet.java

/**
 * Parse specified xml file and add definition to specified definitions set.
 * This method is used to load several description files in one instances list.
 * If filename exists and definition set is <code>null</code>, create a new set. Otherwise, return
 * passed definition set (can be <code>null</code>).
 * @param servletContext Current servlet context. Used to open file.
 * @param filename Name of file to parse.
 * @param xmlDefinitions Definitions set to which definitions will be added. If null, a definitions
 * set is created on request.//from www  . j  av  a2s. c om
 * @return XmlDefinitionsSet The definitions set created or passed as parameter.
 * @throws DefinitionsFactoryException On errors parsing file.
 */
protected XmlDefinitionsSet parseXmlFile(ServletContext servletContext, String filename,
        XmlDefinitionsSet xmlDefinitions) throws DefinitionsFactoryException {

    try {
        InputStream input = servletContext.getResourceAsStream(filename);
        // Try to load using real path.
        // This allow to load config file under websphere 3.5.x
        // Patch proposed Houston, Stephen (LIT) on 5 Apr 2002
        if (null == input) {
            try {
                input = new java.io.FileInputStream(servletContext.getRealPath(filename));
            } catch (Exception e) {
            }
        }

        // If the config isn't in the servlet context, try the class loader
        // which allows the config files to be stored in a jar
        if (input == null) {
            input = getClass().getResourceAsStream(filename);
        }

        // If still nothing found, this mean no config file is associated
        if (input == null) {
            if (log.isDebugEnabled()) {
                log.debug("Can't open file '" + filename + "'");
            }
            return xmlDefinitions;
        }

        // Check if parser already exist.
        // Doesn't seem to work yet.
        //if( xmlParser == null )
        if (true) {
            xmlParser = new XmlParser();
            xmlParser.setValidating(isValidatingParser);
        }

        // Check if definition set already exist.
        if (xmlDefinitions == null) {
            xmlDefinitions = new XmlDefinitionsSet();
        }

        xmlParser.parse(input, xmlDefinitions);

    } catch (SAXException ex) {
        if (log.isDebugEnabled()) {
            log.debug("Error while parsing file '" + filename + "'.");
            ex.printStackTrace();
        }
        throw new DefinitionsFactoryException("Error while parsing file '" + filename + "'. " + ex.getMessage(),
                ex);

    } catch (IOException ex) {
        throw new DefinitionsFactoryException(
                "IO Error while parsing file '" + filename + "'. " + ex.getMessage(), ex);
    }

    return xmlDefinitions;
}