private static void outDivTemplateEnd(Page page, Writer out) throws IOException { final Desktop dt; if (page != null && (dt = page.getDesktop()) != null) { if (dt.getAttribute(ATTR_DESKTOP_CLIENTINFO) != null) { dt.removeAttribute(ATTR_DESKTOP_CLIENTINFO); if (!"CE".equals(WebApps.getEdition())) out.write( "<script type=\"text/javascript\">if(zk.clientinfo === undefined)zk.clientinfo = true;</script>"); } if (dt.getAttribute(ATTR_DESKTOP_VISIBILITYCHANGE) != null) { dt.removeAttribute(ATTR_DESKTOP_VISIBILITYCHANGE); out.write( "<script type=\"text/javascript\">if(zk.visibilitychange === undefined)zk.visibilitychange = true;</script>"); } String resourceURL = (String) page.getAttribute(ATTR_PORTLET2_RESOURCEURL, Page.PAGE_SCOPE); if (resourceURL != null) { page.removeAttribute(ATTR_PORTLET2_RESOURCEURL, Page.PAGE_SCOPE); out.write("<script type=\"text/javascript\">zk.portlet2AjaxURI = '"); out.write(resourceURL); out.write("';</script>"); } } outSEOContent(page, out); out.write("</div>"); }
/** * Generates the special JavaScript code, such as the application's name. It shall be called, * before generating "zkmx(" and "zkx(". * * @since 5.0.6 */ public static final String outSpecialJS(Desktop desktop) { final StringBuffer sb = new StringBuffer(); // output application name String oldnm = (String) desktop.getAttribute(ATTR_APPNM); if (oldnm == null) oldnm = "ZK"; final String appnm = desktop.getWebApp().getAppName(); if (!oldnm.equals(appnm)) { sb.append("zk.appName='"); Strings.escape(sb, appnm, Strings.ESCAPE_JAVASCRIPT).append("';"); desktop.setAttribute(ATTR_APPNM, appnm); } // output zktheme cookie String oldthemenm = (String) desktop.getAttribute(ATTR_THEMENM); if (oldthemenm == null) oldthemenm = ""; final Object request = desktop.getExecution().getNativeRequest(); String themenm = ""; if (request instanceof HttpServletRequest) { themenm = ThemeFns.getThemeResolver().getTheme((HttpServletRequest) request); } if (!oldthemenm.equals(themenm)) { sb.append("zk.themeName='"); Strings.escape(sb, themenm, Strings.ESCAPE_JAVASCRIPT).append("';"); desktop.setAttribute(ATTR_THEMENM, themenm); } // output ZK ICON final Session sess = Sessions.getCurrent(); if (sess != null) { WebApp wapp = desktop.getWebApp(); if (wapp == null || "CE".equals(WebApps.getEdition()) || wapp.getAttribute("org.zkoss.zk.ui.notice") != null) { final PI pi = (PI) sess.getAttribute(ATTR_PI); boolean show = pi == null; if (show) sess.setAttribute(ATTR_PI, new PI()); else show = pi.show(); if (show) sb.append("zk.pi=1;"); } } return sb.toString(); }
public void save(Book book) throws IOException { String savingPath = WebApps.getCurrent().getRealPath("/WEB-INF/books/") + File.separator; File targetFile = new File(savingPath + book.getBookName()); FileOutputStream fos = null; try { // write to temporary file first to avoid write error damage original file File temp = File.createTempFile("temp", targetFile.getName()); fos = new FileOutputStream(temp); Exporters.getExporter().export(book, fos); fos.close(); fos = null; copy(temp, targetFile); temp.delete(); } catch (Exception e) { e.printStackTrace(); } finally { if (fos != null) fos.close(); } }
/** * Returns HTML tags to include all JavaScript files and codes that are required when loading a * ZUML page (never null). * * <p>FUTURE CONSIDERATION: we might generate the inclusion on demand instead of all at once. * * @param exec the execution (never null) * @param wapp the Web application. If null, exec.getDesktop().getWebApp() is used. So you have to * specify it if the execution is not associated with desktop (a fake execution, such as * JSP/DSP). * @param deviceType the device type, such as ajax. If null, exec.getDesktop().getDeviceType() is * used. So you have to specify it if the execution is not associated with desktop (a fake * execution). */ public static final String outLangJavaScripts(Execution exec, WebApp wapp, String deviceType) { if (exec.isAsyncUpdate(null) || exec.getAttribute(ATTR_LANG_JS_GENED) != null) return ""; // nothing to generate exec.setAttribute(ATTR_LANG_JS_GENED, Boolean.TRUE); final Desktop desktop = exec.getDesktop(); if (wapp == null) wapp = desktop.getWebApp(); if (deviceType == null) deviceType = desktop != null ? desktop.getDeviceType() : "ajax"; final StringBuffer sb = new StringBuffer(1536); final Set<JavaScript> jses = new LinkedHashSet<JavaScript>(32); for (LanguageDefinition langdef : LanguageDefinition.getByDeviceType(deviceType)) jses.addAll(langdef.getJavaScripts()); for (JavaScript js : jses) append(sb, js); sb.append("\n<!-- ZK ").append(wapp.getVersion()); if (WebApps.getFeature("ee")) sb.append(" EE"); else if (WebApps.getFeature("pe")) sb.append(" PE"); sb.append(' ').append(wapp.getBuild()); Object o = wapp.getAttribute("org.zkoss.zk.ui.notice"); if (o != null) sb.append(o); sb.append(" -->\n"); int tmout = 0; final Boolean autoTimeout = getAutomaticTimeout(desktop); if (autoTimeout != null ? autoTimeout.booleanValue() : wapp.getConfiguration().isAutomaticTimeout(deviceType)) { if (desktop != null) { tmout = desktop.getSession().getMaxInactiveInterval(); } else { Object req = exec.getNativeRequest(); if (req instanceof HttpServletRequest) { final HttpSession hsess = ((HttpServletRequest) req).getSession(false); if (hsess != null) { final Session sess = SessionsCtrl.getSession(wapp, hsess); if (sess != null) { tmout = sess.getMaxInactiveInterval(); } else { // try configuration first since HttpSession's timeout is set // when ZK Session is created (so it is not set yet) // Note: no need to setMaxInactiveInternval here since it will // be set later or not useful at the end tmout = wapp.getConfiguration().getSessionMaxInactiveInterval(); if (tmout <= 0) // system default tmout = hsess.getMaxInactiveInterval(); } } else tmout = wapp.getConfiguration().getSessionMaxInactiveInterval(); } } if (tmout > 0) { // unit: seconds int extra = tmout / 8; tmout += extra > 60 ? 60 : extra < 5 ? 5 : extra; // Add extra seconds to ensure it is really timeout } } final boolean keepDesktop = exec.getAttribute(Attributes.NO_CACHE) == null && !"page".equals(ExecutionsCtrl.getPageRedrawControl(exec)), groupingAllowed = isGroupingAllowed(desktop); final String progressboxPos = org.zkoss.lang.Library.getProperty("org.zkoss.zul.progressbox.position", ""); if (tmout > 0 || keepDesktop || progressboxPos.length() > 0 || !groupingAllowed) { sb.append("<script class=\"z-runonce\" type=\"text/javascript\">\nzkopt({"); if (keepDesktop) sb.append("kd:1,"); if (!groupingAllowed) sb.append("gd:1,"); if (tmout > 0) sb.append("to:").append(tmout).append(','); if (progressboxPos.length() > 0) sb.append("ppos:'").append(progressboxPos).append('\''); if (sb.charAt(sb.length() - 1) == ',') sb.setLength(sb.length() - 1); sb.append("});\n</script>"); } final Device device = Devices.getDevice(deviceType); String s = device.getEmbedded(); if (s != null) sb.append(s).append('\n'); return sb.toString(); }
private File getFile(String path) { return new File(WebApps.getCurrent().getRealPath(path)); }
/** * This method will make the given component instance become a ZK Composite(an ZK MVC Controller). * <br> * If the instance's class(Composite class) has {@link Composite} annotation, this method will * based on the given meta to generate content children.<br> * If there's no proper zuml content provided, this method will assume the application developer * will assemble the content Component tree themselves. * * @since ZK 6.0 * @param composite the composite instance that need to be processed * @param args ZK parser Context variables, the value inside can be accessed by EL[arg.varName] in * zuml.(can be null) */ public static void doCompose(Component composite, Map args) { CompositeDef def = DEF_CACHE.get(composite.getClass(), WebApps.getCurrent()); doCompose(def, composite, composite, args); }