protected Document createDocument(Element root) { Document doc = new Document(root); DocType docType = new DocType(RSS091NetscapeParser.ELEMENT_NAME, RSS091NetscapeParser.PUBLIC_ID, RSS091NetscapeParser.SYSTEM_ID); doc.setDocType(docType); return doc; }
/** * @deprecated TODO very ugly hack to force documents to be validated against OUR DTD. * We could use an EntityResolver, but it seems that with SAX, the documents will only be * validated if they original have a doctype declaration. * We could also use http://doctypechanger.sourceforge.net/ * ... or switch to XmlSchema. */ private Reader replaceDtd(Reader reader) throws IOException { String content = IOUtils.toString(reader); // remove doctype Pattern pattern = Pattern.compile("<!DOCTYPE .*>"); Matcher matcher = pattern.matcher(content); content = matcher.replaceFirst(""); // set doctype to the dtd try { Document doc = new SAXBuilder().build(new StringReader(content)); doc.setDocType(new DocType("module", dtdUrl)); // write the xml to the string XMLOutputter outputter = new XMLOutputter(); StringWriter writer = new StringWriter(); outputter.output(doc, writer); final String replacedDtd = writer.toString(); return new StringReader(replacedDtd); } catch (JDOMException e) { throw new RuntimeException(e); // TODO } }
protected Document createDocument(Element root) { Document doc = new Document(root); DocType docType = new DocType(RSS091NetscapeParser.ELEMENT_NAME, RSS091NetscapeParser.PUBLIC_ID, RSS091NetscapeParser.SYSTEM_ID); doc.setDocType(docType); return doc; }
public void output(Document document, Writer out) throws IOException { DocType type = new DocType("html", "-//W3C//DTD HTML 4.01//EN", "http://www.w3.org/TR/html4/strict.dtd"); document.setDocType(type); super.output(document, out); }
@Override public void handleOutput(TestSuiteReport suite, Document jdom) throws IOException { log.info("Generate report DOM for " + suite); jdom.setDocType(new DocType("testsuite", "-//Selunit//DTD Selunit Report 1.0.0//EN", "selunit-report_1_0_0.dtd")); try { jdom.setRootElement(getSuiteElement(suite)); } catch (JDOMException e) { throw new IOException("Error during output of suite: " + suite, e); } }
/** * @deprecated TODO very ugly hack to force documents to be validated against OUR DTD. * We could use an EntityResolver, but it seems that with SAX, the documents will only be * validated if they original have a doctype declaration. * We could also use http://doctypechanger.sourceforge.net/ * ... or switch to XmlSchema. */ private Reader replaceDtd(Reader reader) throws IOException { String content = IOUtils.toString(reader); // remove doctype Pattern pattern = Pattern.compile("<!DOCTYPE .*>"); Matcher matcher = pattern.matcher(content); content = matcher.replaceFirst(""); // set doctype to the dtd try { Document doc = new SAXBuilder().build(new StringReader(content)); doc.setDocType(new DocType("components", dtdUrl)); // write the xml to the string XMLOutputter outputter = new XMLOutputter(); StringWriter writer = new StringWriter(); outputter.output(doc, writer); final String replacedDtd = writer.toString(); return new StringReader(replacedDtd); } catch (JDOMException e) { throw new ComponentConfigurationException(e); } }
private void validateAgainstDTD(Document doc) throws RulesDocumentException { doc.setDocType(new DocType("macker", dtdUrlS)); StringWriter out = new StringWriter(); try { xmlOut.output(doc, out); } catch (IOException ioe) { ioe.printStackTrace(); throw new RuntimeException("Unexpected output exception: " + ioe); } Reader in = new StringReader(out.toString()); try { saxBuilderVerify.build(in); } catch (JDOMException jdome) { throw new RulesDocumentException(jdome); } catch (IOException ioe) { throw new RulesDocumentException(ioe); } }
/** * This will create a new <code>Document</code>, * with the supplied <code>{@link Element}</code> * as the root element, the supplied * <code>{@link DocType}</code> declaration, and the specified * base URI. * * @param rootElement <code>Element</code> for document root. * @param docType <code>DocType</code> declaration. * @param baseURI the URI from which this doucment was loaded. * @throws IllegalAddException if the given docType object * is already attached to a document or the given * rootElement already has a parent */ public Document(Element rootElement, DocType docType, String baseURI) { if (rootElement != null) { setRootElement(rootElement); } if (docType != null) { setDocType(docType); } if (baseURI != null) { setBaseURI(baseURI); } }
/** * */ public void writeTo(boolean isShort) throws Exception { Element root = dBase.toXML(); Vector cnt = new Vector(); cnt.add(root); Document doc = new Document(cnt); if (isShort) { TransformerFactory tFactory = TransformerFactory.newInstance(); StreamSource style = getStyle(); JDOMResult result = new JDOMResult(); JDOMSource source = new JDOMSource(doc); Transformer trans = tFactory.newTransformer(style); trans.setOutputProperty(OutputKeys.METHOD, "xml"); trans.setOutputProperty(OutputKeys.INDENT, "yes"); trans.transform(source, result); doc = result.getDocument(); doc.setDocType( new DocType( "database", "-//AIS.PL//DTD Mapping Description 0.4//EN", "http://www.ais.pl/dtds/mapping_0_4.dtd")); } XMLOutputter xo = new XMLOutputter(); String xoDoc = xo.outputString(doc); System.out.println(xoDoc); }
doc.setDocType(docType);
public void writeDocType(String name, String sys, String pub, String subset) throws IOException { DocType docType; if(null != pub) { docType = new DocType(name, pub, sys); } else if(null != sys) { docType = new DocType(name, sys); } else { docType = new DocType(name); } if(null != subset) { docType.setInternalSubset(subset); } this.document.setDocType(docType); }
document.setDocType(new DocType("web-app", "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN", "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd")); document.setDocType(new DocType("web-app", "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN", "http://java.sun.com/dtd/web-app_2_3.dtd")); document.setDocType(new DocType("web-app", "http://java.sun.com/xml/ns/j2ee")); document.setDocType(new DocType("web-app", "http://java.sun.com/xml/ns/j2ee")); document.setDocType(new DocType("web-app", "http://java.sun.com/xml/ns/j2ee")); document.setDocType(new DocType("web-app", "http://java.sun.com/xml/ns/j2ee"));
document.setDocType(new DocType("web-app", "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN", "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd")); document.setDocType(new DocType("web-app", "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN", "http://java.sun.com/dtd/web-app_2_3.dtd")); document.setDocType(new DocType("web-app", "http://java.sun.com/xml/ns/j2ee")); document.setDocType(new DocType("web-app", "http://java.sun.com/xml/ns/j2ee")); document.setDocType(new DocType("web-app", "http://java.sun.com/xml/ns/j2ee")); document.setDocType(new DocType("web-app", "http://java.sun.com/xml/ns/j2ee"));