List of usage examples for org.jdom2 DefaultJDOMFactory DefaultJDOMFactory
public DefaultJDOMFactory()
From source file:com.thoughtworks.xstream.io.xml.JDom2Writer.java
License:Open Source License
/** * @since 1.4.5/*w w w . j a v a 2 s . c o m*/ */ public JDom2Writer(final Element container, final NameCoder nameCoder) { this(container, new DefaultJDOMFactory(), nameCoder); }
From source file:com.thoughtworks.xstream.io.xml.JDom2Writer.java
License:Open Source License
/** * @since 1.4.5 */ public JDom2Writer(final Element container) { this(container, new DefaultJDOMFactory()); }
From source file:com.thoughtworks.xstream.io.xml.JDom2Writer.java
License:Open Source License
/** * @since 1.4.5 */ public JDom2Writer() { this(new DefaultJDOMFactory()); }
From source file:org.kdp.word.Parser.java
License:Apache License
public String process(File infile) throws SAXException, IOException { IllegalArgumentAssertion.assertNotNull(infile, "infile"); log.info("Process: {}", infile); final Path source = Paths.get(infile.toURI()); final Path basedir = source.getParent(); initDefaults(basedir);/* ww w. j ava 2 s . c o m*/ log.debug("Using properties:"); for (String key : getPropertyKeys()) { log.debug(" " + key + " = " + getProperty(key)); } // Parse input file to Document final JDOMFactory factory = new DefaultJDOMFactory(); final Document doc = parseHTML(factory, infile); Context context = new Context() { private Map<String, Object> attributes = new HashMap<>(); @Override public JDOMFactory getJDOMFactory() { return factory; } @Override public Parser getParser() { return Parser.this; } @Override public Options getOptions() { return options; } @Override public Path getBasedir() { return basedir; } @Override public Path getSource() { return source; } @Override public Path getTarget() { Path outpath = options.getOutput(); if (outpath == null) { String fname = source.getFileName().toString(); fname = fname.substring(0, fname.lastIndexOf('.')) + ".html"; outpath = Paths.get(fname); } return outpath; } @Override public Element getSourceRoot() { return doc.getRootElement(); } @Override @SuppressWarnings("unchecked") public <T> T getAttribute(Class<T> type) { return (T) getAttributes().get(type.getName()); } @Override public <T> void putAttribute(Class<T> type, T value) { attributes.put(type.getName(), value); } @Override public Map<String, Object> getAttributes() { return attributes; } }; // Transform the Document for (Transformer tr : transformers) { log.debug("Transforming with: {}", tr); tr.transform(context); } // Get the result ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.writeDocument(context, doc, baos); String result = new String(baos.toByteArray()); // Write output file File outfile = options.getBookDir().resolve(context.getTarget()).toFile(); outfile.getParentFile().mkdirs(); log.debug("Writing output to: {}", outfile); FileOutputStream fos = new FileOutputStream(outfile); IOUtils.writeDocument(context, doc, fos); fos.close(); return result; }
From source file:org.mycore.common.content.transformer.MCRXSL2XMLTransformer.java
License:Open Source License
private Document getDocument(JDOMResult result) { Document resultDoc = result.getDocument(); if (resultDoc == null) { //Sometimes a transformation produces whitespace strings //JDOM would produce a empty document if it detects those //So we remove them, if they exists. List<Content> transformResult = result.getResult(); int origSize = transformResult.size(); Iterator<Content> iterator = transformResult.iterator(); while (iterator.hasNext()) { Content content = iterator.next(); if (content instanceof Text) { String trimmedText = ((Text) content).getTextTrim(); if (trimmedText.length() == 0) { iterator.remove();// ww w . ja v a 2 s .com } } } if (transformResult.size() < origSize) { JDOMFactory f = result.getFactory(); if (f == null) { f = new DefaultJDOMFactory(); } resultDoc = f.document(null); resultDoc.setContent(transformResult); } } return resultDoc; }