List of usage examples for org.jdom2.input SAXBuilder SAXBuilder
public SAXBuilder(final XMLReaderJDOMFactory readersouce)
From source file:com.hotaviano.tableexporter.DefaultStringTableParser.java
License:Open Source License
@Override public Document parse(String table) throws JDOMException, IOException { File xsdfile = new File(XSD_TABLE); XMLReaderJDOMFactory schemafac = new XMLReaderXSDFactory(xsdfile); SAXBuilder builder = new SAXBuilder(schemafac); return builder.build(new StringReader(table)); }
From source file:com.izforge.izpack.util.xmlmerge.merge.DefaultXmlMerge.java
License:Open Source License
@Override public InputStream merge(InputStream[] sources) throws AbstractXmlMergeException { SAXBuilder builder = new SAXBuilder(XMLReaders.NONVALIDATING); // Xerces-specific - see: http://xerces.apache.org/xerces-j/features.html builder.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); Document[] docs = new Document[sources.length]; for (int i = 0; i < sources.length; i++) { try {/*from ww w. j av a 2 s .c o m*/ docs[i] = builder.build(sources[i]); } catch (Exception e) { throw new ParseException(e); } } Document result = doMerge(docs); Format prettyFormatter = Format.getPrettyFormat(); // Use system line seperator to avoid problems // with carriage return under linux prettyFormatter.setLineSeparator(System.getProperty("line.separator")); XMLOutputter sortie = new XMLOutputter(prettyFormatter); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); try { sortie.output(result, buffer); } catch (IOException ex) { throw new DocumentException(result, ex); } return new ByteArrayInputStream(buffer.toByteArray()); }
From source file:com.izforge.izpack.util.xmlmerge.merge.DefaultXmlMerge.java
License:Open Source License
@Override public void merge(File[] sources, File target) throws AbstractXmlMergeException { SAXBuilder builder = new SAXBuilder(XMLReaders.NONVALIDATING); // Xerces-specific - see: http://xerces.apache.org/xerces-j/features.html builder.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); Document[] docs = new Document[sources.length]; for (int i = 0; i < sources.length; i++) { try {//from w ww .ja v a 2s.c om docs[i] = builder.build(sources[i]); } catch (Exception e) { throw new ParseException(e); } } Document result = doMerge(docs); Format prettyFormatter = Format.getPrettyFormat(); // Use system line separator to avoid problems // with carriage return under linux prettyFormatter.setLineSeparator(System.getProperty("line.separator")); XMLOutputter sortie = new XMLOutputter(prettyFormatter); try { sortie.output(result, new FileOutputStream(target)); } catch (IOException ex) { throw new DocumentException(result, ex); } }
From source file:com.kixeye.kixmpp.KixmppWebSocketCodec.java
License:Apache License
@Override protected void decode(ChannelHandlerContext ctx, Object msg, List<Object> out) throws Exception { WebSocketFrame frame = (WebSocketFrame) msg; ByteBuf content = frame.retain().content(); String frameString = content.toString(StandardCharsets.UTF_8); if (logger.isDebugEnabled()) { logger.debug("Received: [{}]", frameString); }//from ww w . j a v a 2 s . c om if (frameString.startsWith("<?xml")) { frameString = frameString.replaceFirst("<\\?xml.*?\\?>", ""); } if (frameString.startsWith("<stream:stream")) { out.add(new KixmppStreamStart(null, true)); } else if (frameString.startsWith("</stream:stream")) { out.add(new KixmppStreamEnd()); } else { SAXBuilder saxBuilder = new SAXBuilder(readerFactory); Document document = saxBuilder.build(new ByteBufInputStream(content)); Element element = document.getRootElement(); out.add(element); } }
From source file:com.marklogic.client.example.handle.JDOMHandle.java
License:Apache License
protected SAXBuilder makeBuilder() { return new SAXBuilder(XMLReaders.NONVALIDATING); }
From source file:com.marklogic.client.example.handle.JDOMHandleExample.java
License:Apache License
public static void runShortcut(ExampleProperties props) throws JDOMException, IOException { String filename = "flipper.xml"; // register the handle from the extra library DatabaseClientFactory.getHandleRegistry().register(JDOMHandle.newFactory()); // create the client DatabaseClient client = DatabaseClientFactory.newClient(props.host, props.port, props.writerUser, props.writerPassword, props.authType); // create a manager for documents of any format XMLDocumentManager docMgr = client.newXMLDocumentManager(); // read the example file InputStream docStream = Util.openStream("data" + File.separator + filename); if (docStream == null) throw new IOException("Could not read document example"); // create an identifier for the document String docId = "/example/" + filename; // parse the example file with JDOM Document writeDocument = new SAXBuilder(XMLReaders.NONVALIDATING) .build(new InputStreamReader(docStream, "UTF-8")); // write the document docMgr.writeAs(docId, writeDocument); // ... at some other time ... // read the document content Document readDocument = docMgr.readAs(docId, Document.class); String rootName = readDocument.getRootElement().getName(); // delete the document docMgr.delete(docId);// w w w .j av a2 s . c o m System.out.println("(Shortcut) Wrote and read /example/" + filename + " content with the <" + rootName + "/> root element using JDOM"); // release the client client.release(); }
From source file:com.rhythm.louie.server.LouieProperties.java
License:Apache License
private static Document loadDocument(URL configs, boolean validate) { Document properties;/*from www . jav a 2 s . co m*/ SAXBuilder docBuilder; if (validate) { docBuilder = new SAXBuilder(XMLReaders.XSDVALIDATING); } else { docBuilder = new SAXBuilder(XMLReaders.NONVALIDATING); } try { properties = docBuilder.build(configs); } catch (NullPointerException ex) { LoggerFactory.getLogger(LouieProperties.class) .error("Failed to load properties file. Defaults will be used.\n{}", ex.toString()); System.out.println(ex.getMessage()); List<Server> empty = Collections.emptyList(); Server.processServers(empty); return null; } catch (IOException | JDOMException ex) { Matcher match = missingElem.matcher(ex.getMessage()); if (match.matches()) { LoggerFactory.getLogger(LouieProperties.class).info("No schema located: no validation performed."); return loadDocument(configs, false); } else { String error = "Properties file error! All services shutdown"; ServiceManager.recordError(error, ex); LoggerFactory.getLogger(LouieProperties.class).error("{}\n{}", error, ex.toString()); List<Server> empty = Collections.emptyList(); ServiceProperties.globalDisable(); //brute disable Server.processServers(empty); return null; } } document = new XMLOutputter().outputString(properties); return properties; }
From source file:com.soulgalore.velocity.MergeXMLWithVelocity.java
License:Apache License
String merge(String xml, String template, String[] extraXMLs) throws JDOMException, IOException { final File xmlFile = new File(xml); final SAXBuilder b = new SAXBuilder(new XMLReaderSAX2Factory(false)); final Document doc = b.build(xmlFile); context.put(CONTEXT_DOCUMENT, doc);// ww w .ja v a 2s. co m // TODO Old legacy naming, make this cleaner in the future int name = 2; for (String extraXML : extraXMLs) { final File xmlFileExtra = new File(extraXML); final Document doc2 = b.build(xmlFileExtra); context.put(CONTEXT_DOCUMENT + name, doc2); name++; } final StringWriter writer = new StringWriter(); final Template fromTemplate = ve.getTemplate(template); fromTemplate.merge(context, writer); return writer.toString(); }
From source file:de.andrena.tools.macker.rule.RuleSetBuilder.java
License:Open Source License
public RuleSetBuilder() { saxBuilder = new SAXBuilder(XMLReaders.XSDVALIDATING); }
From source file:de.herm_detlef.java.application.io.Export.java
License:Apache License
private static void validateDocument(ByteArrayInputStream inputStream) throws JDOMException, IOException { assert schemafac != null; SAXBuilder builder = new SAXBuilder(schemafac); // XML validation against schema definition happens here: builder.build(inputStream);//from ww w .j a va2s . c om }