001 package org.apache.myfaces.tobago.taglib.component; 002 003 /* 004 * Licensed to the Apache Software Foundation (ASF) under one or more 005 * contributor license agreements. See the NOTICE file distributed with 006 * this work for additional information regarding copyright ownership. 007 * The ASF licenses this file to You under the Apache License, Version 2.0 008 * (the "License"); you may not use this file except in compliance with 009 * the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019 020 import org.apache.commons.logging.Log; 021 import org.apache.commons.logging.LogFactory; 022 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DISABLED; 023 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_HEIGHT; 024 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_HIDDEN; 025 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_INLINE; 026 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LABEL; 027 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_READONLY; 028 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_TITLE; 029 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_WIDTH; 030 import static org.apache.myfaces.tobago.TobagoConstants.TOBAGO_COMPONENT_CREATED; 031 import org.apache.myfaces.tobago.component.ComponentUtil; 032 import org.apache.myfaces.tobago.component.OnComponentCreated; 033 034 import javax.faces.component.UIComponent; 035 import javax.faces.webapp.UIComponentTag; 036 import javax.servlet.jsp.JspException; 037 038 public abstract class TobagoTag extends UIComponentTag 039 implements TobagoTagDeclaration { 040 041 private static final Log LOG = LogFactory.getLog(TobagoTag.class); 042 043 private String label; 044 private String title; 045 private String width; 046 private String height; 047 private String hidden; 048 private String readonly; 049 private String disabled; 050 private String inline; 051 052 @Override 053 public int doStartTag() throws JspException { 054 if (LOG.isDebugEnabled()) { 055 LOG.debug("doStartTag() rendererType " + getRendererType()); 056 LOG.debug("doStartTag() componentType " + getComponentType()); 057 } 058 return super.doStartTag(); 059 } 060 061 @Override 062 public String getRendererType() { 063 String name = getClass().getName(); 064 int beginIndex = name.lastIndexOf('.'); 065 if (beginIndex < 0) { 066 beginIndex = 0; 067 } else { 068 beginIndex++; 069 } 070 int endIndex = name.length() - 3; // 3 = "Tag".length() 071 return name.substring(beginIndex, endIndex); 072 } 073 074 @Override 075 public void release() { 076 super.release(); 077 hidden = null; 078 readonly = null; 079 disabled = null; 080 inline = null; 081 label = null; 082 title = null; 083 width = null; 084 height = null; 085 } 086 087 @Override 088 protected void setProperties(UIComponent component) { 089 super.setProperties(component); 090 091 ComponentUtil.setStringProperty(component, ATTR_LABEL, label); 092 ComponentUtil.setStringProperty(component, ATTR_TITLE, title); 093 094 ComponentUtil.setBooleanProperty(component, ATTR_DISABLED, disabled); 095 ComponentUtil.setBooleanProperty(component, ATTR_READONLY, readonly); 096 ComponentUtil.setBooleanProperty(component, ATTR_HIDDEN, hidden); 097 ComponentUtil.setBooleanProperty(component, ATTR_INLINE, inline); 098 099 if (width != null) { 100 LOG.warn("the width attribute is deprecated, please use a layout manager. (" + getClass().getSimpleName() + ")"); 101 } 102 ComponentUtil.setStringProperty(component, ATTR_WIDTH, width); 103 if (height != null) { 104 LOG.warn("the height attribute is deprecated, please use a layout manager. (" + getClass().getSimpleName() + ")"); 105 } 106 ComponentUtil.setStringProperty(component, ATTR_HEIGHT, height); 107 } 108 109 public String getDisabled() { 110 return disabled; 111 } 112 113 public void setDisabled(String disabled) { 114 this.disabled = disabled; 115 } 116 117 public String getHeight() { 118 return height; 119 } 120 121 public void setHeight(String height) { 122 this.height = height; 123 } 124 125 public String getHidden() { 126 return hidden; 127 } 128 129 public void setHidden(String hidden) { 130 this.hidden = hidden; 131 } 132 133 public String getInline() { 134 return inline; 135 } 136 137 public void setInline(String inline) { 138 this.inline = inline; 139 } 140 141 public String getLabel() { 142 return label; 143 } 144 145 public void setLabel(String label) { 146 this.label = label; 147 } 148 149 public String getReadonly() { 150 return readonly; 151 } 152 153 public void setReadonly(String readonly) { 154 this.readonly = readonly; 155 } 156 157 public String getTitle() { 158 return title; 159 } 160 161 public void setTitle(String title) { 162 this.title = title; 163 } 164 165 public String getWidth() { 166 return width; 167 } 168 169 public void setWidth(String width) { 170 this.width = width; 171 } 172 173 public int doEndTag() throws JspException { 174 175 UIComponent component = getComponentInstance(); 176 if (component instanceof OnComponentCreated 177 && component.getAttributes().get(TOBAGO_COMPONENT_CREATED) == null) { 178 component.getAttributes().put(TOBAGO_COMPONENT_CREATED, Boolean.TRUE); 179 ((OnComponentCreated) component).onComponentCreated(); 180 } 181 return super.doEndTag(); 182 } 183 }