List of usage examples for org.jdom2.filter ContentFilter ContentFilter
public ContentFilter(int mask)
From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.OperatorNormalizer.java
License:Apache License
private void normalizeUnicode(final Element ancestor, final Normalizer.Form form) { assert ancestor != null && form != null; final List<Text> texts = new ArrayList<Text>(); final ContentFilter textFilter = new ContentFilter(ContentFilter.TEXT); for (Content text : ancestor.getContent(textFilter)) { texts.add((Text) text);// w ww . j ava 2 s .c o m } for (Element element : ancestor.getDescendants(new ElementFilter())) { for (Content text : element.getContent(textFilter)) { texts.add((Text) text); } } for (Text text : texts) { if (Normalizer.isNormalized(text.getText(), form)) { continue; } final String normalizedString = Normalizer.normalize(text.getText(), form); LOGGER.log(Level.FINE, "Text ''{0}'' normalized to ''{1}''", new Object[] { text.getText(), normalizedString }); text.setText(normalizedString); assert Normalizer.isNormalized(text.getText(), form); } }
From source file:ditatools.translate.DitaTranslator.java
License:Apache License
public DitaTranslator(String api_key, String lang) { apiKey = api_key;//from www . j av a 2 s .c om language = lang; translator = new Translator(apiKey); filter = new ContentFilter(ContentFilter.TEXT); // Allow elements through the filter filter.setElementVisible(true); // Allow text nodes through the filter filter.setTextVisible(true); builder = new SAXBuilder(); builder.setFeature("http://xml.org/sax/features/validation", false); builder.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); }
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 {// www. j a v a2 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()); } }