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

The following examples show how to use javax.xml.transform.TransformerException#getMessage() . 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: TransformerFactoryImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * This method implements XSLTC's SourceLoader interface. It is used to
 * glue a TrAX URIResolver to the XSLTC compiler's Input and Import classes.
 *
 * @param href The URI of the document to load
 * @param context The URI of the currently loaded document
 * @param xsltc The compiler that resuests the document
 * @return An InputSource with the loaded document
 */
@Override
public InputSource loadSource(String href, String context, XSLTC xsltc) {
    try {
        if (_uriResolver != null) {
            final Source source = _uriResolver.resolve(href, context);
            if (source != null) {
                return Util.getInputSource(xsltc, source);
            }
        }
    }
    catch (TransformerException e) {
        // should catch it when the resolver explicitly throws the exception
        final ErrorMsg msg = new ErrorMsg(ErrorMsg.INVALID_URI_ERR, href + "\n" + e.getMessage(), this);
        xsltc.getParser().reportError(Constants.FATAL, msg);
    }

    return null;
}
 
Example 2
Source File: XmlUtil.java    From jsons2xsd with MIT License 6 votes vote down vote up
public static String asXmlString(Node node)
{
    final Source source = new DOMSource(node);
    final StringWriter stringWriter = new StringWriter();
    final Result result = new StreamResult(stringWriter);
    final TransformerFactory factory = TransformerFactory.newInstance();

    try
    {
        final Transformer transformer = factory.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        transformer.transform(source, result);
        return stringWriter.getBuffer().toString();
    }
    catch (TransformerException exc)
    {
        throw new UncheckedIOException(exc.getMessage(), new IOException(exc));
    }
}
 
Example 3
Source File: TransformerIdentityImpl.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Receive notification of the beginning of the document.
 *
 * <p>By default, do nothing.  Application writers may override this
 * method in a subclass to take specific actions at the beginning
 * of a document (such as allocating the root node of a tree or
 * creating an output file).</p>
 *
 * @throws org.xml.sax.SAXException Any SAX exception, possibly
 *            wrapping another exception.
 * @see org.xml.sax.ContentHandler#startDocument
 *
 * @throws SAXException
 */
public void startDocument() throws SAXException
{

  try
  {
    if (null == m_resultContentHandler)
      createResultContentHandler(m_result);
  }
  catch (TransformerException te)
  {
    throw new SAXException(te.getMessage(), te);
  }

  // Reset for multiple transforms with this transformer.
  m_flushedStartDoc = false;
  m_foundFirstElement = false;
}
 
Example 4
Source File: TransformerFactoryImpl.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * This method implements XSLTC's SourceLoader interface. It is used to
 * glue a TrAX URIResolver to the XSLTC compiler's Input and Import classes.
 *
 * @param href The URI of the document to load
 * @param context The URI of the currently loaded document
 * @param xsltc The compiler that resuests the document
 * @return An InputSource with the loaded document
 */
@Override
public InputSource loadSource(String href, String context, XSLTC xsltc) {
    try {
        if (_uriResolver != null) {
            final Source source = _uriResolver.resolve(href, context);
            if (source != null) {
                return Util.getInputSource(xsltc, source);
            }
        }
    }
    catch (TransformerException e) {
        // should catch it when the resolver explicitly throws the exception
        final ErrorMsg msg = new ErrorMsg(ErrorMsg.INVALID_URI_ERR, href + "\n" + e.getMessage(), this);
        xsltc.getParser().reportError(Constants.FATAL, msg);
    }

    return null;
}
 
Example 5
Source File: TransformerFactoryImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * This method implements XSLTC's SourceLoader interface. It is used to
 * glue a TrAX URIResolver to the XSLTC compiler's Input and Import classes.
 *
 * @param href The URI of the document to load
 * @param context The URI of the currently loaded document
 * @param xsltc The compiler that resuests the document
 * @return An InputSource with the loaded document
 */
@Override
public InputSource loadSource(String href, String context, XSLTC xsltc) {
    try {
        if (_uriResolver != null) {
            final Source source = _uriResolver.resolve(href, context);
            if (source != null) {
                return Util.getInputSource(xsltc, source);
            }
        }
    }
    catch (TransformerException e) {
        // should catch it when the resolver explicitly throws the exception
        final ErrorMsg msg = new ErrorMsg(ErrorMsg.INVALID_URI_ERR, href + "\n" + e.getMessage(), this);
        xsltc.getParser().reportError(Constants.FATAL, msg);
    }

    return null;
}
 
Example 6
Source File: SoapWebServiceAdapter.java    From mdw with Apache License 2.0 5 votes vote down vote up
/**
 * Builds the request XML.
 */
protected String getRequestData() throws ActivityException {
    Object request = null;
    String requestVarName = getAttributeValue(REQUEST_VARIABLE);
    if (requestVarName == null)
        throw new ActivityException("Missing attribute: " + REQUEST_VARIABLE);
    String requestVarType = getParameterType(requestVarName);

    request = getParameterValue(requestVarName);
    if (!hasPreScript()) {
        if (request == null)
            throw new ActivityException("Request data is null: " + requestVarName);
        if (!(request instanceof DocumentReference))
            throw new ActivityException("Request data must be a DocumentReference: " + requestVarName);
    }

    try {
        Object requestObj = request == null ? null : getDocument((DocumentReference)request, requestVarType);
        if (hasPreScript()) {
            Object ret = executePreScript(requestObj);
            if (ret == null) {
                // nothing returned; requestVar may have been assigned by script
                Object req = getParameterValue(requestVarName);
                if (req == null)
                  throw new ActivityException("Request data is null: " + requestVarName);
                requestObj = getDocument((DocumentReference)req, requestVarType);
            }
            else {
                requestObj = ret;
                setParameterValueAsDocument(requestVarName, this.getProcessDefinition().getVariable(requestVarName).getType(), requestObj);
            }
        }
        soapRequest = createSoapRequest(requestObj);
        return DomHelper.toXml(soapRequest.getSOAPPart().getDocumentElement());
    }
    catch (TransformerException ex) {
        throw new ActivityException(ex.getMessage(), ex);
    }
}
 
Example 7
Source File: XPathResultImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
         * The value of this single node result, which may be <code>null</code>.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>ANY_UNORDERED_NODE_TYPE</code> or
     *   <code>FIRST_ORDERED_NODE_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#getSingleNodeValue()
         */
        public Node getSingleNodeValue() throws XPathException {

                if ((m_resultType != ANY_UNORDERED_NODE_TYPE) &&
                    (m_resultType != FIRST_ORDERED_NODE_TYPE)) {
                                String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_SINGLENODE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
                                throw new XPathException(XPathException.TYPE_ERR,fmsg);
//                              "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a single node.
//                               This method applies only to types ANY_UNORDERED_NODE_TYPE and FIRST_ORDERED_NODE_TYPE."
            }

                NodeIterator result = null;
                try {
                        result = m_resultObj.nodeset();
                } catch (TransformerException te) {
                        throw new XPathException(XPathException.TYPE_ERR,te.getMessage());
                }

        if (null == result) return null;

        Node node = result.nextNode();

        // Wrap "namespace node" in an XPathNamespace
        if (isNamespaceNode(node)) {
            return new XPathNamespaceImpl(node);
        } else {
            return node;
        }
        }
 
Example 8
Source File: XPathResultImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
         * The value of this single node result, which may be <code>null</code>.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>ANY_UNORDERED_NODE_TYPE</code> or
     *   <code>FIRST_ORDERED_NODE_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#getSingleNodeValue()
         */
        public Node getSingleNodeValue() throws XPathException {

                if ((m_resultType != ANY_UNORDERED_NODE_TYPE) &&
                    (m_resultType != FIRST_ORDERED_NODE_TYPE)) {
                                String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_SINGLENODE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
                                throw new XPathException(XPathException.TYPE_ERR,fmsg);
//                              "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a single node.
//                               This method applies only to types ANY_UNORDERED_NODE_TYPE and FIRST_ORDERED_NODE_TYPE."
            }

                NodeIterator result = null;
                try {
                        result = m_resultObj.nodeset();
                } catch (TransformerException te) {
                        throw new XPathException(XPathException.TYPE_ERR,te.getMessage());
                }

        if (null == result) return null;

        Node node = result.nextNode();

        // Wrap "namespace node" in an XPathNamespace
        if (isNamespaceNode(node)) {
            return new XPathNamespaceImpl(node);
        } else {
            return node;
        }
        }
 
Example 9
Source File: XPathResultImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
         * @see org.w3c.dom.xpath.XPathResult#getBooleanValue()
         */
        public boolean getBooleanValue() throws XPathException {
                if (getResultType() != BOOLEAN_TYPE) {
                        String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_BOOLEAN, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
                        throw new XPathException(XPathException.TYPE_ERR,fmsg);
//              "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a boolean."
                } else {
                        try {
                           return m_resultObj.bool();
                        } catch (TransformerException e) {
                                // Type check above should prevent this exception from occurring.
                                throw new XPathException(XPathException.TYPE_ERR,e.getMessage());
                        }
                }
        }
 
Example 10
Source File: XPathResultImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
         * The value of this single node result, which may be <code>null</code>.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>ANY_UNORDERED_NODE_TYPE</code> or
     *   <code>FIRST_ORDERED_NODE_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#getSingleNodeValue()
         */
        public Node getSingleNodeValue() throws XPathException {

                if ((m_resultType != ANY_UNORDERED_NODE_TYPE) &&
                    (m_resultType != FIRST_ORDERED_NODE_TYPE)) {
                                String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_SINGLENODE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
                                throw new XPathException(XPathException.TYPE_ERR,fmsg);
//                              "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a single node.
//                               This method applies only to types ANY_UNORDERED_NODE_TYPE and FIRST_ORDERED_NODE_TYPE."
            }

                NodeIterator result = null;
                try {
                        result = m_resultObj.nodeset();
                } catch (TransformerException te) {
                        throw new XPathException(XPathException.TYPE_ERR,te.getMessage());
                }

        if (null == result) return null;

        Node node = result.nextNode();

        // Wrap "namespace node" in an XPathNamespace
        if (isNamespaceNode(node)) {
            return new XPathNamespaceImpl(node);
        } else {
            return node;
        }
        }
 
Example 11
Source File: XPathResultImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
         * @see org.w3c.dom.xpath.XPathResult#getBooleanValue()
         */
        public boolean getBooleanValue() throws XPathException {
                if (getResultType() != BOOLEAN_TYPE) {
                        String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_BOOLEAN, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
                        throw new XPathException(XPathException.TYPE_ERR,fmsg);
//              "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a boolean."
                } else {
                        try {
                           return m_resultObj.bool();
                        } catch (TransformerException e) {
                                // Type check above should prevent this exception from occurring.
                                throw new XPathException(XPathException.TYPE_ERR,e.getMessage());
                        }
                }
        }
 
Example 12
Source File: UtilXml.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public static void writeXmlDocument(OutputStream os, Node node) throws java.io.IOException {
    if (node == null) {
        Debug.logWarning("[UtilXml.writeXmlDocument] Node was null, doing nothing" + getLogSuffixDetailed(), module); // SCIPIO: getLogSuffixDetailed
        return;
    }
    // OutputFormat defaults are: indent on, indent = 4, include XML declaration,
    // charset = UTF-8, line width = 72
    try {
        writeXmlDocument(node, os, "UTF-8", false, true, 4);
    } catch (TransformerException e) {
        // Wrapping this exception for backwards compatibility
        throw new IOException(e.getMessage());
    }
}
 
Example 13
Source File: XSLTStreamingOutput.java    From everrest with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void write(OutputStream output) throws IOException {
    try {
        Transformer transformer = templates.newTransformer();
        transformer.transform(source, new StreamResult(output));
    } catch (TransformerException tre) {
        throw new IOException(tre.getMessage(), tre);
    }
}
 
Example 14
Source File: SingleSignOnServiceImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private String toXMLString(Element assertion) throws TechnicalConnectorException {
   try {
      StreamResult sr = new StreamResult(new StringWriter());
      Transformer tf = TransformerFactory.newInstance().newTransformer();
      tf.setOutputProperty("encoding", "utf8");
      tf.setOutputProperty("indent", "no");
      tf.setOutputProperty("media-type", "text/xml");
      tf.setOutputProperty("omit-xml-declaration", "yes");
      tf.transform(new DOMSource(assertion), sr);
      return sr.getWriter().toString();
   } catch (TransformerException var4) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.CORE_TECHNICAL, var4, new Object[]{var4.getMessage()});
   }
}
 
Example 15
Source File: SingleSignOnServiceImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private String toXMLString(Element assertion) throws TechnicalConnectorException {
   try {
      StreamResult sr = new StreamResult(new StringWriter());
      Transformer tf = TransformerFactory.newInstance().newTransformer();
      tf.setOutputProperty("encoding", "utf8");
      tf.setOutputProperty("indent", "no");
      tf.setOutputProperty("media-type", "text/xml");
      tf.setOutputProperty("omit-xml-declaration", "yes");
      tf.transform(new DOMSource(assertion), sr);
      return sr.getWriter().toString();
   } catch (TransformerException var4) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.CORE_TECHNICAL, var4, new Object[]{var4.getMessage()});
   }
}
 
Example 16
Source File: SingleSignOnServiceImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private String toXMLString(Element assertion) throws TechnicalConnectorException {
   try {
      StreamResult sr = new StreamResult(new StringWriter());
      Transformer tf = TransformerFactory.newInstance().newTransformer();
      tf.setOutputProperty("encoding", "utf8");
      tf.setOutputProperty("indent", "no");
      tf.setOutputProperty("media-type", "text/xml");
      tf.setOutputProperty("omit-xml-declaration", "yes");
      tf.transform(new DOMSource(assertion), sr);
      return sr.getWriter().toString();
   } catch (TransformerException var4) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.CORE_TECHNICAL, var4, new Object[]{var4.getMessage()});
   }
}
 
Example 17
Source File: XPathResultImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
         * The value of this single node result, which may be <code>null</code>.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>ANY_UNORDERED_NODE_TYPE</code> or
     *   <code>FIRST_ORDERED_NODE_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#getSingleNodeValue()
         */
        public Node getSingleNodeValue() throws XPathException {

                if ((m_resultType != ANY_UNORDERED_NODE_TYPE) &&
                    (m_resultType != FIRST_ORDERED_NODE_TYPE)) {
                                String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_SINGLENODE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
                                throw new XPathException(XPathException.TYPE_ERR,fmsg);
//                              "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a single node.
//                               This method applies only to types ANY_UNORDERED_NODE_TYPE and FIRST_ORDERED_NODE_TYPE."
            }

                NodeIterator result = null;
                try {
                        result = m_resultObj.nodeset();
                } catch (TransformerException te) {
                        throw new XPathException(XPathException.TYPE_ERR,te.getMessage());
                }

        if (null == result) return null;

        Node node = result.nextNode();

        // Wrap "namespace node" in an XPathNamespace
        if (isNamespaceNode(node)) {
            return new XPathNamespaceImpl(node);
        } else {
            return node;
        }
        }
 
Example 18
Source File: XPathResultImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
         * @see org.w3c.dom.xpath.XPathResult#getBooleanValue()
         */
        public boolean getBooleanValue() throws XPathException {
                if (getResultType() != BOOLEAN_TYPE) {
                        String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_BOOLEAN, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
                        throw new XPathException(XPathException.TYPE_ERR,fmsg);
//              "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a boolean."
                } else {
                        try {
                           return m_resultObj.bool();
                        } catch (TransformerException e) {
                                // Type check above should prevent this exception from occurring.
                                throw new XPathException(XPathException.TYPE_ERR,e.getMessage());
                        }
                }
        }
 
Example 19
Source File: OaiCatalogTest.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testOaiErrorResponseTransformation() throws Exception {
    OaiCatalog c = new OaiCatalog("", "");
    String srcUrl = OaiCatalogTest.class.getResource("oaiErrorResponse.xml").toExternalForm();
    try {
        c.transformOaiResponse(new StreamSource(srcUrl), new StreamResult(new StringWriter()));
        fail();
    } catch (TransformerException result) {
        String msg = result.getMessage();
        assertTrue(msg, msg.contains("cannotDisseminateFormat"));
    }
}
 
Example 20
Source File: XmlDocument.java    From JVoiceXML with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the contents of this object as an XML formatted string.
 *
 * @return XML representation of this object.
 *
 * @exception IOException
 *            Error writing to the writer.
 */
public final String toXml()
        throws IOException {
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final Result result = new StreamResult(out);
    final TransformerFactory transformerFactory =
        TransformerFactory.newInstance();
    try {
        final Transformer transformer = transformerFactory.newTransformer();
        final String encoding = System.getProperty("jvoicexml.xml.encoding",
            "UTF-8");
        transformer.setOutputProperty(OutputKeys.ENCODING, encoding);
        transformer.setOutputProperty(OutputKeys.STANDALONE, "yes");
        final DocumentType type = getDoctype();
        if (type != null) {
            transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,
                    type.getPublicId());
            transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,
                    type.getSystemId());
        }
        final Source source = new DOMSource(document);
        transformer.transform(source, result);
        return out.toString(encoding);
    } catch (TransformerException e) {
        throw new IOException(e.getMessage(), e);
    }
}