本文整理匯總了Java中org.w3c.dom.DOMImplementation.createDocument方法的典型用法代碼示例。如果您正苦於以下問題:Java DOMImplementation.createDocument方法的具體用法?Java DOMImplementation.createDocument怎麽用?Java DOMImplementation.createDocument使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.w3c.dom.DOMImplementation
的用法示例。
在下文中一共展示了DOMImplementation.createDocument方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: writeSVG
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
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);
}
示例2: main
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
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);
}
示例3: canvasInit
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
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.
}
示例4: exportToStream
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
@Override
public void exportToStream(Component aComponent, OutputStream aStream) throws IOException {
DOMImplementation theDomImpl = GenericDOMImplementation.getDOMImplementation();
Document theDocument = theDomImpl.createDocument(null, "svg", null);
SVGGraphics2D theSvgGenerator = new SVGGraphics2D(theDocument);
RepaintManager theRepaintManager = RepaintManager.currentManager(aComponent);
theRepaintManager.setDoubleBufferingEnabled(false);
Dimension theSize = aComponent.getPreferredSize();
aComponent.setSize(theSize);
aComponent.paint(theSvgGenerator);
Writer theWriter = new OutputStreamWriter(aStream, PlatformConfig.getXMLEncoding());
theSvgGenerator.stream(theWriter, false);
theRepaintManager.setDoubleBufferingEnabled(true);
theWriter.flush();
theWriter.close();
}
示例5: newMetadata
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
/**
* Create new metadata file empty
*
* @param apiVersion New value for the apiVersion tag
* @param tagName Root tag's name
*/
public void newMetadata(String apiVersion, String tagName) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
DOMImplementation implementation = builder.getDOMImplementation();
Document newDocument = implementation.createDocument("http://soap.sforce.com/2006/04/metadata", tagName, null);
newDocument.setXmlVersion("1.0");
Element root = newDocument.getDocumentElement();
Element childElement = newDocument.createElement("apiVersion");
childElement.setTextContent(apiVersion);
root.appendChild(childElement);
childElement = newDocument.createElement("status");
childElement.setTextContent("Active");
root.appendChild(childElement);
saveMetadata(newDocument);
} catch (ParserConfigurationException ex) {
Exceptions.printStackTrace(ex);
}
}
示例6: createTranscoderInput
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
/**
* 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);
}
示例7: PListBuilder
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
public PListBuilder() {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
builder = factory.newDocumentBuilder();
DOMImplementation di = builder.getDOMImplementation();
dt = di.createDocumentType("plist",
"-//Apple//DTD PLIST 1.0//EN",
"http://www.apple.com/DTDs/PropertyList-1.0.dtd");
doc = di.createDocument("", "plist", dt);
doc.setXmlStandalone(true);
root = doc.getDocumentElement();
root.setAttribute("version", "1.0");
rootDict = doc.createElement("dict");
root.appendChild(rootDict);
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
}
示例8: test2
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
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());
}
}
示例9: XmlDocument
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
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);
}
示例10: testCanonicalForm003
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
/**
* Equivalence class partitioning with state and input values orientation
* for public void setParameter(String name, Object value) throws
* DOMException, <br>
* <b>pre-conditions</b>: the doc's root element contains superfluous
* namespace declarations, <br>
* <b>name</b>: canonical-form <br>
* <b>value</b>: true. <br>
* <b>Expected results</b>: the superfluous namespace declarations are
* removed
*/
@Test
public void testCanonicalForm003() {
DOMImplementation domImpl = null;
try {
domImpl = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
} catch (ParserConfigurationException pce) {
Assert.fail(pce.toString());
} catch (FactoryConfigurationError fce) {
Assert.fail(fce.toString());
}
Document doc = domImpl.createDocument("namespaceURI", "ns:root", null);
DOMConfiguration config = doc.getDomConfig();
Element root = doc.getDocumentElement();
String XMLNS = "http://www.w3.org/2000/xmlns/";
root.setAttributeNS(XMLNS, "xmlns:extra1", "ExtraNS1");
root.setAttributeNS(XMLNS, "xmlns:extra2", "ExtraNS2");
if (!config.canSetParameter("canonical-form", Boolean.TRUE)) {
System.out.println("OK, setting 'canonical-form' to true is not supported");
return;
}
config.setParameter("canonical-form", Boolean.TRUE);
setHandler(doc);
doc.normalizeDocument();
String xmlns2 = root.getAttributeNS(XMLNS, "extra1");
if (xmlns2 == null || xmlns2.length() != 0) {
Assert.fail("superfluous namespace declarations is not removed: xmlns:extra2 = " + xmlns2);
}
return; // Status.passed("OK");
}
示例11: testCdataSections001
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
/**
* Equivalence class partitioning with state and input values orientation
* for public void setParameter(String name, Object value) throws
* DOMException, <br>
* <b>pre-conditions</b>: the root element has one CDATASection followed by
* one Text node, <br>
* <b>name</b>: cdata-sections <br>
* <b>value</b>: true. <br>
* <b>Expected results</b>: the CDATASection is left intact
*/
@Test
public void testCdataSections001() {
DOMImplementation domImpl = null;
try {
domImpl = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
} catch (ParserConfigurationException pce) {
Assert.fail(pce.toString());
} catch (FactoryConfigurationError fce) {
Assert.fail(fce.toString());
}
Document doc = domImpl.createDocument("namespaceURI", "ns:root", null);
String cdataText = "CDATA CDATA CDATA";
String textText = "text text text";
CDATASection cdata = doc.createCDATASection(cdataText);
Text text = doc.createTextNode(textText);
DOMConfiguration config = doc.getDomConfig();
config.setParameter("cdata-sections", Boolean.TRUE);
Element root = doc.getDocumentElement();
root.appendChild(cdata);
root.appendChild(text);
setHandler(doc);
doc.normalizeDocument();
Node returned = root.getFirstChild();
if (returned.getNodeType() != Node.CDATA_SECTION_NODE) {
Assert.fail("reurned: " + returned + ", expected: CDATASection");
}
return; // Status.passed("OK");
}
示例12: testComments001
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
/**
* Equivalence class partitioning with state and input values orientation
* for public void setParameter(String name, Object value) throws
* DOMException, <br>
* <b>pre-conditions</b>: the root element has two Comment nodes, <br>
* <b>name</b>: comments <br>
* <b>value</b>: true. <br>
* <b>Expected results</b>: the Comment nodes belong to the root element
*/
@Test
public void testComments001() {
DOMImplementation domImpl = null;
try {
domImpl = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
} catch (ParserConfigurationException pce) {
Assert.fail(pce.toString());
} catch (FactoryConfigurationError fce) {
Assert.fail(fce.toString());
}
Document doc = domImpl.createDocument("namespaceURI", "ns:root", null);
Comment comment1 = doc.createComment("comment1");
Comment comment2 = doc.createComment("comment2");
DOMConfiguration config = doc.getDomConfig();
config.setParameter("comments", Boolean.TRUE);
Element root = doc.getDocumentElement();
root.appendChild(comment1);
root.appendChild(comment2);
setHandler(doc);
doc.normalizeDocument();
if (comment1.getParentNode() != root) {
Assert.fail("comment1 is attached to " + comment1.getParentNode() + ", but expected to be a child of root");
}
if (comment2.getParentNode() != root) {
Assert.fail("comment1 is attached to " + comment2.getParentNode() + ", but expected to be a child of root");
}
return; // Status.passed("OK");
}
示例13: testComments002
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
/**
* Equivalence class partitioning with state and input values orientation
* for public void setParameter(String name, Object value) throws
* DOMException, <br>
* <b>pre-conditions</b>: the root element has two Comment nodes, <br>
* <b>name</b>: comments <br>
* <b>value</b>: false. <br>
* <b>Expected results</b>: the root element has no children
*/
@Test
public void testComments002() {
DOMImplementation domImpl = null;
try {
domImpl = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
} catch (ParserConfigurationException pce) {
Assert.fail(pce.toString());
} catch (FactoryConfigurationError fce) {
Assert.fail(fce.toString());
}
Document doc = domImpl.createDocument("namespaceURI", "ns:root", null);
Comment comment1 = doc.createComment("comment1");
Comment comment2 = doc.createComment("comment2");
DOMConfiguration config = doc.getDomConfig();
config.setParameter("comments", Boolean.FALSE);
Element root = doc.getDocumentElement();
root.appendChild(comment1);
root.appendChild(comment2);
doc.normalizeDocument();
if (root.getFirstChild() != null) {
Assert.fail("root has a child " + root.getFirstChild() + ", but expected to has none");
}
return; // Status.passed("OK");
}
示例14: testSplitCDATA001
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
/**
* Equivalence class partitioning with state and input values orientation
* for public void setParameter(String name, Object value) throws
* DOMException, <br>
* <b>pre-conditions</b>: The root contains a CDATASection with the
* termination marker ']]>', <br>
* <b>name</b>: split-cdata-sections <br>
* <b>value</b>: true. <br>
* <b>Expected results</b>: A warning is reported when the section is
* splitted
*/
@Test
public void testSplitCDATA001() {
DOMImplementation domImpl = null;
try {
domImpl = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
} catch (ParserConfigurationException pce) {
Assert.fail(pce.toString());
} catch (FactoryConfigurationError fce) {
Assert.fail(fce.toString());
}
Document doc = domImpl.createDocument("namespaceURI", "ns:root", null);
DOMConfiguration config = doc.getDomConfig();
CDATASection cdata = doc.createCDATASection("text]" + "]>text");
doc.getDocumentElement().appendChild(cdata);
TestHandler testHandler = new TestHandler();
config.setParameter("error-handler", testHandler);
if (!config.canSetParameter("split-cdata-sections", Boolean.TRUE)) {
Assert.fail("cannot set the parameters 'split-cdata-sections' to true");
}
config.setParameter("split-cdata-sections", Boolean.TRUE);
doc.normalizeDocument();
if (null == testHandler.getWarning()) {
Assert.fail("no warning is reported");
}
return; // Status.passed("OK");
}
示例15: testSplitCDATA002
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
/**
* Equivalence class partitioning with state and input values orientation
* for public void setParameter(String name, Object value) throws
* DOMException, <br>
* <b>pre-conditions</b>: The root contains a CDATASection with the
* termination marker ']]>', <br>
* <b>name</b>: split-cdata-sections <br>
* <b>value</b>: false. <br>
* <b>Expected results</b>: No warning is reported
*/
@Test
public void testSplitCDATA002() {
DOMImplementation domImpl = null;
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating(true);
domImpl = dbf.newDocumentBuilder().getDOMImplementation();
} catch (ParserConfigurationException pce) {
Assert.fail(pce.toString());
} catch (FactoryConfigurationError fce) {
Assert.fail(fce.toString());
}
Document doc = domImpl.createDocument("namespaceURI", "ns:root", null);
DOMConfiguration config = doc.getDomConfig();
CDATASection cdata = doc.createCDATASection("text]" + "]>text");
doc.getDocumentElement().appendChild(cdata);
TestHandler testHandler = new TestHandler();
config.setParameter("error-handler", testHandler);
if (!config.canSetParameter("split-cdata-sections", Boolean.FALSE)) {
Assert.fail("cannot set the parameters 'split-cdata-sections' to false");
}
config.setParameter("split-cdata-sections", Boolean.FALSE);
doc.normalizeDocument();
if (null == testHandler.getError()) {
Assert.fail("no error is reported");
}
return; // Status.passed("OK");
}