[exo-jcr-commits] exo-jcr SVN: r1983 - in kernel/trunk/exo.kernel.container/src: main/resources and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Mar 3 03:34:59 EST 2010


Author: nfilotto
Date: 2010-03-03 03:34:58 -0500 (Wed, 03 Mar 2010)
New Revision: 1983

Added:
   kernel/trunk/exo.kernel.container/src/test/resources/test-trim-value.xml
Modified:
   kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/xml/Deserializer.java
   kernel/trunk/exo.kernel.container/src/main/resources/binding.xml
   kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/xml/test/TestConfigurationXML.java
Log:
EXOJCR-556: Now allow the String values are deserialized with a Deserializer that calls trim() on the value. We call also the method trim on the results of the resolved values.

Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/xml/Deserializer.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/xml/Deserializer.java	2010-03-03 08:34:41 UTC (rev 1982)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/xml/Deserializer.java	2010-03-03 08:34:58 UTC (rev 1983)
@@ -54,7 +54,7 @@
     */
    public static String resolveString(String s)
    {
-      return Deserializer.resolveVariables(s);
+      return Deserializer.resolveNClean(s);
    }
 
    /**
@@ -77,7 +77,7 @@
       {
          return null;
       }
-      s = Deserializer.resolveVariables(s);
+      s = Deserializer.resolveNClean(s);
       if (s.equalsIgnoreCase("true"))
       {
          return true;
@@ -107,7 +107,7 @@
       {
          return null;
       }
-      s = Deserializer.resolveVariables(s);
+      s = Deserializer.resolveNClean(s);
       try
       {
          return Integer.parseInt(s);
@@ -136,7 +136,7 @@
       {
          return null;
       }
-      s = Deserializer.resolveVariables(s);
+      s = Deserializer.resolveNClean(s);
       try
       {
          return Long.parseLong(s);
@@ -165,7 +165,7 @@
       {
          return null;
       }
-      s = Deserializer.resolveVariables(s);
+      s = Deserializer.resolveNClean(s);
       try
       {
          return Double.parseDouble(s);
@@ -284,4 +284,25 @@
       return buffer.toString();
    
    }
+   
+   /**
+    * This methods will remove useless characters from the given {@link String} and return the result
+    * @param s the input value
+    * @return <code>null</code> if the input value is <code>null</code>, <code>s.trim()</code>
+    * otherwise
+    */
+   public static String cleanString(String s)
+   {
+      return s == null ? null : s.trim();
+   }
+   
+   /**
+    * This method will first resolves the variables then it will clean the results
+    * @param s the input value
+    * @return the resolve and clean value
+    */
+   public static String resolveNClean(String s)
+   {
+      return cleanString(resolveVariables(s));
+   }
 }

Modified: kernel/trunk/exo.kernel.container/src/main/resources/binding.xml
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/resources/binding.xml	2010-03-03 08:34:41 UTC (rev 1982)
+++ kernel/trunk/exo.kernel.container/src/main/resources/binding.xml	2010-03-03 08:34:58 UTC (rev 1983)
@@ -19,6 +19,9 @@
 
 -->
 <binding>
+  <!-- the default deserializer to use for String -->
+  <format type="java.lang.String" deserializer="org.exoplatform.container.xml.Deserializer.cleanString"/>
+ 
   <!-- xml object mapping -->
   <mapping class="org.exoplatform.xml.object.XMLBaseObject" abstract="true" label="base-object">
     <value name="string" usage="optional" get-method="getString" set-method="setString" deserializer="org.exoplatform.container.xml.Deserializer.resolveString"/>

Modified: kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/xml/test/TestConfigurationXML.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/xml/test/TestConfigurationXML.java	2010-03-03 08:34:41 UTC (rev 1982)
+++ kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/xml/test/TestConfigurationXML.java	2010-03-03 08:34:58 UTC (rev 1983)
@@ -21,24 +21,134 @@
 import junit.framework.TestCase;
 
 import org.exoplatform.container.xml.Component;
+import org.exoplatform.container.xml.ComponentLifecyclePlugin;
+import org.exoplatform.container.xml.ComponentPlugin;
 import org.exoplatform.container.xml.Configuration;
+import org.exoplatform.container.xml.ContainerLifecyclePlugin;
+import org.exoplatform.container.xml.ExternalComponentPlugins;
 import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.container.xml.ManageableComponents;
 import org.exoplatform.container.xml.ObjectParameter;
 import org.exoplatform.container.xml.PropertiesParam;
 import org.exoplatform.container.xml.ValueParam;
+import org.exoplatform.container.xml.ValuesParam;
 import org.exoplatform.xml.object.XMLObject;
 import org.jibx.runtime.BindingDirectory;
 import org.jibx.runtime.IBindingFactory;
 import org.jibx.runtime.IUnmarshallingContext;
 
 import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
  */
 public class TestConfigurationXML extends TestCase
 {
+   
+   @SuppressWarnings("unchecked")
+   public void testTrimValue() throws Exception
+   {
+      InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("test-trim-value.xml");
+      assertNotNull(is);
+      try
+      {
+         IBindingFactory bfact = BindingDirectory.getFactory(XMLObject.class);
+         IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
+         Configuration conf =
+            (Configuration)uctx.unmarshalDocument(is, null);
 
+         assertNotNull(conf);
+         Iterator it = conf.getContainerLifecyclePluginIterator();
+         assertNotNull(it);
+         assertTrue(it.hasNext());
+         ContainerLifecyclePlugin conlp = (ContainerLifecyclePlugin)it.next();
+         assertEquals("container-lifecycle-plugin-type", conlp.getType());
+         assertNotNull(conlp.getInitParams());
+         assertEquals("container-lifecycle-plugin-value-param-value", (conlp.getInitParams().getValueParam("container-lifecycle-plugin-value-param-name")).getValue());
+         it = conf.getComponentLifecyclePluginIterator();
+         assertNotNull(it);
+         assertTrue(it.hasNext());         
+         ComponentLifecyclePlugin comlp = (ComponentLifecyclePlugin)it.next();
+         assertEquals("component-lifecycle-plugin", comlp.getType());
+         ManageableComponents mc = comlp.getManageableComponents();
+         assertNotNull(mc);
+         assertEquals("manageable-components-component-type", mc.getComponentsType().get(0));
+         ValuesParam valuesParam = comlp.getInitParams().getValuesParam("component-lifecycle-plugin-values-param-name");
+         assertNotNull(valuesParam);
+         assertNotNull(valuesParam.getValues());
+         assertTrue(valuesParam.getValues().contains("component-lifecycle-plugin-values-param-value1"));
+         assertTrue(valuesParam.getValues().contains("component-lifecycle-plugin-values-param-value2"));
+         Component c = conf.getComponent("component-key1");
+         assertNotNull(c);
+         assertEquals("component-type1", c.getType());
+         PropertiesParam propertiesParam = c.getInitParams().getPropertiesParam("component-key1-properties-param-name");
+         assertNotNull(propertiesParam);
+         assertEquals("component-key1-properties-param-prop-value", propertiesParam.getProperty("component-key1-properties-param-prop-name"));
+         c = conf.getComponent("component-type2");
+         assertNotNull(c);
+         ObjectParameter objectParameter = c.getInitParams().getObjectParam("component-key2-object-param-name"); 
+         assertNotNull(objectParameter);
+         MyObject o = (MyObject)objectParameter.getObject();
+         assertNotNull(o);
+         assertEquals("string-value", o.field1);
+         assertEquals(1, o.field2);
+         assertEquals(1l, o.field3);
+         assertEquals(1d, o.field4);
+         assertEquals(true, o.field5);
+         assertNotNull(o.field6);
+         assertEquals("entry-value", o.field6.get("entry-name"));
+         assertNotNull(o.field7);
+         assertTrue(o.field7.contains("string-value"));
+         assertNotNull(o.field8);
+         assertEquals(1, o.field8[0]);
+         List list = c.getComponentPlugins();
+         assertNotNull(list);
+         assertFalse(list.isEmpty());
+         ComponentPlugin cp = (ComponentPlugin)list.get(0);
+         assertEquals("component-plugins-name", cp.getName());
+         assertEquals("set-method-name", cp.getSetMethod());
+         assertEquals("component-plugins-type", cp.getType());
+         assertEquals("1", cp.getPriority());
+         it = conf.getExternalComponentPluginsIterator();
+         assertNotNull(it);
+         assertTrue(it.hasNext());         
+         ExternalComponentPlugins ecps = (ExternalComponentPlugins)it.next();
+         assertEquals("target-component-name", ecps.getTargetComponent());
+         list = ecps.getComponentPlugins();
+         assertNotNull(list);
+         assertFalse(list.isEmpty());
+         cp = (ComponentPlugin)list.get(0);
+         assertEquals("component-plugins-name", cp.getName());
+         assertEquals("set-method-name", cp.getSetMethod());
+         assertEquals("component-plugins-type", cp.getType());
+         assertEquals("1", cp.getPriority());
+         list = conf.getImports();
+         assertNotNull(list);
+         assertFalse(list.isEmpty());
+         assertEquals("import-value", list.get(0));
+         list = conf.getRemoveConfiguration();
+         assertNotNull(list);
+         assertFalse(list.isEmpty());
+         assertEquals("remove-configuration-value", list.get(0));
+      }
+      finally
+      {
+         try
+         {
+            is.close();
+         }
+         catch (Exception e)
+         {
+            // ignore me
+         }
+      }
+   }   
+
    public void testSystemPropertyResolving() throws Exception
    {
 
@@ -118,5 +228,17 @@
       assertNotNull(paramName);
       assertEquals(expectedValue, valueParam.getValue());
    }
+   
+   public static class MyObject
+   {
+      public String field1;
+      public int field2;
+      public long field3;
+      public double field4;
+      public boolean field5;
+      public Map field6;
+      public Collection field7;
+      public int[] field8;
+   }
 
 }
\ No newline at end of file

Added: kernel/trunk/exo.kernel.container/src/test/resources/test-trim-value.xml
===================================================================
--- kernel/trunk/exo.kernel.container/src/test/resources/test-trim-value.xml	                        (rev 0)
+++ kernel/trunk/exo.kernel.container/src/test/resources/test-trim-value.xml	2010-03-03 08:34:58 UTC (rev 1983)
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+	<!--
+
+		Copyright (C) 2009 eXo Platform SAS. This is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License
+		as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This software is distributed in the
+		hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+		Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this software; if not,
+		write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+	-->
+<configuration>
+
+	<container-lifecycle-plugin>
+		<type> container-lifecycle-plugin-type 
+      </type>
+		<init-params>
+			<value-param>
+				<name> container-lifecycle-plugin-value-param-name </name>
+				<value> container-lifecycle-plugin-value-param-value </value>
+			</value-param>
+		</init-params>
+	</container-lifecycle-plugin>
+	<component-lifecycle-plugin>
+		<type> component-lifecycle-plugin 
+      </type>
+		<manageable-components>
+			<component-type> manageable-components-component-type</component-type>
+		</manageable-components>
+		<init-params>
+			<values-param>
+				<name> component-lifecycle-plugin-values-param-name </name>
+				<value> component-lifecycle-plugin-values-param-value1 </value>
+				<value> component-lifecycle-plugin-values-param-value2 
+				</value>
+			</values-param>
+		</init-params>
+	</component-lifecycle-plugin>
+	<component>
+		<key> component-key1  
+      </key>
+		<type> component-type1 
+      </type>
+		<init-params>
+			<properties-param>
+				<name> component-key1-properties-param-name </name>
+				<property name=" component-key1-properties-param-prop-name " value=" component-key1-properties-param-prop-value
+			" />
+			</properties-param>
+		</init-params>
+	</component>
+	<component>
+		<type> component-type2 
+      </type>
+		<component-plugins>
+			<component-plugin>
+				<name> component-plugins-name </name>
+				<set-method> set-method-name</set-method>
+				<type> component-plugins-type </type>
+				<priority> 1 </priority>
+			</component-plugin>
+		</component-plugins>
+		<init-params>
+			<object-param>
+				<name> component-key2-object-param-name </name>
+				<object type=" org.exoplatform.xml.test.TestConfigurationXML$MyObject ">
+					<field name=" field1 ">
+						<string> string-value </string>
+					</field>
+					<field name=" field2 ">
+						<int> 1 </int>
+					</field>
+					<field name=" field3 ">
+						<long> 1 </long>
+					</field>
+					<field name=" field4 ">
+						<double> 1 </double>
+					</field>
+					<field name=" field5 ">
+						<boolean> true </boolean>
+					</field>
+					<field name=" field6 ">
+						<map type=" java.util.HashMap ">
+							<entry>
+								<key><string> entry-name </string></key>
+								<value><string> entry-value </string></value>
+							</entry>
+						</map>
+					</field>
+					<field name=" field7 ">
+						<collection type=" java.util.HashSet ">
+							<value>
+								<string> string-value </string>
+							</value>
+						</collection>
+					</field>
+					<field name=" field8 ">
+						<native-array type=" int ">
+							<array> 1 </array>
+						</native-array>
+					</field>
+				</object>
+			</object-param>
+		</init-params>
+	</component>
+	<external-component-plugins>
+		<target-component> target-component-name 
+		</target-component>
+		<component-plugin>
+			<name> component-plugins-name </name>
+			<set-method> set-method-name</set-method>
+			<type> component-plugins-type </type>
+			<priority> 1 </priority>
+		</component-plugin>
+	</external-component-plugins>
+	<import> import-value 
+	</import>
+	<remove-configuration> remove-configuration-value </remove-configuration>
+</configuration>



More information about the exo-jcr-commits mailing list