You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2007/10/30 19:10:41 UTC

svn commit: r590201 - /activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/DomConverter.java

Author: jstrachan
Date: Tue Oct 30 11:10:40 2007
New Revision: 590201

URL: http://svn.apache.org/viewvc?rev=590201&view=rev
Log:
added some type converters from DOM nodes to Strings

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/DomConverter.java   (with props)

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/DomConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/DomConverter.java?rev=590201&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/DomConverter.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/DomConverter.java Tue Oct 30 11:10:40 2007
@@ -0,0 +1,64 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.converter.jaxp;
+
+import org.apache.camel.Converter;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
+/**
+ * Converts from some DOM types to Java types
+ *
+ * @version $Revision: 1.1 $
+ */
+@Converter
+public class DomConverter {
+    @Converter
+    public static String toString(NodeList nodeList) {
+        StringBuffer buffer = new StringBuffer();
+        append(buffer, nodeList);
+        return buffer.toString();
+    }
+
+    @Converter
+    public static String toString(Node node) {
+        StringBuffer buffer = new StringBuffer();
+        append(buffer, node);
+        return buffer.toString();
+    }
+
+    protected static void append(StringBuffer buffer, NodeList nodeList) {
+        int size = nodeList.getLength();
+        for (int i = 0; i < size; i++) {
+            append(buffer, nodeList.item(i));
+        }
+    }
+
+    protected static void append(StringBuffer buffer, Node node) {
+        if (node instanceof Text) {
+            Text text = (Text) node;
+            buffer.append(text.getTextContent());
+        }
+        else if (node instanceof Element) {
+            Element element = (Element) node;
+            append(buffer, element.getChildNodes());
+        }
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/DomConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native