db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r500770 - /db/ojb/trunk/src/java/org/apache/ojb/broker/util/XmlHelper.java
Date Sun, 28 Jan 2007 10:18:02 GMT
Author: arminw
Date: Sun Jan 28 02:18:02 2007
New Revision: 500770

URL: http://svn.apache.org/viewvc?view=rev&rev=500770
Log:
initial check in, helper class for xml output

Added:
    db/ojb/trunk/src/java/org/apache/ojb/broker/util/XmlHelper.java

Added: db/ojb/trunk/src/java/org/apache/ojb/broker/util/XmlHelper.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/util/XmlHelper.java?view=auto&rev=500770
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/util/XmlHelper.java (added)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/util/XmlHelper.java Sun Jan 28 02:18:02 2007
@@ -0,0 +1,82 @@
+package org.apache.ojb.broker.util;
+
+/* Copyright 2002-2005 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+
+import org.apache.commons.lang.SystemUtils;
+
+import java.util.Properties;
+import java.util.Enumeration;
+
+/**
+ * Simple helper class with static methods for common XML-handling tasks.
+ *
+ * @version CVS $Id: XmlHelper.java 365232 2005-12-21 23:36:07 +0100 (Mi, 21 Dez 2005) tomdz
$
+ * @since OJB 1.0.4
+ */
+public class XmlHelper
+{
+
+    /** End-of-line string used in serialized XML. */
+    public static final String XML_EOL = SystemUtils.LINE_SEPARATOR;
+
+    /**
+     * Returns an XML-string with serialized configuration attributes.
+     * Used when serializing {@link org.apache.ojb.broker.metadata.AttributeContainer} attributes.
+     * @param prefix the line prefix (ie indent) or null for no prefix
+     * @param attributeProperties the properties object holding attributes to be serialized
+     * (null-safe)
+     * @return XML-string with serialized configuration attributes (never null)
+     */
+    public static String getSerializedAttributes(final String prefix,
+                                                 final Properties attributeProperties)
+    {
+        final StringBuffer buf = new StringBuffer();
+        appendSerializedAttributes(buf, prefix, attributeProperties);
+        return buf.toString();
+    }
+
+    /**
+     * Appends an XML-string with serialized configuration attributes to the specified buffer.
+     * Used when serializing {@link org.apache.ojb.broker.metadata.AttributeContainer} attributes.
+     * @param buf the string buffer to append to
+     * @param prefix the line prefix (ie indent) or null for no prefix
+     * @param attributeProperties the properties object holding attributes to be serialized
+     * (null-safe)
+     */
+    public static void appendSerializedAttributes(final StringBuffer buf,
+                                                  final String prefix,
+                                                  final Properties attributeProperties)
+    {
+        if (attributeProperties != null)
+        {
+            final Enumeration keys = attributeProperties.keys();
+            while (keys.hasMoreElements())
+            {
+                final String key = (String) keys.nextElement();
+                final String value = attributeProperties.getProperty( key );
+                if (prefix != null)
+                {
+                    buf.append(prefix);
+                }
+                buf.append("<attribute attribute-name=\"").append(key);
+                buf.append("\" attribute-value=\"" ).append(value);
+                buf.append("\"/>");
+                buf.append(XML_EOL);
+            }
+        }
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message