cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r728705 - /cocoon/whiteboard/xml-utils/src/main/java/org/apache/cocoon/xml/util/XMLUtils.java
Date Mon, 22 Dec 2008 14:53:06 GMT
Author: cziegeler
Date: Mon Dec 22 06:53:05 2008
New Revision: 728705

URL: http://svn.apache.org/viewvc?rev=728705&view=rev
Log:
Remove dom stuff from xml utils and remove rather rarely used stuff.

Modified:
    cocoon/whiteboard/xml-utils/src/main/java/org/apache/cocoon/xml/util/XMLUtils.java

Modified: cocoon/whiteboard/xml-utils/src/main/java/org/apache/cocoon/xml/util/XMLUtils.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/xml-utils/src/main/java/org/apache/cocoon/xml/util/XMLUtils.java?rev=728705&r1=728704&r2=728705&view=diff
==============================================================================
--- cocoon/whiteboard/xml-utils/src/main/java/org/apache/cocoon/xml/util/XMLUtils.java (original)
+++ cocoon/whiteboard/xml-utils/src/main/java/org/apache/cocoon/xml/util/XMLUtils.java Mon
Dec 22 06:53:05 2008
@@ -16,30 +16,9 @@
  */
 package org.apache.cocoon.xml.util;
 
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.Properties;
-
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.sax.SAXTransformerFactory;
-import javax.xml.transform.sax.TransformerHandler;
-import javax.xml.transform.stream.StreamResult;
-
-import org.apache.cocoon.xml.util.dom.DOMStreamer;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
 import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
-import org.xml.sax.ext.LexicalHandler;
 
 /**
  * XML utility methods.
@@ -53,155 +32,6 @@
      */
     public static final Attributes EMPTY_ATTRIBUTES = new ImmutableAttributesImpl();
 
-    private static final SAXTransformerFactory FACTORY = (SAXTransformerFactory) TransformerFactory.newInstance();
-    private static final Properties XML_FORMAT = createDefaultPropertiesForXML(false);
-    private static final Properties XML_FORMAT_NODECL = createDefaultPropertiesForXML(true);
-
-
-    // FIXME: parent parameter not used anymore
-    // Using parent because some dom implementations like jtidy are bugged,
-    // cannot get parent or delete child
-    public static void stripDuplicateAttributes(Node node, Node parent) {
-
-        // The output depends on the type of the node
-        switch(node.getNodeType()) {
-        case Node.DOCUMENT_NODE: {
-            Document doc = (Document)node;
-            Node child = doc.getFirstChild();
-            while(child != null) {
-                stripDuplicateAttributes(child, node);
-                child = child.getNextSibling();
-            }
-            break;
-        }
-
-        case Node.ELEMENT_NODE: {
-            Element elt = (Element) node;
-            NamedNodeMap attrs = elt.getAttributes();
-
-            ArrayList<Node> nodesToRemove = new ArrayList<Node>();
-            int nodesToRemoveNum = 0;
-
-            for (int i = 0; i < attrs.getLength(); i++) {
-                final Node a = attrs.item(i);
-
-                for (int j = 0; j < attrs.getLength(); j++) {
-                    final Node b = attrs.item(j);
-
-                    //if there are two attributes with same name
-                    if (i != j && (a.getNodeName().equals(b.getNodeName()))) {
-                        nodesToRemove.add(b);
-                        nodesToRemoveNum++;
-                    }
-                }
-            }
-
-            for (int i = 0; i < nodesToRemoveNum; i++) {
-                Attr nodeToDelete = (Attr) nodesToRemove.get(i);
-                Element nodeToDeleteParent = (Element) node; // nodeToDelete.getParentNode();
-                nodeToDeleteParent.removeAttributeNode(nodeToDelete);
-            }
-
-            nodesToRemove.clear();
-
-            Node child = elt.getFirstChild();
-            while (child != null) {
-                stripDuplicateAttributes(child, node);
-                child = child.getNextSibling();
-            }
-
-            break;
-        }
-
-        default:
-            //do nothing
-            break;
-        }
-    }
-
-    /**
-     * Method for static initializer
-     */
-    private static Properties createDefaultPropertiesForXML(boolean omitXMLDeclaration) {
-        final Properties format = new Properties();
-        format.put(OutputKeys.METHOD, "xml");
-        format.put(OutputKeys.OMIT_XML_DECLARATION, (omitXMLDeclaration ? "yes" : "no"));
-        format.put(OutputKeys.INDENT, "yes");
-        return format;
-    }
-
-    /**
-     * Create a new properties set for serializing xml.
-     * The omit xml declaration property can be controlled by the flag.
-     *
-     * <ul>
-     * <li>Method: xml
-     * <li>Omit xml declaration: according to the flag
-     * <li>Indent: yes
-     * </ul>
-     */
-    public static Properties createPropertiesForXML(boolean omitXMLDeclaration) {
-        /* Properties passed as parameters to the Properties constructor become "default
properties".
-            But Xalan does not use the default properties, so they are lost.
-            Therefore, we must promote them to "set properties".
-         */
-         Properties propertiesForXML = new Properties(omitXMLDeclaration? XML_FORMAT_NODECL:
XML_FORMAT);
-         for (Enumeration e = propertiesForXML.propertyNames(); e.hasMoreElements(); ) {
-             String propertyName = (String)e.nextElement();
-             propertiesForXML.setProperty(propertyName, propertiesForXML.getProperty(propertyName,
""));
-         }
-         return propertiesForXML;
-    }
-
-    /**
-     * Serialize a DOM node into a string using format created by
-     * <code>createPropertiesForXML(false)</code>.
-     *
-     * @see #createPropertiesForXML
-     */
-    public static String serializeNode(Node node)
-    throws TransformerException {
-        // Don't create new properties as we do not intend to modify defaults.
-        return serializeNode(node, XML_FORMAT);
-    }
-
-    /**
-     * Serialize a DOM node into a string.
-     * If the node is null the empty string is returned.
-     *
-     * @param format The format of the output to be used by SAX transformer.
-     * @see OutputKeys
-     */
-    public static String serializeNode(Node node, Properties format)
-    throws TransformerException {
-
-        try {
-            if (node == null) {
-                return "";
-            }
-
-            StringWriter writer = new StringWriter();
-            TransformerHandler transformerHandler;
-            transformerHandler = FACTORY.newTransformerHandler();
-            transformerHandler.getTransformer().setOutputProperties(format);
-            transformerHandler.setResult(new StreamResult(writer));
-            if (node.getNodeType() != Node.DOCUMENT_NODE) {
-                transformerHandler.startDocument();
-            }
-            DOMStreamer domStreamer = new DOMStreamer(transformerHandler, transformerHandler);
-            domStreamer.stream(node);
-            if (node.getNodeType() != Node.DOCUMENT_NODE) {
-                transformerHandler.endDocument();
-            }
-
-            return writer.toString();
-        } catch (TransformerException e) {
-            throw e;
-        } catch (SAXException e) {
-            throw new TransformerException("SAXException while streaming DOM node to SAX:
" + e, e);
-        }
-    }
-
     /**
      * Add string data
      *
@@ -216,127 +46,6 @@
     }
 
     /**
-     * Implementation of &lt;xsp:expr&gt; for <code>String</code> :
-     * outputs characters representing the value.
-     *
-     * @param contentHandler the SAX content handler
-     * @param text the value
-     */
-    public static void valueOf(ContentHandler contentHandler, String text)
-    throws SAXException {
-
-        if (text != null) {
-            data(contentHandler, text);
-        }
-    }
-
-    /**
-     * Implementation of &lt;xsp:expr&gt; for <code>SaxBuffer</code>
:
-     * outputs the value by calling <code>v.toSax(contentHandler)</code>.
-     *
-     * @param contentHandler the SAX content handler
-     * @param v the XML fragment
-     */
-    public static void valueOf(ContentHandler contentHandler,
-                               SaxBuffer v)
-    throws SAXException {
-
-        if (v != null) {
-            v.toSAX(contentHandler);
-        }
-    }
-
-    /**
-     * Implementation of &lt;xsp:expr&gt; for <code>org.w3c.dom.Node</code>
:
-     * converts the Node to a SAX event stream.
-     *
-     * @param contentHandler the SAX content handler
-     * @param v the value
-     */
-    public static void valueOf(ContentHandler contentHandler, Node v)
-    throws SAXException {
-
-        if (v != null) {
-            DOMStreamer streamer = new DOMStreamer(contentHandler);
-            if (contentHandler instanceof LexicalHandler) {
-                streamer.setLexicalHandler((LexicalHandler)contentHandler);
-            }
-            streamer.stream(v);
-        }
-    }
-
-    /**
-     * Implementation of &lt;xsp:expr&gt; for <code>java.util.Collection</code>
:
-     * outputs the value by calling <code>xspExpr()</code> on each element of
the
-     * collection.
-     *
-     * @param contentHandler the SAX content handler
-     * @param v the XML fragment
-     */
-    public static void valueOf(ContentHandler contentHandler,
-                               Collection v)
-    throws SAXException {
-
-        if (v != null) {
-            Iterator iterator = v.iterator();
-            while (iterator.hasNext()) {
-                valueOf(contentHandler, iterator.next());
-            }
-        }
-     }
-
-    /**
-     * Implementation of &lt;xsp:expr&gt; for <code>Object</code> depending
on its class :
-     * <ul>
-     * <li>if it's an array, call <code>xspExpr()</code> on all its elements,</li>
-     * <li>if it's class has a specific <code>xspExpr()</code>implementation,
use it,</li>
-     * <li>else, output it's string representation.</li>
-     * </ul>
-     *
-     * @param contentHandler the SAX content handler
-     * @param v the value
-     */
-    public static void valueOf(ContentHandler contentHandler, Object v)
-    throws SAXException {
-
-        if (v == null) {
-            return;
-        }
-
-        // Array: recurse over each element
-        if (v.getClass().isArray()) {
-            Object[] elements = (Object[]) v;
-
-            for (int i = 0; i < elements.length; i++) {
-                valueOf(contentHandler, elements[i]);
-            }
-            return;
-         }
-
-
-         // XMLizable
-         if (v instanceof SaxBuffer) {
-             valueOf(contentHandler, (SaxBuffer)v);
-             return;
-         }
-
-         // Node
-         if (v instanceof Node) {
-             valueOf(contentHandler, (Node)v);
-             return;
-         }
-
-         // Collection
-         if (v instanceof Collection) {
-             valueOf(contentHandler, (Collection)v);
-             return;
-         }
-
-         // Give up: hope it's a string or has a meaningful string representation
-         data(contentHandler, String.valueOf(v));
-    }
-
-    /**
      * Create a start and endElement with a empty Namespace and without Attributes
      *
      * @param localName The local name (without prefix)



Mime
View raw message