donaldp     2002/09/20 09:37:58

  Modified:    loader/src/java/org/apache/excalibur/policy/reader
                        PolicyReader.java
  Log:
  Make sure empty/missing attributes are returned as null rather than as ""
  
  Revision  Changes    Path
  1.2       +33 -10    
jakarta-avalon-excalibur/loader/src/java/org/apache/excalibur/policy/reader/PolicyReader.java
  
  Index: PolicyReader.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/loader/src/java/org/apache/excalibur/policy/reader/PolicyReader.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PolicyReader.java 20 Sep 2002 09:58:37 -0000      1.1
  +++ PolicyReader.java 20 Sep 2002 16:37:58 -0000      1.2
  @@ -82,9 +82,9 @@
       private GrantMetaData buildGrant( final Element element )
           throws Exception
       {
  -        final String codeBase = element.getAttribute( "code-base" );
  -        final String signedBy = element.getAttribute( "signed-by" );
  -        final String keyStore = element.getAttribute( "key-store" );
  +        final String codeBase = getAttribute( element, "code-base" );
  +        final String signedBy = getAttribute( element, "signed-by" );
  +        final String keyStore = getAttribute( element, "key-store" );
           final NodeList permissionElements =
               element.getElementsByTagName( "permission" );
           final PermissionMetaData[] permissions = buildPermissions( 
permissionElements );
  @@ -122,9 +122,9 @@
       private PermissionMetaData buildPermission( final Element element )
           throws Exception
       {
  -        final String classname = element.getAttribute( "class" );
  -        final String target = element.getAttribute( "target" );
  -        final String action = element.getAttribute( "action" );
  +        final String classname = getAttribute( element, "class" );
  +        final String target = getAttribute( element, "target" );
  +        final String action = getAttribute( element, "action" );
           return new PermissionMetaData( classname, target, action );
       }
   
  @@ -159,9 +159,32 @@
       private KeyStoreMetaData buildKeyStore( final Element element )
           throws Exception
       {
  -        final String name = element.getAttribute( "name" );
  -        final String location = element.getAttribute( "location" );
  -        final String type = element.getAttribute( "type" );
  +        final String name = getAttribute( element, "name" );
  +        final String location = getAttribute( element, "location" );
  +        final String type = getAttribute( element, "type" );
           return new KeyStoreMetaData( name, location, type );
  +    }
  +
  +    /**
  +     * Utility method to get value of attribute. If attribute
  +     * has a empty/null value or does not appear in XML then return
  +     * null, elese return value.
  +     *
  +     * @param element the element
  +     * @param name the attribute name
  +     * @return the cleaned attribute value
  +     */
  +    private String getAttribute( final Element element,
  +                                 final String name )
  +    {
  +        final String value = element.getAttribute( name );
  +        if( "".equals( value ) )
  +        {
  +            return null;
  +        }
  +        else
  +        {
  +            return value;
  +        }
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to