List of usage examples for org.jdom2 Document getContent
@Override public <F extends Content> List<F> getContent(Filter<F> filter)
Document
's content. From source file:org.commonjava.maven.ext.io.PomIO.java
License:Apache License
private void write(final Project project, final File pom, final Model model) throws ManipulationException { try {/* w ww.ja va 2 s . c o m*/ final String manifestInformation = project.isInheritanceRoot() ? ManifestUtils.getManifestInformation() : null; MavenJDOMWriter mjw = new MavenJDOMWriter(model); // We possibly could store the EOL type in the Project when we first read // the file but we would then have to do a dual read, then write as opposed // to a read, then read + write now. LineSeparator ls = determineEOL(pom); mjw.setLineSeparator(ls); mjw.write(model, pom, new DocumentModifier() { @Override public void postProcess(final Document doc) { // Only add the modified by to the top level pom. if (project.isExecutionRoot()) { final Iterator<Content> it = doc.getContent(new ContentFilter(ContentFilter.COMMENT)) .iterator(); while (it.hasNext()) { final Comment c = (Comment) it.next(); if (c.toString().contains(MODIFIED_BY)) { it.remove(); } } doc.addContent(Collections.<Content>singletonList( new Comment("\nModified by POM Manipulation Extension for Maven " + manifestInformation + "\n"))); } } }); } catch (final IOException e) { throw new ManipulationException("Failed to read POM for rewrite: %s. Reason: %s", e, pom, e.getMessage()); } catch (final JDOMException e) { throw new ManipulationException("Failed to parse POM for rewrite: %s. Reason: %s", e, pom, e.getMessage()); } }