1 25 26 package net.killingar.forum.actions.area; 27 28 import net.killingar.BeanUtil; 29 import net.killingar.forum.internal.Area; 30 import net.killingar.forum.internal.FieldData; 31 import net.killingar.forum.internal.PropertyData; 32 import webwork.action.ActionContext; 33 34 import java.util.Map ; 35 36 public class AbstractAreaCustomizer implements AreaCustomizer 37 { 38 public static final String 40 WRITE_VIEW = "write.jsp", 41 MESSAGE_VIEW = "default-message.jsp", 42 VIEW = "view.jsp"; 43 44 public static final AbstractAreaCustomizer DEFAULT_CUSTOMIZER = new AbstractAreaCustomizer(); 45 46 public static String getParam(String key) 48 { 49 return getParam(key, null); 50 } 51 52 public static String getParam(String key, String def) 53 { 54 String [] a = ((String [])ActionContext.getParameters().get(key)); 55 if (a == null) 56 return def; 57 58 return a[0]; 59 } 60 61 public static String putParam(Map map, String key, String def) 62 { 63 String r = getParam(key, def); 64 map.put(key, r); 65 return r; 66 } 67 68 public void updateParam(String key, FieldData fd) 69 { 70 Map m = fd.getFields(); 71 String defaultValue = (String )BeanUtil.getProperty(key, this); 72 String value = putParam(m, key, defaultValue); 73 BeanUtil.setProperty(key, value, this); 74 } 75 76 public Object findValue(String path) 77 { 78 return ActionContext.getValueStack().findValue(path); 79 } 80 81 83 85 public String getWriteView() { return WRITE_VIEW; } 87 public String getEditMessageView() { return getWriteView(); } 88 public String getMessageView() { return MESSAGE_VIEW; } 89 public String getView() { return VIEW; } 90 91 public static AreaCustomizer getAreaCustomizer(Area area) 92 { 93 try 94 { 95 String s = area.getCustom(); 96 int i = s.indexOf('\n'); 97 if (i != -1) 98 { 99 AreaCustomizer ac = (AreaCustomizer)Class.forName(s.substring(0, i-1)).newInstance(); 100 BeanUtil.setProperties(new PropertyData(s.substring(i)).getFields(), ac); 101 102 return ac; 103 } 104 else return (AreaCustomizer)Class.forName(s).newInstance(); 105 } 106 catch (Exception e) 107 { 108 return DEFAULT_CUSTOMIZER; 109 } 110 } 111 112 public boolean addMessagePreProccess(WriteMessage in) { return true; } 113 public boolean editMessagePreProccess(EditMessage in) { return true; } 114 public void previewMessage(WriteMessage in) {} 115 public void previewMessage(EditMessage in) {} 116 } | Popular Tags |