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