Search in sources :

Example 1 with WidgetContextCacheKey

use of org.apache.ofbiz.widget.cache.WidgetContextCacheKey in project ofbiz-framework by apache.

the class ScreenRenderer method render.

/**
 * Renders the named screen using the render environment configured when this ScreenRenderer was created.
 *
 * @param resourceName The name/location of the resource to use, can use "component://[component-name]/" and "ofbiz://" and other special OFBiz style URLs
 * @param screenName The name of the screen within the XML file specified by the resourceName.
 * @throws IOException
 * @throws SAXException
 * @throws ParserConfigurationException
 */
public String render(String resourceName, String screenName) throws GeneralException, IOException, SAXException, ParserConfigurationException {
    ModelScreen modelScreen = ScreenFactory.getScreenFromLocation(resourceName, screenName);
    if (modelScreen.getUseCache()) {
        // if in the screen definition use-cache is set to true
        // then try to get an already built screen output from the cache:
        // 1) if we find it then we get it and attach it to the passed in writer
        // 2) if we can't find one, we create a new StringWriter,
        // and pass it to the renderScreenString;
        // then we wrap its content and put it in the cache;
        // and we attach it to the passed in writer
        WidgetContextCacheKey wcck = new WidgetContextCacheKey(context);
        String screenCombinedName = resourceName + ":" + screenName;
        ScreenCache screenCache = new ScreenCache();
        GenericWidgetOutput gwo = screenCache.get(screenCombinedName, wcck);
        if (gwo == null) {
            Writer sw = new StringWriter();
            modelScreen.renderScreenString(sw, context, screenStringRenderer);
            gwo = new GenericWidgetOutput(sw.toString());
            screenCache.put(screenCombinedName, wcck, gwo);
            writer.append(gwo.toString());
        } else {
            writer.append(gwo.toString());
        }
    } else {
        context.put("renderFormSeqNumber", String.valueOf(renderFormSeqNumber));
        modelScreen.renderScreenString(writer, context, screenStringRenderer);
    }
    return "";
}
Also used : WidgetContextCacheKey(org.apache.ofbiz.widget.cache.WidgetContextCacheKey) ScreenCache(org.apache.ofbiz.widget.cache.ScreenCache) StringWriter(java.io.StringWriter) ModelScreen(org.apache.ofbiz.widget.model.ModelScreen) GenericWidgetOutput(org.apache.ofbiz.widget.cache.GenericWidgetOutput) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Aggregations

StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 GenericWidgetOutput (org.apache.ofbiz.widget.cache.GenericWidgetOutput)1 ScreenCache (org.apache.ofbiz.widget.cache.ScreenCache)1 WidgetContextCacheKey (org.apache.ofbiz.widget.cache.WidgetContextCacheKey)1 ModelScreen (org.apache.ofbiz.widget.model.ModelScreen)1