FileDocCategorySizeDatePackage
MakeCatalog.javaAPI DocGlassfish v2 API6301Fri May 04 22:25:42 BST 2007None

MakeCatalog

public class MakeCatalog extends DefaultHandler

Fields Summary
final String
prefix
private static final String
NAMESPACES
private static final String
PREFIXES
private static final File
SCHEMA
Properties
properties
private String
key
private StringBuffer
sb
Constructors Summary
MakeCatalog()

        prefix = "";
    
MakeCatalog(String prefix)

        this.prefix = (prefix != null ? prefix +"." : "");
    
Methods Summary
public voidcharacters(char[] ch, int start, int length)

        if (null != sb) {
            sb.append(ch, start, length);
        }
    
public voidendElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)

        if (localName.equals("messages")){ // do nothing
        } else if (localName.equals("message")) {
            endMessage();
        } else {
            throw new SAXException("Unknown element: "+uri+":"+localName);
        }
    
private voidendMessage()

        if (null != sb){
            properties.setProperty(key, sb.toString().trim());
        }
        sb = null;
    
java.util.PropertiesgetProperties()

        return properties;
    
public static voidmain(java.lang.String[] args)

        if (args.length < 2 || 3 < args.length ){
            useage();
            System.exit(1);
        }

        final String prefix = (args.length == 2 ? null : args[0]);
        final String in = (args.length == 2 ? args[0] : args[1]);
        final String out = (args.length == 2 ? args[1] : args[2]);
        
        final MakeCatalog mc = new MakeCatalog(prefix);
        final InputSource is = new InputSource(new FileReader(new File(in)));
        is.setSystemId(in);
        mc.makeCatalog(is);
        mc.getProperties().save(new FileOutputStream(new File(out)), null);
        System.exit(0);
    
voidmakeCatalog(org.xml.sax.InputSource is)

        
            
//         final SAXParserFactory spf = SAXParserFactory.newInstance();
        final SAXParserFactory spf = new com.sun.msv.verifier.jaxp.SAXParserFactoryImpl();

        spf.setNamespaceAware(true);
        spf.setValidating(false);
        spf.setFeature(NAMESPACES, true);
        spf.setFeature(PREFIXES, false);

        final SAXParser p = spf.newSAXParser();
        p.setProperty("http://www.sun.com/xml/msv/schema", SCHEMA);        
//         spf.newSAXParser().parse(is, this);
        p.parse(is, this);
    
public voidstartDocument()

        properties = new Properties();
    
public voidstartElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes)

        if (null == localName){
            throw new SAXException("localName is null");
        }
        
        if (localName.equals("messages")){ // do nothing
        } else if (localName.equals("message")) {
            startMessage(attributes);
        } else {
            throw new SAXException("Unknown element: "+uri+":"+localName);
        }
    
private voidstartMessage(org.xml.sax.Attributes attributes)

        key = (prefix != null ? prefix : "") + attributes.getValue("", "id");
        if (null == key){
            throw new SAXException("message element had no id attribute");
        }
        sb = new StringBuffer();
    
private static voiduseage()

        System.err.println("Useage: MakeCatalog [prefix] in out");