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