📄 modelscreenwidget.java
字号:
// render sub-widgets renderSubWidgetsString(this.failWidgets, writer, context, screenStringRenderer); screenStringRenderer.renderSectionEnd(writer, context, this); } catch (IOException e) { String errMsg = "Error rendering fail-widgets section [" + this.getName() + "] in screen named [" + this.modelScreen.getName() + "]: " + e.toString(); Debug.logError(e, errMsg, module); throw new RuntimeException(errMsg); } } } public String getName() { return name; } public String rawString() { return "<section" + (UtilValidate.isNotEmpty(this.name)?" name=\"" + this.name + "\"":"") + ">"; } } public static class Container extends ModelScreenWidget { protected FlexibleStringExpander idExdr; protected FlexibleStringExpander styleExdr; protected List subWidgets; public Container(ModelScreen modelScreen, Element containerElement) { super(modelScreen, containerElement); this.idExdr = new FlexibleStringExpander(containerElement.getAttribute("id")); this.styleExdr = new FlexibleStringExpander(containerElement.getAttribute("style")); // read sub-widgets List subElementList = UtilXml.childElementList(containerElement); this.subWidgets = ModelScreenWidget.readSubWidgets(this.modelScreen, subElementList); return; } public void renderWidgetString(Writer writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException { try { screenStringRenderer.renderContainerBegin(writer, context, this); // render sub-widgets renderSubWidgetsString(this.subWidgets, writer, context, screenStringRenderer); screenStringRenderer.renderContainerEnd(writer, context, this); } catch (IOException e) { String errMsg = "Error rendering container in screen named [" + this.modelScreen.getName() + "]: " + e.toString(); Debug.logError(e, errMsg, module); throw new RuntimeException(errMsg); } } public String getId(Map context) { return this.idExdr.expandString(context); } public String getStyle(Map context) { return this.styleExdr.expandString(context); } public String rawString() { return "<container id=\"" + this.idExdr.getOriginal() + "\" style=\"" + this.styleExdr.getOriginal() + "\">"; } } public static class IncludeScreen extends ModelScreenWidget { protected FlexibleStringExpander nameExdr; protected FlexibleStringExpander locationExdr; protected FlexibleStringExpander shareScopeExdr; public IncludeScreen(ModelScreen modelScreen, Element includeScreenElement) { super(modelScreen, includeScreenElement); this.nameExdr = new FlexibleStringExpander(includeScreenElement.getAttribute("name")); this.locationExdr = new FlexibleStringExpander(includeScreenElement.getAttribute("location")); this.shareScopeExdr = new FlexibleStringExpander(includeScreenElement.getAttribute("share-scope")); } public void renderWidgetString(Writer writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException { // if we are not sharing the scope, protect it using the MapStack boolean protectScope = !shareScope(context); if (protectScope) { if (!(context instanceof MapStack)) { context = MapStack.create(context); } ((MapStack) context).push(); // build the widgetpath List widgetTrail = (List) context.get("_WIDGETTRAIL_"); if (widgetTrail == null) { widgetTrail = new ArrayList(); } String thisName = nameExdr.expandString(context); widgetTrail.add(thisName); context.put("_WIDGETTRAIL_", widgetTrail); } // dont need the renderer here, will just pass this on down to another screen call; screenStringRenderer.renderContainerBegin(writer, context, this); String name = this.getName(context); String location = this.getLocation(context); if (UtilValidate.isEmpty(name)) { if (Debug.infoOn()) Debug.logInfo("In the include-screen tag the screen name was empty, ignoring include; in screen [" + this.modelScreen.getName() + "]", module); return; } // check to see if the name is a composite name separated by a #, if so split it up and get it by the full loc#name if (ScreenFactory.isCombinedName(name)) { String combinedName = name; location = ScreenFactory.getResourceNameFromCombined(combinedName); name = ScreenFactory.getScreenNameFromCombined(combinedName); } ModelScreen modelScreen = null; if (UtilValidate.isNotEmpty(location)) { try { modelScreen = ScreenFactory.getScreenFromLocation(location, name); } catch (IOException e) { String errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString(); Debug.logError(e, errMsg, module); throw new RuntimeException(errMsg); } catch (SAXException e) { String errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString(); Debug.logError(e, errMsg, module); throw new RuntimeException(errMsg); } catch (ParserConfigurationException e) { String errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString(); Debug.logError(e, errMsg, module); throw new RuntimeException(errMsg); } } else { modelScreen = (ModelScreen) this.modelScreen.modelScreenMap.get(name); if (modelScreen == null) { throw new IllegalArgumentException("Could not find screen with name [" + name + "] in the same file as the screen with name [" + this.modelScreen.getName() + "]"); } } modelScreen.renderScreenString(writer, context, screenStringRenderer); if (protectScope) { ((MapStack) context).pop(); } } public String getName(Map context) { return this.nameExdr.expandString(context); } public String getLocation(Map context) { return this.locationExdr.expandString(context); } public boolean shareScope(Map context) { String shareScopeString = this.shareScopeExdr.expandString(context); // defaults to false, so anything but true is false return "true".equals(shareScopeString); } public String rawString() { return "<include-screen name=\"" + this.nameExdr.getOriginal() + "\" location=\"" + this.locationExdr.getOriginal() + "\" share-scope=\"" + this.shareScopeExdr.getOriginal() + "\"/>"; } } public static class DecoratorScreen extends ModelScreenWidget { protected FlexibleStringExpander nameExdr; protected FlexibleStringExpander locationExdr; protected Map sectionMap = new HashMap(); public DecoratorScreen(ModelScreen modelScreen, Element decoratorScreenElement) { super(modelScreen, decoratorScreenElement); this.nameExdr = new FlexibleStringExpander(decoratorScreenElement.getAttribute("name")); this.locationExdr = new FlexibleStringExpander(decoratorScreenElement.getAttribute("location")); List decoratorSectionElementList = UtilXml.childElementList(decoratorScreenElement, "decorator-section"); Iterator decoratorSectionElementIter = decoratorSectionElementList.iterator(); while (decoratorSectionElementIter.hasNext()) { Element decoratorSectionElement = (Element) decoratorSectionElementIter.next(); String name = decoratorSectionElement.getAttribute("name"); this.sectionMap.put(name, new DecoratorSection(modelScreen, decoratorSectionElement)); } } public void renderWidgetString(Writer writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException { // isolate the scope if (!(context instanceof MapStack)) { context = MapStack.create(context); } MapStack contextMs = (MapStack) context; // create a standAloneStack, basically a "save point" for this SectionsRenderer, and make a new "screens" object just for it so it is isolated and doesn't follow the stack down MapStack standAloneStack = contextMs.standAloneChildStack(); standAloneStack.put("screens", new ScreenRenderer(writer, contextMs, screenStringRenderer)); SectionsRenderer sections = new SectionsRenderer(this.sectionMap, standAloneStack, writer, screenStringRenderer); // put the sectionMap in the context, make sure it is in the sub-scope, ie after calling push on the MapStack contextMs.push(); context.put("sections", sections); String name = this.getName(context); String location = this.getLocation(context); // check to see if the name is a composite name separated by a #, if so split it up and get it by the full loc#name if (ScreenFactory.isCombinedName(name)) { String combinedName = name; location = ScreenFactory.getResourceNameFromCombined(combinedName); name = ScreenFactory.getScreenNameFromCombined(combinedName); } ModelScreen modelScreen = null; if (UtilValidate.isNotEmpty(location)) { try { modelScreen = ScreenFactory.getScreenFromLocation(location, name); } catch (IOException e) { String errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString(); Debug.logError(e, errMsg, module); throw new RuntimeException(errMsg); } catch (SAXException e) { String errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString(); Debug.logError(e, errMsg, module); throw new RuntimeException(errMsg); } catch (ParserConfigurationException e) { String errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString(); Debug.logError(e, errMsg, module); throw new RuntimeException(errMsg); } } else { modelScreen = (ModelScreen) this.modelScreen.modelScreenMap.get(name); if (modelScreen == null) { throw new IllegalArgumentException("Could not find screen with name [" + name + "] in the same file as the screen with name [" + this.modelScreen.getName() + "]"); } } modelScreen.renderScreenString(writer, context, screenStringRenderer); contextMs.pop(); } public String getName(Map context) { return this.nameExdr.expandString(context); } public String getLocation(Map context) { return this.locationExdr.expandString(context); } public String rawString() { return "<decorator-screen name=\"" + this.nameExdr.getOriginal() + "\" location=\"" + this.locationExdr.getOriginal() + "\"/>"; } } public static class DecoratorSection extends ModelScreenWidget { protected String name; protected List subWidgets; public DecoratorSection(ModelScreen modelScreen, Element decoratorSectionElement) { super(modelScreen, decoratorSectionElement); this.name = decoratorSectionElement.getAttribute("name"); // read sub-widgets List subElementList = UtilXml.childElementList(decoratorSectionElement); this.subWidgets = ModelScreenWidget.readSubWidgets(this.modelScreen, subElementList); } public void renderWidgetString(Writer writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -