📄 htmlscreenrenderer.java
字号:
/* * $Id: HtmlScreenRenderer.java 7050 2006-03-22 20:53:39Z jonesde $ * * Copyright (c) 2004 The Open For Business Project - www.ofbiz.org * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. */package org.ofbiz.widget.html;import java.io.ByteArrayInputStream;import java.io.IOException;import java.io.Writer;import java.sql.Timestamp;import java.util.Locale;import java.util.Map;import javax.servlet.ServletContext;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.GeneralException;import org.ofbiz.base.util.UtilDateTime;import org.ofbiz.base.util.UtilFormatOut;import org.ofbiz.base.util.UtilHttp;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericValue;import org.ofbiz.webapp.control.RequestHandler;import org.ofbiz.webapp.taglib.ContentUrlTag;import org.ofbiz.webapp.view.ViewHandlerException;import org.ofbiz.widget.WidgetContentWorker;import org.ofbiz.widget.screen.ModelScreenWidget;import org.ofbiz.widget.screen.ScreenStringRenderer;/** * Widget Library - HTML Form Renderer implementation * * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a> * @version $Rev: 7050 $ * @since 3.1 */public class HtmlScreenRenderer implements ScreenStringRenderer { public static final String module = HtmlScreenRenderer.class.getName(); public HtmlScreenRenderer() {} public void renderSectionBegin(Writer writer, Map context, ModelScreenWidget.Section section) throws IOException { // do nothing, this is just a place holder container for HTML } public void renderSectionEnd(Writer writer, Map context, ModelScreenWidget.Section section) throws IOException { // do nothing, this is just a place holder container for HTML } public void renderContainerBegin(Writer writer, Map context, ModelScreenWidget.Container container) throws IOException { writer.write("<div"); String id = container.getId(context); if (UtilValidate.isNotEmpty(id)) { writer.write(" id=\""); writer.write(id); writer.write("\""); } String style = container.getStyle(context); if (UtilValidate.isNotEmpty(style)) { writer.write(" class=\""); writer.write(style); writer.write("\""); } writer.write(">"); appendWhitespace(writer); } public void renderContainerEnd(Writer writer, Map context, ModelScreenWidget.Container container) throws IOException { writer.write("</div>"); appendWhitespace(writer); } public void renderLabel(Writer writer, Map context, ModelScreenWidget.Label label) throws IOException { // open tag String style = label.getStyle(context); String id = label.getId(context); if (UtilValidate.isNotEmpty(style) || UtilValidate.isNotEmpty(id) ) { writer.write("<span"); if (UtilValidate.isNotEmpty(id)) { writer.write(" id=\""); writer.write(id); writer.write("\""); } if (UtilValidate.isNotEmpty(style)) { writer.write(" class=\""); writer.write(style); writer.write("\""); } writer.write(">"); // the text writer.write(label.getText(context)); // close tag writer.write("</span>"); } else { writer.write(label.getText(context)); } appendWhitespace(writer); } public void renderLink(Writer writer, Map context, ModelScreenWidget.Link link) throws IOException { // open tag writer.write("<a"); String id = link.getId(context); if (UtilValidate.isNotEmpty(id)) { writer.write(" id=\""); writer.write(id); writer.write("\""); } String style = link.getStyle(context); if (UtilValidate.isNotEmpty(style)) { writer.write(" class=\""); writer.write(style); writer.write("\""); } String name = link.getName(context); if (UtilValidate.isNotEmpty(name)) { writer.write(" name=\""); writer.write(name); writer.write("\""); } String targetWindow = link.getTargetWindow(context); if (UtilValidate.isNotEmpty(targetWindow)) { writer.write(" target=\""); writer.write(targetWindow); writer.write("\""); } String target = link.getTarget(context); if (UtilValidate.isNotEmpty(target)) { writer.write(" href=\""); String urlMode = link.getUrlMode(); String prefix = link.getPrefix(context); boolean fullPath = link.getFullPath(); boolean secure = link.getSecure(); boolean encode = link.getEncode(); HttpServletResponse response = (HttpServletResponse) context.get("response"); HttpServletRequest request = (HttpServletRequest) context.get("request"); if (urlMode != null && urlMode.equalsIgnoreCase("intra-app")) { if (request != null && response != null) { ServletContext ctx = (ServletContext) request.getAttribute("servletContext"); RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_"); String urlString = rh.makeLink(request, response, target, fullPath, secure, encode); writer.write(urlString); } else if (prefix != null) { writer.write(prefix + target); } else { writer.write(target); } } else if (urlMode != null && urlMode.equalsIgnoreCase("content")) { if (request != null && response != null) { StringBuffer newURL = new StringBuffer(); ContentUrlTag.appendContentPrefix(request, newURL); newURL.append(target); writer.write(newURL.toString()); } } else { writer.write(target); } writer.write("\""); } writer.write(">"); // the text ModelScreenWidget.Image img = link.getImage(); if (img == null) writer.write(link.getText(context)); else renderImage(writer, context, img); // close tag writer.write("</a>"); appendWhitespace(writer); } public void renderImage(Writer writer, Map context, ModelScreenWidget.Image image) throws IOException { // open tag writer.write("<img "); String id = image.getId(context); if (UtilValidate.isNotEmpty(id)) { writer.write(" id=\""); writer.write(id); writer.write("\""); } String style = image.getStyle(context); if (UtilValidate.isNotEmpty(style)) { writer.write(" class=\""); writer.write(style); writer.write("\""); } String wid = image.getWidth(context); if (UtilValidate.isNotEmpty(wid)) { writer.write(" width=\""); writer.write(wid); writer.write("\""); } String hgt = image.getHeight(context); if (UtilValidate.isNotEmpty(hgt)) { writer.write(" height=\""); writer.write(hgt); writer.write("\""); } String border = image.getBorder(context); if (UtilValidate.isNotEmpty(border)) { writer.write(" border=\""); writer.write(border); writer.write("\""); } String src = image.getSrc(context); if (UtilValidate.isNotEmpty(src)) { writer.write(" src=\""); String urlMode = image.getUrlMode(); boolean fullPath = false; boolean secure = false; boolean encode = false; HttpServletResponse response = (HttpServletResponse) context.get("response"); HttpServletRequest request = (HttpServletRequest) context.get("request"); if (urlMode != null && urlMode.equalsIgnoreCase("intra-app")) { if (request != null && response != null) { ServletContext ctx = (ServletContext) request.getAttribute("servletContext"); RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_"); String urlString = rh.makeLink(request, response, src, fullPath, secure, encode); writer.write(urlString); } else { writer.write(src); } } else if (urlMode != null && urlMode.equalsIgnoreCase("content")) { if (request != null && response != null) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -