View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.application;
21  
22  import org.apache.myfaces.tobago.util.MessageUtils;
23  
24  import javax.faces.application.FacesMessage;
25  import javax.faces.context.FacesContext;
26  import javax.faces.el.ValueBinding;
27  import javax.faces.webapp.UIComponentTag;
28  import java.util.Locale;
29  
30  /**
31   * @deprecated since 1.6.0. Please use LabelValueExpressionFacesMessage
32   */
33  @Deprecated
34  public class LabelValueBindingFacesMessage extends FacesMessage {
35    private Locale locale;
36    private Object[] args;
37  
38    public LabelValueBindingFacesMessage() {
39      super();
40    }
41  
42    public LabelValueBindingFacesMessage(FacesMessage.Severity severity, String summary, String detail,
43        Locale locale, Object... args) {
44      super(severity, summary, detail);
45      this.locale = locale;
46      this.args = args;
47    }
48  
49    public LabelValueBindingFacesMessage(String summary, String detail) {
50      super(summary, detail);
51    }
52  
53    public LabelValueBindingFacesMessage(String summary) {
54      super(summary);
55    }
56  
57    @Override
58    public String getDetail() {
59      String detail = super.getDetail();
60      if (args != null && args.length > 0) {
61        if (args.length == 1 && UIComponentTag.isValueReference(args[0].toString())) {
62          FacesContext facesContext = FacesContext.getCurrentInstance();
63          ValueBinding value = facesContext.getApplication().createValueBinding(detail);
64          return MessageUtils.getFormatedMessage(detail, locale, value.getValue(facesContext));
65        }
66        return MessageUtils.getFormatedMessage(detail, locale, args);
67      }
68      return detail;
69    }
70  
71    @Override
72    public String getSummary() {
73      String summary = super.getSummary();
74      if (args != null && args.length > 0) {
75        if (args.length == 1 && UIComponentTag.isValueReference(args[0].toString())) {
76          FacesContext facesContext = FacesContext.getCurrentInstance();
77          ValueBinding value = facesContext.getApplication().createValueBinding(summary);
78          return MessageUtils.getFormatedMessage(summary, locale, value.getValue(facesContext));
79        }
80        return MessageUtils.getFormatedMessage(summary, locale, args);
81      }
82      return summary;
83    }
84  
85  }