private void setupResource ( List resource ) throws ParsingException { mapAttributes ( resource , resourceMap ) ; // make sure there resource-id attribute was included List < Attribute > resourceId = resourceMap . get ( RESOURCE_ID ) ; if ( resourceId == null ) { logger . warn ( "Resource must contain resource-id attr" ) ; //throw new ParsingException("resource missing resource-id"); } else { // make sure there's only one value for this if ( resourceId . size ( ) != 1 ) { logger . warn ( "Resource must contain only one resource-id Attribute" ) ; //throw new ParsingException("too many resource-id attrs"); } else { // keep track of the resource-id attribute this . resourceId = resourceId . get ( 0 ) . getValue ( ) ; } } //SECURITY-162: Relax resource-id requirement if ( this . resourceId == null ) this . resourceId = new StringAttribute ( "" ) ; List < Attribute > resourceScope = resourceMap . get ( RESOURCE_SCOPE ) ; // see if a resource-scope attribute was included if ( resourceScope != null && ! resourceScope . isEmpty ( ) ) { // make sure there's only one value for resource-scope if ( resourceScope . size ( ) > 1 ) { System . err . println ( "Resource may contain only one " + "resource-scope Attribute" ) ; throw new ParsingException ( "too many resource-scope attrs" ) ; } AttributeValue attrValue = resourceScope . get ( 0 ) . getValue ( ) ; // scope must be a string, so throw an exception otherwise if ( ! attrValue . getType ( ) . toString ( ) . equals ( StringAttribute . identifier ) ) throw new ParsingException ( "scope attr must be a string" ) ; String value = ( ( StringAttribute ) attrValue ) . getValue ( ) ; if ( value . equals ( "Immediate" ) ) { scope = SCOPE_IMMEDIATE ; } else if ( value . equals ( "Children" ) ) { scope = SCOPE_CHILDREN ; } else if ( value . equals ( "Descendants" ) ) { scope = SCOPE_DESCENDANTS ; } else { System . err . println ( "Unknown scope type: " + value ) ; throw new ParsingException ( "invalid scope type: " + value ) ; } } else { // by default, the scope is always Immediate scope = SCOPE_IMMEDIATE ; } }
This basically does the same thing that the other types need to do except that we also look for a resource - id attribute not because we re going to use but only to make sure that it s actually there and for the optional scope attribute to see what the scope of the attribute is