FileDocCategorySizeDatePackage
WebAppDisplayer.javaAPI DocExample5185Fri Feb 08 11:15:44 GMT 2002javajaxb

WebAppDisplayer

public class WebAppDisplayer extends Object

Fields Summary
private File
descriptor
The descriptor to read in
private File
outputFile
The output file to write to
private WebApp
webApp
The object tree read in
Constructors Summary
public WebAppDisplayer(File descriptor, File outputFile)

This takes in the descriptor to be processed.

param
descriptor the file for the web.xml to process
param
outputFile the file to write changes to.

        this.descriptor = descriptor;
        this.outputFile = outputFile;
    
Methods Summary
public voiddisplay(boolean validate)

This will display some basic information about the web.xml deployment descriptor.

param
validate whether or not to validate the descriptor when processing

        WebAppUnmarshaller.setErrorHandler(new CommandLineErrorHandler());
        System.out.print("\n\nProcessing ");
        if (validate) {
            System.out.print("and Validating");
        }
        System.out.println("...");
        webApp = WebAppUnmarshaller.unmarshal(descriptor, validate);
        System.out.println("\nProcessed Web XML...");
        
        // Display some information
        System.out.println("Application Display Name: " + webApp.getDisplayName());
        System.out.println("Application Display Name: " + webApp.getDescription());
        System.out.println("Number of servlets: " + 
            webApp.getServletList().size() + "\n");
        
        // List the servlets
        System.out.println("Listing servlets...");
        for (Iterator i = webApp.getServletList().iterator(); i.hasNext(); ) {
            Servlet servlet = (Servlet)i.next();
            System.out.println(" * Servlet name: " + servlet.getServletName());
            System.out.println(" * Servlet class: " + 
                servlet.getServletClass() + "\n");
        }
    
public static voidmain(java.lang.String[] args)

        try {
            if (args.length != 2) {
                System.out.println("Usage: java javajaxb.WebAppDisplayer " +
                    "[web.xml filename] [output.xml filename]");
                return;
            }
            
            WebAppDisplayer displayer = 
                new WebAppDisplayer(new File(args[0]), new File(args[1]));
            displayer.display(true);
            displayer.modify();
        } catch (Exception e) {
            e.printStackTrace();
        }
    
public voidmodify()

This will make some simple changes to the descriptor and write it back out to a new file.

        // Change the encoding
        webApp.setOutputEncoding("ISO-8859-1");
        
        // Change the DTD to a local version
        webApp.setDocType("web-app", null, "dtds/sun/web-app_2_2.dtd");
        
        // Modify the display name
        webApp.setDisplayName(webApp.getDisplayName() + 
            " [Modified by WebAppDisplayer]");
            
        // Add a new servlet
        Servlet servlet = new ServletImpl();
        servlet.setServletName("WelcomeServlet");
        servlet.setServletClass("javajaxb.servlet.WelcomeServlet");
        webApp.addServlet(servlet);
        
        // marshal
        webApp.marshal(outputFile);