use of org.apache.ofbiz.webapp.control.RequestHandler in project ofbiz-framework by apache.
the class HtmlMenuRenderer method renderImage.
public void renderImage(Appendable writer, Map<String, Object> context, Image image) throws IOException {
// open tag
writer.append("<img ");
String id = image.getId(context);
if (UtilValidate.isNotEmpty(id)) {
writer.append(" id=\"");
writer.append(id);
writer.append("\"");
}
String style = image.getStyle(context);
if (UtilValidate.isNotEmpty(style)) {
writer.append(" class=\"");
writer.append(style);
writer.append("\"");
}
String wid = image.getWidth(context);
if (UtilValidate.isNotEmpty(wid)) {
writer.append(" width=\"");
writer.append(wid);
writer.append("\"");
}
String hgt = image.getHeight(context);
if (UtilValidate.isNotEmpty(hgt)) {
writer.append(" height=\"");
writer.append(hgt);
writer.append("\"");
}
String border = image.getBorder(context);
if (UtilValidate.isNotEmpty(border)) {
writer.append(" border=\"");
writer.append(border);
writer.append("\"");
}
String src = image.getSrc(context);
if (UtilValidate.isNotEmpty(src)) {
writer.append(" src=\"");
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");
if (urlMode != null && "ofbiz".equalsIgnoreCase(urlMode)) {
if (request != null && response != null) {
ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
String urlString = rh.makeLink(request, response, src, fullPath, secure, encode);
writer.append(urlString);
} else {
writer.append(src);
}
} else if (urlMode != null && "content".equalsIgnoreCase(urlMode)) {
if (request != null && response != null) {
StringBuilder newURL = new StringBuilder();
ContentUrlTag.appendContentPrefix(request, newURL);
newURL.append(src);
writer.append(newURL.toString());
}
} else {
writer.append(src);
}
writer.append("\"");
}
writer.append("/>");
}
use of org.apache.ofbiz.webapp.control.RequestHandler in project ofbiz-framework by apache.
the class HtmlMenuRenderer method appendOfbizUrl.
public void appendOfbizUrl(Appendable writer, String location) throws IOException {
ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
if (ctx == null) {
HttpSession session = request.getSession();
if (session != null) {
ctx = session.getServletContext();
}
if (ctx == null) {
throw new RuntimeException("ctx is null. location:" + location);
}
}
RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
// make and append the link
String s = rh.makeLink(this.request, this.response, location);
writer.append(s);
}
use of org.apache.ofbiz.webapp.control.RequestHandler in project ofbiz-framework by apache.
the class HtmlTreeRenderer method renderImage.
public void renderImage(Appendable writer, Map<String, Object> context, ModelTree.ModelNode.Image image) throws IOException {
// open tag
writer.append("<img ");
String id = image.getId(context);
if (UtilValidate.isNotEmpty(id)) {
writer.append(" id=\"");
writer.append(id);
writer.append("\"");
}
String style = image.getStyle(context);
if (UtilValidate.isNotEmpty(style)) {
writer.append(" class=\"");
writer.append(style);
writer.append("\"");
}
String wid = image.getWidth(context);
if (UtilValidate.isNotEmpty(wid)) {
writer.append(" width=\"");
writer.append(wid);
writer.append("\"");
}
String hgt = image.getHeight(context);
if (UtilValidate.isNotEmpty(hgt)) {
writer.append(" height=\"");
writer.append(hgt);
writer.append("\"");
}
String border = image.getBorder(context);
if (UtilValidate.isNotEmpty(border)) {
writer.append(" border=\"");
writer.append(border);
writer.append("\"");
}
String src = image.getSrc(context);
if (UtilValidate.isNotEmpty(src)) {
writer.append(" src=\"");
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");
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_");
String urlString = rh.makeLink(request, response, src, fullPath, secure, encode);
writer.append(urlString);
} else {
writer.append(src);
}
} else if (urlMode != null && "content".equalsIgnoreCase(urlMode)) {
if (request != null && response != null) {
StringBuilder newURL = new StringBuilder();
ContentUrlTag.appendContentPrefix(request, newURL);
newURL.append(src);
writer.append(newURL.toString());
}
} else {
writer.append(src);
}
writer.append("\"");
}
writer.append("/>");
}
use of org.apache.ofbiz.webapp.control.RequestHandler in project ofbiz-framework by apache.
the class MacroScreenRenderer method renderScreenletPaginateMenu.
protected void renderScreenletPaginateMenu(Appendable writer, Map<String, Object> context, ModelScreenWidget.Form form) throws IOException {
HttpServletResponse response = (HttpServletResponse) context.get("response");
HttpServletRequest request = (HttpServletRequest) context.get("request");
ModelForm modelForm;
try {
modelForm = form.getModelForm(context);
} catch (Exception e) {
throw new IOException(e);
}
modelForm.runFormActions(context);
Paginator.preparePager(modelForm, context);
String targetService = modelForm.getPaginateTarget(context);
if (targetService == null) {
targetService = "${targetService}";
}
// get the parametrized pagination index and size fields
int paginatorNumber = WidgetWorker.getPaginatorNumber(context);
String viewIndexParam = modelForm.getMultiPaginateIndexField(context);
String viewSizeParam = modelForm.getMultiPaginateSizeField(context);
int viewIndex = Paginator.getViewIndex(modelForm, context);
int viewSize = Paginator.getViewSize(modelForm, context);
int listSize = Paginator.getListSize(context);
int highIndex = Paginator.getHighIndex(context);
int actualPageSize = Paginator.getActualPageSize(context);
// if this is all there seems to be (if listSize < 0, then size is unknown)
if (actualPageSize >= listSize && listSize >= 0) {
return;
}
// needed for the "Page" and "rows" labels
Map<String, String> uiLabelMap = UtilGenerics.cast(context.get("uiLabelMap"));
String ofLabel = "";
if (uiLabelMap == null) {
Debug.logWarning("Could not find uiLabelMap in context", module);
} else {
ofLabel = uiLabelMap.get("CommonOf");
ofLabel = ofLabel.toLowerCase(Locale.getDefault());
}
// for legacy support, the viewSizeParam is VIEW_SIZE and viewIndexParam is VIEW_INDEX when the fields are "viewSize" and "viewIndex"
if (("viewIndex" + "_" + paginatorNumber).equals(viewIndexParam)) {
viewIndexParam = "VIEW_INDEX" + "_" + paginatorNumber;
}
if (("viewSize" + "_" + paginatorNumber).equals(viewSizeParam)) {
viewSizeParam = "VIEW_SIZE" + "_" + paginatorNumber;
}
ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
Map<String, Object> inputFields = UtilGenerics.toMap(context.get("requestParameters"));
// strip out any multi form fields if the form is of type multi
if ("multi".equals(modelForm.getType())) {
inputFields = UtilHttp.removeMultiFormParameters(inputFields);
}
String queryString = UtilHttp.urlEncodeArgs(inputFields);
// strip legacy viewIndex/viewSize params from the query string
queryString = UtilHttp.stripViewParamsFromQueryString(queryString, "" + paginatorNumber);
// strip parametrized index/size params from the query string
HashSet<String> paramNames = new HashSet<>();
paramNames.add(viewIndexParam);
paramNames.add(viewSizeParam);
queryString = UtilHttp.stripNamedParamsFromQueryString(queryString, paramNames);
String anchor = "";
String paginateAnchor = modelForm.getPaginateTargetAnchor();
if (paginateAnchor != null) {
anchor = "#" + paginateAnchor;
}
// preparing the link text, so that later in the code we can reuse this and just add the viewIndex
String prepLinkText = "";
prepLinkText = targetService;
if (prepLinkText.indexOf('?') < 0) {
prepLinkText += "?";
} else if (!prepLinkText.endsWith("?")) {
prepLinkText += "&";
}
if (UtilValidate.isNotEmpty(queryString) && !"null".equals(queryString)) {
prepLinkText += queryString + "&";
}
prepLinkText += viewSizeParam + "=" + viewSize + "&" + viewIndexParam + "=";
String linkText;
// The current screenlet title bar navigation syling requires rendering
// these links in reverse order
// Last button
String lastLinkUrl = "";
if (highIndex < listSize) {
int lastIndex = UtilMisc.getViewLastIndex(listSize, viewSize);
linkText = prepLinkText + lastIndex + anchor;
lastLinkUrl = rh.makeLink(request, response, linkText);
}
String nextLinkUrl = "";
if (highIndex < listSize) {
linkText = prepLinkText + (viewIndex + 1) + anchor;
// - make the link
nextLinkUrl = rh.makeLink(request, response, linkText);
}
String previousLinkUrl = "";
if (viewIndex > 0) {
linkText = prepLinkText + (viewIndex - 1) + anchor;
previousLinkUrl = rh.makeLink(request, response, linkText);
}
String firstLinkUrl = "";
if (viewIndex > 0) {
linkText = prepLinkText + 0 + anchor;
firstLinkUrl = rh.makeLink(request, response, linkText);
}
Map<String, Object> parameters = new HashMap<>();
parameters.put("lowIndex", Paginator.getLowIndex(context));
parameters.put("actualPageSize", actualPageSize);
parameters.put("ofLabel", ofLabel);
parameters.put("listSize", listSize);
parameters.put("paginateLastStyle", modelForm.getPaginateLastStyle());
parameters.put("lastLinkUrl", lastLinkUrl);
parameters.put("paginateLastLabel", modelForm.getPaginateLastLabel(context));
parameters.put("paginateNextStyle", modelForm.getPaginateNextStyle());
parameters.put("nextLinkUrl", nextLinkUrl);
parameters.put("paginateNextLabel", modelForm.getPaginateNextLabel(context));
parameters.put("paginatePreviousStyle", modelForm.getPaginatePreviousStyle());
parameters.put("paginatePreviousLabel", modelForm.getPaginatePreviousLabel(context));
parameters.put("previousLinkUrl", previousLinkUrl);
parameters.put("paginateFirstStyle", modelForm.getPaginateFirstStyle());
parameters.put("paginateFirstLabel", modelForm.getPaginateFirstLabel(context));
parameters.put("firstLinkUrl", firstLinkUrl);
executeMacro(writer, "renderScreenletPaginateMenu", parameters);
}
use of org.apache.ofbiz.webapp.control.RequestHandler in project ofbiz-framework by apache.
the class RomeEventHandler method invoke.
/**
* @see org.apache.ofbiz.webapp.event.EventHandler#invoke(ConfigXMLReader.Event, ConfigXMLReader.RequestMap, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public String invoke(Event event, RequestMap requestMap, HttpServletRequest request, HttpServletResponse response) throws EventHandlerException {
RequestHandler handler = (RequestHandler) request.getSession().getServletContext().getAttribute("_REQUEST_HANDLER_");
if (handler == null) {
throw new EventHandlerException("No request handler found in servlet context!");
}
// generate the main and entry links
String entryLinkReq = request.getParameter("entryLinkReq");
String mainLinkReq = request.getParameter("mainLinkReq");
// create the links; but the query string must be created by the service
String entryLink = handler.makeLink(request, response, entryLinkReq, true, false, false);
String mainLink = handler.makeLink(request, response, mainLinkReq, true, false, false);
request.setAttribute("entryLink", entryLink);
request.setAttribute("mainLink", mainLink);
String feedType = request.getParameter("feedType");
if (feedType == null) {
request.setAttribute("feedType", defaultFeedType);
}
// invoke the feed generator service (implements rssFeedInterface)
String respCode = service.invoke(event, requestMap, request, response);
// pull out the RSS feed from the request attributes
WireFeed wireFeed = (WireFeed) request.getAttribute("wireFeed");
response.setContentType(mime);
try {
out.output(wireFeed, response.getWriter());
} catch (IOException e) {
throw new EventHandlerException("Unable to get response writer", e);
} catch (FeedException e) {
throw new EventHandlerException("Unable to write RSS feed", e);
}
return respCode;
}
Aggregations