1
2
3
4
5 package gboat2.base.view.components;
6
7 import gboat2.base.view.model.Comp;
8 import gboat2.base.view.model.CompContainer;
9 import gboat2.base.view.util.DescJsonUtil;
10
11 import java.io.Writer;
12 import java.util.ArrayList;
13 import java.util.Collections;
14 import java.util.List;
15
16 import javax.servlet.http.HttpServletRequest;
17 import javax.servlet.http.HttpServletResponse;
18
19 import org.apache.struts2.components.UIBean;
20 import org.apache.struts2.views.annotations.StrutsTag;
21
22 import com.opensymphony.xwork2.util.ValueStack;
23
24
25
26
27
28
29
30 @StrutsTag(
31 name="staticcomponents",
32 tldTagClass="gboat2.base.view.jsp.StaticComponentsTag",
33 description="组件集合",
34 allowDynamicAttributes = false)
35 public class StaticComponents extends UIBean {
36
37 public static final String TEMPLATE = "staticcomponents";
38
39
40 protected String names;
41
42
43 protected String devMode = "false";
44
45 protected String withDependency = "false";
46
47 protected String path;
48
49 private List<Comp> compList = new ArrayList<Comp>();
50
51 public StaticComponents(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
52 super(stack, request, response);
53 }
54
55 @Override
56 protected String getDefaultTemplate() {
57 return TEMPLATE;
58 }
59
60 @Override
61 protected void evaluateExtraParams() {
62 super.evaluateExtraParams();
63 String[] namess = names.split(",");
64 Comp co = null;
65 for(String tmpName : namess){
66 co = CompContainer.getInstance().getComp(tmpName);
67 if(co == null){
68 String resource = DescJsonUtil.computeResourceUrl(tmpName);
69 co = DescJsonUtil.loadDescJson(resource+"/"+DescJsonUtil.jsonFileName);
70 co = DescJsonUtil.covertComp(co,path);
71 CompContainer.getInstance().addComp(co.getName(), (Comp)co.clone());
72 }
73 }
74
75 Comp com = null;
76
77 for(String tmpName:namess){
78 com = CompContainer.getInstance().getComp(tmpName);
79 compList.add(com);
80
81 if(!"false".equals(withDependency)){
82 for(Comp cc : com.getDependencies()){
83 compList.add(CompContainer.getInstance().getComp(cc.getName()));
84 }
85 }
86 }
87
88 if(DescJsonUtil.isNeedAddMinSign(devMode)){
89 for(Comp comp:compList){
90 DescJsonUtil.covertCompToMinMode(comp);
91 }
92 }
93 Collections.sort(compList,new Comp());
94 addParameter("compList", compList);
95 }
96
97 @Override
98 public boolean end(Writer writer, String body) {
99 return super.end(writer, body);
100 }
101
102
103 public String getNames() {
104 return names;
105 }
106
107 public void setNames(String names) {
108 this.names = names;
109 }
110
111 public List<Comp> getCompList() {
112 return compList;
113 }
114
115 public void setCompList(List<Comp> compList) {
116 this.compList = compList;
117 }
118
119 public String getDevMode() {
120 return devMode;
121 }
122
123 public void setDevMode(String devMode) {
124 this.devMode = devMode;
125 }
126
127 public String getWithDependency() {
128 return withDependency;
129 }
130
131 public void setWithDependency(String withDependency) {
132 this.withDependency = withDependency;
133 }
134
135 public String getPath() {
136 return path;
137 }
138
139 public void setPath(String path) {
140 this.path = path;
141 }
142
143 }