⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 document.java

📁 java 3d game jme 工程开发源代码
💻 JAVA
字号:
/**
 * Document.java
 *
 * This file was generated by XMLSpy 2007sp2 Enterprise Edition.
 *
 * YOU SHOULD NOT MODIFY THIS FILE, BECAUSE IT WILL BE
 * OVERWRITTEN WHEN YOU RE-RUN CODE GENERATION.
 *
 * Refer to the XMLSpy Documentation for further details.
 * http://www.altova.com/xmlspy
 */


package com.jmex.xml.xml;



public abstract class Document implements java.io.Serializable {
	protected static javax.xml.parsers.DocumentBuilderFactory	factory		= null;
	protected static javax.xml.parsers.DocumentBuilder			builder		= null;

	protected static boolean									validation = false;

	protected org.w3c.dom.Document		domDocument;
	protected String encoding			= "UTF-8";

	protected String schemaLocation		= null;
	protected String dtdLocation				= null;
	public boolean prettyPrint = true;
		
	public Document() {
	}

	public static void enableValidation(boolean enable) {
		validation = enable;
	}

	protected static synchronized javax.xml.parsers.DocumentBuilder getDomBuilder() {
		try {
			if (builder == null) {
				if (factory == null) {
					factory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
					factory.setIgnoringElementContentWhitespace(true);
					factory.setNamespaceAware(true);
					if (validation) {
						factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
						factory.setValidating(true);
					}
				}
				builder = factory.newDocumentBuilder();

				builder.setErrorHandler(new org.xml.sax.ErrorHandler() {
					public void warning(org.xml.sax.SAXParseException e) {
					}
					public void error(org.xml.sax.SAXParseException e) throws XmlException {
						throw new XmlException(e);
					}
					public void fatalError(org.xml.sax.SAXParseException e) throws XmlException {
						throw new XmlException(e);
					}
				});
			}
			return builder;
		} catch (javax.xml.parsers.ParserConfigurationException e) {
			throw new XmlException(e);
		}
	}


	public synchronized org.w3c.dom.Document getDomDocument() {
		if (domDocument == null)
			domDocument = getDomBuilder().newDocument();
		return domDocument;
	}

	public org.w3c.dom.Element createRootElement(String namespaceURI, String name) {
		org.w3c.dom.Element rootElement = null;
		if (dtdLocation != null && dtdLocation.length() != 0) {
			org.w3c.dom.DocumentType docType = getDomBuilder().getDOMImplementation().createDocumentType(name, null, dtdLocation);
			domDocument = getDomBuilder().getDOMImplementation().createDocument(namespaceURI, name, docType);
			rootElement = domDocument.getDocumentElement();
		}
		else {
			rootElement = getDomDocument().createElementNS(namespaceURI, name);
			domDocument.appendChild(rootElement);
	
			rootElement.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
			if (schemaLocation != null && schemaLocation.length() != 0) {
				if (namespaceURI == null || namespaceURI.equals("")) {
					rootElement.setAttribute("xsi:noNamespaceSchemaLocation", schemaLocation);
				} else {
					rootElement.setAttribute("xsi:schemaLocation", namespaceURI + " " + schemaLocation);
				}
			}
		}
		return rootElement;
	}

	public void setEncoding(String encoding) {
		this.encoding = encoding;
	}


	public void setSchemaLocation(String schemaLocation) {
		this.schemaLocation = schemaLocation;
	}
	
	public void setDTDLocation(String dtdLocation) {
		this.dtdLocation = dtdLocation;
	}

	public org.w3c.dom.Node load(String filename) {
		try {
			return getDomBuilder().parse(new java.io.File(filename)).getDocumentElement();
		} catch (org.xml.sax.SAXException e) {
			throw new XmlException(e);
		} catch (java.io.IOException e) {
			throw new XmlException(e);
		}
	}

	public org.w3c.dom.Node load(java.io.InputStream istream) {
		try {
			return getDomBuilder().parse(istream).getDocumentElement();
		} catch (org.xml.sax.SAXException e) {
			throw new XmlException(e);
		} catch (java.io.IOException e) {
			throw new XmlException(e);
		}
	}

	public org.w3c.dom.Node loadFromString(String xml) {
		try {
			return getDomBuilder().parse(new java.io.ByteArrayInputStream(xml.getBytes())).getDocumentElement();
		} catch (org.xml.sax.SAXException e) {
			throw new XmlException(e);
		} catch (java.io.IOException e) {
			throw new XmlException(e);
		}
	}

	public void save(String filename, Node node) {


		Node.internalAdjustPrefix(node.domNode, true);
		node.adjustPrefix();
		
		if(prettyPrint)
			indentNode(node.domNode, 0);
		
		internalSave(
				new javax.xml.transform.stream.StreamResult(
						new java.io.File(filename)
						),
				node.domNode.getOwnerDocument(),
				encoding
				);
		System.gc();
	}

	public void save(java.io.OutputStream ostream, Node node) {

		Node.internalAdjustPrefix(node.domNode, true);
		node.adjustPrefix();
		
		if(prettyPrint)
			indentNode(node.domNode, 0);

		internalSave(
				new javax.xml.transform.stream.StreamResult(ostream),
				node.domNode.getOwnerDocument(),
				encoding
				);
		try	{
		ostream.close();
		}
		catch (Exception e)	{
			throw new XmlException(e);
		}
	}

	public String saveToString(Node node) {

		Node.internalAdjustPrefix(node.domNode, true);
		node.adjustPrefix();

		if(prettyPrint)
			indentNode(node.domNode, 0);

		java.io.StringWriter sw = new java.io.StringWriter();
		internalSave(
				  new javax.xml.transform.stream.StreamResult(sw),
				  node.domNode.getOwnerDocument(),
				  encoding
				  );
		return sw.toString();
	}

	protected static void internalSave(javax.xml.transform.Result result, org.w3c.dom.Document doc, String encoding) {
		try {
			javax.xml.transform.Source source
					= new javax.xml.transform.dom.DOMSource(doc);
			javax.xml.transform.Transformer transformer
					= javax.xml.transform.TransformerFactory.newInstance().newTransformer();
			if (encoding != null)
				transformer.setOutputProperty("encoding", encoding);
			if (doc.getDoctype() != null) {
				if (doc.getDoctype().getPublicId() != null)
					transformer.setOutputProperty(javax.xml.transform.OutputKeys.DOCTYPE_PUBLIC, doc.getDoctype().getPublicId());
				if (doc.getDoctype().getSystemId() != null)
					transformer.setOutputProperty(javax.xml.transform.OutputKeys.DOCTYPE_SYSTEM, doc.getDoctype().getSystemId());
			}
			transformer.setOutputProperty("indent", "yes");
			transformer.transform(source, result);
		} catch (javax.xml.transform.TransformerConfigurationException e) {
			throw new XmlException(e);
		} catch (javax.xml.transform.TransformerException e) {
			throw new XmlException(e);
		}
	}

	public org.w3c.dom.Node transform(Node node, String xslFilename) {
		try {
			javax.xml.transform.TransformerFactory factory = javax.xml.transform.TransformerFactory.newInstance();
			javax.xml.transform.Transformer transformer = factory.newTransformer(
					new javax.xml.transform.stream.StreamSource(xslFilename)
					);

			javax.xml.transform.dom.DOMResult result = new javax.xml.transform.dom.DOMResult();
			transformer.transform(
					new javax.xml.transform.dom.DOMSource(node.domNode),
					result
					);

			return result.getNode();
		} catch (javax.xml.transform.TransformerException e) {
			throw new XmlException(e);
		}
	}


	public abstract void declareNamespaces(Node node);

	protected void declareNamespace(Node node, String prefix, String URI) {
		node.declareNamespace(prefix, URI);
	}
	
	private void indentNode(org.w3c.dom.Node node, int nIndent) {
		if (node == null)
			return;
		
		if (nIndent > 0 && (node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE || node.getNodeType() == org.w3c.dom.Node.COMMENT_NODE))
		{
			if (node.getPreviousSibling() == null || 
				(node.getPreviousSibling().getNodeType() != org.w3c.dom.Node.CDATA_SECTION_NODE && 
				 node.getPreviousSibling().getNodeType() != org.w3c.dom.Node.TEXT_NODE))
			{
				String sIndent = "\n";
				for (int i=0; i<nIndent; i++) sIndent += "\t";
				node.getParentNode().insertBefore(node.getOwnerDocument().createTextNode(sIndent), node);
				if (node.getNextSibling() == null)
				{
					sIndent = sIndent.substring(0, nIndent);
					node.getParentNode().appendChild(node.getOwnerDocument().createTextNode(sIndent));
				}
			}
		}
	
		for (org.w3c.dom.Node child = node.getFirstChild(); child != null; child = child.getNextSibling())
			indentNode(child, nIndent+1);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -