KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > faces > webapp > parser > JsfJspDigester


1 /*
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * "The contents of this file are subject to the Mozilla Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
11  * License for the specific language governing rights and limitations under
12  * the License.
13  *
14  * The Original Code is ICEfaces 1.5 open source software code, released
15  * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
16  * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
17  * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
18  *
19  * Contributor(s): _____________________.
20  *
21  * Alternatively, the contents of this file may be used under the terms of
22  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
23  * License), in which case the provisions of the LGPL License are
24  * applicable instead of those above. If you wish to allow use of your
25  * version of this file only under the terms of the LGPL License and not to
26  * allow others to use your version of this file under the MPL, indicate
27  * your decision by deleting the provisions above and replace them with
28  * the notice and other provisions required by the LGPL License. If you do
29  * not delete the provisions above, a recipient may use your version of
30  * this file under either the MPL or the LGPL License."
31  *
32  */

33
34 package com.icesoft.faces.webapp.parser;
35
36 import org.apache.commons.digester.Digester;
37
38 import javax.faces.context.ExternalContext;
39 import javax.faces.context.FacesContext;
40 import java.io.IOException JavaDoc;
41 import java.io.InputStream JavaDoc;
42 import java.util.Vector JavaDoc;
43
44 /**
45  * A customized Digester that gives us access to the body text of the containing
46  * tags.
47  *
48  * @author Steve Maryka
49  */

50 public class JsfJspDigester extends Digester {
51
52     Vector JavaDoc loadedNamespaces;
53     String JavaDoc viewTagClassName;
54
55     /**
56      * Constructor.
57      */

58     public JsfJspDigester() {
59         super();
60         loadedNamespaces = new Vector JavaDoc();
61         // the html and core namespaces are dynamically loaded now.
62
// loadedNamespaces.add("http://java.sun.com/jsf/html");
63
// loadedNamespaces.add("http://java.sun.com/jsf/core");
64
}
65
66     /**
67      * This member gets the previous body text and returns it. It also clears
68      * out that body text from the parent.
69      *
70      * @return The parent's body text.
71      */

72     public String JavaDoc stealParentBodyText() {
73
74         StringBuffer JavaDoc parentBodyText = (StringBuffer JavaDoc) bodyTexts.peek();
75         if (parentBodyText == null || parentBodyText.length() == 0) {
76             return null;
77         }
78
79         String JavaDoc returnString = new String JavaDoc(parentBodyText.toString());
80         if (returnString.trim().length() == 0) {
81             // Don't want to create whitespace only components;
82
returnString = null;
83         }
84
85         // Get rid of body text that we just processed;
86
parentBodyText.delete(0, parentBodyText.length());
87
88         return returnString;
89     }
90
91     public void startPrefixMapping(String JavaDoc prefix, String JavaDoc namespaceURI) {
92         ExternalContext context = FacesContext
93                 .getCurrentInstance().getExternalContext();
94         if (loadedNamespaces.contains(namespaceURI)) {
95             return;
96         }
97         try {
98             TagToComponentMap tagMap = new TagToComponentMap();
99             InputStream JavaDoc tldStream = JspPageToDocument.getTldInputStream(
100                     context, namespaceURI);
101             if (null == tldStream) {
102                 if (log.isDebugEnabled()) {
103                     log.debug("tldStream null");
104                 }
105                 return;
106             }
107             tagMap.addTags(tldStream);
108             ComponentRuleSet rules = new ComponentRuleSet(tagMap, namespaceURI);
109             rules.addRuleInstances(this);
110             loadedNamespaces.add(namespaceURI);
111
112             if (log.isDebugEnabled()) {
113                 log.debug(
114                         "JsfJspDigester loaded " + prefix + ":" + namespaceURI);
115             }
116         } catch (IOException JavaDoc e) {
117             if (log.isDebugEnabled()) {
118                 log.debug(e.getMessage(), e);
119             }
120         }
121     }
122
123
124     public void setViewTagClassName(String JavaDoc className) {
125         viewTagClassName = className;
126     }
127
128     public String JavaDoc getViewTagClassName() {
129         return viewTagClassName;
130     }
131
132 }
133
Popular Tags