~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to dhis-2/dhis-support/dhis-support-webwork/src/main/java/org/hisp/dhis/webwork/interceptor/WebWorkDataDictionaryModeInterceptor.java

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.hisp.dhis.webwork.interceptor;
 
2
 
 
3
import java.util.HashMap;
 
4
import java.util.Map;
 
5
 
 
6
import ognl.NoSuchPropertyException;
 
7
import ognl.Ognl;
 
8
 
 
9
import org.hisp.dhis.options.datadictionary.DataDictionaryModeManager;
 
10
 
 
11
import com.opensymphony.xwork.Action;
 
12
import com.opensymphony.xwork.ActionInvocation;
 
13
import com.opensymphony.xwork.interceptor.AroundInterceptor;
 
14
 
 
15
public class WebWorkDataDictionaryModeInterceptor
 
16
    extends AroundInterceptor
 
17
{
 
18
    private static final String KEY_DATA_DICTIONARY_MODE = "dataDictionaryMode";
 
19
    
 
20
    // -------------------------------------------------------------------------
 
21
    // Dependencies
 
22
    // -------------------------------------------------------------------------
 
23
 
 
24
    private DataDictionaryModeManager dataDictionaryModeManager;
 
25
 
 
26
    public void setDataDictionaryModeManager( DataDictionaryModeManager dataDictionaryModeManager )
 
27
    {
 
28
        this.dataDictionaryModeManager = dataDictionaryModeManager;
 
29
    }
 
30
    
 
31
    // -------------------------------------------------------------------------
 
32
    // AroundInterceptor implementation
 
33
    // -------------------------------------------------------------------------
 
34
 
 
35
    protected void before( ActionInvocation invocation )
 
36
        throws Exception
 
37
    {
 
38
        Action action = (Action) invocation.getAction();
 
39
        
 
40
        String currentMode = dataDictionaryModeManager.getCurrentDataDictionaryMode();
 
41
        
 
42
        // ---------------------------------------------------------------------
 
43
        // Make the objects available for web templates
 
44
        // ---------------------------------------------------------------------
 
45
        
 
46
        Map<String, Object> templateMap = new HashMap<String, Object>( 1 );
 
47
        
 
48
        templateMap.put( KEY_DATA_DICTIONARY_MODE, currentMode );
 
49
        
 
50
        invocation.getStack().push( templateMap );
 
51
        
 
52
        // ---------------------------------------------------------------------
 
53
        // Set the objects in the action class if the properties exist
 
54
        // ---------------------------------------------------------------------
 
55
 
 
56
        Map<?, ?> contextMap = invocation.getInvocationContext().getContextMap();
 
57
        
 
58
        try
 
59
        {
 
60
            Ognl.setValue( KEY_DATA_DICTIONARY_MODE, contextMap, action, currentMode );
 
61
        }
 
62
        catch ( NoSuchPropertyException e )
 
63
        {
 
64
        }
 
65
    }
 
66
    
 
67
    protected void after( ActionInvocation invocation, String result )
 
68
        throws Exception
 
69
    {
 
70
        // Not in use
 
71
    }   
 
72
}