📄 modelscreenwidget.java
字号:
super(modelScreen, platformSpecificElement); Element childElement = UtilXml.firstChildElement(platformSpecificElement); if ("html".equals(childElement.getNodeName())) { subWidget = new HtmlWidget(modelScreen, childElement); } else { throw new IllegalArgumentException("Tag not supported under the platform-specific tag with name: " + childElement.getNodeName()); } } public void renderWidgetString(Writer writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException { subWidget.renderWidgetString(writer, context, screenStringRenderer); } public String rawString() { return "<platform-specific>" + (this.subWidget==null?"":this.subWidget.rawString()); } } public static class Content extends ModelScreenWidget { protected FlexibleStringExpander contentId; protected FlexibleStringExpander editRequest; protected FlexibleStringExpander editContainerStyle; protected FlexibleStringExpander enableEditName; protected boolean xmlEscape = false; protected FlexibleStringExpander dataResourceId; protected String width; protected String height; protected String border; public Content(ModelScreen modelScreen, Element subContentElement) { super(modelScreen, subContentElement); // put the text attribute first, then the pcdata under the element, if both are there of course this.contentId = new FlexibleStringExpander(subContentElement.getAttribute("content-id")); this.dataResourceId = new FlexibleStringExpander(subContentElement.getAttribute("dataresource-id")); this.editRequest = new FlexibleStringExpander(subContentElement.getAttribute("edit-request")); this.editContainerStyle = new FlexibleStringExpander(subContentElement.getAttribute("edit-container-style")); this.enableEditName = new FlexibleStringExpander(subContentElement.getAttribute("enable-edit-name")); this.xmlEscape = "true".equals(subContentElement.getAttribute("xml-escape")); this.width = subContentElement.getAttribute("width"); if (UtilValidate.isEmpty(this.width)) this.width="60%"; this.height = subContentElement.getAttribute("height"); if (UtilValidate.isEmpty(this.height)) this.width="400px"; this.border = subContentElement.getAttribute("border"); return; } public void renderWidgetString(Writer writer, Map context, ScreenStringRenderer screenStringRenderer) { try { // pushing the contentId on the context as "contentId" is done // because many times there will be embedded "subcontent" elements // that use the syntax: <subcontent content-id="${contentId}"... // and this is a step to make sure that it is there. GenericDelegator delegator = (GenericDelegator) context.get("delegator"); GenericValue content = null; String expandedDataResourceId = getDataResourceId(context); if (UtilValidate.isEmpty(expandedDataResourceId)) { String expandedContentId = getContentId(context); if (!(context instanceof MapStack)) { context = MapStack.create(context); } // This is an important step to make sure that the current contentId is in the context // as templates that contain "subcontent" elements will expect to find the master // contentId in the context as "contentId". ((MapStack) context).push(); context.put("contentId", expandedContentId); if (UtilValidate.isNotEmpty(expandedContentId)) { content = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", expandedContentId)); } expandedDataResourceId = content.getString("dataResourceId"); } GenericValue dataResource = null; if (UtilValidate.isNotEmpty(expandedDataResourceId)) { dataResource = delegator.findByPrimaryKeyCache("DataResource", UtilMisc.toMap("dataResourceId", expandedDataResourceId)); } String mimeTypeId = null; if (dataResource != null) { mimeTypeId = dataResource.getString("mimeTypeId"); } if (UtilValidate.isNotEmpty(mimeTypeId) && ((mimeTypeId.indexOf("application") >= 0) || (mimeTypeId.indexOf("image")) >= 0) ) { screenStringRenderer.renderContentFrame(writer, context, this); } else { screenStringRenderer.renderContentBegin(writer, context, this); screenStringRenderer.renderContentBody(writer, context, this); screenStringRenderer.renderContentEnd(writer, context, this); } ((MapStack) context).pop(); } catch (IOException e) { String errMsg = "Error rendering content with contentId [" + getContentId(context) + "]: " + e.toString(); Debug.logError(e, errMsg, module); throw new RuntimeException(errMsg); } catch (GenericEntityException e) { String errMsg = "Error obtaining content with contentId [" + getContentId(context) + "]: " + e.toString(); Debug.logError(e, errMsg, module); throw new RuntimeException(errMsg); } } public String getContentId(Map context) { return this.contentId.expandString(context); } public String getDataResourceId(Map context) { return this.dataResourceId.expandString(context); } public String getEditRequest(Map context) { return this.editRequest.expandString(context); } public String getEditContainerStyle(Map context) { return this.editContainerStyle.expandString(context); } public String getEnableEditName(Map context) { return this.enableEditName.expandString(context); } public boolean xmlEscape() { return this.xmlEscape; } public String rawString() { // may want to expand this a bit more return "<content content-id=\"" + this.contentId.getOriginal() + "\" xml-escape=\"" + this.xmlEscape + "\"/>"; } public String getWidth() { return this.width; } public String getHeight() { return this.height; } public String getBorder() { return this.border; } } public static class SubContent extends ModelScreenWidget { protected FlexibleStringExpander contentId; protected FlexibleStringExpander assocName; protected FlexibleStringExpander editRequest; protected FlexibleStringExpander editContainerStyle; protected FlexibleStringExpander enableEditName; protected boolean xmlEscape = false; public SubContent(ModelScreen modelScreen, Element subContentElement) { super(modelScreen, subContentElement); // put the text attribute first, then the pcdata under the element, if both are there of course this.contentId = new FlexibleStringExpander(UtilFormatOut.checkNull(subContentElement.getAttribute("content-id"))); this.assocName = new FlexibleStringExpander(UtilFormatOut.checkNull(subContentElement.getAttribute("assoc-name"))); this.editRequest = new FlexibleStringExpander(UtilFormatOut.checkNull(subContentElement.getAttribute("edit-request"))); this.editContainerStyle = new FlexibleStringExpander(subContentElement.getAttribute("edit-container-style")); this.enableEditName = new FlexibleStringExpander(subContentElement.getAttribute("enable-edit-name")); this.xmlEscape = "true".equals(subContentElement.getAttribute("xml-escape")); } public void renderWidgetString(Writer writer, Map context, ScreenStringRenderer screenStringRenderer) { try { screenStringRenderer.renderSubContentBegin(writer, context, this); screenStringRenderer.renderSubContentBody(writer, context, this); screenStringRenderer.renderSubContentEnd(writer, context, this); } catch (IOException e) { String errMsg = "Error rendering subContent with contentId [" + getContentId(context) + "]: " + e.toString(); Debug.logError(e, errMsg, module); throw new RuntimeException(errMsg); } } public String getContentId(Map context) { return this.contentId.expandString(context); } public String getAssocName(Map context) { return this.assocName.expandString(context); } public String getEditRequest(Map context) { return this.editRequest.expandString(context); } public String getEditContainerStyle(Map context) { return this.editContainerStyle.expandString(context); } public String getEnableEditName(Map context) { return this.enableEditName.expandString(context); } public boolean xmlEscape() { return this.xmlEscape; } public String rawString() { // may want to expand this a bit more return "<sub-content content-id=\"" + this.contentId.getOriginal() + "\" assoc-name=\"" + this.assocName.getOriginal() + "\" xml-escape=\"" + this.xmlEscape + "\"/>"; } } public static class Menu extends ModelScreenWidget { protected FlexibleStringExpander nameExdr; protected FlexibleStringExpander locationExdr; public Menu(ModelScreen modelScreen, Element menuElement) { super(modelScreen, menuElement); this.nameExdr = new FlexibleStringExpander(menuElement.getAttribute("name")); this.locationExdr = new FlexibleStringExpander(menuElement.getAttribute("location")); } public void renderWidgetString(Writer writer, Map context, ScreenStringRenderer screenStringRenderer) { String name = this.getName(context); String location = this.getLocation(context); ModelMenu modelMenu = null; try { modelMenu = MenuFactory.getMenuFromLocation(this.getLocation(context), this.getName(context), this.modelScreen.getDelegator(context), this.modelScreen.getDispatcher(context)); } catch (IOException e) { String errMsg = "Error rendering included menu named [" + name + "] at location [" + location + "]: " + e.toString(); Debug.logError(e, errMsg, module); throw new RuntimeException(errMsg); } catch (SAXException e) { String errMsg = "Error rendering included menu named [" + name + "] at location [" + location + "]: " + e.toString(); Debug.logError(e, errMsg, module); throw new RuntimeException(errMsg); } catch (ParserConfigurationException e) { String errMsg = "Error rendering included menu named [" + name + "] at location [" + location + "]: " + e.toString(); Debug.logError(e, errMsg, module); throw new RuntimeException(errMsg); } // try finding the menuStringRenderer by name in the context in case one was prepared and put there MenuStringRenderer menuStringRenderer = (MenuStringRenderer) context.get("menuStringRenderer"); // if there was no menuStringRenderer put in place, now try finding the request/response in the context and creating a new one if (menuStringRenderer == null) { HttpServletRequest request = (HttpServletRequest) context.get("request"); HttpServletResponse response = (HttpServletResponse) context.get("response"); if (request != null && response != null) { menuStringRenderer = new HtmlMenuRenderer(request, response); } } // still null, throw an error if (menuStringRenderer == null) { throw new IllegalArgumentException("Could not find a menuStringRenderer in the context, and could not find HTTP request/response objects need to create one."); } StringBuffer renderBuffer = new StringBuffer(); modelMenu.renderMenuString(renderBuffer, context, menuStringRenderer); try { writer.write(renderBuffer.toString()); } catch (IOException e) { String errMsg = "Error rendering included menu named [" + name + "] at location [" + location + "]: " + e.toString(); Debug.logError(e, errMsg, module); throw new RuntimeException(errMsg); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -