public static void checkAttributes(String typeOfTag,Node n,ValidAttribute[] validAttributes,ErrorDispatcher err) throws JasperException {
  Attributes attrs=n.getAttributes();
  Mark start=n.getStart();
  boolean valid=true;
  int tempLength=(attrs == null) ? 0 : attrs.getLength();
  ArrayList<String> temp=new ArrayList<String>(tempLength);
  for (int i=0; i < tempLength; i++) {
    String qName=attrs.getQName(i);
    if ((!qName.equals("xmlns")) && (!qName.startsWith("xmlns:")))     temp.add(qName);
  }
  Node.Nodes tagBody=n.getBody();
  if (tagBody != null) {
    int numSubElements=tagBody.size();
    for (int i=0; i < numSubElements; i++) {
      Node node=tagBody.getNode(i);
      if (node instanceof Node.NamedAttribute) {
        String attrName=node.getAttributeValue("name");
        temp.add(attrName);
        if (n.getAttributeValue(attrName) != null) {
          err.jspError(n,"jsp.error.duplicate.name.jspattribute",attrName);
        }
      }
 else {
        break;
      }
    }
  }
  String missingAttribute=null;
  for (int i=0; i < validAttributes.length; i++) {
    int attrPos;
    if (validAttributes[i].mandatory) {
      attrPos=temp.indexOf(validAttributes[i].name);
      if (attrPos != -1) {
        temp.remove(attrPos);
        valid=true;
      }
 else {
        valid=false;
        missingAttribute=validAttributes[i].name;
        break;
      }
    }
  }
  if (!valid)   err.jspError(start,"jsp.error.mandatory.attribute",typeOfTag,missingAttribute);
  int attrLeftLength=temp.size();
  if (attrLeftLength == 0)   return;
  String attribute=null;
  for (int j=0; j < attrLeftLength; j++) {
    valid=false;
    attribute=temp.get(j);
    for (int i=0; i < validAttributes.length; i++) {
      if (attribute.equals(validAttributes[i].name)) {
        valid=true;
        break;
      }
    }
    if (!valid)     err.jspError(start,"jsp.error.invalid.attribute",typeOfTag,attribute);
  }
}

public static void checkAttributes ( String typeOfTag , Node n , ValidAttribute [ ] validAttributes , ErrorDispatcher err ) throws JasperException { Attributes attrs = n . getAttributes ( ) ; Mark start = n . getStart ( ) ; boolean valid = true ; int tempLength = ( attrs == null ) ? 0 : attrs . getLength ( ) ; ArrayList < String > temp = new ArrayList < String > ( tempLength ) ; for ( int i = 0 ; i < tempLength ; i ++ ) { String qName = attrs . getQName ( i ) ; if ( ( ! qName . equals ( "xmlns" ) ) && ( ! qName . startsWith ( "xmlns:" ) ) ) temp . add ( qName ) ; } Node . Nodes tagBody = n . getBody ( ) ; if ( tagBody != null ) { int numSubElements = tagBody . size ( ) ; for ( int i = 0 ; i < numSubElements ; i ++ ) { Node node = tagBody . getNode ( i ) ; if ( node instanceof Node . NamedAttribute ) { String attrName = node . getAttributeValue ( "name" ) ; temp . add ( attrName ) ; if ( n . getAttributeValue ( attrName ) != null ) { err . jspError ( n , "jsp.error.duplicate.name.jspattribute" , attrName ) ; } } else { break ; } } } String missingAttribute = null ; for ( int i = 0 ; i < validAttributes . length ; i ++ ) { int attrPos ; if ( validAttributes [ i ] . mandatory ) { attrPos = temp . indexOf ( validAttributes [ i ] . name ) ; if ( attrPos != - 1 ) { temp . remove ( attrPos ) ; valid = true ; } else { valid = false ; missingAttribute = validAttributes [ i ] . name ; break ; } } } if ( ! valid ) err . jspError ( start , "jsp.error.mandatory.attribute" , typeOfTag , missingAttribute ) ; int attrLeftLength = temp . size ( ) ; if ( attrLeftLength == 0 ) return ; String attribute = null ; for ( int j = 0 ; j < attrLeftLength ; j ++ ) { valid = false ; attribute = temp . get ( j ) ; for ( int i = 0 ; i < validAttributes . length ; i ++ ) { if ( attribute . equals ( validAttributes [ i ] . name ) ) { valid = true ; break ; } } if ( ! valid ) err . jspError ( start , "jsp.error.invalid.attribute" , typeOfTag , attribute ) ; } }
checks if all mandatory attributes are present and if all attributes present have valid names . checks attributes specified as xml - style attributes as well as attributes specified using the jsp : attribute standard action .
