1 package fr.improve.struts.taglib.layout.workflow; 2 3 import javax.servlet.ServletException ; 4 5 import org.apache.commons.logging.Log; 6 import org.apache.commons.logging.LogFactory; 7 import org.apache.struts.action.ActionMapping; 8 import org.apache.struts.action.ActionServlet; 9 import org.apache.struts.action.PlugIn; 10 import org.apache.struts.config.ActionConfig; 11 import org.apache.struts.config.ModuleConfig; 12 13 import fr.improve.struts.taglib.layout.skin.Skin; 14 import fr.improve.struts.taglib.layout.sort.SortAction; 15 import fr.improve.struts.taglib.layout.treeview.TreeviewAction; 16 17 26 public class LayoutPlugin implements PlugIn { 27 30 private static final Log LOG = LogFactory.getLog(LayoutPlugin.class); 31 32 36 private String skinResources = "Struts-Layout"; 37 38 41 public void destroy() { 42 LOG.debug("Destroying Struts-Layout plugin"); 44 } 45 46 private static final String SORT_PATH = "/sort"; 47 private static final String TREEVIEW_PATH = "/treeview"; 48 49 54 public void init(ActionServlet in_servlet, ModuleConfig in_config) 55 throws ServletException { 56 57 LOG.debug("Setting skin properties name to " + skinResources); 59 Skin.setResourcesName(skinResources); 60 61 boolean sortAction = false; 63 boolean treeAction = false; 64 boolean sortPath = false; 65 boolean treePath = false; 66 ActionConfig[] configs = in_config.findActionConfigs(); 67 for (int i=0;i<configs.length;i++) { 68 if (SortAction.class.getName().equals(configs[i].getType())) { 69 sortAction = true; 70 LOG.debug("Found Struts-Layout sort action mapped to " + configs[i].getPath()); 71 } 72 if (SORT_PATH.equals(configs[i].getPath())) { 73 sortPath = true; 74 } 75 if (TreeviewAction.class.getName().equals(configs[i].getType())) { 76 treeAction = true; 77 LOG.debug("Found Struts-Layout treeview action mapped to " + configs[i].getPath()); 78 } 79 if (TREEVIEW_PATH.equals(configs[i].getPath())) { 80 treePath = true; 81 } 82 } 83 84 if (!sortAction) { 86 if (!sortPath) { 87 ActionConfig config = new ActionMapping(); 88 config.setPath(SORT_PATH); 89 config.setType(SortAction.class.getName()); 90 in_config.addActionConfig(config); 91 LOG.debug("Mapping Struts-Layout sort action to /sort"); 92 } else { 93 LOG.warn("Don't mapping Struts-Layout sort action : /sort is already used"); 94 } 95 } 96 97 if (!treeAction) { 99 if (!treePath) { 100 ActionConfig config = new ActionMapping(); 101 config.setPath(TREEVIEW_PATH); 102 config.setType(TreeviewAction.class.getName()); 103 in_config.addActionConfig(config); 104 LOG.debug("Mapping Struts-Layout sort action to /treeview"); 105 } else { 106 LOG.warn("Don't mapping Struts-Layout treeview action : /treeview is already used"); 107 } 108 } 109 110 LOG.debug("Struts-Layout plugin initialized"); 111 } 112 113 117 public void setSkinResources(String in_skinResources) { 118 skinResources = in_skinResources; 119 } 120 121 } 122 | Popular Tags |