📄 zkfns.java
字号:
public static final List getStyleSheets(Execution exec) { //Process all languages final Desktop desktop = exec.getDesktop(); final Configuration config = desktop.getWebApp().getConfiguration(); final Set disabled = config.getDisabledThemeURIs(); final String deviceType = desktop.getDeviceType(); final List sses = new LinkedList(); //a list of StyleSheet for (Iterator it = LanguageDefinition.getByDeviceType(deviceType).iterator(); it.hasNext();) { final LanguageDefinition langdef = (LanguageDefinition)it.next(); for (Iterator e = langdef.getStyleSheets().iterator(); e.hasNext();) { final StyleSheet ss = (StyleSheet)e.next(); if (!disabled.contains(ss.getHref())) sses.add(ss); } } //Process configuration final ThemeProvider themeProvider = config.getThemeProvider(); if (themeProvider != null) { final List org = new LinkedList(); for (Iterator it = sses.iterator(); it.hasNext();) { final StyleSheet ss = (StyleSheet)it.next(); org.add(ss.getHref()); //we don't support getContent } final String[] hrefs = config.getThemeURIs(); for (int j = 0; j < hrefs.length; ++j) org.add(hrefs[j]); sses.clear(); final Collection res = themeProvider.getThemeURIs(exec, org); if (res != null) { for (Iterator it = res.iterator(); it.hasNext();) sses.add(new StyleSheet((String)it.next(), "text/css")); } } else { final String[] hrefs = config.getThemeURIs(); for (int j = 0; j < hrefs.length; ++j) sses.add(new StyleSheet(hrefs[j], "text/css")); } return sses; } private static void append(StringBuffer sb, StyleSheet ss, Execution exec, Page page) { String href = ss.getHref(); if (href != null) { try { if (exec != null) href = (String)exec.evaluate(page, href, String.class); if (href != null && href.length() > 0) sb.append("\n<link rel=\"stylesheet\" type=\"") .append(ss.getType()).append("\" href=\"") .append(ServletFns.encodeURL(href)) .append("\"/>"); } catch (javax.servlet.ServletException ex) { throw new UiException(ex); } } else { sb.append("\n<style"); if (ss.getType() != null) sb.append(" type=\"").append(ss.getType()).append('"'); sb.append(">\n").append(ss.getContent()).append("\n</style>"); } } /** Converts the specified URI to absolute if necessary. * Refer to {@link Execution#toAbsoluteURI}. * * @param skipInclude whether not to convert to an absolute URI if * the current page is included by another page. * When use the include directive, skipInclude shall be true. */ public static String toAbsoluteURI(String uri, boolean skipInclude) { return Executions.getCurrent().toAbsoluteURI(uri, skipInclude); } /** Converts the specified URI to absolute if not included by another page. * It is a shortcut of {@link #toAbsoluteURI(String, boolean)} with skipInclude * is true. */ public static String toAbsoluteURI(String uri) { return toAbsoluteURI(uri, true); //we preserve this method for backward compatibility (since some developers //might have old version core.dsp.tld } /** Returns the content that will be placed inside the header element * of the specified page. * For HTML, the header element is the HEAD element. */ public static final String outHeaders(Page page) { return ((PageCtrl)page).getHeaders(); } /** Returns the content that will be generated * as the attributes of the root element of the specified page. * For HTML, the root element is the HTML element. */ public static final String outRootAttributes(Page page) { return ((PageCtrl)page).getRootAttributes(); } /** Returns the content type (never null). * @since 3.0.0 */ public static final String outContentType(Page page) { final String contentType = ((PageCtrl)page).getContentType(); return contentType != null ? contentType: page.getDesktop().getDevice().getContentType(); } /** Returns the doc type, or null if not available. * It is null or <!DOCTYPE ...>. * @since 3.0.0 */ public static final String outDocType(Page page) { final String docType = ((PageCtrl)page).getDocType(); return trimAndLF(docType != null ? docType: page.getDesktop().getDevice().getDocType()); } /** Trims and appends a linefeed if necessary. */ private static final String trimAndLF(String s) { if (s != null) { s = s.trim(); final int len = s.length(); if (len > 0 && s.charAt(len-1) != '\n') s += '\n'; } return s; } /** Returns the first line to be generated to the output, * or null if no special first line. */ public static final String outFirstLine(Page page) { return trimAndLF(((PageCtrl)page).getFirstLine()); } /** Generates Locale-dependent strings in JavaScript syntax. */ public final static String outLocaleJavaScript() { final Locale locale = Locales.getCurrent(); return outNumberJavaScript(locale) + outDateJavaScript(locale); } /** Output number relevant texts. */ private final static String outNumberJavaScript(Locale locale) { final DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale); final StringBuffer sb = new StringBuffer(128); appendAssignJavaScript( sb, "zk.GROUPING", symbols.getGroupingSeparator()); appendAssignJavaScript( sb, "zk.DECIMAL", symbols.getDecimalSeparator()); appendAssignJavaScript( sb, "zk.PERCENT", symbols.getPercent()); appendAssignJavaScript( sb, "zk.MINUS", symbols.getMinusSign()); return sb.toString(); } private final static void appendAssignJavaScript(StringBuffer sb, String nm, char val) { final char quot = val == '"' ? '\'': '"'; sb.append(nm).append('=').append(quot).append(val).append(quot).append(";\n"); } /** Output date/calendar relevant labels. */ private final static String outDateJavaScript(Locale locale) { synchronized (_datejs) { final String djs = (String)_datejs.get(locale); if (djs != null) return djs; } String djs = getDateJavaScript(locale); synchronized (_datejs) { //OK to race //To minimize memory use, reuse the string if they are the same //which is common for (Iterator it = _datejs.values().iterator(); it.hasNext();) { final String val = (String)it.next(); if (val.equals(djs)) djs = val; } _datejs.put(locale, djs); } return djs; } private final static String getDateJavaScript(Locale locale) { final StringBuffer sb = new StringBuffer(512); final Calendar cal = Calendar.getInstance(locale); cal.clear(); final int firstDayOfWeek = cal.getFirstDayOfWeek(); sb.append("zk.DOW_1ST=") .append(firstDayOfWeek - Calendar.SUNDAY) .append(";\n"); final boolean zhlang = locale.getLanguage().equals("zh"); SimpleDateFormat df = new SimpleDateFormat("E", locale); final String[] sdow = new String[7], s2dow = new String[7]; for (int j = firstDayOfWeek, k = 0; k < 7; ++k) { cal.set(Calendar.DAY_OF_WEEK, j); sdow[k] = df.format(cal.getTime()); if (++j > Calendar.SATURDAY) j = Calendar.SUNDAY; if (zhlang) { s2dow[k] = sdow[k].length() >= 3 ? sdow[k].substring(2): sdow[k]; } else { final int len = sdow[k].length(); final char cc = sdow[k].charAt(len - 1); s2dow[k] = cc == '.' || cc == ',' ? sdow[k].substring(0, len - 1): sdow[k]; } } df = new SimpleDateFormat("EEEE", locale); final String[] fdow = new String[7]; for (int j = firstDayOfWeek, k = 0; k < 7; ++k) { cal.set(Calendar.DAY_OF_WEEK, j); fdow[k] = df.format(cal.getTime()); if (++j > Calendar.SATURDAY) j = Calendar.SUNDAY; } df = new SimpleDateFormat("MMM", locale); final String[] smon = new String[12], s2mon = new String[12]; for (int j = 0; j < 12; ++j) { cal.set(Calendar.MONTH, j); smon[j] = df.format(cal.getTime()); if (zhlang) { s2mon[j] = smon[0].length() >= 2 ? //remove the last char smon[j].substring(0, smon[j].length() -1): smon[j]; } else { final int len = smon[j].length(); final char cc = smon[j].charAt(len - 1); s2mon[j] = cc == '.' || cc == ',' ? smon[j].substring(0, len - 1): smon[j]; } } df = new SimpleDateFormat("MMMM", locale); final String[] fmon = new String[12]; for (int j = 0; j < 12; ++j) { cal.set(Calendar.MONTH, j); fmon[j] = df.format(cal.getTime()); } appendJavaScriptArray(sb, "SDOW", sdow); if (Objects.equals(s2dow, sdow)) sb.append("zk.S2DOW=zk.SDOW;\n"); else appendJavaScriptArray(sb, "S2DOW", s2dow); if (Objects.equals(fdow, sdow)) sb.append("zk.FDOW=zk.SDOW;\n"); else appendJavaScriptArray(sb, "FDOW", fdow); appendJavaScriptArray(sb, "SMON", smon); if (Objects.equals(s2mon, smon)) sb.append("zk.S2MON=zk.SMON;\n"); else appendJavaScriptArray(sb, "S2MON", s2mon); if (Objects.equals(fmon, smon)) sb.append("zk.FMON=zk.SMON;\n"); else appendJavaScriptArray(sb, "FMON", fmon); //AM/PM available since ZK 3.0 df = new SimpleDateFormat("a", locale); cal.set(Calendar.HOUR_OF_DAY, 3); final String[] ampm = new String[2]; ampm[0] = df.format(cal.getTime()); cal.set(Calendar.HOUR_OF_DAY, 15); ampm[1] = df.format(cal.getTime()); appendJavaScriptArray(sb, "APM", ampm); return sb.toString(); } private static final void appendJavaScriptArray(StringBuffer sb, String varnm, String[] vals) { sb.append("zk.").append(varnm).append("=["); for (int j = 0;;) { sb.append('"').append(Strings.escape(vals[j], "\\\"")).append('"'); if (++j >= vals.length) break; else sb.append(','); } sb.append("];\n"); } private static final CacheMap _datejs; static { _datejs = new CacheMap(8); _datejs.setLifetime(24*60*60*1000); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -