001: package com.icesoft.faces.facelets;
002:
003: import com.sun.facelets.tag.TagLibrary;
004: import com.sun.facelets.tag.TagHandler;
005: import com.sun.facelets.tag.TagConfig;
006: import com.sun.facelets.tag.Tag;
007: import com.sun.facelets.tag.jsf.ComponentConfig;
008: import com.sun.facelets.tag.jsf.ComponentHandler;
009: import com.sun.facelets.FaceletHandler;
010: import com.icesoft.faces.component.UIXhtmlComponent;
011:
012: import javax.faces.FacesException;
013: import java.lang.reflect.Method;
014:
015: /**
016: * @author Mark Collette
017: * @since 1.6
018: */
019: public class UIXhtmlTagLibrary implements TagLibrary {
020: static final String NAMESPACE = "http://www.icesoft.com/icefaces/html/internal";
021: private static final String[] MATCHING_NAMESPACES = new String[] {
022: NAMESPACE, "http://www.w3.org/1999/xhtml", "" };
023:
024: public UIXhtmlTagLibrary() {
025: super ();
026: }
027:
028: /**
029: * @see TagLibrary#containsNamespace(String)
030: */
031: public boolean containsNamespace(String ns) {
032: boolean matches = false;
033: if (ns == null)
034: matches = true;
035: else {
036: for (int i = 0; i < MATCHING_NAMESPACES.length; i++) {
037: if (ns.equals(MATCHING_NAMESPACES[i])) {
038: matches = true;
039: break;
040: }
041: }
042: }
043: //System.out.println("UIXhtmlTagLibrary.containsNamespace() ns: " + ns + " ==> " + matches);
044: return matches;
045: }
046:
047: /**
048: * @see TagLibrary#containsTagHandler(String, String)
049: */
050: public boolean containsTagHandler(String ns, String localName) {
051: //System.out.println("UIXhtmlTagLibrary.containsTagHandler() ns: " + ns + " localName: " + localName);
052: return containsNamespace(ns);
053: }
054:
055: /**
056: * @see TagLibrary#createTagHandler(String, String, TagConfig)
057: */
058: public TagHandler createTagHandler(String ns, String localName,
059: TagConfig tagConfig) throws FacesException {
060: //System.out.println("UIXhtmlTagLibrary.createTagHandler() ns: " + ns + " localName: " + localName + " tagConfig: " + tagConfig);
061: ComponentConfig ccfg = new ComponentConfigWrapper(tagConfig,
062: UIXhtmlComponent.COMPONENT_FAMILY,
063: UIXhtmlComponent.RENDERER_TYPE);
064: return new UIXhtmlComponentHandler(ccfg);
065: }
066:
067: /**
068: * @see TagLibrary#containsFunction(String, String)
069: */
070: public boolean containsFunction(String ns, String name) {
071: return false;
072: }
073:
074: /**
075: * @see TagLibrary#createFunction(String, String)
076: */
077: public Method createFunction(String ns, String name) {
078: return null;
079: }
080:
081: private static class ComponentConfigWrapper implements
082: ComponentConfig {
083: private final TagConfig wrapped;
084: private final String componentType;
085: private final String rendererType;
086:
087: public ComponentConfigWrapper(TagConfig parent,
088: String componentType, String rendererType) {
089: this .wrapped = parent;
090: this .componentType = componentType;
091: this .rendererType = rendererType;
092: }
093:
094: public String getComponentType() {
095: return componentType;
096: }
097:
098: public String getRendererType() {
099: return rendererType;
100: }
101:
102: public FaceletHandler getNextHandler() {
103: return wrapped.getNextHandler();
104: }
105:
106: public Tag getTag() {
107: return wrapped.getTag();
108: }
109:
110: public String getTagId() {
111: return wrapped.getTagId();
112: }
113: }
114: }
|