diff options
Diffstat (limited to 'bundles/org.eclipse.wst.ws.explorer/wsexplorer-src/org/eclipse/wst/ws/internal/explorer/platform/util/XMLUtils.java')
-rw-r--r-- | bundles/org.eclipse.wst.ws.explorer/wsexplorer-src/org/eclipse/wst/ws/internal/explorer/platform/util/XMLUtils.java | 140 |
1 files changed, 0 insertions, 140 deletions
diff --git a/bundles/org.eclipse.wst.ws.explorer/wsexplorer-src/org/eclipse/wst/ws/internal/explorer/platform/util/XMLUtils.java b/bundles/org.eclipse.wst.ws.explorer/wsexplorer-src/org/eclipse/wst/ws/internal/explorer/platform/util/XMLUtils.java deleted file mode 100644 index bcbe4d487..000000000 --- a/bundles/org.eclipse.wst.ws.explorer/wsexplorer-src/org/eclipse/wst/ws/internal/explorer/platform/util/XMLUtils.java +++ /dev/null @@ -1,140 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.ws.internal.explorer.platform.util; - -import org.w3c.dom.*; -import org.xml.sax.*; - -import javax.xml.parsers.*; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import java.io.*; - -public final class XMLUtils -{ - /** - * Serialize an XML Element into a String. - * @param e Element to be serialized. - * @param omitXMLDeclaration boolean representing whether or not to omit the XML declaration. - * @return String representation of the XML document fragment. - */ - public static final String serialize(Element e,boolean omitXMLDeclaration) - { - if (e != null) - { - try - { - DOMSource domSource = new DOMSource(e); - Transformer serializer = TransformerFactory.newInstance().newTransformer(); - serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, ((omitXMLDeclaration) ? "yes" : "no")); - serializer.setOutputProperty(OutputKeys.INDENT, "yes"); - serializer.setOutputProperty(OutputKeys.ENCODING, HTMLUtils.UTF8_ENCODING); - serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - serializer.transform(domSource, new StreamResult(baos)); - baos.close(); - return new String(baos.toByteArray(), HTMLUtils.UTF8_ENCODING); - } - catch (Throwable t) - { - } - } - return null; - } - - /** - * Serialize an XML Element into a String. - * @param df DocumentFragment to be serialized. - * @param omitXMLDeclaration boolean representing whether or not to omit the XML declaration. - * @return String representation of the XML document fragment. - */ - public static final String serialize(DocumentFragment df,boolean omitXMLDeclaration) - { - if (df != null) - { - try - { - DOMSource domSource = new DOMSource(df); - Transformer serializer = TransformerFactory.newInstance().newTransformer(); - serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, ((omitXMLDeclaration) ? "yes" : "no")); - serializer.setOutputProperty(OutputKeys.INDENT, "yes"); - serializer.setOutputProperty(OutputKeys.ENCODING, HTMLUtils.UTF8_ENCODING); - serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - serializer.transform(domSource, new StreamResult(baos)); - baos.close(); - return new String(baos.toByteArray(), HTMLUtils.UTF8_ENCODING); - } - catch (Throwable t) - { - } - } - return null; - } - - /** - * Create a new XML Document. - * @param docBuilder DocumentBuilder. Setting this to null will create a new DocumentBuilder. - * @return Document - */ - public static final Document createNewDocument(DocumentBuilder docBuilder) throws ParserConfigurationException - { - if (docBuilder == null) - { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(false); - factory.setValidating(false); - docBuilder = factory.newDocumentBuilder(); - } - Document doc = docBuilder.newDocument(); - return doc; - } - - /** - * Convert the String representation of an Element into an Element - * @param String representation of an Element. - * @return Element - */ - public static Element stringToElement(String s) throws ParserConfigurationException, SAXException, UnsupportedEncodingException, IOException { - return stringToElement(s, false); - } - - /** - * Convert the String representation of an Element into an Element - * @param String representation of an Element. - * @param boolean set whether the return Element should be namespace aware. - * @return Element - */ - public static Element stringToElement(String s, boolean namespaceAware) throws ParserConfigurationException, SAXException, UnsupportedEncodingException, IOException - { - return byteArrayToElement(s.getBytes(HTMLUtils.UTF8_ENCODING), namespaceAware); - } - - /** - * Convert the byte array representation of an Element into an Element - * @param byte[] representation of an Element. - * @param boolean set whether the return Element should be namespace aware. - * @return Element - */ - public static Element byteArrayToElement(byte[] b, boolean namespaceAware) throws ParserConfigurationException, SAXException, UnsupportedEncodingException, IOException - { - DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); - docBuilderFactory.setNamespaceAware(namespaceAware); - docBuilderFactory.setValidating(false); - DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); - Document doc = docBuilder.parse(new ByteArrayInputStream(b)); - return doc.getDocumentElement(); - } -} |