/** * @return the current working directory as an URL-form string */ private String getDefaultSystemId() { try { return PWD.toURL().toExternalForm(); } catch (MalformedURLException e) { throw new XMLUnitRuntimeException("Unable to determine current " + "working directory!", e); } } /**
/** * @return the current working directory as an URL-form string */ private String getDefaultSystemId() { try { return PWD.toURL().toExternalForm(); } catch (MalformedURLException e) { throw new XMLUnitRuntimeException("Unable to determine current " + "working directory!", e); } } /**
private static void addSchemaSources(Object schemaSources, List<Source> targetList) { if (schemaSources instanceof String) { targetList.add(new StreamSource((String) schemaSources)); } else if (schemaSources instanceof File) { targetList.add(new StreamSource((File) schemaSources)); } else if (schemaSources instanceof InputStream) { targetList.add(new StreamSource((InputStream) schemaSources)); } else if (schemaSources instanceof InputSource) { targetList.add(new SAXSource((InputSource) schemaSources)); } else if (schemaSources instanceof Object[]) { for (Object s : (Object[]) schemaSources) { addSchemaSources(s, targetList); } } else if (schemaSources != null) { throw new XMLUnitRuntimeException("Unknown schema source type: " + schemaSources.getClass()); } }
private static Document stripWhiteSpaceUsingXSLT(Document forDoc) { try { Transform whitespaceStripper = getStripWhitespaceTransform(forDoc); return whitespaceStripper.getResultDocument(); } catch (TransformerException e) { throw new XMLUnitRuntimeException(e.getMessage(), e.getCause()); } }
schema = parseSchema(null); } catch (SAXException e) { throw new XMLUnitRuntimeException("Schema is invalid", e); throw new XMLUnitRuntimeException("Error reading instance source", i);
private static Document stripWhiteSpaceUsingXSLT(Document forDoc) { try { Transform whitespaceStripper = getStripWhitespaceTransform(forDoc); return whitespaceStripper.getResultDocument(); } catch (TransformerException e) { throw new XMLUnitRuntimeException(e.getMessage(), e.getCause()); } }
throw new XMLUnitRuntimeException("failed to resolve entity: " + publicId, e); } catch (IOException e) { throw new XMLUnitRuntimeException("failed to resolve entity: " + publicId, e);
/** * Encapsulates a DOCTYPE declaration for the given name and system id. */ DoctypeSupport(String name, String systemId, Readable original, boolean characters, String encoding) { this.original = original; StringBuilder sb = new StringBuilder(DOCTYPE_OPEN_DECL); sb.append(DOCTYPE).append(name).append(SYSTEM) .append(systemId).append('\"').append(DOCTYPE_CLOSE_DECL); String s = sb.toString(); IntegerBuffer buf = new IntegerBuffer(s.length() * (characters ? 1 : 2)); if (characters) { char[] c = s.toCharArray(); for (int i = 0; i < c.length; i++) { buf.append(c[i]); } } else { try { byte[] b = encoding == null ? s.getBytes() : s.getBytes(encoding); for (int i = 0; i < b.length; i++) { buf.append(b[i] & 0xFF); } } catch (java.io.UnsupportedEncodingException use) { throw new XMLUnitRuntimeException("Unsupported encoding", use); } } decl = new IntBufferReadable(buf); }
/** * Encapsulates a DOCTYPE declaration for the given name and system id. */ DoctypeSupport(String name, String systemId, Readable original, boolean characters, String encoding) { this.original = original; StringBuffer sb = new StringBuffer(DOCTYPE_OPEN_DECL); sb.append(DOCTYPE).append(name).append(SYSTEM) .append(systemId).append('\"').append(DOCTYPE_CLOSE_DECL); String s = sb.toString(); IntegerBuffer buf = new IntegerBuffer(s.length() * (characters ? 1 : 2)); if (characters) { char[] c = s.toCharArray(); for (int i = 0; i < c.length; i++) { buf.append(c[i]); } } else { try { byte[] b = encoding == null ? s.getBytes() : s.getBytes(encoding); for (int i = 0; i < b.length; i++) { buf.append(b[i] & 0xFF); } } catch (java.io.UnsupportedEncodingException use) { throw new XMLUnitRuntimeException("Unsupported encoding", use); } } decl = new IntBufferReadable(buf); }
/** * Removes all comment nodes if {@link XMLUnit#getIgnoreComments * comments are ignored}. * * @param orig a document making up one half of this difference * @return manipulated doc */ private Document getCommentlessDocument(Document orig) { if (!XMLUnit.getIgnoreComments()) { return orig; } try { Transform commentStripper = XMLUnit.getStripCommentsTransform(orig); return commentStripper.getResultDocument(); } catch (TransformerException e) { throw new XMLUnitRuntimeException(e.getMessage(), e.getCause()); } }
/** * Removes all comment nodes if {@link XMLUnit.getIgnoreComments * comments are ignored}. * * @param originalDoc a document making up one half of this difference * @return manipulated doc */ private Document getCommentlessDocument(Document orig) { if (!XMLUnit.getIgnoreComments()) { return orig; } try { Transform commentStripper = XMLUnit.getStripCommentsTransform(orig); return commentStripper.getResultDocument(); } catch (TransformerException e) { throw new XMLUnitRuntimeException(e.getMessage(), e.getCause()); } }
/** * Is the given schema instance valid according to the configured * schema definition(s)? * * @throws XMLUnitRuntimeException if the schema definition is * invalid or the Source is a SAXSource and the underlying * XMLReader throws an IOException (see {@link * javax.xml.validation.Validator#validate validate in * Validator}). */ public boolean isInstanceValid(Source instance) { try { return validator.validateInstance(instance).isValid(); } catch (XMLUnitException e) { throw new XMLUnitRuntimeException(e.getMessage(), e.getCause()); } }
throw new ConfigurationException(e.getCause()); } catch (org.xmlunit.XMLUnitException e) { throw new XMLUnitRuntimeException(e.getMessage(), e.getCause());
/** * Obtain a list of all errors in the given instance. * * <p>The list contains {@link org.xml.sax.SAXParseException * SAXParseException}s.</p> * * @throws XMLUnitRuntimeException if the schema definition is * invalid or the Source is a SAXSource and the underlying * XMLReader throws an IOException (see {@link * javax.xml.validation.Validator#validate validate in * Validator}). */ public List<SAXParseException> getInstanceErrors(Source instance) { try { return problemToExceptionList(validator.validateInstance(instance). getProblems()); } catch (XMLUnitException e) { throw new XMLUnitRuntimeException(e.getMessage(), e.getCause()); } }
static <R> R withExceptionHandling(Trans<R> trans) throws TransformerException { try { return trans.transform(); } catch (org.xmlunit.ConfigurationException ex) { throw new ConfigurationException(ex.getMessage(), ex.getCause()); } catch (XMLUnitException ex) { Throwable cause = ex.getCause(); if (cause instanceof TransformerException) { throw (TransformerException) cause; } throw new XMLUnitRuntimeException(ex.getMessage(), cause); } }