KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > webapp > filter > WelcomeFileHandler


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.myfaces.webapp.filter;
17
18 import org.xml.sax.Attributes JavaDoc;
19 import org.xml.sax.SAXException JavaDoc;
20 import org.xml.sax.helpers.DefaultHandler JavaDoc;
21
22 import java.util.Vector JavaDoc;
23
24
25 /**
26  * DOCUMENT ME!
27  *
28  * @author Robert J. Lebowitz (latest modification by $Author: matze $)
29  * @version $Revision: 1.6 $ $Date: 2004/10/13 11:51:01 $
30  */

31 public class WelcomeFileHandler
32 extends DefaultHandler JavaDoc
33 {
34     //~ Instance fields --------------------------------------------------------
35

36     private StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
37     private Vector JavaDoc welcomeFiles;
38     private String JavaDoc[] files;
39     private boolean fileFlag = false;
40
41     //~ Constructors -----------------------------------------------------------
42

43     /**
44      * Creates a new WelcomeFileHandler object.
45      */

46     public WelcomeFileHandler()
47     {
48         super();
49     }
50
51     //~ Methods ----------------------------------------------------------------
52

53     /**
54      * Accessor method used to get the array of welcome files.
55      * @return The string array of welcome files.
56      *
57      */

58     public String JavaDoc[] getWelcomeFiles()
59     {
60         return files;
61     }
62
63     /**
64      *
65      * Method used to examine, modify or extract text in body of an element
66      * @param ch character array containing the tag's body information.
67      * @param start starting index of the body text in the character array.
68      * @param length length of the text found in the body.
69      * @throws SAXException
70      *
71      */

72     public void characters(char[] ch, int start, int length)
73     throws SAXException JavaDoc
74     {
75         if (fileFlag)
76         {
77             sb.append(ch, start, length);
78         }
79
80         super.characters(ch, start, length);
81     }
82
83     /**
84      * Method called with each end element in an XML Document
85      * @param ns The namespace associated with this element
86      * @param local The local name of this element
87      * @param qName The qualified name of this element
88      * @throws SAXException
89      *
90      */

91     public void endElement(String JavaDoc ns, String JavaDoc local, String JavaDoc qName)
92     throws SAXException JavaDoc
93     {
94         if (qName.equals("welcome-file-list"))
95         {
96             files = new String JavaDoc[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     /**
112      *
113      * Method called with each start element in an XML document
114      * @param ns The namespace associated with this element
115      * @param local The local name of this element
116      * @param qName The qualified name of this element
117      * @param atts Attributes associated with this element
118      * @throws SAXException
119      *
120      */

121     public void startElement(
122         String JavaDoc ns, String JavaDoc local, String JavaDoc qName, Attributes JavaDoc atts)
123     throws SAXException JavaDoc
124     {
125         if (qName.equals("welcome-file-list"))
126         {
127             welcomeFiles = new Vector JavaDoc();
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