001: /*
002: * $Id: BaseRenderer.java 55441 2004-10-24 16:14:10Z cziegeler $
003: */
004:
005: /*
006: * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
007: *
008: * Redistribution and use in source and binary forms, with or
009: * without modification, are permitted provided that the following
010: * conditions are met:
011: *
012: * - Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * - Redistribution in binary form must reproduce the above
016: * copyright notice, this list of conditions and the following
017: * disclaimer in the documentation and/or other materials
018: * provided with the distribution.
019: *
020: * Neither the name of Sun Microsystems, Inc. or the names of
021: * contributors may be used to endorse or promote products derived
022: * from this software without specific prior written permission.
023: *
024: * This software is provided "AS IS," without a warranty of any
025: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
026: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
027: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
028: * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
029: * DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR
030: * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR
031: * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
032: * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
033: * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
034: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
035: * THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
036: * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
037: *
038: * You acknowledge that this software is not designed, licensed or
039: * intended for use in the design, construction, operation or
040: * maintenance of any nuclear facility.
041: */
042:
043: package org.apache.cocoon.faces.samples.components.renderkit;
044:
045: import javax.faces.component.UIComponent;
046: import javax.faces.context.FacesContext;
047: import javax.faces.render.Renderer;
048:
049: import java.io.IOException;
050: import java.util.Iterator;
051:
052: /**
053: * <p>Convenient base class for <code>Renderer</code> implementations.</p>
054: */
055:
056: public abstract class BaseRenderer extends Renderer {
057:
058: public static final String BUNDLE_ATTR = "com.sun.faces.bundle";
059:
060: public String convertClientId(FacesContext context, String clientId) {
061: return clientId;
062: }
063:
064: /*
065: * NOTE: Commented out to remove JSTL dependency.
066: protected String getKeyAndLookupInBundle(FacesContext context,
067: UIComponent component,
068: String keyAttr)
069: throws MissingResourceException {
070: String key = null, bundleName = null;
071: ResourceBundle bundle = null;
072:
073: key = (String) component.getAttributes().get(keyAttr);
074: bundleName = (String) component.getAttributes().get(BUNDLE_ATTR);
075:
076: // if the bundleName is null for this component, it might have
077: // been set on the root component.
078: if (bundleName == null) {
079: UIComponent root = context.getViewRoot();
080:
081: bundleName = (String) root.getAttributes().get(BUNDLE_ATTR);
082: }
083: // verify our component has the proper attributes for key and bundle.
084: if (null == key || null == bundleName) {
085: throw new MissingResourceException("Can't load JSTL classes",
086: bundleName, key);
087: }
088:
089: // verify the required Class is loadable
090: // PENDING(edburns): Find a way to do this once per ServletContext.
091: if (null == Thread.currentThread().getContextClassLoader().
092: getResource("javax.servlet.jsp.jstl.fmt.LocalizationContext")) {
093: Object[] params = {
094: "javax.servlet.jsp.jstl.fmt.LocalizationContext"
095: };
096: throw new MissingResourceException("Can't load JSTL classes",
097: bundleName, key);
098: }
099:
100: // verify there is a ResourceBundle in scoped namescape.
101: javax.servlet.jsp.jstl.fmt.LocalizationContext locCtx = null;
102: if (null == (locCtx = (javax.servlet.jsp.jstl.fmt.LocalizationContext)
103: (Util.getValueBinding(bundleName)).getValue(context)) ||
104: null == (bundle = locCtx.getResourceBundle())) {
105: throw new MissingResourceException("Can't load ResourceBundle ",
106: bundleName, key);
107: }
108:
109: return bundle.getString(key);
110: }
111: */
112:
113: protected void encodeRecursive(FacesContext context,
114: UIComponent component) throws IOException {
115:
116: component.encodeBegin(context);
117: if (component.getRendersChildren()) {
118: component.encodeChildren(context);
119: } else {
120: Iterator kids = component.getChildren().iterator();
121: while (kids.hasNext()) {
122: UIComponent kid = (UIComponent) kids.next();
123: encodeRecursive(context, kid);
124: }
125: }
126: component.encodeEnd(context);
127:
128: }
129:
130: }
|