~ubuntu-branches/ubuntu/lucid/libstruts1.2-java/lucid

« back to all changes in this revision

Viewing changes to contrib/struts-faces/core-library/src/java/org/apache/struts/faces/taglib/LoadMessagesTag.java

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Vandyck
  • Date: 2006-04-24 12:14:23 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060424121423-naev53qigqgks0sa
Tags: 1.2.9-1
New upstream  release Fixes  three security  problems: CVE-2006-1546,
CVE-2006-1547,  CVE-2006-1548  (closes:  #360551),  thanks  to  Moritz
Muehlenhoff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2002,2004 The Apache Software Foundation.
 
3
 * 
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 * 
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 * 
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
package org.apache.struts.faces.taglib;
 
18
 
 
19
 
 
20
import java.util.Locale;
 
21
 
 
22
import javax.faces.context.FacesContext;
 
23
 
 
24
import javax.servlet.jsp.PageContext;
 
25
import javax.servlet.jsp.tagext.TagSupport;
 
26
 
 
27
import org.apache.struts.Globals;
 
28
import org.apache.struts.faces.util.MessagesMap;
 
29
import org.apache.struts.util.MessageResources;
 
30
 
 
31
 
 
32
/**
 
33
 * <p>Tag that exposes a specified <code>MessageResources</code> instance
 
34
 * as <code>Map</code>, so that the embedded messages may be retrieved via
 
35
 * value binding expressions.</p>
 
36
 */
 
37
 
 
38
public class LoadMessagesTag extends TagSupport {
 
39
 
 
40
 
 
41
    // ---------------------------------------------------------- Tag Attributes
 
42
 
 
43
 
 
44
    /**
 
45
     * <p>The name of the <code>MessageResources</code> to expose, or
 
46
     * <code>null</code> for the default <code>MessageResources</code>
 
47
     * for this application module.</p>
 
48
     */
 
49
    private String messages = null;
 
50
    public void setMessages(String messages) {
 
51
        this.messages = messages;
 
52
    }
 
53
 
 
54
 
 
55
    /**
 
56
     * <p>The request attribute key under which a <code>Map</code>
 
57
     * will be exposed.</p>
 
58
     */
 
59
    private String var = null;
 
60
    public void setVar(String var) {
 
61
        this.var = var;
 
62
    }
 
63
 
 
64
 
 
65
    // ------------------------------------------------------------- Tag Methods
 
66
 
 
67
 
 
68
    /**
 
69
     * <p>Expose a <code>Map</code> wrapping the specified
 
70
     * <code>MessageResources</code> instance, for the <code>Locale</code>
 
71
     * specified in the view root component of the current view.</p>
 
72
     */
 
73
    public int doStartTag() {
 
74
 
 
75
        // Acquire the Locale to be wrapped
 
76
        Locale locale =
 
77
            FacesContext.getCurrentInstance().getViewRoot().getLocale();
 
78
 
 
79
        // Acquire the MessageResources to be wrapped
 
80
        MessageResources messages = null;
 
81
        if (this.messages == null) {
 
82
            messages = (MessageResources)
 
83
                pageContext.getAttribute(Globals.MESSAGES_KEY,
 
84
                                         PageContext.REQUEST_SCOPE);
 
85
            if (messages == null) {
 
86
                messages = (MessageResources)
 
87
                    pageContext.getAttribute(Globals.MESSAGES_KEY,
 
88
                                             PageContext.APPLICATION_SCOPE);
 
89
            }
 
90
        } else {
 
91
            messages = (MessageResources)
 
92
                pageContext.getAttribute(this.messages,
 
93
                                         PageContext.APPLICATION_SCOPE);
 
94
        }
 
95
 
 
96
        // Expose a Map instance under the specified request attribute key
 
97
        pageContext.setAttribute(var,
 
98
                                 new MessagesMap(messages, locale),
 
99
                                 PageContext.REQUEST_SCOPE);
 
100
 
 
101
        // Skip the body of this tag (if any)
 
102
        return (SKIP_BODY);
 
103
 
 
104
    }
 
105
 
 
106
 
 
107
    /**
 
108
     * <p>Release any resources allocated by this tag instance.</p>
 
109
     */
 
110
    public void release() {
 
111
 
 
112
        this.messages = null;
 
113
        this.var = null;
 
114
 
 
115
    }
 
116
 
 
117
 
 
118
}