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 import org.apache.myfaces.tobago.util.Deprecation; 034 035 import javax.faces.component.UIComponent; 036 import javax.faces.webapp.UIComponentTag; 037 import javax.servlet.jsp.JspException; 038 039 public abstract class TobagoTag extends UIComponentTag 040 implements TobagoTagDeclaration { 041 042 private static final Log LOG = LogFactory.getLog(TobagoTag.class); 043 044 private String label; 045 private String title; 046 private String width; 047 private String height; 048 private String hidden; 049 private String readonly; 050 private String disabled; 051 private String inline; 052 053 @Override 054 public int doStartTag() throws JspException { 055 if (LOG.isDebugEnabled()) { 056 LOG.debug("doStartTag() rendererType " + getRendererType()); 057 LOG.debug("doStartTag() componentType " + getComponentType()); 058 } 059 return super.doStartTag(); 060 } 061 062 @Override 063 public String getRendererType() { 064 String name = getClass().getName(); 065 int beginIndex = name.lastIndexOf('.'); 066 if (beginIndex < 0) { 067 beginIndex = 0; 068 } else { 069 beginIndex++; 070 } 071 int endIndex = name.length() - 3; // 3 = "Tag".length() 072 return name.substring(beginIndex, endIndex); 073 } 074 075 @Override 076 public void release() { 077 super.release(); 078 hidden = null; 079 readonly = null; 080 disabled = null; 081 inline = null; 082 label = null; 083 title = null; 084 width = null; 085 height = null; 086 } 087 088 @Override 089 protected void setProperties(UIComponent component) { 090 super.setProperties(component); 091 092 ComponentUtil.setStringProperty(component, ATTR_LABEL, label); 093 ComponentUtil.setStringProperty(component, ATTR_TITLE, title); 094 095 ComponentUtil.setBooleanProperty(component, ATTR_DISABLED, disabled); 096 ComponentUtil.setBooleanProperty(component, ATTR_READONLY, readonly); 097 ComponentUtil.setBooleanProperty(component, ATTR_HIDDEN, hidden); 098 ComponentUtil.setBooleanProperty(component, ATTR_INLINE, inline); 099 100 if (width != null) { 101 LOG.warn("the width attribute is deprecated, please use a layout manager. (" + getClass().getSimpleName() + ")"); 102 } 103 ComponentUtil.setStringProperty(component, ATTR_WIDTH, width); 104 if (height != null) { 105 LOG.warn("the height attribute is deprecated, please use a layout manager. (" + getClass().getSimpleName() + ")"); 106 } 107 ComponentUtil.setStringProperty(component, ATTR_HEIGHT, height); 108 } 109 110 public String getDisabled() { 111 return disabled; 112 } 113 114 public void setDisabled(String disabled) { 115 this.disabled = disabled; 116 } 117 118 public String getHeight() { 119 return height; 120 } 121 122 public void setHeight(String height) { 123 if (Deprecation.LOG.isWarnEnabled()) { 124 Deprecation.LOG.warn("Attribute 'height' is deprecated, " 125 + "and will removed soon! Please use a layout manager instead."); 126 } 127 this.height = height; 128 } 129 130 public String getHidden() { 131 return hidden; 132 } 133 134 public void setHidden(String hidden) { 135 this.hidden = hidden; 136 } 137 138 public String getInline() { 139 return inline; 140 } 141 142 public void setInline(String inline) { 143 this.inline = inline; 144 } 145 146 public String getLabel() { 147 return label; 148 } 149 150 public void setLabel(String label) { 151 this.label = label; 152 } 153 154 public String getReadonly() { 155 return readonly; 156 } 157 158 public void setReadonly(String readonly) { 159 this.readonly = readonly; 160 } 161 162 public String getTitle() { 163 return title; 164 } 165 166 public void setTitle(String title) { 167 this.title = title; 168 } 169 170 public String getWidth() { 171 return width; 172 } 173 174 public void setWidth(String width) { 175 if (Deprecation.LOG.isWarnEnabled()) { 176 Deprecation.LOG.warn("Attribute 'width' is deprecated, " 177 + "and will removed soon! Please use a layout manager instead."); 178 } 179 this.width = width; 180 } 181 182 public int doEndTag() throws JspException { 183 184 UIComponent component = getComponentInstance(); 185 if (component instanceof OnComponentCreated 186 && component.getAttributes().get(TOBAGO_COMPONENT_CREATED) == null) { 187 component.getAttributes().put(TOBAGO_COMPONENT_CREATED, Boolean.TRUE); 188 ((OnComponentCreated) component).onComponentCreated(); 189 } 190 return super.doEndTag(); 191 } 192 }