Java Code Examples for javax.xml.transform.TransformerException#getMessageAndLocation()

The following examples show how to use javax.xml.transform.TransformerException#getMessageAndLocation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XPathEvaluatorImpl.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
* Creates a parsed XPath expression with resolved namespaces. This is
* useful when an expression will be reused in an application since it
* makes it possible to compile the expression string into a more
* efficient internal form and preresolve all namespace prefixes which
* occur within the expression.
*
* @param expression The XPath expression string to be parsed.
* @param resolver The <code>resolver</code> permits translation of
*   prefixes within the XPath expression into appropriate namespace URIs
*   . If this is specified as <code>null</code>, any namespace prefix
*   within the expression will result in <code>DOMException</code>
*   being thrown with the code <code>NAMESPACE_ERR</code>.
* @return The compiled form of the XPath expression.
* @exception XPathException
*   INVALID_EXPRESSION_ERR: Raised if the expression is not legal
*   according to the rules of the <code>XPathEvaluator</code>i
* @exception DOMException
*   NAMESPACE_ERR: Raised if the expression contains namespace prefixes
*   which cannot be resolved by the specified
*   <code>XPathNSResolver</code>.
*
    * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver)
    */
   public XPathExpression createExpression(
           String expression,
           XPathNSResolver resolver)
           throws XPathException, DOMException {

           try {

                   // If the resolver is null, create a dummy prefix resolver
                   XPath xpath =  new XPath(expression,null,
                        ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)),
                         XPath.SELECT);

       return new XPathExpressionImpl(xpath, m_doc);

           } catch (TransformerException e) {
                   // Need to pass back exception code DOMException.NAMESPACE_ERR also.
                   // Error found in DOM Level 3 XPath Test Suite.
                   if(e instanceof XPathStylesheetDOM3Exception)
                           throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation());
                   else
                           throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());

           }
   }
 
Example 2
Source File: XPathEvaluatorImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
* Creates a parsed XPath expression with resolved namespaces. This is
* useful when an expression will be reused in an application since it
* makes it possible to compile the expression string into a more
* efficient internal form and preresolve all namespace prefixes which
* occur within the expression.
*
* @param expression The XPath expression string to be parsed.
* @param resolver The <code>resolver</code> permits translation of
*   prefixes within the XPath expression into appropriate namespace URIs
*   . If this is specified as <code>null</code>, any namespace prefix
*   within the expression will result in <code>DOMException</code>
*   being thrown with the code <code>NAMESPACE_ERR</code>.
* @return The compiled form of the XPath expression.
* @exception XPathException
*   INVALID_EXPRESSION_ERR: Raised if the expression is not legal
*   according to the rules of the <code>XPathEvaluator</code>i
* @exception DOMException
*   NAMESPACE_ERR: Raised if the expression contains namespace prefixes
*   which cannot be resolved by the specified
*   <code>XPathNSResolver</code>.
*
    * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver)
    */
   public XPathExpression createExpression(
           String expression,
           XPathNSResolver resolver)
           throws XPathException, DOMException {

           try {

                   // If the resolver is null, create a dummy prefix resolver
                   XPath xpath =  new XPath(expression,null,
                        ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)),
                         XPath.SELECT);

       return new XPathExpressionImpl(xpath, m_doc);

           } catch (TransformerException e) {
                   // Need to pass back exception code DOMException.NAMESPACE_ERR also.
                   // Error found in DOM Level 3 XPath Test Suite.
                   if(e instanceof XPathStylesheetDOM3Exception)
                           throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation());
                   else
                           throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());

           }
   }
 
Example 3
Source File: XPathEvaluatorImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
* Creates a parsed XPath expression with resolved namespaces. This is
* useful when an expression will be reused in an application since it
* makes it possible to compile the expression string into a more
* efficient internal form and preresolve all namespace prefixes which
* occur within the expression.
*
* @param expression The XPath expression string to be parsed.
* @param resolver The <code>resolver</code> permits translation of
*   prefixes within the XPath expression into appropriate namespace URIs
*   . If this is specified as <code>null</code>, any namespace prefix
*   within the expression will result in <code>DOMException</code>
*   being thrown with the code <code>NAMESPACE_ERR</code>.
* @return The compiled form of the XPath expression.
* @exception XPathException
*   INVALID_EXPRESSION_ERR: Raised if the expression is not legal
*   according to the rules of the <code>XPathEvaluator</code>i
* @exception DOMException
*   NAMESPACE_ERR: Raised if the expression contains namespace prefixes
*   which cannot be resolved by the specified
*   <code>XPathNSResolver</code>.
*
    * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver)
    */
   public XPathExpression createExpression(
           String expression,
           XPathNSResolver resolver)
           throws XPathException, DOMException {

           try {

                   // If the resolver is null, create a dummy prefix resolver
                   XPath xpath =  new XPath(expression,null,
                        ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)),
                         XPath.SELECT);

       return new XPathExpressionImpl(xpath, m_doc);

           } catch (TransformerException e) {
                   // Need to pass back exception code DOMException.NAMESPACE_ERR also.
                   // Error found in DOM Level 3 XPath Test Suite.
                   if(e instanceof XPathStylesheetDOM3Exception)
                           throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation());
                   else
                           throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());

           }
   }
 
Example 4
Source File: XPathEvaluatorImpl.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
* Creates a parsed XPath expression with resolved namespaces. This is
* useful when an expression will be reused in an application since it
* makes it possible to compile the expression string into a more
* efficient internal form and preresolve all namespace prefixes which
* occur within the expression.
*
* @param expression The XPath expression string to be parsed.
* @param resolver The <code>resolver</code> permits translation of
*   prefixes within the XPath expression into appropriate namespace URIs
*   . If this is specified as <code>null</code>, any namespace prefix
*   within the expression will result in <code>DOMException</code>
*   being thrown with the code <code>NAMESPACE_ERR</code>.
* @return The compiled form of the XPath expression.
* @exception XPathException
*   INVALID_EXPRESSION_ERR: Raised if the expression is not legal
*   according to the rules of the <code>XPathEvaluator</code>i
* @exception DOMException
*   NAMESPACE_ERR: Raised if the expression contains namespace prefixes
*   which cannot be resolved by the specified
*   <code>XPathNSResolver</code>.
*
    * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver)
    */
   public XPathExpression createExpression(
           String expression,
           XPathNSResolver resolver)
           throws XPathException, DOMException {

           try {

                   // If the resolver is null, create a dummy prefix resolver
                   XPath xpath =  new XPath(expression,null,
                        ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)),
                         XPath.SELECT);

       return new XPathExpressionImpl(xpath, m_doc);

           } catch (TransformerException e) {
                   // Need to pass back exception code DOMException.NAMESPACE_ERR also.
                   // Error found in DOM Level 3 XPath Test Suite.
                   if(e instanceof XPathStylesheetDOM3Exception)
                           throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation());
                   else
                           throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());

           }
   }
 
Example 5
Source File: XPathEvaluatorImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
* Creates a parsed XPath expression with resolved namespaces. This is
* useful when an expression will be reused in an application since it
* makes it possible to compile the expression string into a more
* efficient internal form and preresolve all namespace prefixes which
* occur within the expression.
*
* @param expression The XPath expression string to be parsed.
* @param resolver The <code>resolver</code> permits translation of
*   prefixes within the XPath expression into appropriate namespace URIs
*   . If this is specified as <code>null</code>, any namespace prefix
*   within the expression will result in <code>DOMException</code>
*   being thrown with the code <code>NAMESPACE_ERR</code>.
* @return The compiled form of the XPath expression.
* @exception XPathException
*   INVALID_EXPRESSION_ERR: Raised if the expression is not legal
*   according to the rules of the <code>XPathEvaluator</code>i
* @exception DOMException
*   NAMESPACE_ERR: Raised if the expression contains namespace prefixes
*   which cannot be resolved by the specified
*   <code>XPathNSResolver</code>.
*
    * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver)
    */
   public XPathExpression createExpression(
           String expression,
           XPathNSResolver resolver)
           throws XPathException, DOMException {

           try {

                   // If the resolver is null, create a dummy prefix resolver
                   XPath xpath =  new XPath(expression,null,
                        ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)),
                         XPath.SELECT);

       return new XPathExpressionImpl(xpath, m_doc);

           } catch (TransformerException e) {
                   // Need to pass back exception code DOMException.NAMESPACE_ERR also.
                   // Error found in DOM Level 3 XPath Test Suite.
                   if(e instanceof XPathStylesheetDOM3Exception)
                           throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation());
                   else
                           throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());

           }
   }
 
Example 6
Source File: XPathEvaluatorImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
* Creates a parsed XPath expression with resolved namespaces. This is
* useful when an expression will be reused in an application since it
* makes it possible to compile the expression string into a more
* efficient internal form and preresolve all namespace prefixes which
* occur within the expression.
*
* @param expression The XPath expression string to be parsed.
* @param resolver The <code>resolver</code> permits translation of
*   prefixes within the XPath expression into appropriate namespace URIs
*   . If this is specified as <code>null</code>, any namespace prefix
*   within the expression will result in <code>DOMException</code>
*   being thrown with the code <code>NAMESPACE_ERR</code>.
* @return The compiled form of the XPath expression.
* @exception XPathException
*   INVALID_EXPRESSION_ERR: Raised if the expression is not legal
*   according to the rules of the <code>XPathEvaluator</code>i
* @exception DOMException
*   NAMESPACE_ERR: Raised if the expression contains namespace prefixes
*   which cannot be resolved by the specified
*   <code>XPathNSResolver</code>.
*
    * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver)
    */
   public XPathExpression createExpression(
           String expression,
           XPathNSResolver resolver)
           throws XPathException, DOMException {

           try {

                   // If the resolver is null, create a dummy prefix resolver
                   XPath xpath =  new XPath(expression,null,
                        ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)),
                         XPath.SELECT);

       return new XPathExpressionImpl(xpath, m_doc);

           } catch (TransformerException e) {
                   // Need to pass back exception code DOMException.NAMESPACE_ERR also.
                   // Error found in DOM Level 3 XPath Test Suite.
                   if(e instanceof XPathStylesheetDOM3Exception)
                           throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation());
                   else
                           throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());

           }
   }
 
Example 7
Source File: XPathEvaluatorImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
* Creates a parsed XPath expression with resolved namespaces. This is
* useful when an expression will be reused in an application since it
* makes it possible to compile the expression string into a more
* efficient internal form and preresolve all namespace prefixes which
* occur within the expression.
*
* @param expression The XPath expression string to be parsed.
* @param resolver The <code>resolver</code> permits translation of
*   prefixes within the XPath expression into appropriate namespace URIs
*   . If this is specified as <code>null</code>, any namespace prefix
*   within the expression will result in <code>DOMException</code>
*   being thrown with the code <code>NAMESPACE_ERR</code>.
* @return The compiled form of the XPath expression.
* @exception XPathException
*   INVALID_EXPRESSION_ERR: Raised if the expression is not legal
*   according to the rules of the <code>XPathEvaluator</code>i
* @exception DOMException
*   NAMESPACE_ERR: Raised if the expression contains namespace prefixes
*   which cannot be resolved by the specified
*   <code>XPathNSResolver</code>.
*
    * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver)
    */
   public XPathExpression createExpression(
           String expression,
           XPathNSResolver resolver)
           throws XPathException, DOMException {

           try {

                   // If the resolver is null, create a dummy prefix resolver
                   XPath xpath =  new XPath(expression,null,
                        ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)),
                         XPath.SELECT);

       return new XPathExpressionImpl(xpath, m_doc);

           } catch (TransformerException e) {
                   // Need to pass back exception code DOMException.NAMESPACE_ERR also.
                   // Error found in DOM Level 3 XPath Test Suite.
                   if(e instanceof XPathStylesheetDOM3Exception)
                           throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation());
                   else
                           throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());

           }
   }
 
Example 8
Source File: XPathEvaluatorImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
* Creates a parsed XPath expression with resolved namespaces. This is
* useful when an expression will be reused in an application since it
* makes it possible to compile the expression string into a more
* efficient internal form and preresolve all namespace prefixes which
* occur within the expression.
*
* @param expression The XPath expression string to be parsed.
* @param resolver The <code>resolver</code> permits translation of
*   prefixes within the XPath expression into appropriate namespace URIs
*   . If this is specified as <code>null</code>, any namespace prefix
*   within the expression will result in <code>DOMException</code>
*   being thrown with the code <code>NAMESPACE_ERR</code>.
* @return The compiled form of the XPath expression.
* @exception XPathException
*   INVALID_EXPRESSION_ERR: Raised if the expression is not legal
*   according to the rules of the <code>XPathEvaluator</code>i
* @exception DOMException
*   NAMESPACE_ERR: Raised if the expression contains namespace prefixes
*   which cannot be resolved by the specified
*   <code>XPathNSResolver</code>.
*
    * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver)
    */
   public XPathExpression createExpression(
           String expression,
           XPathNSResolver resolver)
           throws XPathException, DOMException {

           try {

                   // If the resolver is null, create a dummy prefix resolver
                   XPath xpath =  new XPath(expression,null,
                        ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)),
                         XPath.SELECT);

       return new XPathExpressionImpl(xpath, m_doc);

           } catch (TransformerException e) {
                   // Need to pass back exception code DOMException.NAMESPACE_ERR also.
                   // Error found in DOM Level 3 XPath Test Suite.
                   if(e instanceof XPathStylesheetDOM3Exception)
                           throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation());
                   else
                           throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());

           }
   }
 
Example 9
Source File: XPathEvaluatorImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
* Creates a parsed XPath expression with resolved namespaces. This is
* useful when an expression will be reused in an application since it
* makes it possible to compile the expression string into a more
* efficient internal form and preresolve all namespace prefixes which
* occur within the expression.
*
* @param expression The XPath expression string to be parsed.
* @param resolver The <code>resolver</code> permits translation of
*   prefixes within the XPath expression into appropriate namespace URIs
*   . If this is specified as <code>null</code>, any namespace prefix
*   within the expression will result in <code>DOMException</code>
*   being thrown with the code <code>NAMESPACE_ERR</code>.
* @return The compiled form of the XPath expression.
* @exception XPathException
*   INVALID_EXPRESSION_ERR: Raised if the expression is not legal
*   according to the rules of the <code>XPathEvaluator</code>i
* @exception DOMException
*   NAMESPACE_ERR: Raised if the expression contains namespace prefixes
*   which cannot be resolved by the specified
*   <code>XPathNSResolver</code>.
*
    * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver)
    */
   public XPathExpression createExpression(
           String expression,
           XPathNSResolver resolver)
           throws XPathException, DOMException {

           try {

                   // If the resolver is null, create a dummy prefix resolver
                   XPath xpath =  new XPath(expression,null,
                        ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)),
                         XPath.SELECT);

       return new XPathExpressionImpl(xpath, m_doc);

           } catch (TransformerException e) {
                   // Need to pass back exception code DOMException.NAMESPACE_ERR also.
                   // Error found in DOM Level 3 XPath Test Suite.
                   if(e instanceof XPathStylesheetDOM3Exception)
                           throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation());
                   else
                           throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());

           }
   }
 
Example 10
Source File: CCGBankExtract.java    From openccg with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected InputSource nextFile(File file) throws BuildException {
	try {
		ruleProcessor.process(super.nextFile(file));
	}
	catch(IOException io) {
		throw new BuildException("I/O problem processing " + file + ": "
			+ io.getMessage(), io, getLocation());
	}
	catch(SAXException se) {
		throw new BuildException("Problem processing " + file + ": "
			+ se.getMessage(), se, getLocation());
	}
	catch(TransformerException te) {
		throw new BuildException("Problem processing " + file + ": "
			+ te.getMessageAndLocation(), te, getLocation());
	}
	
	return super.nextFile(file); // TODO is this right?
}
 
Example 11
Source File: XMLUtil.java    From flex-blazeds with Apache License 2.0 5 votes vote down vote up
/**
 * Uses a TransformerFactory with an identity transformation to convert a
 * Document into a String representation of the XML.
 *
 * @param document Document.
 * @return An XML String.
 * @throws IOException if an error occurs during transformation.
 */
public static String documentToString(Document document) throws IOException
{
    String xml;

    try
    {
        DOMSource dom = new DOMSource(document);
        StringWriter writer = new StringWriter();
        StreamResult output = new StreamResult(writer);

        // Use Transformer to serialize a DOM
        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer = factory.newTransformer();

        // No need for pretty printing
        transformer.setOutputProperty(OutputKeys.INDENT, INDENT_XML);

        // XML Declarations unexpected whitespace for legacy AS XMLDocument type,
        // so we always omit it. We can't tell whether one was present when
        // constructing the Document in the first place anyway...
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, OMIT_XML_DECLARATION);

        transformer.transform(dom, output);

        xml = writer.toString();
    }
    catch (TransformerException te)
    {
        throw new IOException("Error serializing Document as String: " + te.getMessageAndLocation());
    }
    return xml;
}