Java Code Examples for org.apache.ivy.util.XMLHelper#parse()
The following examples show how to use
org.apache.ivy.util.XMLHelper#parse() .
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: XmlModuleDescriptorUpdater.java From ant-ivy with Apache License 2.0 | 6 votes |
public static void update(URL inStreamCtx, InputStream inStream, OutputStream outStream, final UpdateOptions options) throws IOException, SAXException { final PrintWriter out = new PrintWriter(new OutputStreamWriter(outStream, StandardCharsets.UTF_8)); out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); out.write(LINE_SEPARATOR); try { UpdaterHandler updaterHandler = new UpdaterHandler(inStreamCtx, out, options); InputSource inSrc = new InputSource(new BufferedInputStream(inStream)); if (inStreamCtx != null) { inSrc.setSystemId(inStreamCtx.toExternalForm()); } XMLHelper.parse(inSrc, null, updaterHandler, updaterHandler); } catch (ParserConfigurationException e) { throw new IllegalStateException("impossible to update Ivy files: parser problem", e); } }
Example 2
Source File: IvyXmlModuleDescriptorParser.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
private void includeConfStarted(Attributes attributes) throws SAXException, IOException, ParserConfigurationException, ParseException { URL url = relativeUrlResolver.getURL(descriptorURL, substitute(attributes.getValue("file")), substitute(attributes.getValue("url"))); if (url == null) { throw new SAXException("include tag must have a file or an url attribute"); } // create a new temporary parser to read the configurations from // the specified file. Parser parser = newParser(new UrlExternalResource(url), url); XMLHelper.parse(url , null, parser); // add the configurations from this temporary parser to this module descriptor Configuration[] configs = parser.getModuleDescriptor().getConfigurations(); for (Configuration config : configs) { getMd().addConfiguration(config); } if (parser.getDefaultConfMapping() != null) { LOGGER.debug("setting default conf mapping from imported configurations file: " + parser.getDefaultConfMapping()); setDefaultConfMapping(parser.getDefaultConfMapping()); } if (parser.getDefaultConf() != null) { LOGGER.debug("setting default conf from imported configurations file: " + parser.getDefaultConf()); setDefaultConf(parser.getDefaultConf()); } if (parser.getMd().isMappingOverride()) { LOGGER.debug("enabling mapping-override from imported configurations file"); getMd().setMappingOverride(true); } }
Example 3
Source File: IvyXmlModuleDescriptorParser.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
private void includeConfStarted(Attributes attributes) throws SAXException, IOException, ParserConfigurationException, ParseException { URL url = relativeUrlResolver.getURL(descriptorURL, substitute(attributes.getValue("file")), substitute(attributes.getValue("url"))); if (url == null) { throw new SAXException("include tag must have a file or an url attribute"); } // create a new temporary parser to read the configurations from // the specified file. Parser parser = newParser(new UrlExternalResource(url), url); XMLHelper.parse(url , null, parser); // add the configurations from this temporary parser to this module descriptor Configuration[] configs = parser.getModuleDescriptor().getConfigurations(); for (Configuration config : configs) { getMd().addConfiguration(config); } if (parser.getDefaultConfMapping() != null) { LOGGER.debug("setting default conf mapping from imported configurations file: " + parser.getDefaultConfMapping()); setDefaultConfMapping(parser.getDefaultConfMapping()); } if (parser.getDefaultConf() != null) { LOGGER.debug("setting default conf from imported configurations file: " + parser.getDefaultConf()); setDefaultConf(parser.getDefaultConf()); } if (parser.getMd().isMappingOverride()) { LOGGER.debug("enabling mapping-override from imported configurations file"); getMd().setMappingOverride(true); } }
Example 4
Source File: P2MetadataParser.java From ant-ivy with Apache License 2.0 | 5 votes |
public void parse(InputStream in) throws IOException, ParseException, SAXException { RepositoryHandler handler = new RepositoryHandler(p2Descriptor); try { XMLHelper.parse(in, null, handler, null); } catch (ParserConfigurationException e) { throw new SAXException(e); } }
Example 5
Source File: P2CompositeParser.java From ant-ivy with Apache License 2.0 | 5 votes |
public void parse(InputStream in) throws IOException, ParseException, SAXException { RepositoryHandler handler = new RepositoryHandler(); try { XMLHelper.parse(in, null, handler, null); } catch (ParserConfigurationException e) { throw new SAXException(e); } childLocations.addAll(handler.childLocations); }
Example 6
Source File: P2ArtifactParser.java From ant-ivy with Apache License 2.0 | 5 votes |
public void parse(InputStream in) throws IOException, ParseException, SAXException { RepositoryHandler handler = new RepositoryHandler(p2Descriptor, repoUrl); try { XMLHelper.parse(in, null, handler, null); } catch (ParserConfigurationException e) { throw new SAXException(e); } }
Example 7
Source File: UpdateSiteDigestParser.java From ant-ivy with Apache License 2.0 | 5 votes |
public static UpdateSiteDescriptor parse(InputStream in, UpdateSite site) throws IOException, SAXException { DigestHandler handler = new DigestHandler(site); try { XMLHelper.parse(in, null, handler, null); } catch (ParserConfigurationException e) { throw new SAXException(e); } return handler.repoDescriptor; }
Example 8
Source File: FeatureParser.java From ant-ivy with Apache License 2.0 | 5 votes |
public static EclipseFeature parse(InputStream in) throws IOException, SAXException { FeatureHandler handler = new FeatureHandler(); try { XMLHelper.parse(in, null, handler, null); } catch (ParserConfigurationException e) { throw new SAXException(e); } return handler.feature; }
Example 9
Source File: EclipseUpdateSiteParser.java From ant-ivy with Apache License 2.0 | 5 votes |
public static UpdateSite parse(InputStream in) throws IOException, SAXException { SiteHandler handler = new SiteHandler(); try { XMLHelper.parse(in, null, handler, null); } catch (ParserConfigurationException e) { throw new SAXException(e); } return handler.updatesite; }
Example 10
Source File: OBRXMLParser.java From ant-ivy with Apache License 2.0 | 5 votes |
public static BundleRepoDescriptor parse(URI baseUri, InputStream in) throws IOException, SAXException { RepositoryHandler handler = new RepositoryHandler(baseUri); try { XMLHelper.parse(in, null, handler, null); } catch (ParserConfigurationException e) { throw new SAXException(e); } return handler.repo; }
Example 11
Source File: XmlModuleDescriptorParser.java From ant-ivy with Apache License 2.0 | 5 votes |
protected void includeConfStarted(Attributes attributes) throws SAXException, IOException, ParserConfigurationException, ParseException { URL url = settings.getRelativeUrlResolver().getURL(descriptorURL, settings.substitute(attributes.getValue("file")), settings.substitute(attributes.getValue("url"))); if (url == null) { throw new SAXException("include tag must have a file or an url attribute"); } // create a new temporary parser to read the configurations from // the specified file. Parser parser = new Parser(getModuleDescriptorParser(), settings); parser.setInput(url); parser.setMd(new DefaultModuleDescriptor(getModuleDescriptorParser(), new URLResource(url))); XMLHelper.parse(url, null, parser); // add the configurations from this temporary parser to this module descriptor for (Configuration config : parser.getModuleDescriptor().getConfigurations()) { getMd().addConfiguration(config); } if (parser.getDefaultConfMapping() != null) { Message.debug("setting default conf mapping from imported configurations file: " + parser.getDefaultConfMapping()); setDefaultConfMapping(parser.getDefaultConfMapping()); } if (parser.getDefaultConf() != null) { Message.debug("setting default conf from imported configurations file: " + parser.getDefaultConf()); setDefaultConf(parser.getDefaultConf()); } if (parser.getMd().isMappingOverride()) { Message.debug("enabling mapping-override from imported configurations" + " file"); getMd().setMappingOverride(true); } }
Example 12
Source File: XmlReportWriterTest.java From ant-ivy with Apache License 2.0 | 5 votes |
@Test public void testWriteOrigin() throws Exception { ResolveReport report = ivy.resolve(new File( "test/repositories/1/special-encoding-root-ivy.xml"), getResolveOptions(new String[] {"default"})); assertNotNull(report); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); XmlReportWriter writer = new XmlReportWriter(); writer.output(report.getConfigurationReport("default"), buffer); buffer.flush(); String xml = buffer.toString(XmlReportWriter.REPORT_ENCODING); String expectedLocation = "location=\"" + new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar").getAbsolutePath() + "\""; String expectedIsLocal = "is-local=\"true\""; String expectedOrg = "organisation=\"sp\u00E9cial\""; assertTrue("XML doesn't contain artifact location attribute", xml.contains(expectedLocation)); assertTrue("XML doesn't contain artifact is-local attribute", xml.contains(expectedIsLocal)); assertTrue("XML doesn't contain the organisation", xml.contains(expectedOrg)); // check that the XML is valid XMLHelper.parse(new ByteArrayInputStream(buffer.toByteArray()), null, new DefaultHandler(), null); }
Example 13
Source File: IBiblioResolver.java From ant-ivy with Apache License 2.0 | 4 votes |
private String findTimestampedSnapshotVersion(final ModuleRevisionId mrid) { if (!isM2compatible()) { return null; } if (!shouldUseMavenMetadata(getWholePattern())) { return null; } try { final String metadataLocation = IvyPatternHelper.substitute(root + "[organisation]/[module]/[revision]/maven-metadata.xml", mrid); final Resource metadata = getRepository().getResource(metadataLocation); if (!metadata.exists()) { Message.verbose("\tmaven-metadata not available for: " + mrid); return null; } try (final InputStream metadataStream = metadata.openStream()) { final StringBuilder timestamp = new StringBuilder(); final StringBuilder buildNumber = new StringBuilder(); XMLHelper.parse(metadataStream, null, new ContextualSAXHandler() { @Override public void endElement(String uri, String localName, String qName) throws SAXException { if ("metadata/versioning/snapshot/timestamp".equals(getContext())) { timestamp.append(getText()); } if ("metadata/versioning/snapshot/buildNumber".equals(getContext())) { buildNumber.append(getText()); } super.endElement(uri, localName, qName); } }, null); if (timestamp.length() > 0) { // we have found a timestamp, so this is a snapshot unique version String rev = mrid.getRevision(); rev = rev.substring(0, rev.length() - "SNAPSHOT".length()); rev += timestamp.toString() + "-" + buildNumber.toString(); return rev; } } } catch (IOException | SAXException | ParserConfigurationException e) { Message.debug("impossible to access maven metadata file, ignored", e); } return null; }