📄 jnlpfilehandler.java
字号:
if( vmArgs != null ) { NodeList j2seNL = root.getElementsByTagName("j2se"); if (j2seNL != null) { Element j2se = (Element) j2seNL.item(0); String vmOptions = j2se.getAttribute("java-vm-args"); if( vmOptions.length() > 0){ _log.addDebug("Setting the VM-Args given in the query string: " + vmArgs); j2se.setAttribute("java-vm-args", vmArgs); } else { _log.addDebug("Adding new attribute in the string : " + vmArgs); j2se.setAttribute("java-vm-args", vmArgs); } modified = true; } } if (root.hasAttribute("href") && query != null) { String href = root.getAttribute("href"); root.setAttribute("href", href + "?" + query); modified = true; } // Update version value for j2se tag if (testJRE != null) { NodeList j2seNL = root.getElementsByTagName("j2se"); if (j2seNL != null) { Element j2se = (Element) j2seNL.item(0); String ver = j2se.getAttribute("version"); if (ver.length() > 0) { j2se.setAttribute("version", testJRE); modified = true; } } } TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); DOMSource source = new DOMSource(document); StringWriter sw = new StringWriter(); StreamResult result = new StreamResult(sw); transformer.transform(source, result); jnlpFileContent = sw.toString(); _log.addDebug("Converted jnlpFileContent: " + jnlpFileContent); // Since we modified the file on the fly, we always update the timestamp value with current time if (modified) { timeStamp = new java.util.Date().getTime(); _log.addDebug("Last modified on the fly: " + timeStamp); } } } catch (Exception e) { _log.addDebug(e.toString(), e); } } // Convert to bytes as a UTF-8 encoding byte[] byteContent = jnlpFileContent.getBytes("UTF-8"); // Create entry DownloadResponse resp = DownloadResponse.getFileDownloadResponse(byteContent, mimeType, timeStamp, jnlpres.getReturnVersionId()); jnlpFile = new JnlpFileEntry(resp, lastModified); _jnlpFiles.put(reqUrl, jnlpFile); return resp; } /* This method performs the following substituations * $$name * $$codebase * $$context */ private String specializeJnlpTemplate(HttpServletRequest request, String respath, String jnlpTemplate) { String urlprefix = getUrlPrefix(request); int idx = respath.lastIndexOf('/'); // String name = respath.substring(idx + 1); // Exclude / String codebase = respath.substring(0, idx + 1); // Include / jnlpTemplate = substitute(jnlpTemplate, "$$name", name); jnlpTemplate = substitute(jnlpTemplate, "$$codebase", urlprefix + request.getContextPath() + codebase); jnlpTemplate = substitute(jnlpTemplate, "$$context", urlprefix + request.getContextPath()); return jnlpTemplate; } // This code is heavily inspired by the stuff in HttpUtils.getRequestURL private String getUrlPrefix(HttpServletRequest req) { StringBuffer url = new StringBuffer(); String scheme = req.getScheme(); int port = req.getServerPort(); url.append(scheme); // http, https url.append("://"); url.append(req.getServerName()); if ((scheme.equals("http") && port != 80) || (scheme.equals("https") && port != 443)) { url.append(':'); url.append(req.getServerPort()); } return url.toString(); } private String substitute(String target, String key, String value) { int start = 0; do { int idx = target.indexOf(key, start); if (idx == -1) return target; target = target.substring(0, idx) + value + target.substring(idx + key.length()); start = idx + value.length(); } while(true); } /** Parses a ISO 8601 Timestamp. The format of the timestamp is: * * YYYY-MM-DD hh:mm:ss or YYYYMMDDhhmmss * * Hours (hh) is in 24h format. ss are optional. Time are by default relative * to the current timezone. Timezone information can be specified * by: * * - Appending a 'Z', e.g., 2001-12-19 12:00Z * - Appending +hh:mm, +hhmm, +hh, -hh:mm -hhmm, -hh to * indicate that the locale timezone used is either the specified * amound before or after GMT. For example, * * 12:00Z = 13:00+1:00 = 0700-0500 * * The method returns 0 if it cannot pass the string. Otherwise, it is * the number of milliseconds size sometime in 1969. */ private long parseTimeStamp(String timestamp) { int YYYY = 0; int MM = 0; int DD = 0; int hh = 0; int mm = 0; int ss = 0; timestamp = timestamp.trim(); try { // Check what format is used if (matchPattern("####-##-## ##:##", timestamp)) { YYYY = getIntValue(timestamp, 0, 4); MM = getIntValue(timestamp, 5, 7); DD = getIntValue(timestamp, 8, 10); hh = getIntValue(timestamp, 11, 13); mm = getIntValue(timestamp, 14, 16); timestamp = timestamp.substring(16); if (matchPattern(":##", timestamp)) { ss = getIntValue(timestamp, 1, 3); timestamp = timestamp.substring(3); } } else if (matchPattern("############", timestamp)) { YYYY = getIntValue(timestamp, 0, 4); MM = getIntValue(timestamp, 4, 6); DD = getIntValue(timestamp, 6, 8); hh = getIntValue(timestamp, 8, 10); mm = getIntValue(timestamp, 10, 12); timestamp = timestamp.substring(12); if (matchPattern("##", timestamp)) { ss = getIntValue(timestamp, 0, 2); timestamp = timestamp.substring(2); } } else { // Unknown format return 0; } } catch(NumberFormatException e) { // Bad number return 0; } String timezone = null; // Remove timezone information timestamp = timestamp.trim(); if (timestamp.equalsIgnoreCase("Z")) { timezone ="GMT"; } else if (timestamp.startsWith("+") || timestamp.startsWith("-")) { timezone = "GMT" + timestamp; } if (timezone == null) { // Date is relative to current locale Calendar cal = Calendar.getInstance(); cal.set(YYYY, MM - 1, DD, hh, mm, ss); return cal.getTime().getTime(); } else { // Date is relative to a timezone Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(timezone)); cal.set(YYYY, MM - 1, DD, hh, mm, ss); return cal.getTime().getTime(); } } private int getIntValue(String key, int start, int end) { return Integer.parseInt(key.substring(start, end)); } private boolean matchPattern(String pattern, String key) { // Key must be longer than pattern if (key.length() < pattern.length()) return false; for(int i = 0; i < pattern.length(); i++) { char format = pattern.charAt(i); char ch = key.charAt(i); if (!((format == '#' && Character.isDigit(ch)) || (format == ch))) { return false; } } return true; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -