private SAXBuilder getBuilder() { SAXBuilder saxBuilder = saxBuilderThreadLocal.get(); if (saxBuilder == null) { saxBuilder = new SAXBuilder(); saxBuilderThreadLocal.set(saxBuilder); } return saxBuilder; }
/** * 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 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); } }
private Document parseXML(byte[] xml) throws Exception { SAXBuilder builder = new SAXBuilder(); InputStream stream = new ByteArrayInputStream(xml); return builder.build(stream); } }
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)); } }
private Element elementFor(String content) throws JDOMException, IOException { SAXBuilder builder = new SAXBuilder(); return builder.build(new ByteArrayInputStream(content.getBytes())).getRootElement(); } }
private Element getRenderedDocument(HtmlRenderer renderer) throws JDOMException, IOException { String renderedString = "<div>" + renderer.asString() + "</div>"; return new SAXBuilder().build(new StringReader(renderedString)).getRootElement(); }
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(); }
@Test public void shouldParseSvnLogContainingNullComments() throws IOException { String xml; try (InputStream stream = getClass().getResourceAsStream("jemstep_svn_log.xml")) { xml = IOUtils.toString(stream, UTF_8); } SvnLogXmlParser parser = new SvnLogXmlParser(); List<Modification> revisions = parser.parse(xml, "", new SAXBuilder()); assertThat(revisions.size(), is(43)); Modification modWithoutComment = null; for (Modification revision : revisions) { if (revision.getRevision().equals("7815")) { modWithoutComment = revision; } } assertThat(modWithoutComment.getComment(), is(nullValue())); }
@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)); }
@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")); } }
@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()); } }
@Test public void shouldMaskPassword_remoteInfo() { try { badUserNameCommand().remoteInfo(new SAXBuilder()); fail("should have failed"); } catch (Exception e) { assertThat("Plain text password detected!", e.getMessage().contains(HARRYS_PASSWORD), is(false)); } try { badPasswordCommand().remoteInfo(new SAXBuilder()); fail("should have failed"); } catch (Exception e) { assertThat("Plain text password detected!", e.getMessage().contains("some_bad_password"), is(false)); } try { badUrlCommand().remoteInfo(new SAXBuilder()); fail("should have failed"); } catch (Exception e) { assertThat("Plain text password detected!", e.getMessage().contains(HARRYS_PASSWORD), is(false)); } }
@Test public void shouldGetAllModifiedFilesUnderRootPath() { SvnLogXmlParser parser = new SvnLogXmlParser(); List<Modification> materialRevisions = parser.parse(MULTIPLE_FILES, "", new SAXBuilder()); Modification mod = materialRevisions.get(0); List<ModifiedFile> files = mod.getModifiedFiles(); assertThat(files.size(), is(2)); ModifiedFile file = files.get(0); assertThat(file.getFileName(), is("/trunk/revision3.txt")); assertThat(file.getAction(), is(ModifiedAction.added)); file = files.get(1); assertThat(file.getFileName(), is("/branch/1.1/readme.txt")); assertThat(file.getAction(), is(ModifiedAction.deleted)); }
@Test public void shouldSupportSvnInfo() throws Exception { SvnCommand.SvnInfo info = command.remoteInfo(new SAXBuilder()); assertThat(info.getUrl(), is(repository.getUrl())); }
@Test public void shouldParse() throws ParseException { SvnLogXmlParser parser = new SvnLogXmlParser(); List<Modification> materialRevisions = parser.parse(XML, "", new SAXBuilder()); assertThat(materialRevisions.size(), is(1)); Modification mod = materialRevisions.get(0); assertThat(mod.getRevision(), is("3")); assertThat(mod.getUserName(), is("cceuser")); assertThat(mod.getModifiedTime(), is(convertDate("2008-03-11T07:52:41.162075Z"))); assertThat(mod.getComment(), is("[Liyanhui & Gabbar] Checked in new file for test")); List<ModifiedFile> files = mod.getModifiedFiles(); assertThat(files.size(), is(1)); ModifiedFile file = files.get(0); assertThat(file.getFileName(), is("/trunk/revision3.txt")); assertThat(file.getAction(), is(ModifiedAction.added)); }
@Test public void shouldParsePartlyEncodedUrlAndPath() { String output = "<?xml version=\"1.0\"?>\n" + "<info>\n" + "<entry\n" + " kind=\"dir\"\n" + " path=\"unit-reports\"\n" + " revision=\"3\">\n" + "<url>svn+ssh://hostname/foo%20bar%20baz/end2end</url>\n" + "<repository>\n" + "<root>svn+ssh://hostname/foo%20bar%20baz</root>\n" + "<uuid>f953918e-915c-4459-8d4c-83860cce9d9a</uuid>\n" + "</repository>\n" + "<commit\n" + " revision=\"1\">\n" + "<author>cceuser</author>\n" + "<date>2008-03-20T04:00:43.976517Z</date>\n" + "</commit>\n" + "</entry>\n" + "</info>"; SvnCommand.SvnInfo svnInfo = new SvnCommand.SvnInfo(); svnInfo.parse(output, new SAXBuilder()); assertThat(svnInfo.getUrl(), is("svn+ssh://hostname/foo%20bar%20baz/end2end")); assertThat(svnInfo.getPath(), is("/end2end")); }
@Test public void shouldParseEncodedUrl() { String output = "<?xml version=\"1.0\"?>\n" + "<info>\n" + "<entry\n" + " kind=\"dir\"\n" + " path=\"trunk\"\n" + " revision=\"8650\">\n" + "<url>https://217.45.214.17:8443/svn/Entropy%20System/Envoy%20Enterprise/trunk</url>\n" + "<repository>\n" + "<root>https://217.45.214.17:8443/svn</root>\n" + "<uuid>3ed677eb-f12f-3343-ac77-786e4d01a301</uuid>\n" + "</repository>\n" + "<commit\n" + " revision=\"8650\">\n" + "<author>BuildServer</author>\n" + "<date>2009-04-03 15:52:16 +0800 (Fri, 03 Apr 2009)</date>\n" + "</commit>\n" + "</entry>\n" + "</info>"; SvnCommand.SvnInfo svnInfo = new SvnCommand.SvnInfo(); svnInfo.parse(output, new SAXBuilder()); assertThat(svnInfo.getUrl(), is("https://217.45.214.17:8443/svn/Entropy%20System/Envoy%20Enterprise/trunk")); assertThat(svnInfo.getPath(), is("/Entropy System/Envoy Enterprise/trunk")); }
@Test public void shouldParseEncodedUrlAndPath() { String output = "<?xml version=\"1.0\"?>\n" + "<info>\n" + "<entry\n" + " kind=\"dir\"\n" + " path=\"unit-reports\"\n" + " revision=\"3\">\n" + "<url>file:///C:/Documents%20and%20Settings/cceuser/Local%20Settings/Temp/testSvnRepo-1243722556125/end2end/unit-reports</url>\n" + "<repository>\n" + "<root>file:///C:/Documents%20and%20Settings/cceuser/Local%20Settings/Temp/testSvnRepo-1243722556125/end2end</root>\n" + "<uuid>f953918e-915c-4459-8d4c-83860cce9d9a</uuid>\n" + "</repository>\n" + "<commit\n" + " revision=\"1\">\n" + "<author>cceuser</author>\n" + "<date>2008-03-20T04:00:43.976517Z</date>\n" + "</commit>\n" + "</entry>\n" + "</info>"; SvnCommand.SvnInfo svnInfo = new SvnCommand.SvnInfo(); svnInfo.parse(output, new SAXBuilder()); assertThat(svnInfo.getUrl(), is("file:///C:/Documents%20and%20Settings/cceuser/Local%20Settings/Temp/testSvnRepo-1243722556125/end2end/unit-reports")); assertThat(svnInfo.getPath(), is("/unit-reports")); }
public List<SvnExternal> getAllExternalURLs() { CommandLine svnExternalCommand = svn(true) .withArgs("propget", "--non-interactive", "svn:externals", "-R") .withArg(repositoryUrl); ConsoleResult result = executeCommand(svnExternalCommand); String svnExternalConsoleOut = result.outputAsString(); SvnInfo remoteInfo = remoteInfo(new SAXBuilder()); String repoUrl = remoteInfo.getUrl(); String repoRoot = remoteInfo.getRoot(); List<SvnExternal> svnExternalList = null; try { svnExternalList = new SvnExternalParser().parse(svnExternalConsoleOut, repoUrl, repoRoot); } catch (RuntimeException e) { throw (RuntimeException) result.smudgedException(e); } return svnExternalList; }