[jdom-interest] RE: Please Help me ASAP with JDOM to SAX

Smith, Jonathan jsmith4 at PaineWebber.com
Thu Jul 20 11:19:55 PDT 2000


> Do to memory issues I have to write a program like this in SAX.
> 
> Can help out help me I have to get this done today and I dont know sax
> 
> import java.io.*;
> import java.util.*;
> import org.jdom.*;
> import org.jdom.input.*;
> import org.jdom.output.*;
> 
> public class WarReader {
> 
> public static void main(String[] args) {
> 
> PrintStream out = System.out;
> 
> if (args.length != 1 && args.length != 2) {
> out.println("Usage: WarReader [web.xml]");
> return;
> }
> 
> try {
> // Request document building without validation
> SAXBuilder builder = new SAXBuilder(false);
> Document doc = builder.build(new File(args[0]));
> 
> // Get the root element
> Element root = doc.getRootElement();
> 
> // Print servlet information
> List servlets = root.getChildren("servlet");
> out.println("This WAR has "+ servlets.size() +" registered servlets:");
> Iterator i = servlets.iterator();
> while (i.hasNext()) {
> Element servlet = (Element) i.next();
> out.print("\t" + servlet.getChild("servlet-name")
> .getContent() +
> " for " + servlet.getChild("servlet-class")
> .getContent());
> List initParams = servlet.getChildren("init-param");
> out.println(" (it has " + initParams.size() + " init params)");
> }
> 
> // Print security role information
> List securityRoles = root.getChildren("security-role");
> if (securityRoles.size() == 0) {
> out.println("This WAR contains no roles");
> }
> else {
> Element securityRole = (Element) securityRoles.get(0);
> List roleNames = securityRole.getChildren("role-name");
> out.println("This WAR contains " + roleNames.size() + " roles:");
> i = roleNames.iterator();
> while (i.hasNext()) {
> Element e = (Element) i.next();
> out.println("\t" + e.getContent());
> }
> }
> 
> // Print distributed information (notice this is out of order)
> List distrib = root.getChildren("distributed");
> if (distrib.size() == 0) {
> out.println("This WAR is not distributed");
> } else {
> out.println("This WAR is distributed");
> }
> 
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> }
> 



More information about the jdom-interest mailing list