1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.kuali.mobility.admin.util;
16
17 import java.util.Properties;
18
19 import org.kuali.mobility.admin.entity.HomeScreen;
20
21
22
23
24
25
26
27 public class LayoutUtil {
28
29 public static final String PROP_LAYOUT_DEFAULT = "home.layout.default";
30
31 public static final String PROP_LAYOUT_EDITABLE = "home.layout.userEditable";
32
33
34
35
36
37
38
39
40 public static final String getValidLayout(String requestedLayout, Properties kmeProperties){
41 String defaultLayout = getDefaultLayout(kmeProperties);
42 return isLayoutAllowed(requestedLayout, kmeProperties) ? requestedLayout : defaultLayout;
43 }
44
45
46
47
48
49
50
51 public static final boolean isLayoutAllowed(String layout, Properties kmeProperties){
52
53 if(!isValidLayout(layout)){
54 return false;
55 }
56
57
58 if(isLayoutChangeAllowed(kmeProperties) || getDefaultLayout(kmeProperties).equals(layout)){
59 return true;
60 }
61
62 return false;
63 }
64
65
66
67
68
69
70 public static final boolean isLayoutChangeAllowed(Properties kmeProperties){
71 if(kmeProperties == null){
72 return false;
73 }
74 return Boolean.parseBoolean(kmeProperties.getProperty(PROP_LAYOUT_EDITABLE, "false"));
75 }
76
77
78
79
80
81
82 public static final String getDefaultLayout(Properties kmeProperties){
83 if (kmeProperties == null){
84 return HomeScreen.LAYOUT_LIST;
85 }
86 return kmeProperties.getProperty(PROP_LAYOUT_DEFAULT, HomeScreen.LAYOUT_LIST);
87 }
88
89
90
91
92
93
94
95 public static final boolean isValidLayout(String layout){
96 if(layout == null){
97 return false;
98 }
99 for(String l : HomeScreen.LAYOUTS){
100 if(l.equals(layout)){
101 return true;
102 }
103 }
104 return false;
105 }
106 }