private void saveDocumentTo() throws XMLException { try { TransformerFactory tfactory = TransformerFactory.newInstance(); Transformer transf = tfactory.newTransformer(); transf.setOutputProperty( OutputKeys.INDENT, "yes" ); transf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); transf.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, "no" ); transf.setOutputProperty( OutputKeys.METHOD, "xml" ); DOMImplementation impl = doc.getImplementation(); DocumentType doctype = impl.createDocumentType( "doctype", "-//Recordare//DTD MusicXML 3.0 Partwise//EN", "http://www.musicxml.org/dtds/partwise.dtd" ); transf.setOutputProperty( OutputKeys.DOCTYPE_PUBLIC, doctype.getPublicId() ); transf.setOutputProperty( OutputKeys.DOCTYPE_SYSTEM, doctype.getSystemId() ); DOMSource src = new DOMSource( doc ); StreamResult resultS = new StreamResult( file ); transf.transform( src, resultS ); } catch ( TransformerException e ) { throw new XMLException( "Could not save the File" ); } }
private static DocumentType getDocumentType(Document doc) { DOMImplementation domImpl = doc.getImplementation(); // <!DOCTYPE datafile PUBLIC "-//Logiqx//DTD ROM Management Datafile//EN" "http://www.logiqx.com/Dats/datafile.dtd"> DocumentType doctype = domImpl.createDocumentType("datafile", "-//Logiqx//DTD ROM Management Datafile//EN", "http://www.logiqx.com/Dats/datafile.dtd"); return doctype; }
/** * Obtains DOMImpementaton interface providing a number of methods for performing * operations that are independent of any particular DOM instance. * * @throw DOMException <code>NOT_SUPPORTED_ERR</code> if cannot get DOMImplementation * @throw FactoryConfigurationError Application developers should never need to directly catch errors of this type. * * @return DOMImplementation implementation */ private static DOMImplementation getDOMImplementation() throws DOMException { //can be made public DocumentBuilderFactory factory = getFactory(false, false); try { return factory.newDocumentBuilder().getDOMImplementation(); } catch (ParserConfigurationException ex) { throw new DOMException( DOMException.NOT_SUPPORTED_ERR, "Cannot create parser satisfying configuration parameters" ); //NOI18N } catch (RuntimeException e) { // E.g. #36578, IllegalArgumentException. Try to recover gracefully. throw (DOMException) new DOMException(DOMException.NOT_SUPPORTED_ERR, e.toString()).initCause(e); } }
/** * @return with which to create document instances. * @throws java.sql.SQLException when unable to obtain the DOM * implementation instance. */ protected static DOMImplementation getDOMImplementation() throws SQLException { if (domImplementation == null) { domImplementation = getDOMImplementationRegistry().getDOMImplementation( domFeatures); } if (domImplementation == null) { Exception ex = new RuntimeException("Not supported: " + domFeatures); throw Exceptions.domInstantiation(ex); } return domImplementation; }
private void writeSVG(OutputStream stream) throws IOException { DOMImplementation impl = GenericDOMImplementation .getDOMImplementation(); String svgNS = "http://www.w3.org/2000/svg"; Document myFactory = impl.createDocument(svgNS, "svg", null); SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(myFactory); ctx.setEmbeddedFontsOn(Options.getBoolean("EMBEDDED_SVG_FONTS", true)); SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, Options.getBoolean( "EMBEDDED_SVG_FONTS", true)); svgGenerator.setSVGCanvasSize(size); paint(svgGenerator, 0, 0); boolean useCSS = true; Writer out = new OutputStreamWriter(stream, "UTF-8"); svgGenerator.stream(out, useCSS); }
/** * Return a list of implementations that support the * desired features. * * @param features * A string that specifies which features are required. This is * a space separated list in which each feature is specified by * its name optionally followed by a space and a version number. * This is something like: "XML 1.0 Traversal +Events 2.0" * @return A list of DOMImplementations that support the desired features. */ public DOMImplementationList getDOMImplementationList(final String features) { final Vector implementations = new Vector(); int size = sources.size(); for (int i = 0; i < size; i++) { DOMImplementationSource source = (DOMImplementationSource) sources.elementAt(i); DOMImplementationList impls = source.getDOMImplementationList(features); for (int j = 0; j < impls.getLength(); j++) { DOMImplementation impl = impls.item(j); implementations.addElement(impl); } } return new DOMImplementationList() { public DOMImplementation item(final int index) { if (index >= 0 && index < implementations.size()) { try { return (DOMImplementation) implementations.elementAt(index); } catch (ArrayIndexOutOfBoundsException e) { return null; } } return null; } public int getLength() { return implementations.size(); } }; }
/** * A method to request a DOM implementation. * @param features A string that specifies which features are required. * This is a space separated list in which each feature is specified * by its name optionally followed by a space and a version number. * This is something like: "XML 1.0 Traversal Events 2.0" * @return An implementation that has the desired features, or * <code>null</code> if this source has none. */ public DOMImplementation getDOMImplementation(String features) { // first check whether the CoreDOMImplementation would do DOMImplementation impl = CoreDOMImplementationImpl.getDOMImplementation(); if (testImpl(impl, features)) { return impl; } // if not try the DOMImplementation impl = DOMImplementationImpl.getDOMImplementation(); if (testImpl(impl, features)) { return impl; } return null; }
/** * A method to request a DOM implementation. * @param features A string that specifies which features are required. * This is a space separated list in which each feature is specified * by its name optionally followed by a space and a version number. * This is something like: "XML 1.0 Traversal Events 2.0" * @return An implementation that has the desired features, or * <code>null</code> if this source has none. */ public DOMImplementation getDOMImplementation(String features) { DOMImplementation impl = super.getDOMImplementation(features); if (impl != null){ return impl; } // if not try the PSVIDOMImplementation impl = PSVIDOMImplementationImpl.getDOMImplementation(); if (testImpl(impl, features)) { return impl; } // if not try the XSImplementation impl = XSImplementationImpl.getDOMImplementation(); if (testImpl(impl, features)) { return impl; } return null; }
/** * A method to request a list of DOM implementations that support the * specified features and versions, as specified in . * @param features A string that specifies which features and versions * are required. This is a space separated list in which each feature * is specified by its name optionally followed by a space and a * version number. This is something like: "XML 3.0 Traversal +Events * 2.0" * @return A list of DOM implementations that support the desired * features. */ public DOMImplementationList getDOMImplementationList(String features) { final Vector implementations = new Vector(); // first check whether the CoreDOMImplementation would do DOMImplementationList list = super.getDOMImplementationList(features); //Add core DOMImplementations for (int i=0; i < list.getLength(); i++ ) { implementations.addElement(list.item(i)); } DOMImplementation impl = PSVIDOMImplementationImpl.getDOMImplementation(); if (testImpl(impl, features)) { implementations.addElement(impl); } impl = XSImplementationImpl.getDOMImplementation(); if (testImpl(impl, features)) { implementations.addElement(impl); } return new DOMImplementationListImpl(implementations); }
public static void main(String[] args) throws Exception { String format = "javax_imageio_1.0"; BufferedImage img = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB); ImageWriter iw = ImageIO.getImageWritersByMIMEType("image/png").next(); IIOMetadata meta = iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), null); DOMImplementationRegistry registry; registry = DOMImplementationRegistry.newInstance(); DOMImplementation impl = registry.getDOMImplementation("XML 3.0"); Document doc = impl.createDocument(null, format, null); Element root, text, entry; root = doc.getDocumentElement(); root.appendChild(text = doc.createElement("Text")); text.appendChild(entry = doc.createElement("TextEntry")); // keyword isn't #REQUIRED by the standard metadata format. // However, it is required by the PNG format, so we include it here. entry.setAttribute("keyword", "Comment"); entry.setAttribute("value", "Some demo comment"); meta.mergeTree(format, root); }
public static void main(String[] args) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.newDocument(); DOMImplementation impl = document.getImplementation(); DOMImplementationLS implLS = (DOMImplementationLS) impl.getFeature("LS", "3.0"); LSSerializer dsi = implLS.createLSSerializer(); /* We should have here incorrect document without getXmlVersion() method: * Such Document is generated by replacing the JDK bootclasses with it's * own Node,Document and DocumentImpl classes (see run.sh). According to * XERCESJ-1007 the AbstractMethodError should be thrown in such case. */ String result = dsi.writeToString(document); System.out.println("Result:" + result); }
@DataProvider(name = "feature-supported") public Object[][] getFeatureSupportedList() throws ParserConfigurationException { DOMImplementation impl = getDOMImplementation(); return new Object[][] { { impl, "XML", "2.0", true }, { impl, "HTML", "2.0", false }, { impl, "Views", "2.0", false }, { impl, "StyleSheets", "2.0", false }, { impl, "CSS", "2.0", false }, { impl, "CSS2", "2.0", false }, { impl, "Events", "2.0", true }, { impl, "UIEvents", "2.0", false }, { impl, "MouseEvents", "2.0", false }, { impl, "HTMLEvents", "2.0", false }, { impl, "Traversal", "2.0", true }, { impl, "Range", "2.0", true }, { impl, "Core", "2.0", true }, { impl, "XML", "", true } }; }
public boolean canvasInit(JSVGCanvas canvas) { DOMImplementation impl = GenericDOMImplementation.getDOMImplementation(); Document doc = impl.createDocument(SVGConstants.SVG_NAMESPACE_URI, SVGConstants.SVG_SVG_TAG, null); Element e = doc.createElementNS(SVGConstants.SVG_NAMESPACE_URI, SVGConstants.SVG_RECT_TAG); e.setAttribute("x", "10"); e.setAttribute("y", "10"); e.setAttribute("width", "100"); e.setAttribute("height", "50"); e.setAttribute("fill", "crimson"); doc.getDocumentElement().appendChild(e); e = doc.createElementNS(SVGConstants.SVG_NAMESPACE_URI, SVGConstants.SVG_CIRCLE_TAG); e.setAttribute("cx", "55"); e.setAttribute("cy", "35"); e.setAttribute("r", "30"); e.setAttribute("fill", "gold"); doc.getDocumentElement().appendChild(e); canvas.setDocument(doc); return false; // We didn't trigger a load event. }
public org.w3c.dom.Document write(Document document, org.w3c.dom.DOMImplementation domImpl) throws DocumentException { if (document instanceof org.w3c.dom.Document) { return (org.w3c.dom.Document)document; } resetNamespaceStack(); org.w3c.dom.Document domDocument = createDomDocument(document, domImpl); appendDOMTree(domDocument, domDocument, document.content()); namespaceStack.clear(); return domDocument; }
/** * Returns a list of the implementations that support the specified * features. */ private final List getImplementations(String features) { List available = new ArrayList(Arrays.asList(implementations)); for (Iterator i = parseFeatures(features).iterator(); i.hasNext(); ) { String feature = (String) i.next(); String version = null; int si = feature.indexOf(' '); if (si != -1) { version = feature.substring(si + 1); feature = feature.substring(0, si); } for (Iterator j = available.iterator(); j.hasNext(); ) { DOMImplementation impl = (DOMImplementation) j.next(); if (!impl.hasFeature(feature, version)) { j.remove(); } } } return available; }
@Override public void fullExportToStream(ERDesignerGraph aGraph, OutputStream aStream) throws IOException { Object[] cells = aGraph.getRoots(); Rectangle2D bounds = aGraph.toScreen(aGraph.getCellBounds(cells)); if (bounds != null) { DOMImplementation theDomImpl = SVGDOMImplementation.getDOMImplementation(); String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; Document theDocument = theDomImpl.createDocument(svgNS, "svg", null); SVGGraphics2D theSvgGenerator = new SVGGraphics2D(theDocument); theSvgGenerator.translate(-bounds.getX() + 10, -bounds.getY() + 0); RepaintManager theRepaintManager = RepaintManager.currentManager(aGraph); theRepaintManager.setDoubleBufferingEnabled(false); boolean theDoubleBuffered = aGraph.isDoubleBuffered(); // Disable double buffering to allow Batik to render svg elements // instead of images aGraph.setDoubleBuffered(false); aGraph.paint(theSvgGenerator); aGraph.setDoubleBuffered(theDoubleBuffered); Writer theWriter = new OutputStreamWriter(aStream, PlatformConfig.getXMLEncoding()); theSvgGenerator.stream(theWriter, false); theRepaintManager.setDoubleBufferingEnabled(true); theWriter.flush(); theWriter.close(); } }
public static String toXml(Document domDoc) throws TransformerException { DOMImplementation domImplementation = domDoc.getImplementation(); if (domImplementation.hasFeature("LS", "3.0") && domImplementation.hasFeature("Core", "2.0")) { DOMImplementationLS domImplementationLS = (DOMImplementationLS) domImplementation.getFeature("LS", "3.0"); LSSerializer lsSerializer = domImplementationLS.createLSSerializer(); DOMConfiguration domConfiguration = lsSerializer.getDomConfig(); if (domConfiguration.canSetParameter("xml-declaration", Boolean.TRUE)) lsSerializer.getDomConfig().setParameter("xml-declaration", Boolean.FALSE); if (domConfiguration.canSetParameter("format-pretty-print", Boolean.TRUE)) { lsSerializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); LSOutput lsOutput = domImplementationLS.createLSOutput(); lsOutput.setEncoding("UTF-8"); StringWriter stringWriter = new StringWriter(); lsOutput.setCharacterStream(stringWriter); lsSerializer.write(domDoc, lsOutput); return stringWriter.toString(); } } return toXml((Node)domDoc); }
/** * Exports a JFreeChart to a SVG file. * * @param chart JFreeChart to export * @param bounds the dimensions of the viewport * @param svgFile the output file. * @throws IOException if writing the svgFile fails. */ public static void exportChartAsSVG( JFreeChart chart, Rectangle bounds, File svgFile) throws IOException { // Get a DOMImplementation and create an XML document DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); Document document = domImpl.createDocument(null, "svg", null); // Create an instance of the SVG Generator SVGGraphics2D svgGenerator = new SVGGraphics2D(document); // draw the chart in the SVG generator chart.draw(svgGenerator, bounds); // Write svg file OutputStream outputStream = new FileOutputStream(svgFile); Writer out = new OutputStreamWriter(outputStream, "UTF-8"); svgGenerator.stream(out, true /* use css */); outputStream.flush(); outputStream.close(); }
public static <T, U> void exportAsSVG(VennFigureParameters<T> parameters, File file, Dimension size) throws IOException { // Get a DOMImplementation. DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); // Create an instance of org.w3c.dom.Document. String svgNS = "http://www.w3.org/2000/svg"; Document document = domImpl.createDocument(svgNS, "svg", null); // Create an instance of the SVG Generator. SVGGraphics2D svgGenerator = new SVGGraphics2D(document); VennDrawGraphics2D.draw(VennFigureCreator.createVennFigure(parameters), svgGenerator, size); try (Writer writer = new FileWriter(file)) { svgGenerator.stream(writer, true); } }
/** * Creates a new {@link Document} that has a root element that is in a * namespace. * * @throws XMLException * if the {@link Document} can't be created * * @param builder * the {@link DocumentBuilder} to use when creating the * {@link Document}, or <code>null</code> to use a * {@link DocumentBuilder} from the internal pool * @param namespaceURI * the namespace URI of the document root element, or * <code>null</code> * @param qualifiedName * the qualified name of the document root element * @return a new {@link Document} (never <code>null</code>) */ public static Document newDocumentNS( DocumentBuilder builder, final String namespaceURI, final String qualifiedName) { final boolean useCache = (builder == null); if (useCache) { builder = cache.takeDocumentBuilder(); } try { final DOMImplementation implementation = builder.getDOMImplementation(); return implementation.createDocument(namespaceURI, qualifiedName, null); } finally { if (useCache) { cache.releaseDocumentBuilder(builder); } } }
private Document createNewXMLDocument(String namespace, String qualifiedTagName) { DocumentBuilderFactory dbf;// = DocumentBuilderFactory.newInstance(); DocumentBuilder db; Document doc = null; try { dbf = DocumentBuilderFactory.newInstance(); db = dbf.newDocumentBuilder(); DOMImplementation di = db.getDOMImplementation(); doc = di.createDocument(namespace, qualifiedTagName, null); } catch (ParserConfigurationException e) { log(e, "could not create document"); } return doc; }
private static void test2() { File selecteddFile = new File("test2.svg"); try { DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); // Create an instance of org.w3c.dom.Document. String svgNS = "http://www.w3.org/2000/svg"; Document document = domImpl.createDocument(svgNS, "svg", null); // Create an instance of the SVG Generator. org.apache.batik.svggen.SVGGraphics2D svgGenerator = new SVGGraphics2D(document); draw(svgGenerator); Writer out = new BufferedWriter(new FileWriter(selecteddFile)); //logger.info("Writing output"); svgGenerator.stream(out, false); //logger.info("Done"); } catch (Exception e) { MessageUtils.showMessage("Error encountered creating SVG file: " + e.toString()); } }
/** * Creates the <code>TranscoderInput</code>. */ protected TranscoderInput createTranscoderInput() { DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; Document doc = impl.createDocument(svgNS, "svg", null); Element root = doc.getDocumentElement(); root.setAttributeNS(null, "width", "400"); root.setAttributeNS(null, "height", "400"); Element r = doc.createElementNS(svgNS, "rect"); r.setAttributeNS(null, "x", "100"); r.setAttributeNS(null, "y", "50"); r.setAttributeNS(null, "width", "100"); r.setAttributeNS(null, "height", "50"); r.setAttributeNS(null, "style", "fill:red"); root.appendChild(r); return new TranscoderInput(doc); }
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) { LSInput lsi = mDelegate.resolveResource(type, namespaceURI, publicId, systemId, baseURI); if (lsi == null) { //if we can not get an input from catalog, then it could that //there as a schema in types section which refer to schema compoment from other inline schema //so we try to check in other inline schema. WSDLSchema schema = findSchema(namespaceURI); if(schema != null) { Reader in = createInlineSchemaSource(mWsdlText, mWsdlPrefixes, mWsdlLinePositions, schema); if(in != null) { //create LSInput object DOMImplementation domImpl = null; try { domImpl = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation(); } catch (ParserConfigurationException ex) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, "resolveResource", ex); //NOI18N return null; } DOMImplementationLS dols = (DOMImplementationLS) domImpl.getFeature("LS","3.0"); lsi = dols.createLSInput(); lsi.setCharacterStream(in); if(mWsdlSystemId != null) { lsi.setSystemId(mWsdlSystemId); } return lsi; } } } return lsi; }
/** * Get the DOM Level 3 Load/Save {@link DOMImplementationLS} for the given node. * * @param node the node to evaluate * @return the DOMImplementationLS for the given node */ public static DOMImplementationLS getLSDOMImpl(Node node) { DOMImplementation domImpl; if (node instanceof Document) { domImpl = ((Document) node).getImplementation(); } else { domImpl = node.getOwnerDocument().getImplementation(); } DOMImplementationLS domImplLS = (DOMImplementationLS) domImpl.getFeature("LS", "3.0"); return domImplLS; }
/** * Return the first implementation that has the desired * features, or <code>null</code> if none is found. * * @param features * A string that specifies which features are required. This is * a space separated list in which each feature is specified by * its name optionally followed by a space and a version number. * This is something like: "XML 1.0 Traversal +Events 2.0" * @return An implementation that has the desired features, * or <code>null</code> if none found. */ public DOMImplementation getDOMImplementation(final String features) { int size = sources.size(); String name = null; for (int i = 0; i < size; i++) { DOMImplementationSource source = (DOMImplementationSource) sources.elementAt(i); DOMImplementation impl = source.getDOMImplementation(features); if (impl != null) { return impl; } } return null; }
/** * Returns the indexth item in the collection. * * @param index The index of the DOMImplemetation from the list to return. */ public DOMImplementation item(int index) { try { return (DOMImplementation) fImplementations.elementAt(index); } catch (ArrayIndexOutOfBoundsException e) { return null; } }
/** * A method to request a list of DOM implementations that support the * specified features and versions, as specified in . * @param features A string that specifies which features and versions * are required. This is a space separated list in which each feature * is specified by its name optionally followed by a space and a * version number. This is something like: "XML 3.0 Traversal +Events * 2.0" * @return A list of DOM implementations that support the desired * features. */ public DOMImplementationList getDOMImplementationList(String features) { // first check whether the CoreDOMImplementation would do DOMImplementation impl = CoreDOMImplementationImpl.getDOMImplementation(); final Vector implementations = new Vector(); if (testImpl(impl, features)) { implementations.addElement(impl); } impl = DOMImplementationImpl.getDOMImplementation(); if (testImpl(impl, features)) { implementations.addElement(impl); } return new DOMImplementationListImpl(implementations); }
/** * Unimplemented. See org.w3c.dom.Document * * @return null */ public DOMImplementation getImplementation() { error(XMLErrorResources.ER_FUNCTION_NOT_SUPPORTED); return null; }
public XmlDocument() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); DOMImplementation impl = builder.getDOMImplementation(); Document doc = impl.createDocument(null,null,null); setNode(doc); }