public Document createDocument() throws XMLPlatformException { try { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); return documentBuilder.newDocument(); } catch (Exception e) { throw XMLPlatformException.xmlPlatformCouldNotCreateDocument(e); } }
public void setXMLSchema(URL url) throws XMLPlatformException { if (null == url) { return; } try { documentBuilderFactory.setAttribute(SCHEMA_LANGUAGE, XML_SCHEMA); documentBuilderFactory.setAttribute(JAXP_SCHEMA_SOURCE, url.toString()); } catch (IllegalArgumentException e) { // The attribute isn't supported so do nothing } catch (Exception e) { XMLPlatformException.xmlPlatformErrorResolvingXMLSchema(url, e); } }
public void setXMLSchemas(Object[] schemas) throws XMLPlatformException { if ((null == schemas) || (schemas.length == 0)) { return; } try { documentBuilderFactory.setAttribute(SCHEMA_LANGUAGE, XML_SCHEMA); documentBuilderFactory.setAttribute(JAXP_SCHEMA_SOURCE, schemas); } catch (IllegalArgumentException e) { // The attribute isn't supported so do nothing } catch (Exception e) { XMLPlatformException.xmlPlatformErrorResolvingXMLSchemas(schemas, e); } }
/** * Takes an error messsage string */ public static XMLPlatformException xmlPlatformValidationException(String errorMessage) { int errorCode = XML_PLATFORM_VALIDATION_EXCEPTION; XMLPlatformException exception = new XMLPlatformException(errorMessage); exception.setErrorCode(errorCode); return exception; }
public static XMLPlatformException xmlPlatformInvalidXPath(Exception nestedException) { Object[] args = { }; int errorCode = XML_PLATFORM_INVALID_XPATH; XMLPlatformException exception = new XMLPlatformException(ExceptionMessageGenerator.buildMessage(XMLPlatformException.class, errorCode, args)); exception.setErrorCode(errorCode); exception.setInternalException(nestedException); return exception; }
public Document parse(File file) throws XMLPlatformException { try { return getDocumentBuilder().parse(file); } catch (SAXParseException e) { throw XMLPlatformException.xmlPlatformSAXParseException(e); } catch (SAXException e) { throw XMLPlatformException.xmlPlatformParseException(e); } catch (IOException e) { throw XMLPlatformException.xmlPlatformFileNotFoundException(file, e); } }
public Document parse(InputStream inputStream) throws XMLPlatformException { try { return getDocumentBuilder().parse(inputStream); } catch (SAXParseException e) { throw XMLPlatformException.xmlPlatformSAXParseException(e); } catch (SAXException e) { throw XMLPlatformException.xmlPlatformParseException(e); } catch (IOException e) { throw XMLPlatformException.xmlPlatformParseException(e); } }
public boolean validateDocument(Document document, URL xmlSchemaURL, ErrorHandler errorHandler) throws XMLPlatformException { Schema xmlSchema; try { xmlSchema = getSchemaFactory().newSchema(xmlSchemaURL); } catch(SAXException e) { throw XMLPlatformException.xmlPlatformErrorResolvingXMLSchema(xmlSchemaURL, e); } try { Validator validator = xmlSchema.newValidator(); validator.setErrorHandler(errorHandler); validator.validate(new DOMSource(document)); } catch(Exception e) { throw XMLPlatformException.xmlPlatformValidationException(e); } return true; }
@Override public void warning(TransformerException exception) throws TransformerException { throw XMLPlatformException.xmlPlatformTransformException(exception); }
public JAXPParser(Map<String, Boolean> parserFeatures) { this(); try { if(null != parserFeatures) { for(String parserFeature : parserFeatures.keySet()) { documentBuilderFactory.setFeature(parserFeature, parserFeatures.get(parserFeature)); } } } catch(Exception e) { throw XMLPlatformException.xmlPlatformParseException(e); } }
/** * Execute advanced XPath statements that are required for TopLink EIS. * @param contextNode the node relative to which the XPath * statement will be executed. * xPath the XPath statement * namespaceResolver used to resolve namespace prefixes * to the corresponding namespace URI * @return the XPath result * @throws XMLPlatformException */ @Override public NodeList selectNodesAdvanced(Node contextNode, String xPathString, XMLNamespaceResolver xmlNamespaceResolver) throws XMLPlatformException { try { XPath xPath = getXPathFactory().newXPath(); if(null != xmlNamespaceResolver) { JAXPNamespaceContext namespaceContext = new JAXPNamespaceContext(xmlNamespaceResolver); xPath.setNamespaceContext(namespaceContext); } XPathExpression xPathExpression = xPath.compile(xPathString); return (NodeList) xPathExpression.evaluate(contextNode, XPathConstants.NODESET); } catch(XPathException e) { throw XMLPlatformException.xmlPlatformInvalidXPath(e); } }
private void handleErrors(XMLError xmlErr, ErrorHandler errorHandler) { try { int numberOfMessages = xmlErr.getNumMessages(); SAXParseException saxParseException; for (int x = 0; x < numberOfMessages; x++) { saxParseException = new SAXParseException(xmlErr.getMessage(x), xmlErr.getPublicId(x), xmlErr.getSystemId(x), xmlErr.getLineNumber(x), xmlErr.getColumnNumber(x), xmlErr.getException(x)); if (null == errorHandler) { throw saxParseException; } errorHandler.fatalError(saxParseException); } } catch (SAXException xmlex) { throw XMLPlatformException.xmlPlatformValidationException(xmlex); } }
public static XMLPlatformException xmlPlatformTransformException(Exception nestedException) { Object[] args = { }; int errorCode = XML_PLATFORM_TRANSFORM_EXCEPTION; XMLPlatformException exception = new XMLPlatformException(ExceptionMessageGenerator.buildMessage(XMLPlatformException.class, errorCode, args)); exception.setErrorCode(errorCode); exception.setInternalException(nestedException); return exception; } }
public Document parse(File file) throws XMLPlatformException { try { return getDocumentBuilder().parse(file); } catch (SAXParseException e) { throw XMLPlatformException.xmlPlatformSAXParseException(e); } catch (SAXException e) { throw XMLPlatformException.xmlPlatformParseException(e); } catch (IOException e) { throw XMLPlatformException.xmlPlatformFileNotFoundException(file, e); } }
public Document parse(InputStream inputStream) throws XMLPlatformException { try { return getDocumentBuilder().parse(inputStream); } catch (SAXParseException e) { throw XMLPlatformException.xmlPlatformSAXParseException(e); } catch (SAXException e) { throw XMLPlatformException.xmlPlatformParseException(e); } catch (IOException e) { throw XMLPlatformException.xmlPlatformParseException(e); } }
@Override public boolean validateDocument(Document document, URL xmlSchemaURL, ErrorHandler errorHandler) throws XMLPlatformException { Schema xmlSchema; try { xmlSchema = getSchemaFactory().newSchema(xmlSchemaURL); } catch(SAXException e) { throw XMLPlatformException.xmlPlatformErrorResolvingXMLSchema(xmlSchemaURL, e); } try { Validator validator = xmlSchema.newValidator(); validator.setErrorHandler(errorHandler); validator.validate(new DOMSource(document)); } catch(Exception e) { throw XMLPlatformException.xmlPlatformValidationException(e); } return true; }
@Override public void error(TransformerException exception) throws TransformerException { throw XMLPlatformException.xmlPlatformTransformException(exception); }
public Document parse(InputSource inputSource) throws XMLPlatformException { try { return getDocumentBuilder().parse(inputSource); } catch (SAXException e) { throw XMLPlatformException.xmlPlatformParseException(e); } catch (IOException e) { throw XMLPlatformException.xmlPlatformParseException(e); } }
/** * Execute advanced XPath statements that are required for TopLink EIS. * @param contextNode * @param xPathString * @param xmlNamespaceResolver * @return * @throws XMLPlatformException */ public Node selectSingleNodeAdvanced(Node contextNode, String xPathString, XMLNamespaceResolver xmlNamespaceResolver) throws XMLPlatformException { try { XPath xPath = getXPathFactory().newXPath(); if(null != xmlNamespaceResolver) { JAXPNamespaceContext namespaceContext = new JAXPNamespaceContext(xmlNamespaceResolver); xPath.setNamespaceContext(namespaceContext); } XPathExpression xPathExpression = xPath.compile(xPathString); return (Node) xPathExpression.evaluate(contextNode, XPathConstants.NODE); } catch(XPathException e) { throw XMLPlatformException.xmlPlatformInvalidXPath(e); } }
/** * Takes an error messsage string */ public static XMLPlatformException xmlPlatformValidationException(String errorMessage) { int errorCode = XML_PLATFORM_VALIDATION_EXCEPTION; XMLPlatformException exception = new XMLPlatformException(errorMessage); exception.setErrorCode(errorCode); return exception; }