public void renderSubContentBegin(
      Appendable writer, Map<String, Object> context, ModelScreenWidget.SubContent content)
      throws IOException {
    String enableEditName = content.getEnableEditName(context);
    String enableEditValue = (String) context.get(enableEditName);

    Map<String, Object> parameters = FastMap.newInstance();
    parameters.put("editContainerStyle", content.getEditContainerStyle(context));
    parameters.put("editRequest", content.getEditRequest(context));
    parameters.put("enableEditValue", enableEditValue == null ? "" : enableEditValue);
    executeMacro(writer, "renderSubContentBegin", parameters);
  }
  public void renderSubContentEnd(
      Appendable writer, Map<String, Object> context, ModelScreenWidget.SubContent content)
      throws IOException {
    String editMode = "Edit";
    String editRequest = content.getEditRequest(context);
    String enableEditName = content.getEnableEditName(context);
    String enableEditValue = (String) context.get(enableEditName);
    String expandedContentId = content.getContentId(context);
    String expandedMapKey = content.getMapKey(context);
    String urlString = "";
    if (editRequest != null && editRequest.toUpperCase().indexOf("IMAGE") > 0) {
      editMode += " Image";
    }
    if (UtilValidate.isNotEmpty(editRequest) && "true".equals(enableEditValue)) {
      HttpServletResponse response = (HttpServletResponse) context.get("response");
      HttpServletRequest request = (HttpServletRequest) context.get("request");
      if (request != null && response != null) {
        if (editRequest.indexOf("?") < 0) editRequest += "?";
        else editRequest += "&amp;";
        editRequest += "contentId=" + expandedContentId;
        if (UtilValidate.isNotEmpty(expandedMapKey)) {
          editRequest += "&amp;mapKey=" + expandedMapKey;
        }
        ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
        RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
        urlString = rh.makeLink(request, response, editRequest, false, false, false);
      }
    }

    Map<String, Object> parameters = FastMap.newInstance();
    parameters.put("urlString", urlString);
    parameters.put("editMode", editMode);
    parameters.put("editContainerStyle", content.getEditContainerStyle(context));
    parameters.put("editRequest", editRequest);
    parameters.put("enableEditValue", enableEditValue == null ? "" : enableEditValue);
    executeMacro(writer, "renderSubContentEnd", parameters);
  }
  public void renderSubContentBody(
      Appendable writer, Map<String, Object> context, ModelScreenWidget.SubContent content)
      throws IOException {
    Locale locale = UtilMisc.ensureLocale(context.get("locale"));
    String mimeTypeId = "text/html";
    String expandedContentId = content.getContentId(context);
    String expandedMapKey = content.getMapKey(context);
    String renderedContent = "";
    LocalDispatcher dispatcher = (LocalDispatcher) context.get("dispatcher");
    Delegator delegator = (Delegator) context.get("delegator");

    // create a new map for the content rendering; so our current context does not get overwritten!
    Map<String, Object> contentContext = FastMap.newInstance();
    contentContext.putAll(context);

    try {
      if (WidgetContentWorker.contentWorker != null) {
        renderedContent =
            WidgetContentWorker.contentWorker.renderSubContentAsTextExt(
                dispatcher,
                delegator,
                expandedContentId,
                expandedMapKey,
                contentContext,
                locale,
                mimeTypeId,
                true);
        // Debug.logInfo("renderedContent=" + renderedContent, module);
      } else {
        Debug.logError(
            "Not rendering content, WidgetContentWorker.contentWorker not found.", module);
      }
      if (UtilValidate.isEmpty(renderedContent)) {
        String editRequest = content.getEditRequest(context);
        if (UtilValidate.isNotEmpty(editRequest)) {
          if (WidgetContentWorker.contentWorker != null) {
            WidgetContentWorker.contentWorker.renderContentAsTextExt(
                dispatcher,
                delegator,
                "NOCONTENTFOUND",
                writer,
                contentContext,
                locale,
                mimeTypeId,
                true);
          } else {
            Debug.logError(
                "Not rendering content, WidgetContentWorker.contentWorker not found.", module);
          }
        }
      } else {
        if (content.xmlEscape()) {
          renderedContent = UtilFormatOut.encodeXmlValue(renderedContent);
        }

        writer.append(renderedContent);
      }

    } catch (GeneralException e) {
      String errMsg =
          "Error rendering included content with id [" + expandedContentId + "] : " + e.toString();
      Debug.logError(e, errMsg, module);
      // throw new RuntimeException(errMsg);
    } catch (IOException e2) {
      String errMsg =
          "Error rendering included content with id [" + expandedContentId + "] : " + e2.toString();
      Debug.logError(e2, errMsg, module);
      // throw new RuntimeException(errMsg);
    }
  }