[jboss-cvs] Picketlink SVN: r757 - in federation/trunk/picketlink-fed-core/src: main/java/org/picketlink/identity/federation/core/util and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Feb 22 12:32:17 EST 2011


Author: anil.saldhana at jboss.com
Date: 2011-02-22 12:32:17 -0500 (Tue, 22 Feb 2011)
New Revision: 757

Added:
   federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/SystemPropertyAsStringUnitTestCase.java
Modified:
   federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/StaxParserUtil.java
   federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/StringUtil.java
Log:
PLFED-138: add a method to StringUtil to pick a system property if needed

Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/StaxParserUtil.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/StaxParserUtil.java	2011-02-18 19:17:35 UTC (rev 756)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/StaxParserUtil.java	2011-02-22 17:32:17 UTC (rev 757)
@@ -41,6 +41,7 @@
 import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
 import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants;
 import org.picketlink.identity.federation.core.saml.v2.util.DocumentUtil;
+import org.picketlink.identity.federation.core.util.StringUtil;
 import org.picketlink.identity.federation.core.util.TransformerUtil;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -79,7 +80,9 @@
     */
    public static String getAttributeValue(Attribute attribute)
    {
-      return trim(attribute.getValue());
+      String str = trim(attribute.getValue());
+      str = StringUtil.getSystemPropertyAsString(str);
+      return str;
    }
    
    /**
@@ -150,15 +153,18 @@
     * @throws ParsingException
     */
    public static String getElementText( XMLEventReader xmlEventReader ) throws ParsingException
-   {
+   {  
+      String str = null;
       try
       {
-         return xmlEventReader.getElementText().trim();
+         str =  xmlEventReader.getElementText().trim();
+         str = StringUtil.getSystemPropertyAsString(str);
       }
       catch (XMLStreamException e)
       {
          throw new ParsingException( e );
       }
+      return str;
    }
    
    /**

Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/StringUtil.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/StringUtil.java	2011-02-18 19:17:35 UTC (rev 756)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/StringUtil.java	2011-02-22 17:32:17 UTC (rev 757)
@@ -21,6 +21,7 @@
  */
 package org.picketlink.identity.federation.core.util;
 
+
 /**
  * Utility dealing with Strings
  * @author Anil.Saldhana at redhat.com
@@ -38,8 +39,32 @@
       return str != null && !"".equals(str);
    } 
    
+   /**
+    * Check whether the string is null or empty
+    * @param str
+    * @return
+    */
    public static boolean isNullOrEmpty(String str)
    {
-      return str == null || "".equals(str);
+      return str == null || str.isEmpty();
    }
+    
+   /**
+    * Get the system property value if the string is of the format ${sysproperty}
+    * @param str
+    * @return
+    */
+   public static String getSystemPropertyAsString( String str )
+   {
+      if( str.startsWith( "${") && str.endsWith( "}" ))
+      {
+         int len = str.length();
+         str = str.substring( 2, len -1 );
+         String sysPropertyValue = SecurityActions.getSystemProperty(str, "" );
+         if( sysPropertyValue.isEmpty() )
+            throw new IllegalArgumentException( "System Property " + str + " is not set" );
+         str = sysPropertyValue;
+      }
+      return str;
+   }
 }
\ No newline at end of file

Added: federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/SystemPropertyAsStringUnitTestCase.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/SystemPropertyAsStringUnitTestCase.java	                        (rev 0)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/SystemPropertyAsStringUnitTestCase.java	2011-02-22 17:32:17 UTC (rev 757)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * 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.
+ */
+package org.picketlink.test.identity.federation.core.parser;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.picketlink.identity.federation.core.util.StringUtil;
+
+/**
+ * Unit Test {@link StringUtil#getSystemPropertyAsString(String)}
+ * that parses a string that represents a system property
+ * @author Anil.Saldhana at redhat.com
+ * @since Feb 22, 2011
+ */
+public class SystemPropertyAsStringUnitTestCase
+{
+   
+   @Test
+   public void testSystemProperty() throws Exception
+   {
+      System.setProperty( "test", "anil" );
+      String str = "${test}";
+      assertEquals( "anil", StringUtil.getSystemPropertyAsString( str ) );
+   }
+
+}
\ No newline at end of file



More information about the jboss-cvs-commits mailing list