Search in sources :

Example 16 with RequestHandler

use of org.apache.ofbiz.webapp.control.RequestHandler in project ofbiz-framework by apache.

the class MacroScreenRenderer method renderContainerBegin.

public void renderContainerBegin(Appendable writer, Map<String, Object> context, ModelScreenWidget.Container container) throws IOException {
    String containerId = container.getId(context);
    String autoUpdateTarget = container.getAutoUpdateTargetExdr(context);
    HttpServletRequest request = (HttpServletRequest) context.get("request");
    String autoUpdateLink = "";
    if (UtilValidate.isNotEmpty(autoUpdateTarget) && UtilHttp.isJavaScriptEnabled(request)) {
        if (UtilValidate.isEmpty(containerId)) {
            containerId = getNextElementId();
        }
        HttpServletResponse response = (HttpServletResponse) context.get("response");
        ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
        RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
        autoUpdateLink = rh.makeLink(request, response, autoUpdateTarget);
    }
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("id", containerId);
    parameters.put("style", container.getStyle(context));
    parameters.put("autoUpdateLink", autoUpdateLink);
    parameters.put("autoUpdateInterval", container.getAutoUpdateInterval(context));
    executeMacro(writer, "renderContainerBegin", parameters);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RequestHandler(org.apache.ofbiz.webapp.control.RequestHandler) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletContext(javax.servlet.ServletContext)

Example 17 with RequestHandler

use of org.apache.ofbiz.webapp.control.RequestHandler in project ofbiz-framework by apache.

the class MacroScreenRenderer method renderContentFrame.

public void renderContentFrame(Appendable writer, Map<String, Object> context, ModelScreenWidget.Content content) throws IOException {
    String dataResourceId = content.getDataResourceId(context);
    String urlString = "/ViewSimpleContent?dataResourceId=" + dataResourceId;
    String fullUrlString = "";
    HttpServletRequest request = (HttpServletRequest) context.get("request");
    HttpServletResponse response = (HttpServletResponse) context.get("response");
    if (request != null && response != null) {
        ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
        RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
        fullUrlString = rh.makeLink(request, response, urlString, true, false, false);
    }
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("fullUrl", fullUrlString);
    parameters.put("width", content.getWidth());
    parameters.put("height", content.getHeight());
    parameters.put("border", content.getBorder());
    executeMacro(writer, "renderContentFrame", parameters);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RequestHandler(org.apache.ofbiz.webapp.control.RequestHandler) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletContext(javax.servlet.ServletContext)

Example 18 with RequestHandler

use of org.apache.ofbiz.webapp.control.RequestHandler in project ofbiz-framework by apache.

the class MacroScreenRenderer method renderContentEnd.

public void renderContentEnd(Appendable writer, Map<String, Object> context, ModelScreenWidget.Content content) throws IOException {
    String expandedContentId = content.getContentId(context);
    String editMode = "Edit";
    String editRequest = content.getEditRequest(context);
    String enableEditName = content.getEnableEditName(context);
    String enableEditValue = (String) context.get(enableEditName);
    String urlString = "";
    if (editRequest != null && editRequest.toUpperCase(Locale.getDefault()).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;
            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 = new HashMap<>();
        parameters.put("urlString", urlString);
        parameters.put("editMode", editMode);
        parameters.put("editContainerStyle", content.getEditContainerStyle(context));
        parameters.put("editRequest", editRequest);
        parameters.put("enableEditValue", enableEditValue);
        executeMacro(writer, "renderContentEnd", parameters);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RequestHandler(org.apache.ofbiz.webapp.control.RequestHandler) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletContext(javax.servlet.ServletContext)

Example 19 with RequestHandler

use of org.apache.ofbiz.webapp.control.RequestHandler in project ofbiz-framework by apache.

the class MacroScreenRenderer method renderImage.

public void renderImage(Appendable writer, Map<String, Object> context, ModelScreenWidget.ScreenImage image) throws IOException {
    if (image == null) {
        return;
    }
    String src = image.getSrc(context);
    String urlMode = image.getUrlMode();
    boolean fullPath = false;
    boolean secure = false;
    boolean encode = false;
    HttpServletResponse response = (HttpServletResponse) context.get("response");
    HttpServletRequest request = (HttpServletRequest) context.get("request");
    String urlString = "";
    if (urlMode != null && "intra-app".equalsIgnoreCase(urlMode)) {
        if (request != null && response != null) {
            ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
            RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
            urlString = rh.makeLink(request, response, src, fullPath, secure, encode);
        } else {
            urlString = src;
        }
    } else if (urlMode != null && "content".equalsIgnoreCase(urlMode)) {
        if (request != null && response != null) {
            StringBuilder newURL = new StringBuilder();
            ContentUrlTag.appendContentPrefix(request, newURL);
            newURL.append(src);
            urlString = newURL.toString();
        }
    } else {
        urlString = src;
    }
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("src", src);
    parameters.put("id", image.getId(context));
    parameters.put("style", image.getStyle(context));
    parameters.put("wid", image.getWidth(context));
    parameters.put("hgt", image.getHeight(context));
    parameters.put("border", image.getBorder(context));
    parameters.put("alt", image.getAlt(context));
    parameters.put("urlString", urlString);
    executeMacro(writer, "renderImage", parameters);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RequestHandler(org.apache.ofbiz.webapp.control.RequestHandler) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletContext(javax.servlet.ServletContext)

Example 20 with RequestHandler

use of org.apache.ofbiz.webapp.control.RequestHandler in project ofbiz-framework by apache.

the class MacroScreenRenderer method renderSubContentEnd.

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(Locale.getDefault()).indexOf("IMAGE") < 1)) {
        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 = new HashMap<>();
    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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RequestHandler(org.apache.ofbiz.webapp.control.RequestHandler) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletContext(javax.servlet.ServletContext)

Aggregations

RequestHandler (org.apache.ofbiz.webapp.control.RequestHandler)27 ServletContext (javax.servlet.ServletContext)24 HttpServletRequest (javax.servlet.http.HttpServletRequest)17 HttpServletResponse (javax.servlet.http.HttpServletResponse)17 HashMap (java.util.HashMap)10 IOException (java.io.IOException)9 Writer (java.io.Writer)7 Environment (freemarker.core.Environment)6 Locale (java.util.Locale)6 WeakHashMap (java.util.WeakHashMap)6 GeneralException (org.apache.ofbiz.base.util.GeneralException)6 GenericValue (org.apache.ofbiz.entity.GenericValue)6 HttpSession (javax.servlet.http.HttpSession)5 Delegator (org.apache.ofbiz.entity.Delegator)5 Map (java.util.Map)4 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)4 TemplateModelException (freemarker.template.TemplateModelException)3 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)3 EventHandlerException (org.apache.ofbiz.webapp.event.EventHandlerException)3 BeanModel (freemarker.ext.beans.BeanModel)2