1 16 package org.apache.myfaces.webapp.filter; 17 18 import org.xml.sax.Attributes ; 19 import org.xml.sax.SAXException ; 20 import org.xml.sax.helpers.DefaultHandler ; 21 22 import java.util.Vector ; 23 24 25 31 public class WelcomeFileHandler 32 extends DefaultHandler 33 { 34 36 private StringBuffer sb = new StringBuffer (); 37 private Vector welcomeFiles; 38 private String [] files; 39 private boolean fileFlag = false; 40 41 43 46 public WelcomeFileHandler() 47 { 48 super(); 49 } 50 51 53 58 public String [] getWelcomeFiles() 59 { 60 return files; 61 } 62 63 72 public void characters(char[] ch, int start, int length) 73 throws SAXException 74 { 75 if (fileFlag) 76 { 77 sb.append(ch, start, length); 78 } 79 80 super.characters(ch, start, length); 81 } 82 83 91 public void endElement(String ns, String local, String qName) 92 throws SAXException 93 { 94 if (qName.equals("welcome-file-list")) 95 { 96 files = new String [welcomeFiles.size()]; 97 welcomeFiles.toArray(files); 98 welcomeFiles = null; 99 } 100 101 if (qName.equals("welcome-file")) 102 { 103 welcomeFiles.add(sb.toString()); 104 sb.setLength(0); 105 fileFlag = false; 106 } 107 108 super.endElement(ns, local, qName); 109 } 110 111 121 public void startElement( 122 String ns, String local, String qName, Attributes atts) 123 throws SAXException 124 { 125 if (qName.equals("welcome-file-list")) 126 { 127 welcomeFiles = new Vector (); 128 } 129 130 if (qName.equals("welcome-file")) 131 { 132 sb.setLength(0); 133 fileFlag = true; 134 } 135 136 super.startElement(ns, local, qName, atts); 137 } 138 } 139 | Popular Tags |