FileDocCategorySizeDatePackage
AttributeExtracter.javaAPI DocGlassfish v2 API4976Fri May 04 22:35:10 BST 2007com.sun.enterprise.tools.upgrade.transform

AttributeExtracter

public class AttributeExtracter extends Object
author
prakash

Fields Summary
private String
fileName
private static AttributeExtracter
attrExtracter
private HashMap
attributeMap
Constructors Summary
private AttributeExtracter(String fileName)
Creates a new instance of SomeClass

        this.fileName = fileName;
        attributeMap = new HashMap();
    
Methods Summary
private voidextractAttributes(java.io.BufferedReader reader, java.util.List attrList)

        for(int i=0; i<50; i++){
            String attrLine = reader.readLine().trim();
            attrList.add(getAttributeFromLine(attrLine.trim()));
            if(attrLine.endsWith(">"))
                break;
        }
    
private java.lang.StringgetAttributeFromLine(java.lang.String attrLine)

        StringTokenizer stk = new StringTokenizer(attrLine);
        return stk.nextToken();
    
private java.lang.StringgetAttributeLine(java.lang.String elementName, java.lang.String line)

        if(line.startsWith("<!ATTLIST")){
            String atLine = line.substring("<!ATTLIST".length()).trim();
            StringTokenizer stk = new StringTokenizer(atLine);
            if(stk.nextToken().equals(elementName))
                return atLine.substring(elementName.length());
        }
        return null;
    
public java.util.ListgetAttributeList(java.lang.String elementName)

        if(attributeMap.get(elementName) != null)
            return (List)attributeMap.get(elementName);
        ArrayList attrList = new ArrayList();
        try{
            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(fileName)));
            String readLine = null;
            while((readLine = reader.readLine())!= null){
                String attrLine = this.getAttributeLine(elementName, readLine);
                if(attrLine == null)
                    continue;
                if((attrLine.length() > 0) && (!attrLine.trim().equals("")))
                    attrList.add(this.getAttributeFromLine(attrLine));
                this.extractAttributes(reader, attrList);
            }
            this.attributeMap.put(elementName, attrList);
        }catch(Exception ex){
            ex.printStackTrace();
        }
        return attrList;
    
public static com.sun.enterprise.tools.upgrade.transform.AttributeExtractergetExtracter(java.lang.String fileName)

        if(attrExtracter == null){
            attrExtracter = new AttributeExtracter(fileName);
        }
        return attrExtracter;
    
public static voidmain(java.lang.String[] args)

     /*   //AttributeExtracter extracter = new AttributeExtracter("c:\\temp\\sundomain.dtd");
        AttributeExtracter extracter =  AttributeExtracter.getExtracter("/home/paradhya/junk/sundomain.dtd");
        List list = extracter.getAttributeList("http-listener");
        System.out.println(list);
        for(int i=0; i<list.size(); i++){
            System.out.println(list.get(i));
        }
      */