View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.shared_orchestra.test;
21  
22  import java.util.List;
23  import java.util.ArrayList;
24  
25  import org.xml.sax.Attributes;
26  import org.xml.sax.SAXException;
27  import org.xml.sax.helpers.DefaultHandler;
28  
29  /**
30   * @see AbstractClassElementTestCase
31   * @author Dennis Byrne
32   */
33  
34  public class ClassElementHandler extends DefaultHandler
35  {
36      
37      private boolean clazz ;
38      private List elementName = new ArrayList();
39      private List className = new ArrayList();
40      private StringBuffer buffer ;
41      
42      public ClassElementHandler(){
43          
44          elementName.add("component-class");
45          elementName.add("tag-class");
46          elementName.add("renderer-class");
47          elementName.add("validator-class");
48          elementName.add("converter-class");
49          elementName.add("action-listener");
50          elementName.add("navigation-handler");
51          elementName.add("variable-resolver");
52          elementName.add("property-resolver");
53          elementName.add("phase-listener");
54          
55      }
56  
57      public void characters(char[] ch, int start, int length)
58      throws SAXException
59      {
60          if (clazz)
61          {
62              String string = new String(ch, start, length);
63              if(string != null)
64              {
65                  buffer.append(string.trim());
66              }
67          }
68      }
69      
70      public void startElement(
71              String ns, String local, String qName, Attributes atts) 
72              throws SAXException
73      {
74         
75           clazz = elementName.contains(qName);
76           
77           if(clazz)
78               buffer = new StringBuffer();
79          
80      }
81  
82      public void endElement(String ns, String local, String qName) 
83          throws SAXException
84      {
85          
86          if(clazz){
87              className.add(buffer.toString());
88              clazz = false;
89          }
90          
91      }
92  
93      public List getClassName()
94      {
95          return className;
96      }
97      
98  }