// Path: src/main/java/com/codefork/refine/NameType.java
// public enum NameType {
//     Person("/people/person", "Person", "Personal", "local.personalNames all \"%s\""),
//     Organization("/organization/organization", "Corporate Name", "Corporate", "local.corporateNames all \"%s\""),
//     Location("/location/location", "Geographic Name", "Geographic", "local.geographicNames all \"%s\""),
//     // can't find better freebase ids for these two
//     Book("/book/book", "Work", "UniformTitleWork", "local.uniformTitleWorks all \"%s\""),
//     Edition("/book/book edition", "Expression", "UniformTitleExpression", "local.uniformTitleExpressions all \"%s\"");
// 
//     // ids are from freebase identifier ns
//     private final String id;
//     private final String displayName;
//     private final String viafCode;
//     private final String cqlString;
// 
//     NameType(String id, String displayName, String viafCode, String cqlString) {
//        this.id = id;
//        this.displayName = displayName;
//        this.viafCode = viafCode;
//        this.cqlString = cqlString;
//     }
// 
//     public String getId() {
//         return id;
//     }
// 
//     public String getDisplayName() {
//         return displayName;
//     }
// 
//     public String getViafCode() {
//         return viafCode;
//     }
// 
//     public String getCqlString() {
//         return cqlString;
//     }
// 
//     public VIAFNameType asVIAFNameType() {
//         return new VIAFNameType(getId(), getDisplayName());
//     }
// 
//     public static NameType getByViafCode(String viafCodeArg) {
//         for(NameType nameType: NameType.values()) {
//             if(nameType.viafCode.equals(viafCodeArg)) {
//                 return nameType;
//             }
//         }
//         return null;
//     }
// 
//     public static NameType getById(String idArg) {
//         for(NameType nameType: NameType.values()) {
//             if(nameType.id.equals(idArg)) {
//                 return nameType;
//             }
//         }
//         return null;
//     }
// 
// }


import com.codefork.refine.NameType;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;

        StartElementHandler captureHandler = new StartElementHandler() {
            public void handle(VIAFParser parser, String uri, String localName, String qName, Attributes attributes) {
                parser.captureChars = true;
            }
        };

        startElementHandlers.put("searchRetrieveResponse/records/record/recordData/VIAFCluster/nameType",
                captureHandler);
        startElementHandlers.put("searchRetrieveResponse/records/record/recordData/VIAFCluster/viafID",
                captureHandler);
        startElementHandlers.put("searchRetrieveResponse/records/record/recordData/VIAFCluster/mainHeadings/data/text",
                captureHandler);
        startElementHandlers.put("searchRetrieveResponse/records/record/recordData/VIAFCluster/mainHeadings/data/sources/s",
                captureHandler);
        startElementHandlers.put("searchRetrieveResponse/records/record/recordData/VIAFCluster/mainHeadings/data/sources/sid",
                captureHandler);

        endElementHandlers.put("searchRetrieveResponse/records/record",
                new EndElementHandler() {
                    public void handle(VIAFParser parser, String uri, String localName, String qName) {
                        parser.associateSourceIds();

                        parser.results.add(parser.result);
                        parser.result = null;
                    }
                });
        endElementHandlers.put("searchRetrieveResponse/records/record/recordData/VIAFCluster/nameType",
                new EndElementHandler() {
                    public void handle(VIAFParser parser, String uri, String localName, String qName) {
// Path: src/main/java/com/codefork/refine/NameType.java
// public enum NameType {
//     Person("/people/person", "Person", "Personal", "local.personalNames all \"%s\""),
//     Organization("/organization/organization", "Corporate Name", "Corporate", "local.corporateNames all \"%s\""),
//     Location("/location/location", "Geographic Name", "Geographic", "local.geographicNames all \"%s\""),
//     // can't find better freebase ids for these two
//     Book("/book/book", "Work", "UniformTitleWork", "local.uniformTitleWorks all \"%s\""),
//     Edition("/book/book edition", "Expression", "UniformTitleExpression", "local.uniformTitleExpressions all \"%s\"");
// 
//     // ids are from freebase identifier ns
//     private final String id;
//     private final String displayName;
//     private final String viafCode;
//     private final String cqlString;
// 
//     NameType(String id, String displayName, String viafCode, String cqlString) {
//        this.id = id;
//        this.displayName = displayName;
//        this.viafCode = viafCode;
//        this.cqlString = cqlString;
//     }
// 
//     public String getId() {
//         return id;
//     }
// 
//     public String getDisplayName() {
//         return displayName;
//     }
// 
//     public String getViafCode() {
//         return viafCode;
//     }
// 
//     public String getCqlString() {
//         return cqlString;
//     }
// 
//     public VIAFNameType asVIAFNameType() {
//         return new VIAFNameType(getId(), getDisplayName());
//     }
// 
//     public static NameType getByViafCode(String viafCodeArg) {
//         for(NameType nameType: NameType.values()) {
//             if(nameType.viafCode.equals(viafCodeArg)) {
//                 return nameType;
//             }
//         }
//         return null;
//     }
// 
//     public static NameType getById(String idArg) {
//         for(NameType nameType: NameType.values()) {
//             if(nameType.id.equals(idArg)) {
//                 return nameType;
//             }
//         }
//         return null;
//     }
// 
// }


// Path: src/main/java/com/codefork/refine/viaf/VIAFParser.java
import com.codefork.refine.NameType;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;


        StartElementHandler captureHandler = new StartElementHandler() {
            public void handle(VIAFParser parser, String uri, String localName, String qName, Attributes attributes) {
                parser.captureChars = true;
            }
        };

        startElementHandlers.put("searchRetrieveResponse/records/record/recordData/VIAFCluster/nameType",
                captureHandler);
        startElementHandlers.put("searchRetrieveResponse/records/record/recordData/VIAFCluster/viafID",
                captureHandler);
        startElementHandlers.put("searchRetrieveResponse/records/record/recordData/VIAFCluster/mainHeadings/data/text",
                captureHandler);
        startElementHandlers.put("searchRetrieveResponse/records/record/recordData/VIAFCluster/mainHeadings/data/sources/s",
                captureHandler);
        startElementHandlers.put("searchRetrieveResponse/records/record/recordData/VIAFCluster/mainHeadings/data/sources/sid",
                captureHandler);

        endElementHandlers.put("searchRetrieveResponse/records/record",
                new EndElementHandler() {
                    public void handle(VIAFParser parser, String uri, String localName, String qName) {
                        parser.associateSourceIds();

                        parser.results.add(parser.result);
                        parser.result = null;
                    }
                });
        endElementHandlers.put("searchRetrieveResponse/records/record/recordData/VIAFCluster/nameType",
                new EndElementHandler() {
                    public void handle(VIAFParser parser, String uri, String localName, String qName) {
                        parser.result.setNameType(NameType.getByViafCode(parser.buf.toString())) ;