001: /*
002: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
003: *
004: * "The contents of this file are subject to the Mozilla Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License at
007: * http://www.mozilla.org/MPL/
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
011: * License for the specific language governing rights and limitations under
012: * the License.
013: *
014: * The Original Code is ICEfaces 1.5 open source software code, released
015: * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
016: * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
017: * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
018: *
019: * Contributor(s): _____________________.
020: *
021: * Alternatively, the contents of this file may be used under the terms of
022: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
023: * License), in which case the provisions of the LGPL License are
024: * applicable instead of those above. If you wish to allow use of your
025: * version of this file only under the terms of the LGPL License and not to
026: * allow others to use your version of this file under the MPL, indicate
027: * your decision by deleting the provisions above and replace them with
028: * the notice and other provisions required by the LGPL License. If you do
029: * not delete the provisions above, a recipient may use your version of
030: * this file under either the MPL or the LGPL License."
031: *
032: */
033:
034: package com.icesoft.faces.webapp.parser;
035:
036: import org.apache.commons.digester.Digester;
037:
038: import javax.faces.context.ExternalContext;
039: import javax.faces.context.FacesContext;
040: import java.io.IOException;
041: import java.io.InputStream;
042: import java.util.Vector;
043:
044: /**
045: * A customized Digester that gives us access to the body text of the containing
046: * tags.
047: *
048: * @author Steve Maryka
049: */
050: public class JsfJspDigester extends Digester {
051:
052: Vector loadedNamespaces;
053: String viewTagClassName;
054:
055: /**
056: * Constructor.
057: */
058: public JsfJspDigester() {
059: super ();
060: loadedNamespaces = new Vector();
061: // the html and core namespaces are dynamically loaded now.
062: // loadedNamespaces.add("http://java.sun.com/jsf/html");
063: // loadedNamespaces.add("http://java.sun.com/jsf/core");
064: }
065:
066: /**
067: * This member gets the previous body text and returns it. It also clears
068: * out that body text from the parent.
069: *
070: * @return The parent's body text.
071: */
072: public String stealParentBodyText() {
073:
074: StringBuffer parentBodyText = (StringBuffer) bodyTexts.peek();
075: if (parentBodyText == null || parentBodyText.length() == 0) {
076: return null;
077: }
078:
079: String returnString = new String(parentBodyText.toString());
080: if (returnString.trim().length() == 0) {
081: // Don't want to create whitespace only components;
082: returnString = null;
083: }
084:
085: // Get rid of body text that we just processed;
086: parentBodyText.delete(0, parentBodyText.length());
087:
088: return returnString;
089: }
090:
091: public void startPrefixMapping(String prefix, String namespaceURI) {
092: ExternalContext context = FacesContext.getCurrentInstance()
093: .getExternalContext();
094: if (loadedNamespaces.contains(namespaceURI)) {
095: return;
096: }
097: try {
098: TagToComponentMap tagMap = new TagToComponentMap();
099: InputStream tldStream = JspPageToDocument
100: .getTldInputStream(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,
109: namespaceURI);
110: rules.addRuleInstances(this );
111: loadedNamespaces.add(namespaceURI);
112:
113: if (log.isDebugEnabled()) {
114: log.debug("JsfJspDigester loaded " + prefix + ":"
115: + namespaceURI);
116: }
117: } catch (IOException e) {
118: if (log.isDebugEnabled()) {
119: log.debug(e.getMessage(), e);
120: }
121: }
122: }
123:
124: public void setViewTagClassName(String className) {
125: viewTagClassName = className;
126: }
127:
128: public String getViewTagClassName() {
129: return viewTagClassName;
130: }
131:
132: }
|