Changeset 6562
- Timestamp:
- Oct 14, 2014, 7:53:51 AM (9 years ago)
- Location:
- branches/3.3-stable/src/clients/web/net/sf/basedb/clients/web
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3-stable/src/clients/web/net/sf/basedb/clients/web/extensions/WebClientRegisterExtensionsProcessor.java
r6417 r6562 23 23 24 24 import net.sf.basedb.clients.web.servlet.ContentSecurityPolicyFilter; 25 import net.sf.basedb.clients.web.taglib.Head; 25 26 import net.sf.basedb.core.plugin.About; 26 27 import net.sf.basedb.util.Values; … … 98 99 ContentSecurityPolicyFilter.setSafeResources(xtFile.getName(), safeResources); 99 100 } 101 // Register the version of this extension so 102 // we can append ?version to script and css URLs 103 if (about != null && about.getVersion() != null) 104 { 105 Head.setExtensionVersion(xtFile.getName(), about.getVersion()); 106 } 100 107 101 108 super.processFile(manager, wFile); -
branches/3.3-stable/src/clients/web/net/sf/basedb/clients/web/taglib/Head.java
r6525 r6562 23 23 package net.sf.basedb.clients.web.taglib; 24 24 25 import net.sf.basedb.clients.web.extensions.ExtensionsControl; 26 import net.sf.basedb.clients.web.util.HTML; 25 27 import net.sf.basedb.core.SessionControl; 28 import net.sf.basedb.core.Version; 26 29 import net.sf.basedb.util.Values; 27 30 31 import java.util.HashMap; 28 32 import java.util.LinkedHashSet; 29 33 import java.util.Arrays; 30 34 import java.util.Map; 35 import java.util.regex.Matcher; 36 import java.util.regex.Pattern; 37 38 import javax.servlet.http.HttpServletRequest; 31 39 import javax.servlet.jsp.JspException; 32 40 import javax.servlet.jsp.JspTagException; 41 import javax.servlet.jsp.PageContext; 33 42 import javax.servlet.jsp.tagext.TagSupport; 34 43 … … 91 100 private static final long serialVersionUID = 948719986796860767L; 92 101 102 // Contain the file name of extension JAR files mapped to versions 103 private static final Map<String, String> xtVersions = new HashMap<String, String>(); 104 105 // Match files under /extensions path. group 2 is the JAR file name 106 private static final Pattern PATH_MATCH = 107 Pattern.compile("(" + ExtensionsControl.RESOURCES_URL + "/([^/]+)/(.*))"); 108 109 /** 110 Register the version for an exteniosn JAR file 111 @since 3.3.2 112 */ 113 public static void setExtensionVersion(String jarName, String version) 114 { 115 synchronized (xtVersions) 116 { 117 xtVersions.put(jarName, "v="+HTML.urlEncode(version)); 118 } 119 } 120 93 121 /** 94 122 The parent <base:page> tag. … … 105 133 */ 106 134 private String scripts = null; 135 136 private static final String globalVersion = "v=" + Version.getMajor()+"."+Version.getMinor()+"."+Version.getMaintenance(); 137 private String localVersion; 107 138 108 139 /* … … 143 174 for (String style : allStyles) 144 175 { 176 char pp = style.indexOf('?') == -1 ? '?' : '&'; 145 177 sb.append("\t<link rel=\"stylesheet\" type=\"text/css\" href=\""); 146 178 if (style.startsWith(appRoot)) 147 179 { 148 180 // Full absolute path 149 sb.append(style) ;181 sb.append(style).append(pp).append(globalVersion); 150 182 } 151 183 else if (style.startsWith("/")) 152 184 { 153 185 // Absolute path is relative the page root (eg. /foo/bar.css --> /base/foo/bar.css) 154 sb.append(appRoot).append(style.substring(1)) ;186 sb.append(appRoot).append(style.substring(1)).append(pp).append(globalVersion); 155 187 } 156 188 else if (style.startsWith("~")) 157 189 { 158 190 // Relative path is relative the current page (eg. ~bar.css --> bar.css) 159 sb.append(style.substring(1)) ;191 sb.append(style.substring(1)).append(pp).append(localVersion); 160 192 } 161 193 else 162 194 { 163 195 // All other style sheets are in the /include/styles folder 164 sb.append(appRoot).append("include/styles/").append(style) ;196 sb.append(appRoot).append("include/styles/").append(style).append(pp).append(globalVersion); 165 197 } 166 198 sb.append("\">\n"); … … 192 224 for (String script : allScripts) 193 225 { 226 char pp = script.indexOf('?') == -1 ? '?' : '&'; 194 227 sb.append("\t<script type=\"text/javascript\" charset=\"UTF-8\" src=\""); 195 228 if (script.startsWith(appRoot)) 196 229 { 197 230 // Full absolute path 198 sb.append(script) ;231 sb.append(script).append(pp).append(globalVersion); 199 232 } 200 233 else if (script.startsWith("/")) 201 234 { 202 235 // Absolute path that is relative the BASE root (eg. /foo/bar.js --> /base/foo/bar.js) 203 sb.append(appRoot).append(script.substring(1)) ;236 sb.append(appRoot).append(script.substring(1)).append(pp).append(globalVersion); 204 237 } 205 238 else if (script.startsWith("~")) 206 239 { 207 240 // Relative path is relative the current page (eg. ~bar.js --> bar.js) 208 sb.append(script.substring(1)) ;241 sb.append(script.substring(1)).append(pp).append(localVersion); 209 242 } 210 243 else 211 244 { 212 245 // All other scripts are in the /include/scripts folder 213 sb.append(appRoot).append("include/scripts/").append(script) ;246 sb.append(appRoot).append("include/scripts/").append(script).append(pp).append(globalVersion); 214 247 } 215 248 sb.append("\"></script>\n"); … … 217 250 } 218 251 252 @Override 253 public void setPageContext(PageContext pageContext) 254 { 255 super.setPageContext(pageContext); 256 257 // If we are on /extension subpage, the localVersion is the 258 // version for the extension, otherwise we use the global version 259 localVersion = globalVersion; 260 HttpServletRequest req = (HttpServletRequest)pageContext.getRequest(); 261 Matcher m = PATH_MATCH.matcher(req.getServletPath()); 262 if (m.matches()) 263 { 264 String jarFile = m.group(2); 265 if (xtVersions.containsKey(jarFile)) 266 { 267 localVersion = xtVersions.get(jarFile); 268 } 269 } 270 } 271 272 219 273 @Override 220 274 public int doStartTag()
Note: See TracChangeset
for help on using the changeset viewer.