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 2.0.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(
43        final Severity severity, final String summary, final String detail,
44        final Locale locale, final Object... args) {
45      super(severity, summary, detail);
46      this.locale = locale;
47      this.args = args;
48    }
49  
50    public LabelValueBindingFacesMessage(final String summary, final String detail) {
51      super(summary, detail);
52    }
53  
54    public LabelValueBindingFacesMessage(final String summary) {
55      super(summary);
56    }
57  
58    @Override
59    public String getDetail() {
60      final String detail = super.getDetail();
61      if (args != null && args.length > 0) {
62        if (args.length == 1 && UIComponentTag.isValueReference(args[0].toString())) {
63          final FacesContext facesContext = FacesContext.getCurrentInstance();
64          final ValueBinding value = facesContext.getApplication().createValueBinding(detail);
65          return MessageUtils.getFormatedMessage(detail, locale, value.getValue(facesContext));
66        }
67        return MessageUtils.getFormatedMessage(detail, locale, args);
68      }
69      return detail;
70    }
71  
72    @Override
73    public String getSummary() {
74      final String summary = super.getSummary();
75      if (args != null && args.length > 0) {
76        if (args.length == 1 && UIComponentTag.isValueReference(args[0].toString())) {
77          final FacesContext facesContext = FacesContext.getCurrentInstance();
78          final ValueBinding value = facesContext.getApplication().createValueBinding(summary);
79          return MessageUtils.getFormatedMessage(summary, locale, value.getValue(facesContext));
80        }
81        return MessageUtils.getFormatedMessage(summary, locale, args);
82      }
83      return summary;
84    }
85  
86  }