/** * Create and initialize the SAX builder. * * @return the SAX builder instance. * @since 1.4.9 */ protected SAXBuilder createBuilder() { final SAXBuilder builder = new SAXBuilder(); builder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); return builder; } }
private SAXBuilder getBuilder() { SAXBuilder saxBuilder = saxBuilderThreadLocal.get(); if (saxBuilder == null) { saxBuilder = new SAXBuilder(); saxBuilderThreadLocal.set(saxBuilder); } return saxBuilder; }
private Document parseXML(byte[] xml) throws Exception { SAXBuilder builder = new SAXBuilder(); InputStream stream = new ByteArrayInputStream(xml); return builder.build(stream); } }
public void parse(String xmlOutput, SAXBuilder builder) { try { Document document = builder.build(new StringReader(xmlOutput)); parseDOMTree(document); } catch (Exception e) { bomb("Unable to parse svn info output: " + xmlOutput, e); } }
private static Document buildXmlDocument(InputStream inputStream, SAXBuilder builder) throws JDOMException, IOException { XsdErrorTranslator errorHandler = new XsdErrorTranslator(); builder.setErrorHandler(errorHandler); Document cruiseRoot = builder.build(inputStream); if (errorHandler.hasValidationError()) { throw new XsdValidationException(errorHandler.translate()); } return cruiseRoot; }
public List<Modification> modifications() { try { SAXBuilder builder = new SAXBuilder(); Document document = builder.build(new StringReader(output)); return parseDOMTree(document); } catch (Exception e) { throw ExceptionUtils.bomb("Unable to parse hg log output: " + result.replaceSecretInfo(output), result.smudgedException(e)); } }
public List<Modification> parse(String svnLogOutput, String path, SAXBuilder builder) { try { Document document = builder.build(new StringReader(svnLogOutput)); return parseDOMTree(document, path); } catch (Exception e) { throw bomb("Unable to parse svn log output: " + svnLogOutput, e); } }
@Test(expected = RuntimeException.class) public void shouldThrowUpWhenSvnInfoOutputIsInvalidToMapUrlToUUID() { final SvnLogXmlParser svnLogXmlParser = new SvnLogXmlParser(); svnLogXmlParser.parseInfoToGetUUID("Svn threw up and it's drunk", "does not matter", new SAXBuilder()); } }
private Element elementFor(String content) throws JDOMException, IOException { SAXBuilder builder = new SAXBuilder(); return builder.build(new ByteArrayInputStream(content.getBytes())).getRootElement(); } }
public HashMap<String, String> parseInfoToGetUUID(String output, String queryURL, SAXBuilder builder) { HashMap<String, String> uidToUrlMap = new HashMap<>(); try { Document document = builder.build(new StringReader(output)); Element root = document.getRootElement(); List<Element> entries = root.getChildren("entry"); for (Element entry : entries) { uidToUrlMap.put(queryURL, entry.getChild("repository").getChild("uuid").getValue()); } } catch (Exception e) { throw new RuntimeException(e); } return uidToUrlMap; }
@Test public void shouldReportSvnOutputWhenErrorsHappen() { SvnLogXmlParser parser = new SvnLogXmlParser(); try { parser.parse("invalid xml", "", new SAXBuilder()); fail("should have failed when invalid xml is parsed"); } catch (Exception e) { assertThat(e.getMessage(), containsString("invalid xml")); } }
private int getCurrentSchemaVersion(String content) { try { SAXBuilder builder = new SAXBuilder(); Document document = builder.build(new ByteArrayInputStream(content.getBytes())); Element root = document.getRootElement(); String currentVersion = root.getAttributeValue(schemaVersion) == null ? "0" : root.getAttributeValue(schemaVersion); return Integer.parseInt(currentVersion); } catch (Exception e) { throw bomb(e); } }
public HierarchicalStreamReader createReader(URL in) { try { final SAXBuilder builder = createBuilder(); final Document document = builder.build(in); return new JDom2Reader(document, getNameCoder()); } catch (IOException e) { throw new StreamException(e); } catch (JDOMException e) { throw new StreamException(e); } }
@Test public void shouldFilterModifiedFilesByPath() { SvnLogXmlParser parser = new SvnLogXmlParser(); List<Modification> materialRevisions = parser.parse(MULTIPLE_FILES, "/branch", new SAXBuilder()); Modification mod = materialRevisions.get(0); List<ModifiedFile> files = mod.getModifiedFiles(); assertThat(files.size(), is(1)); ModifiedFile file = files.get(0); assertThat(file.getFileName(), is("/branch/1.1/readme.txt")); assertThat(file.getAction(), is(ModifiedAction.deleted)); }
public <T> T fromXmlPartial(InputStream inputStream, Class<T> o) throws Exception { Document document = new SAXBuilder().build(inputStream); Element element = document.getRootElement(); return classParser(element, o, configCache, new GoCipher(), registry, new ConfigReferenceElements()).parse(); }
public HierarchicalStreamReader createReader(File in) { try { final SAXBuilder builder = createBuilder(); final Document document = builder.build(in); return new JDom2Reader(document, getNameCoder()); } catch (IOException e) { throw new StreamException(e); } catch (JDOMException e) { throw new StreamException(e); } }
@Test public void shouldSupportSvnInfo() throws Exception { SvnCommand.SvnInfo info = command.remoteInfo(new SAXBuilder()); assertThat(info.getUrl(), is(repository.getUrl())); }
private Element getRenderedDocument(HtmlRenderer renderer) throws JDOMException, IOException { String renderedString = "<div>" + renderer.asString() + "</div>"; return new SAXBuilder().build(new StringReader(renderedString)).getRootElement(); }
public HierarchicalStreamReader createReader(InputStream in) { try { final SAXBuilder builder = createBuilder(); final Document document = builder.build(in); return new JDom2Reader(document, getNameCoder()); } catch (IOException e) { throw new StreamException(e); } catch (JDOMException e) { throw new StreamException(e); } }
public HierarchicalStreamReader createReader(Reader reader) { try { final SAXBuilder builder = createBuilder(); final Document document = builder.build(reader); return new JDom2Reader(document, getNameCoder()); } catch (IOException e) { throw new StreamException(e); } catch (JDOMException e) { throw new StreamException(e); } }