You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@excalibur.apache.org by cz...@apache.org on 2007/03/29 11:44:36 UTC

svn commit: r523657 - in /excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source: AvalonSourceUtil.java SourceParameters.java SourceUtil.java

Author: cziegeler
Date: Thu Mar 29 02:44:31 2007
New Revision: 523657

URL: http://svn.apache.org/viewvc?view=rev&rev=523657
Log:
Move dependencies to Avalon Framework into separate class and deprecate methods directly using Avalon classes

Added:
    excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/AvalonSourceUtil.java   (with props)
Modified:
    excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/SourceParameters.java
    excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/SourceUtil.java

Added: excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/AvalonSourceUtil.java
URL: http://svn.apache.org/viewvc/excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/AvalonSourceUtil.java?view=auto&rev=523657
==============================================================================
--- excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/AvalonSourceUtil.java (added)
+++ excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/AvalonSourceUtil.java Thu Mar 29 02:44:31 2007
@@ -0,0 +1,117 @@
+/*
+ * 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.excalibur.source;
+
+import java.util.Iterator;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.parameters.Parameters;
+
+/**
+ * This is a helper class for using the Avalon framework together with the
+ * source resolver package.
+ *
+ * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
+ * @version $Id$
+ */
+public abstract class AvalonSourceUtil
+{
+    /**
+     * Create a new parameters object from the
+     * children of the configuration.
+     * If no children are available <code>null</code>
+     * is returned.
+     */
+    public static SourceParameters createSourceParameters( Configuration conf )
+    {
+        Configuration[] children = conf.getChildren();
+        if( children != null && children.length > 0 )
+        {
+            SourceParameters pars = new SourceParameters();
+            String name;
+            String value;
+            for( int i = 0; i < children.length; i++ )
+            {
+                name = children[ i ].getName();
+                try
+                {
+                    value = children[ i ].getValue();
+                }
+                catch( ConfigurationException local )
+                {
+                    value = ""; // ignore exception
+                }
+                pars.setParameter( name, value );
+            }
+            return pars;
+        }
+        return null;
+    }
+
+    /**
+     * Create a Parameters object.
+     * The first value of each parameter is added to the Parameters object.
+     * @return An Parameters object - if no parameters are defined this is an
+     *         empty object.
+     */
+    public static Parameters getFirstParameters(SourceParameters params)
+    {
+        Parameters result = new Parameters();
+        Iterator iter = params.getParameterNames();
+        String parName;
+        while( iter.hasNext() )
+        {
+            parName = (String)iter.next();
+            result.setParameter( parName, params.getParameter( parName ) );
+        }
+        return result;
+    }
+
+    /**
+     * Append parameters to the uri.
+     * Each parameter is appended to the uri with "parameter=value",
+     * the parameters are separated by "&".
+     */
+    public static String appendParameters( String uri,
+                                           Parameters parameters )
+    {
+        if( parameters != null )
+        {
+            StringBuffer buffer = new StringBuffer( uri );
+            String[] keys = parameters.getNames();
+            String current;
+            char separator = ( uri.indexOf( "?" ) == -1 ? '?' : '&' );
+
+            if( keys != null )
+            {
+                for( int i = 0; i < keys.length; i++ )
+                {
+                    current = keys[ i ];
+                    buffer.append( separator )
+                        .append( current )
+                        .append( '=' )
+                        .append( SourceUtil.encode( parameters.getParameter( current, null ) ) );
+                    separator = '&';
+                }
+            }
+            return buffer.toString();
+        }
+
+        return uri;
+    }
+}

Propchange: excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/AvalonSourceUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/AvalonSourceUtil.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/SourceParameters.java
URL: http://svn.apache.org/viewvc/excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/SourceParameters.java?view=diff&rev=523657&r1=523656&r2=523657
==============================================================================
--- excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/SourceParameters.java (original)
+++ excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/SourceParameters.java Thu Mar 29 02:44:31 2007
@@ -95,6 +95,7 @@
      * children of the configuration.
      * If no children are available <code>null</code>
      * is returned.
+     * @deprecated Use {@link AvalonSourceUtil#createSourceParameters(Configuration)} instead.
      */
     public static SourceParameters create( Configuration conf )
     {
@@ -292,6 +293,8 @@
     /**
      * Create a Parameters object.
      * The first value of each parameter is added to the Parameters object.
+     * @deprecated Use {@link AvalonSourceUtil#getFirstParameters(SourceParameters)} or
+     *             {@link #getFirstParametersMap}.
      * @return An Parameters object - if no parameters are defined this is an
      *         empty object.
      */
@@ -309,6 +312,25 @@
     }
 
     /**
+     * Create a map object.
+     * The first value of each parameter is added to the map.
+     * @return A new map - if no parameters are defined this is an
+     *         empty map.
+     */
+    public Map getFirstParametersMap()
+    {
+        final Map result = new HashMap();
+        Iterator iter = this.getParameterNames();
+        String parName;
+        while( iter.hasNext() )
+        {
+            parName = (String)iter.next();
+            result.put( parName, this.getParameter( parName ) );
+        }
+        return result;
+    }
+
+    /**
      * Build a query string.
      * The query string can e.g. be used for http connections.
      * @return A query string which contains for each parameter/value pair
@@ -487,17 +509,17 @@
             this.names.remove( name );
         }
     }
-    
+
     /**
-     * Returns an immutable java.util.Map containing parameter names as keys and 
-     * parameter values as map values. The keys in the parameter map are of type String. 
+     * Returns an immutable java.util.Map containing parameter names as keys and
+     * parameter values as map values. The keys in the parameter map are of type String.
      * The values in the parameter map are of type String array.
      */
-    public Map getParameterMap() 
+    public Map getParameterMap()
     {
         final Map m = new HashMap(this.names);
         Iterator entries = m.entrySet().iterator();
-        while (entries.hasNext()) 
+        while (entries.hasNext())
         {
             Map.Entry entry = (Map.Entry)entries.next();
             ArrayList list = (ArrayList)entry.getValue();

Modified: excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/SourceUtil.java
URL: http://svn.apache.org/viewvc/excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/SourceUtil.java?view=diff&rev=523657&r1=523656&r2=523657
==============================================================================
--- excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/SourceUtil.java (original)
+++ excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/SourceUtil.java Thu Mar 29 02:44:31 2007
@@ -52,6 +52,7 @@
      * Append parameters to the uri.
      * Each parameter is appended to the uri with "parameter=value",
      * the parameters are separated by "&".
+     * @deprecated Use {@link AvalonSourceUtil#appendParameters(String, Parameters)} instead.
      */
     public static String appendParameters( String uri,
                                            Parameters parameters )
@@ -499,7 +500,7 @@
                                           destination.getURI()+
                                           "' is not writeable");
             }
-            
+
             IOException firstE = null;
             ModifiableSource modDestination = (ModifiableSource)destination;
             try
@@ -519,7 +520,7 @@
                             // Remebver the original exception in case there are problems closing
                             //  any streams.
                             firstE = e;
-                            
+
                             // If possible, cancel the destination.
                             if ( modDestination.canCancel( out ) )
                             {
@@ -547,7 +548,7 @@
                     firstE = ioe;
                 }
             }
-            
+
             // If there were any problems then wrap the original exception in a SourceException.
             if ( firstE != null )
             {



---------------------------------------------------------------------
To unsubscribe, e-mail: scm-unsubscribe@excalibur.apache.org
For additional commands, e-mail: scm-help@excalibur.apache.org