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 static org.apache.myfaces.tobago.TobagoConstants.ATTR_CONFIRMATION; 023 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_FOR; 024 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_GLOBAL_ONLY; 025 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_MAX_NUMBER; 026 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_MAX_SEVERITY; 027 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_MIN_SEVERITY; 028 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ORDER_BY; 029 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_DETAIL; 030 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_SUMMARY; 031 import org.apache.myfaces.tobago.component.ComponentUtil; 032 import org.apache.myfaces.tobago.component.UIMessages; 033 034 import javax.faces.application.FacesMessage; 035 import javax.faces.component.UIComponent; 036 import javax.faces.webapp.UIComponentTag; 037 038 039 public class MessagesTag extends TobagoTag 040 implements MessagesTagDeclaration { 041 042 private String forComponent; 043 private String showSummary; 044 private String showDetail; 045 private String globalOnly; 046 private String minSeverity; 047 private String maxSeverity; 048 private String maxNumber; 049 private String orderBy; 050 private String confirmation; 051 052 public String getComponentType() { 053 return UIMessages.COMPONENT_TYPE; 054 } 055 056 protected void setProperties(UIComponent component) { 057 super.setProperties(component); 058 ComponentUtil.setStringProperty(component, ATTR_FOR, forComponent); 059 ComponentUtil.setBooleanProperty(component, ATTR_GLOBAL_ONLY, globalOnly); 060 ComponentUtil.setBooleanProperty(component, ATTR_SHOW_SUMMARY, showSummary); 061 ComponentUtil.setBooleanProperty(component, ATTR_SHOW_DETAIL, showDetail); 062 setSeverityProperty(component, ATTR_MIN_SEVERITY, minSeverity); 063 setSeverityProperty(component, ATTR_MAX_SEVERITY, maxSeverity); 064 ComponentUtil.setIntegerProperty(component, ATTR_MAX_NUMBER, maxNumber); 065 setOrderByProperty(component, ATTR_ORDER_BY, orderBy); 066 ComponentUtil.setBooleanProperty(component, ATTR_CONFIRMATION, confirmation); 067 } 068 069 private void setSeverityProperty(UIComponent component, String name, String value) { 070 if (value != null) { 071 if (UIComponentTag.isValueReference(value)) { 072 component.setValueBinding(name, ComponentUtil.createValueBinding(value)); 073 } else { 074 component.getAttributes().put(name, FacesMessage.VALUES_MAP.get(value)); 075 } 076 } 077 } 078 079 private void setOrderByProperty(UIComponent component, String name, String value) { 080 if (value != null) { 081 if (UIComponentTag.isValueReference(value)) { 082 component.setValueBinding(name, ComponentUtil.createValueBinding(value)); 083 } else { 084 component.getAttributes().put(name, UIMessages.OrderBy.parse(value)); 085 } 086 } 087 } 088 089 public void release() { 090 super.release(); 091 forComponent = null; 092 showSummary = null; 093 showDetail = null; 094 minSeverity = null; 095 maxSeverity = null; 096 maxNumber = null; 097 orderBy = null; 098 } 099 100 public String getFor() { 101 return forComponent; 102 } 103 104 public void setFor(String forComponent) { 105 this.forComponent = forComponent; 106 } 107 108 public void setGlobalOnly(String globalOnly) { 109 this.globalOnly = globalOnly; 110 } 111 112 public void setShowSummary(String showSummary) { 113 this.showSummary = showSummary; 114 } 115 116 public void setShowDetail(String showDetail) { 117 this.showDetail = showDetail; 118 } 119 120 public void setMinSeverity(String minSeverity) { 121 this.minSeverity = minSeverity; 122 } 123 124 public void setMaxSeverity(String maxSeverity) { 125 this.maxSeverity = maxSeverity; 126 } 127 128 public void setMaxNumber(String maxNumber) { 129 this.maxNumber = maxNumber; 130 } 131 132 public void setOrderBy(String orderBy) { 133 this.orderBy = orderBy; 134 } 135 136 public void setConfirmation(String confirmation) { 137 this.confirmation = confirmation; 138 } 139 }