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