Changeset 8039 for branches/3.19-stable
- Timestamp:
- May 30, 2022, 7:52:36 AM (10 months ago)
- Location:
- branches/3.19-stable
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.19-stable/src/clients/web/net/sf/basedb/clients/web/extensions/JspContext.java
r6875 r8039 23 23 24 24 import java.util.Collection; 25 import java.util.HashMap; 25 26 import java.util.HashSet; 27 import java.util.Map; 26 28 import java.util.Set; 27 29 … … 89 91 private final GuiContext guiContext; 90 92 91 private Set<String> scripts; 92 private Set<String> stylesheets; 93 private boolean needResourcesPerExtension; 94 private Map<String, Set<String>> scripts; 95 private Map<String, Set<String>> stylesheets; 93 96 94 97 JspContext(SessionControl sc, DbControl dc, … … 100 103 } 101 104 105 /** 106 Set a flag indicating that resources (eg. scripts and stylesheets) 107 should be tracked per extension. If this is set, it is possible to 108 use {@link #getScripts(String)} and {@link #getStylesheets(String)} 109 to get the resources that was added by the given extension. 110 @since 3.19.3 111 */ 112 public void setNeedResourcesPerExtension(boolean nrpe) 113 { 114 this.needResourcesPerExtension = nrpe; 115 } 116 102 117 /** 103 118 Get the JSP Page context object for the current request. … … 176 191 public void addScript(String absolutePath) 177 192 { 178 if (scripts == null) scripts = new HashSet<String>(); 179 scripts.add(absolutePath); 193 if (scripts == null) scripts = new HashMap<>(); 194 getSet(scripts, null).add(absolutePath); 195 if (needResourcesPerExtension) 196 { 197 getSet(scripts, getCurrentExtension().getId()).add(absolutePath); 198 } 199 } 200 201 /** 202 Get the Set that is stored under the given key. If 203 no Set exists it is created and stored in the map. 204 */ 205 private Set<String> getSet(Map<String, Set<String>> map, String key) 206 { 207 Set<String> set = map.get(key); 208 if (set == null) 209 { 210 set = new HashSet<>(); 211 map.put(key, set); 212 } 213 return set; 180 214 } 181 215 … … 200 234 public void addStylesheet(String absolutePath) 201 235 { 202 if (stylesheets == null) stylesheets = new HashSet<String>(); 203 stylesheets.add(absolutePath); 236 if (stylesheets == null) stylesheets = new HashMap<>(); 237 getSet(stylesheets, null).add(absolutePath); 238 if (needResourcesPerExtension) 239 { 240 getSet(stylesheets, getCurrentExtension().getId()).add(absolutePath); 241 } 204 242 } 205 243 … … 210 248 public Collection<String> getScripts() 211 249 { 212 return scripts; 250 return scripts == null ? null : scripts.get(null); 251 } 252 253 /** 254 Get all scripts that has been added to this context 255 by the given extension 256 @return A collection of scripts 257 @since 3.19.3 258 */ 259 public Collection<String> getScripts(String xtId) 260 { 261 return scripts == null ? null : scripts.get(xtId); 213 262 } 214 263 … … 219 268 public Collection<String> getStylesheets() 220 269 { 221 return stylesheets; 270 return stylesheets == null ? null : stylesheets.get(null); 271 } 272 273 /** 274 Get all stylesheets that has been added to this context 275 by the given extension. 276 @return A collection of stylesheets 277 @since 3.19.3 278 */ 279 public Collection<String> getStylesheets(String xtId) 280 { 281 return stylesheets == null ? null : stylesheets.get(xtId); 222 282 } 223 283 -
branches/3.19-stable/src/clients/web/net/sf/basedb/clients/web/taglib/extensions/Scripts.java
r7703 r8039 63 63 </td> 64 64 </tr> 65 <tr> 66 <td>extension</td> 67 <td>-</td> 68 <td>no</td> 69 <td> 70 If set, only scripts defined by the given extension are 71 included in the output. 72 </td> 73 </tr> 65 74 </table> 66 75 … … 76 85 // The JSP context 77 86 private JspContext context = null; 87 // If set, only output scripts defined by the given extension 88 private String extensionId; 78 89 79 90 public void setContext(JspContext context) 80 91 { 81 92 this.context = context; 93 } 94 95 /** 96 @since 3.19.3 97 */ 98 public void setExtension(String extensionId) 99 { 100 this.extensionId = extensionId; 82 101 } 83 102 … … 88 107 if (context == null) return SKIP_BODY; 89 108 90 Collection<String> scripts = context.getScripts( );109 Collection<String> scripts = context.getScripts(extensionId); 91 110 if (scripts == null) return SKIP_BODY; 92 111 -
branches/3.19-stable/src/clients/web/net/sf/basedb/clients/web/taglib/extensions/Stylesheets.java
r7703 r8039 64 64 </td> 65 65 </tr> 66 <tr> 67 <td>extension</td> 68 <td>-</td> 69 <td>no</td> 70 <td> 71 If set, only scripts defined by the given extension are 72 included in the output. 73 </td> 74 </tr> 66 75 </table> 67 76 … … 77 86 // The JSP context 78 87 private JspContext context = null; 88 // If set, only output scripts defined by the given extension 89 private String extensionId; 79 90 80 91 public void setContext(JspContext context) 81 92 { 82 93 this.context = context; 94 } 95 96 /** 97 @since 3.19.3 98 */ 99 public void setExtension(String extensionId) 100 { 101 this.extensionId = extensionId; 83 102 } 84 103 … … 89 108 if (context == null) return SKIP_BODY; 90 109 91 Collection<String> stylesheets = context.getStylesheets( );110 Collection<String> stylesheets = context.getStylesheets(extensionId); 92 111 if (stylesheets == null) return SKIP_BODY; 93 112 -
branches/3.19-stable/src/core/net/sf/basedb/util/extensions/ClientContext.java
r7895 r8039 69 69 private final SessionControl sc; 70 70 private final DbControl dc; 71 private ExtensionPoint<?> currentXtPoint; 72 private Extension<?> currentXt; 71 73 private Object item; 72 74 private Map<String, Object> attributes; … … 173 175 { 174 176 this.item = item; 177 } 178 179 /** 180 Get the currently active extension point. 181 @since 3.19.3 182 */ 183 public ExtensionPoint<?> getCurrentExtensionPoint() 184 { 185 return currentXtPoint; 186 } 187 protected void setCurrentExtensionPoint(ExtensionPoint<?> xtPoint) 188 { 189 this.currentXtPoint = xtPoint; 190 } 191 192 /** 193 Get the currently active extension point. 194 @since 3.19.3 195 */ 196 public Extension<?> getCurrentExtension() 197 { 198 return currentXt; 199 } 200 protected void setCurrentExtension(Extension<?> xt) 201 { 202 this.currentXt = xt; 175 203 } 176 204 -
branches/3.19-stable/src/core/net/sf/basedb/util/extensions/Registry.java
r7642 r8039 673 673 674 674 // YES! ... 675 if (clientContext != null) clientContext.setCurrentExtensionPoint(rep); 675 676 ErrorHandlerFactory ehf = rep.getErrorHandlerFactory(); 676 677 ExtensionPointContext<Action> mainContext = new ExtensionPointContext<Action>(this, … … 690 691 691 692 // Create invokation context for the extension 693 if (clientContext != null) clientContext.setCurrentExtension(ext); 692 694 ExtensionContext<A> context = 693 695 new ExtensionContext(mainContext, ext); -
branches/3.19-stable/www/WEB-INF/extensions.tld
r7604 r8039 41 41 <rtexprvalue>true</rtexprvalue> 42 42 </attribute> 43 <attribute> 44 <name>extension</name> 45 <required>false</required> 46 <rtexprvalue>true</rtexprvalue> 47 </attribute> 43 48 </tag> 44 49 … … 50 55 <name>context</name> 51 56 <required>true</required> 57 <rtexprvalue>true</rtexprvalue> 58 </attribute> 59 <attribute> 60 <name>extension</name> 61 <required>false</required> 52 62 <rtexprvalue>true</rtexprvalue> 53 63 </attribute> -
branches/3.19-stable/www/main.jsp
r8037 r8039 88 88 ItemResultIterator<News> news = null; 89 89 JspContext jspContext = ExtensionsControl.createContext(dc, pageContext); 90 jspContext.setNeedResourcesPerExtension(true); 90 91 ExtensionsInvoker<LoginFormAction> invoker = ExtensionsControl.useExtensions(jspContext, "net.sf.basedb.clients.web.login-form"); 91 92 92 93 LoginFormAction loginAction = null; 93 94 String selectedLoginForm = null; 95 String selectedExtension = null; 94 96 Map<String, String> allForms = new TreeMap<String, String>(); 95 97 … … 110 112 loginAction = action; 111 113 selectedLoginForm = formId; 114 selectedExtension = it.getExtension().getId(); 112 115 } 113 116 } … … 125 128 <base:page type="default"> 126 129 <base:head styles="login.css" scripts="~login.js"> 127 <ext:scripts context="<%=jspContext%>" />128 <ext:stylesheets context="<%=jspContext%>" />130 <ext:scripts context="<%=jspContext%>" extension="<%=selectedExtension%>" /> 131 <ext:stylesheets context="<%=jspContext%>" extension="<%=selectedExtension%>" /> 129 132 </base:head> 130 133 <base:body style="padding-top: 5em;" data-login-form="<%=HTML.encodeTags(selectedLoginForm)%>" data-requested-form="<%=HTML.encodeTags(requestedLoginForm) %>"> -
branches/3.19-stable/www/switch.jsp
r8037 r8039 65 65 { 66 66 JspContext jspContext = ExtensionsControl.createContext(dc, pageContext); 67 jspContext.setNeedResourcesPerExtension(true); 67 68 ExtensionsInvoker<LoginFormAction> invoker = ExtensionsControl.useExtensions(jspContext, "net.sf.basedb.clients.web.login-form"); 68 69 69 70 LoginFormAction loginAction = null; 70 71 String selectedLoginForm = null; 72 String selectedExtension = null; 71 73 Map<String, String> allForms = new TreeMap<String, String>(); 72 74 … … 87 89 loginAction = action; 88 90 selectedLoginForm = formId; 91 selectedExtension = it.getExtension().getId(); 89 92 } 90 93 } … … 101 104 <base:page type="popup" title="Switch user"> 102 105 <base:head styles="login.css" scripts="~login.js"> 103 <ext:scripts context="<%=jspContext%>" />104 <ext:stylesheets context="<%=jspContext%>" />106 <ext:scripts context="<%=jspContext%>" extension="<%=selectedExtension%>" /> 107 <ext:stylesheets context="<%=jspContext%>" extension="<%=selectedExtension%>" /> 105 108 </base:head> 106 109 <base:body data-login-form="<%=HTML.encodeTags(selectedLoginForm)%>" data-requested-form="<%=HTML.encodeTags(requestedLoginForm) %>">
Note: See TracChangeset
for help on using the changeset viewer.