Example usage for java.lang Appendable append

List of usage examples for java.lang Appendable append

Introduction

In this page you can find the example usage for java.lang Appendable append.

Prototype

Appendable append(char c) throws IOException;

Source Link

Document

Appends the specified character to this Appendable .

Usage

From source file:org.ramadda.util.HtmlUtils.java

/**
 * _more_/*  ww  w. j av a  2  s . co  m*/
 *
 * @param sb _more_
 * @param icon _more_
 * @param msg _more_
 *
 * @throws Exception _more_
 */
public static void tooltip(Appendable sb, String icon, String msg) throws Exception {
    String id = getUniqueId("tooltipblock_");
    String opener = getUniqueId("tooltipopener_");
    sb.append(img(icon, "Help", attr(ATTR_ID, opener) + cssClass("ramadda-tooltip-icon")));
    tag(sb, TAG_DIV, cssClass("ramadda-tooltip-contents") + attr(ATTR_ID, id), msg);
    HtmlUtils.script(sb,
            HtmlUtils.call("HtmlUtil.tooltipInit", HtmlUtils.squote(opener), HtmlUtils.squote(id)));
}

From source file:org.ramadda.util.HtmlUtils.java

/**
 * _more_/*from   w  ww  .  j  a v a  2s.com*/
 *
 * @param sb _more_
 * @param name _more_
 * @param value _more_
 * @param checked _more_
 * @param extra _more_
 */
public static void checkbox(Appendable sb, String name, String value, boolean checked, String extra) {
    try {
        dangleOpen(sb, TAG_INPUT);
        if (extra.length() > 0) {
            sb.append(extra);
        }
        attrs(sb, ATTR_TYPE, TYPE_CHECKBOX, ATTR_NAME, name, ATTR_VALUE, value);
        if (checked) {
            sb.append(" checked ");
        }
        sb.append(">");
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }

}

From source file:org.ramadda.util.HtmlUtils.java

/**
 * Add an accordian of sections to the page
 *
 * @param sb        the StringBuilder/StringBuilder to append to
 * @param titles    the title for each section
 * @param contents  the contents of each section
 * @param collapse  set the sections to be collapsed initially
 * @param wrapperClass _more_//from   w w w .  j  av  a2  s  .c  o  m
 * @param headerClass _more_
 *
 * @throws Exception  some problem
 */
public static void makeAccordian(Appendable sb, List<String> titles, List<String> contents, boolean collapse,
        String wrapperClass, String headerClass) throws Exception {

    String accordianId = "accordion_" + (blockCnt++);
    sb.append(HtmlUtils.open(HtmlUtils.TAG_DIV,
            HtmlUtils.cssClass(
                    ((wrapperClass != null) ? wrapperClass : "") + " ui-accordion ui-widget ui-helper-reset")
                    + HtmlUtils.id(accordianId)));
    for (int i = 0; i < titles.size(); i++) {
        String title = titles.get(i);
        String content = contents.get(i);
        sb.append(HtmlUtils.open(HtmlUtils.TAG_H3,
                HtmlUtils.cssClass(((headerClass != null) ? headerClass + " " : "")
                        + " ui-accordion-header ui-helper-reset ui-state-active ui-corner-top")));
        sb.append("<a href=\"#\">");
        sb.append(title);
        sb.append("</a></h3>");
        String contentsId = "accordion_contents_" + (blockCnt++);
        content = HtmlUtils.div(content,
                HtmlUtils.id(contentsId) + HtmlUtils.cssClass("ramadda-accordian-contents"));
        sb.append(HtmlUtils.div(content));
    }
    sb.append("</div>");

    String args = "{autoHeight: false, navigation: true, collapsible: true";
    if (collapse) {
        args += ", active: false}";
    } else {
        args += ", active: 0}";
    }

    HtmlUtils.script(sb, "HtmlUtil.makeAccordian(\"#" + accordianId + "\" " + "," + args + ");\n");
}

From source file:org.ramadda.data.services.PointFormHandler.java

/**
 * add the Settings//from ww  w  .  j ava 2s.c  o m
 *
 * @param request request
 * @param entry the entry
 * @param sb buffer to append to
 * @param recordEntry the recordentry
 *
 * @throws Exception On badness
 */
public void addSettingsForm(Request request, Entry entry, Appendable sb, RecordEntry recordEntry)
        throws Exception {

    boolean showUrl = request.get(ARG_SHOWURL, false);
    StringBuffer extra = new StringBuffer();
    extra.append(HtmlUtils.formTable());
    String initialDegrees = "" + getDefaultRadiusDegrees(request, entry.getBounds());

    if (request.defined(ARG_GRID_RADIUS_DEGREES)) {
        initialDegrees = request.getString(ARG_GRID_RADIUS_DEGREES, "");
    }

    String initialCells = "0";
    if (request.defined(ARG_GRID_RADIUS_CELLS)) {
        initialCells = request.getString(ARG_GRID_RADIUS_CELLS, "");
    }
    extra.append(HtmlUtils.hidden(ARG_GRID_RADIUS_DEGREES_ORIG, initialDegrees));
    extra.append(HtmlUtils.formEntry(msgLabel("Grid radius for IDW"),
            msgLabel("Degrees") + HtmlUtils.input(ARG_GRID_RADIUS_DEGREES, initialDegrees, 12)
                    + HtmlUtils.space(4) + msgLabel("or # of grid cells")
                    + HtmlUtils.input(ARG_GRID_RADIUS_CELLS, initialCells, 4)));

    extra.append(HtmlUtils.formEntry(msgLabel("Fill missing"),
            HtmlUtils.checkbox(PointOutputHandler.ARG_FILLMISSING, "true", false)));

    extra.append(HtmlUtils.formEntry(msgLabel("Hill shading"),
            msgLabel("Azimuth") + HtmlUtils.input(ARG_HILLSHADE_AZIMUTH, "315", 4) + HtmlUtils.space(4)
                    + msgLabel("Angle") + HtmlUtils.input(ARG_HILLSHADE_ANGLE, "45", 4)));
    extra.append(HtmlUtils.formEntry(msgLabel("Image Dimensions"),
            HtmlUtils.input(ARG_WIDTH, request.getString(ARG_WIDTH, "" + DFLT_WIDTH), 5) + " X "
                    + HtmlUtils.input(ARG_HEIGHT, request.getString(ARG_HEIGHT, "" + DFLT_HEIGHT), 5)));

    String paramWidget = null;
    List params = new ArrayList();
    //TODO: we need a better way to say this is a elevation point cloud
    //        if(pointEntry.isCapable(PointFile.ACTION_ELEVATION)) {
    params.add(new TwoFacedObject(msg(LABEL_ALTITUDE), ""));
    //        }
    if (recordEntry != null) {
        for (RecordField attr : recordEntry.getRecordFile().getChartableFields()) {
            params.add(new TwoFacedObject(attr.getLabel(), "" + attr.getParamId()));
        }
    }

    if (params.size() > 1) {
        extra.append(HtmlUtils.formEntry(msgLabel("Parameter for Image and Grid"),
                HtmlUtils.select(RecordOutputHandler.ARG_PARAMETER, params,
                        request.getString(RecordOutputHandler.ARG_PARAMETER, (String) null))));
    }

    extra.append(HtmlUtils.formEntry(msgLabel("Color Table"), HtmlUtils.select(ARG_COLORTABLE,
            ColorTable.getColorTableNames(), request.getString(ARG_COLORTABLE, (String) null))));

    extra.append(HtmlUtils.formTableClose());

    sb.append(HtmlUtils.row(HtmlUtils.colspan(formHeader("Advanced Settings"), 2)));

    if (recordEntry.isCapable(PointFile.ACTION_GRID)) {
        sb.append(HtmlUtils.formEntryTop(msgLabel("Gridding"),
                HtmlUtils.makeShowHideBlock(msg(""), extra.toString(), showUrl)));
    }

    StringBuffer points = new StringBuffer();
    points.append(HtmlUtils.formTable());
    points.append(HtmlUtils.formEntry("", HtmlUtils.checkbox(ARG_GEOREFERENCE, "true", false) + " "
            + msg("Convert coordinates to lat/lon if needed")));

    points.append(HtmlUtils.formEntry("",
            HtmlUtils.checkbox(ARG_INCLUDEWAVEFORM, "true", false) + " " + msg("Include waveforms")));

    points.append(HtmlUtils.formTableClose());
    sb.append(HtmlUtils.formEntryTop(msgLabel("Points"),
            HtmlUtils.makeShowHideBlock(msg(""), points.toString(), false)));

    StringBuffer processSB = new StringBuffer();
    processSB.append(HtmlUtils.formTable());
    processSB.append(
            HtmlUtils.formEntry("", HtmlUtils.checkbox(ARG_ASYNCH, "true", true) + " " + msg("Asynchronous")));

    processSB.append(HtmlUtils.formEntry(msgLabel("Alternate header"),
            HtmlUtils.input(ARG_HEADER, "") + " " + "Enter 'none' for no header"));

    processSB.append(HtmlUtils.formEntry("",
            HtmlUtils.checkbox(ARG_RESPONSE, RESPONSE_XML, false) + " Return response in XML"));

    processSB.append(HtmlUtils.formEntry("",
            HtmlUtils.checkbox(ARG_POINTCOUNT, "true", false) + " Just return the estimated point count"));

    getOutputHandler().addPublishWidget(request, entry, processSB,
            msg("Select a folder to publish the product to"));

    processSB.append(HtmlUtils.formTableClose());

    sb.append(HtmlUtils.formEntryTop(msgLabel("Processing"),
            HtmlUtils.makeShowHideBlock(msg(""), processSB.toString(), false)));

    sb.append(HtmlUtils.row(HtmlUtils.colspan(formHeader("Job Information"), 2)));

    User user = request.getUser();
    if (getAdmin().isEmailCapable()) {
        sb.append(HtmlUtils.formEntry(msgLabel("Send email to"),
                HtmlUtils.input(ARG_JOB_EMAIL, user.getEmail(), 40)));
    }
    sb.append(HtmlUtils.formEntry(msgLabel("Your name"), HtmlUtils.input(ARG_JOB_USER, user.getName(), 40)));

    sb.append(HtmlUtils.formEntry(msgLabel("Job name"), HtmlUtils.input(ARG_JOB_NAME, "", 40)));

    sb.append(HtmlUtils.formEntryTop(msgLabel("Description"),
            HtmlUtils.textArea(ARG_JOB_DESCRIPTION, "", 5, 40)));

}

From source file:org.ramadda.util.HtmlUtils.java

/**
 * _more_//from w  ww .j av  a 2  s .  c o m
 *
 * @param sb _more_
 * @param label _more_
 * @param content _more_
 * @param visible _more_
 */
public static void makeToggleInline(Appendable sb, String label, String content, boolean visible) {

    try {
        String hideImg = inlineHideImageUrl;
        String showImg = inlineShowImageUrl;
        if (hideImg == null) {
            hideImg = blockHideImageUrl;
        }
        if (showImg == null) {
            showImg = blockShowImageUrl;
        }
        String id = getUniqueId("block_");
        String img = "";
        if ((showImg != null) && (showImg.length() > 0)) {
            img = HtmlUtils.img(visible ? hideImg : showImg, "", " id='" + id + "img' ") + HtmlUtils.space(1);
        }
        String link = HtmlUtils.jsLink(HtmlUtils.onMouseClick(
                concat("toggleInlineVisibility('", id, "','", id, "img','", hideImg, "','", showImg, "')")),
                img + label, HtmlUtils.cssClass("toggleblocklabellink"));

        //        sb.append(RepositoryManager.tableSubHeader(link));
        sb.append(link);
        open(sb, TAG_SPAN, "class", "hideshowblock", "id", id, "style", "display:inline;visibility:visible");
        if (!visible) {
            HtmlUtils.script(sb, HtmlUtils.call("hide", HtmlUtils.squote(id)));
        }
        sb.append(content);
        sb.append(close(TAG_SPAN));
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }

}

From source file:org.ofbiz.widget.form.MacroFormRenderer.java

public void renderMultiFormClose(Appendable writer, Map<String, Object> context, ModelForm modelForm)
        throws IOException {
    //FIXME copy from HtmlFormRenderer.java (except for the closing form tag itself, that is now converted)
    Iterator<ModelFormField> submitFields = modelForm.getMultiSubmitFields().iterator();
    while (submitFields.hasNext()) {
        ModelFormField submitField = submitFields.next();
        if (submitField != null && submitField.shouldUse(context)) {

            // Threw this in that as a hack to keep the submit button from expanding the first field
            // Needs a more rugged solution
            // WARNING: this method (renderMultiFormClose) must be called after the
            // table that contains the list has been closed (to avoid validation errors) so
            // we cannot call here the methods renderFormatItemRowCell*: for this reason
            // they are now commented.

            // this.renderFormatItemRowCellOpen(writer, context, modelForm, submitField);
            // this.renderFormatItemRowCellClose(writer, context, modelForm, submitField);

            // this.renderFormatItemRowCellOpen(writer, context, modelForm, submitField);

            submitField.renderFieldString(writer, context, this);

            // this.renderFormatItemRowCellClose(writer, context, modelForm, submitField);

        }/*from  w ww . ja va 2 s  . c  om*/
    }
    StringWriter sr = new StringWriter();
    sr.append("<@renderMultiFormClose />");
    executeMacro(writer, sr.toString());

    // see if there is anything that needs to be added outside of the multi-form
    Map<String, Object> wholeFormContext = UtilGenerics.checkMap(context.get("wholeFormContext"));
    Appendable postMultiFormWriter = wholeFormContext != null
            ? (Appendable) wholeFormContext.get("postMultiFormWriter")
            : null;
    if (postMultiFormWriter != null) {
        writer.append(postMultiFormWriter.toString());
        appendWhitespace(writer);
    }

    renderEndingBoundaryComment(writer, "Form Widget - Form Element (Multi)", modelForm);
}

From source file:org.apache.ofbiz.content.data.DataResourceWorker.java

public static void renderDataResourceAsText(Delegator delegator, String dataResourceId, Appendable out,
        Map<String, Object> templateContext, Locale locale, String targetMimeTypeId, boolean cache,
        List<GenericValue> webAnalytics) throws GeneralException, IOException {
    if (dataResourceId == null) {
        throw new GeneralException("Cannot lookup data resource with for a null dataResourceId");
    }// www  .j ava2 s.c o m
    if (templateContext == null) {
        templateContext = new HashMap<String, Object>();
    }
    if (UtilValidate.isEmpty(targetMimeTypeId)) {
        targetMimeTypeId = "text/html";
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }

    // if the target mimeTypeId is not a text type, throw an exception
    if (!targetMimeTypeId.startsWith("text/")) {
        throw new GeneralException(
                "The desired mime-type is not a text type, cannot render as text: " + targetMimeTypeId);
    }

    // get the data resource object
    GenericValue dataResource = EntityQuery.use(delegator).from("DataResource")
            .where("dataResourceId", dataResourceId).cache(cache).queryOne();

    if (dataResource == null) {
        throw new GeneralException(
                "No data resource object found for dataResourceId: [" + dataResourceId + "]");
    }

    // a data template attached to the data resource
    String dataTemplateTypeId = dataResource.getString("dataTemplateTypeId");

    // no template; or template is NONE; render the data
    if (UtilValidate.isEmpty(dataTemplateTypeId) || "NONE".equals(dataTemplateTypeId)) {
        DataResourceWorker.writeDataResourceText(dataResource, targetMimeTypeId, locale, templateContext,
                delegator, out, cache);
    } else {
        // a template is defined; render the template first
        templateContext.put("mimeTypeId", targetMimeTypeId);

        // FTL template
        if ("FTL".equals(dataTemplateTypeId)) {
            try {
                // get the template data for rendering
                String templateText = getDataResourceText(dataResource, targetMimeTypeId, locale,
                        templateContext, delegator, cache);

                // if use web analytics.
                if (UtilValidate.isNotEmpty(webAnalytics)) {
                    StringBuffer newTemplateText = new StringBuffer(templateText);
                    String webAnalyticsCode = "<script language=\"JavaScript\" type=\"text/javascript\">";
                    for (GenericValue webAnalytic : webAnalytics) {
                        StringWrapper wrapString = StringUtil
                                .wrapString((String) webAnalytic.get("webAnalyticsCode"));
                        webAnalyticsCode += wrapString.toString();
                    }
                    webAnalyticsCode += "</script>";
                    newTemplateText.insert(templateText.lastIndexOf("</head>"), webAnalyticsCode);
                    templateText = newTemplateText.toString();
                }

                // render the FTL template
                boolean useTemplateCache = cache
                        && !UtilProperties.getPropertyAsBoolean("content", "disable.ftl.template.cache", false);
                Timestamp lastUpdatedStamp = dataResource.getTimestamp("lastUpdatedStamp");
                FreeMarkerWorker.renderTemplateFromString(
                        "delegator:" + delegator.getDelegatorName() + ":DataResource:" + dataResourceId,
                        templateText, templateContext, out, lastUpdatedStamp.getTime(), useTemplateCache);
            } catch (TemplateException e) {
                throw new GeneralException("Error rendering FTL template", e);
            }

        } else if ("XSLT".equals(dataTemplateTypeId)) {
            File sourceFileLocation = null;
            File targetFileLocation = new File(
                    System.getProperty("ofbiz.home") + "/runtime/tempfiles/docbook.css");
            if (templateContext.get("visualThemeId") != null) {
                Map<String, Object> layoutSettings = UtilGenerics
                        .checkMap(templateContext.get("layoutSettings"));
                List<String> docbookStyleSheets = UtilGenerics
                        .checkList(layoutSettings.get("VT_DOCBOOKSTYLESHEET"));
                String docbookStyleLocation = docbookStyleSheets.get(0);
                sourceFileLocation = new File(
                        System.getProperty("ofbiz.home") + "/themes" + docbookStyleLocation);
            }
            if (sourceFileLocation != null && sourceFileLocation.exists()) {
                UtilMisc.copyFile(sourceFileLocation, targetFileLocation);
            } else {
                String defaultVisualThemeId = EntityUtilProperties.getPropertyValue("general", "VISUAL_THEME",
                        delegator);
                if (defaultVisualThemeId != null) {
                    GenericValue themeValue = EntityQuery.use(delegator).from("VisualThemeResource")
                            .where("visualThemeId", defaultVisualThemeId, "resourceTypeEnumId",
                                    "VT_DOCBOOKSTYLESHEET", "sequenceId", "01")
                            .cache().queryOne();
                    sourceFileLocation = new File(
                            System.getProperty("ofbiz.home") + "/themes" + themeValue.get("resourceValue"));
                    UtilMisc.copyFile(sourceFileLocation, targetFileLocation);
                }
            }
            // get the template data for rendering
            String templateLocation = DataResourceWorker
                    .getContentFile(dataResource.getString("dataResourceTypeId"),
                            dataResource.getString("objectInfo"), (String) templateContext.get("contextRoot"))
                    .toString();
            // render the XSLT template and file
            String outDoc = null;
            try {
                outDoc = XslTransform.renderTemplate(templateLocation, (String) templateContext.get("docFile"));
            } catch (TransformerException c) {
                Debug.logError("XSL TransformerException: " + c.getMessage(), module);
            }
            out.append(outDoc);

            // Screen Widget template
        } else if ("SCREEN_COMBINED".equals(dataTemplateTypeId)) {
            try {
                MapStack<String> context = MapStack.create(templateContext);
                context.put("locale", locale);
                // prepare the map for preRenderedContent
                String textData = (String) context.get("textData");
                if (UtilValidate.isNotEmpty(textData)) {
                    Map<String, Object> prc = new HashMap<String, Object>();
                    String mapKey = (String) context.get("mapKey");
                    if (mapKey != null) {
                        prc.put(mapKey, mapKey);
                    }
                    prc.put("body", textData); // used for default screen defs
                    context.put("preRenderedContent", prc);
                }
                // get the screen renderer; or create a new one
                ScreenRenderer screens = (ScreenRenderer) context.get("screens");
                if (screens == null) {
                    // TODO: replace "screen" to support dynamic rendering of different output
                    ScreenStringRenderer screenStringRenderer = new MacroScreenRenderer(
                            EntityUtilProperties.getPropertyValue("widget", "screen.name", delegator),
                            EntityUtilProperties.getPropertyValue("widget", "screen.screenrenderer",
                                    delegator));
                    screens = new ScreenRenderer(out, context, screenStringRenderer);
                    screens.getContext().put("screens", screens);
                }
                // render the screen
                ModelScreen modelScreen = null;
                ScreenStringRenderer renderer = screens.getScreenStringRenderer();
                String combinedName = dataResource.getString("objectInfo");
                if ("URL_RESOURCE".equals(dataResource.getString("dataResourceTypeId"))
                        && UtilValidate.isNotEmpty(combinedName) && combinedName.startsWith("component://")) {
                    modelScreen = ScreenFactory.getScreenFromLocation(combinedName);
                } else { // stored in  a single file, long or short text
                    Document screenXml = UtilXml.readXmlDocument(getDataResourceText(dataResource,
                            targetMimeTypeId, locale, templateContext, delegator, cache), true, true);
                    Map<String, ModelScreen> modelScreenMap = ScreenFactory.readScreenDocument(screenXml,
                            "DataResourceId: " + dataResource.getString("dataResourceId"));
                    if (UtilValidate.isNotEmpty(modelScreenMap)) {
                        Map.Entry<String, ModelScreen> entry = modelScreenMap.entrySet().iterator().next(); // get first entry, only one screen allowed per file
                        modelScreen = entry.getValue();
                    }
                }
                if (UtilValidate.isNotEmpty(modelScreen)) {
                    modelScreen.renderScreenString(out, context, renderer);
                } else {
                    throw new GeneralException(
                            "The dataResource file [" + dataResourceId + "] could not be found");
                }
            } catch (SAXException e) {
                throw new GeneralException("Error rendering Screen template", e);
            } catch (ParserConfigurationException e) {
                throw new GeneralException("Error rendering Screen template", e);
            } catch (TemplateException e) {
                throw new GeneralException("Error creating Screen renderer", e);
            }
        } else {
            throw new GeneralException(
                    "The dataTemplateTypeId [" + dataTemplateTypeId + "] is not yet supported");
        }
    }
}

From source file:org.ofbiz.content.data.DataResourceWorker.java

public static void renderDataResourceAsText(Delegator delegator, String dataResourceId, Appendable out,
        Map<String, Object> templateContext, Locale locale, String targetMimeTypeId, boolean cache,
        List<GenericValue> webAnalytics) throws GeneralException, IOException {
    if (dataResourceId == null) {
        throw new GeneralException("Cannot lookup data resource with for a null dataResourceId");
    }/*  www.j a  v a2 s.  c o m*/
    if (templateContext == null) {
        templateContext = FastMap.newInstance();
    }
    if (UtilValidate.isEmpty(targetMimeTypeId)) {
        targetMimeTypeId = "text/html";
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }

    // check for a cached template
    if (cache) {
        String disableCache = EntityUtilProperties.getPropertyValue("content", "disable.ftl.template.cache",
                delegator);
        if (disableCache == null || !disableCache.equalsIgnoreCase("true")) {
            try {
                Template cachedTemplate = FreeMarkerWorker.getTemplate("DataResource:" + dataResourceId);
                if (cachedTemplate != null) {
                    String subContentId = (String) templateContext.get("subContentId");
                    if (UtilValidate.isNotEmpty(subContentId)) {
                        templateContext.put("contentId", subContentId);
                        templateContext.put("subContentId", null);
                        templateContext.put("globalNodeTrail", null); // Force getCurrentContent to query for subContent
                    }
                    FreeMarkerWorker.renderTemplate(cachedTemplate, templateContext, out);
                }
            } catch (TemplateException e) {
                Debug.logError("Error rendering FTL template. " + e.getMessage(), module);
                throw new GeneralException("Error rendering FTL template", e);
            }
            return;
        }
    }

    // if the target mimeTypeId is not a text type, throw an exception
    if (!targetMimeTypeId.startsWith("text/")) {
        throw new GeneralException(
                "The desired mime-type is not a text type, cannot render as text: " + targetMimeTypeId);
    }

    // get the data resource object
    GenericValue dataResource = EntityQuery.use(delegator).from("DataResource")
            .where("dataResourceId", dataResourceId).cache(cache).queryOne();

    if (dataResource == null) {
        throw new GeneralException(
                "No data resource object found for dataResourceId: [" + dataResourceId + "]");
    }

    // a data template attached to the data resource
    String dataTemplateTypeId = dataResource.getString("dataTemplateTypeId");

    // no template; or template is NONE; render the data
    if (UtilValidate.isEmpty(dataTemplateTypeId) || "NONE".equals(dataTemplateTypeId)) {
        DataResourceWorker.writeDataResourceText(dataResource, targetMimeTypeId, locale, templateContext,
                delegator, out, true);
    } else {
        // a template is defined; render the template first
        templateContext.put("mimeTypeId", targetMimeTypeId);

        // FTL template
        if ("FTL".equals(dataTemplateTypeId)) {
            try {
                // get the template data for rendering
                String templateText = getDataResourceText(dataResource, targetMimeTypeId, locale,
                        templateContext, delegator, cache);

                // if use web analytics.
                if (UtilValidate.isNotEmpty(webAnalytics)) {
                    StringBuffer newTemplateText = new StringBuffer(templateText);
                    String webAnalyticsCode = "<script language=\"JavaScript\" type=\"text/javascript\">";
                    for (GenericValue webAnalytic : webAnalytics) {
                        StringWrapper wrapString = StringUtil
                                .wrapString((String) webAnalytic.get("webAnalyticsCode"));
                        webAnalyticsCode += wrapString.toString();
                    }
                    webAnalyticsCode += "</script>";
                    newTemplateText.insert(templateText.lastIndexOf("</head>"), webAnalyticsCode);
                    templateText = newTemplateText.toString();
                }

                // render the FTL template
                FreeMarkerWorker.renderTemplate("DataResource:" + dataResourceId, templateText, templateContext,
                        out);
            } catch (TemplateException e) {
                throw new GeneralException("Error rendering FTL template", e);
            }

        } else if ("XSLT".equals(dataTemplateTypeId)) {
            File sourceFileLocation = null;
            File targetFileLocation = new File(
                    System.getProperty("ofbiz.home") + "/runtime/tempfiles/docbook.css");
            if (templateContext.get("visualThemeId") != null) {
                Map<String, Object> layoutSettings = UtilGenerics
                        .checkMap(templateContext.get("layoutSettings"));
                List<String> docbookStyleSheets = UtilGenerics
                        .checkList(layoutSettings.get("VT_DOCBOOKSTYLESHEET"));
                String docbookStyleLocation = docbookStyleSheets.get(0);
                sourceFileLocation = new File(
                        System.getProperty("ofbiz.home") + "/themes" + docbookStyleLocation);
            }
            if (sourceFileLocation != null && sourceFileLocation.exists()) {
                UtilMisc.copyFile(sourceFileLocation, targetFileLocation);
            } else {
                String defaultVisualThemeId = EntityUtilProperties.getPropertyValue("general", "VISUAL_THEME",
                        delegator);
                if (defaultVisualThemeId != null) {
                    GenericValue themeValue = EntityQuery.use(delegator).from("VisualThemeResource")
                            .where("visualThemeId", defaultVisualThemeId, "resourceTypeEnumId",
                                    "VT_DOCBOOKSTYLESHEET", "sequenceId", "01")
                            .cache().queryOne();
                    sourceFileLocation = new File(
                            System.getProperty("ofbiz.home") + "/themes" + themeValue.get("resourceValue"));
                    UtilMisc.copyFile(sourceFileLocation, targetFileLocation);
                }
            }
            // get the template data for rendering
            String templateLocation = DataResourceWorker
                    .getContentFile(dataResource.getString("dataResourceTypeId"),
                            dataResource.getString("objectInfo"), (String) templateContext.get("contextRoot"))
                    .toString();
            // render the XSLT template and file
            String outDoc = null;
            try {
                outDoc = XslTransform.renderTemplate(templateLocation, (String) templateContext.get("docFile"));
            } catch (TransformerException c) {
                Debug.logError("XSL TransformerException: " + c.getMessage(), module);
            }
            out.append(outDoc);

            // Screen Widget template
        } else if ("SCREEN_COMBINED".equals(dataTemplateTypeId)) {
            try {
                MapStack<String> context = MapStack.create(templateContext);
                context.put("locale", locale);
                // prepare the map for preRenderedContent
                String textData = (String) context.get("textData");
                if (UtilValidate.isNotEmpty(textData)) {
                    Map<String, Object> prc = FastMap.newInstance();
                    String mapKey = (String) context.get("mapKey");
                    if (mapKey != null) {
                        prc.put(mapKey, mapKey);
                    }
                    prc.put("body", textData); // used for default screen defs
                    context.put("preRenderedContent", prc);
                }
                // get the screen renderer; or create a new one
                ScreenRenderer screens = (ScreenRenderer) context.get("screens");
                if (screens == null) {
                    // TODO: replace "screen" to support dynamic rendering of different output
                    ScreenStringRenderer screenStringRenderer = new MacroScreenRenderer(
                            EntityUtilProperties.getPropertyValue("widget", "screen.name", delegator),
                            EntityUtilProperties.getPropertyValue("widget", "screen.screenrenderer",
                                    delegator));
                    screens = new ScreenRenderer(out, context, screenStringRenderer);
                    screens.getContext().put("screens", screens);
                }
                // render the screen
                ModelScreen modelScreen = null;
                ScreenStringRenderer renderer = screens.getScreenStringRenderer();
                String combinedName = dataResource.getString("objectInfo");
                if ("URL_RESOURCE".equals(dataResource.getString("dataResourceTypeId"))
                        && UtilValidate.isNotEmpty(combinedName) && combinedName.startsWith("component://")) {
                    modelScreen = ScreenFactory.getScreenFromLocation(combinedName);
                } else { // stored in  a single file, long or short text
                    Document screenXml = UtilXml.readXmlDocument(getDataResourceText(dataResource,
                            targetMimeTypeId, locale, templateContext, delegator, cache), true, true);
                    Map<String, ModelScreen> modelScreenMap = ScreenFactory.readScreenDocument(screenXml,
                            "DataResourceId: " + dataResource.getString("dataResourceId"));
                    if (UtilValidate.isNotEmpty(modelScreenMap)) {
                        Map.Entry<String, ModelScreen> entry = modelScreenMap.entrySet().iterator().next(); // get first entry, only one screen allowed per file
                        modelScreen = entry.getValue();
                    }
                }
                if (UtilValidate.isNotEmpty(modelScreen)) {
                    modelScreen.renderScreenString(out, context, renderer);
                } else {
                    throw new GeneralException(
                            "The dataResource file [" + dataResourceId + "] could not be found");
                }
            } catch (SAXException e) {
                throw new GeneralException("Error rendering Screen template", e);
            } catch (ParserConfigurationException e) {
                throw new GeneralException("Error rendering Screen template", e);
            } catch (TemplateException e) {
                throw new GeneralException("Error creating Screen renderer", e);
            }
        } else {
            throw new GeneralException(
                    "The dataTemplateTypeId [" + dataTemplateTypeId + "] is not yet supported");
        }
    }
}