FileDocCategorySizeDatePackage
TagNameIsUnique.javaAPI DocGlassfish v2 API5042Fri May 04 22:34:10 BST 2007com.sun.enterprise.tools.verifier.tests.web

TagNameIsUnique

public class TagNameIsUnique extends WebTest implements WebCheck
The name of tag must be unique.
author
Sudipto Ghosh

Fields Summary
boolean
oneFailed
Constructors Summary
Methods Summary
public com.sun.enterprise.tools.verifier.Resultcheck(com.sun.enterprise.deployment.WebBundleDescriptor descriptor)


        
        ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
        Context context = getVerifierContext();
        Result result = loadWarFile(descriptor);

        TagLibDescriptor tlds[] = context.getTagLibDescriptors();
        if (tlds == null) {
            addGoodDetails(result, compName);
            result.passed(smh.getLocalString
                    (getClass().getName() + ".passed",
                            "No tag lib files are specified"));
            return result;
        }
        for(TagLibDescriptor tld : tlds) {
            TagDescriptor[] tagDesc = tld.getTagDescriptors();
            List<String> name = new ArrayList<String>();
            for(TagDescriptor td : tagDesc) {
                name.add(td.getTagName());
            }
            if (name != null) {
                String[] names = (String[])name.toArray(new String[0]);
                if (!checkForDuplicateNames(result, compName, names, tld)) {
                    addGoodDetails(result, compName);
                    result.addGoodDetails(smh.getLocalString
                            (getClass().getName() + ".passed1",
                                    "All 'name' elements are defined properly under tag element of [ {0} ]",
                                    new Object[]{tld.getUri()}));
                }
            }
        }
        if(oneFailed){
            result.setStatus(Result.FAILED);
        } else {
            result.setStatus(Result.PASSED);
        }
        return result;
    
public booleancheckForDuplicateNames(com.sun.enterprise.tools.verifier.Result result, com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor compName, java.lang.String[] names, com.sun.enterprise.tools.verifier.TagLibDescriptor tld)

        boolean duplicate = false;
        for(int i=0; i<names.length-1;i++){
            for (int j=i+1; j<names.length; j++) {
                duplicate = names[i].trim().equals(names[j]);
                if(duplicate) {
                    oneFailed=true;
                    addErrorDetails(result, compName);
                    result.addErrorDetails(smh.getLocalString
                            (getClass().getName() + ".failed",
                                    "The name element value [ {0} ] under tag " +
                            "element in [ {1} ] is not unique",
                                    new Object[] {names[i], tld.getUri()}));
                }
            }
        }
        return oneFailed;