use of org.apache.ofbiz.webapp.control.RequestHandler in project ofbiz-framework by apache.
the class MacroTreeRenderer method renderImage.
public void renderImage(Appendable writer, Map<String, Object> context, ModelTree.ModelNode.Image image) throws IOException {
if (image == null) {
return;
}
HttpServletResponse response = (HttpServletResponse) context.get("response");
HttpServletRequest request = (HttpServletRequest) context.get("request");
String urlMode = image.getUrlMode();
String src = image.getSrc(context);
String id = image.getId(context);
String style = image.getStyle(context);
String wid = image.getWidth(context);
String hgt = image.getHeight(context);
String border = image.getBorder(context);
// TODO add alt to tree images image.getAlt(context);
String alt = "";
boolean fullPath = false;
boolean secure = false;
boolean encode = false;
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;
}
StringWriter sr = new StringWriter();
sr.append("<@renderImage ");
sr.append("src=\"");
sr.append(src);
sr.append("\" id=\"");
sr.append(id);
sr.append("\" style=\"");
sr.append(style);
sr.append("\" wid=\"");
sr.append(wid);
sr.append("\" hgt=\"");
sr.append(hgt);
sr.append("\" border=\"");
sr.append(border);
sr.append("\" alt=\"");
sr.append(alt);
sr.append("\" urlString=\"");
sr.append(urlString);
sr.append("\" />");
executeMacro(sr.toString());
}
use of org.apache.ofbiz.webapp.control.RequestHandler in project ofbiz-framework by apache.
the class MacroMenuRenderer method createImageParameters.
// Made this a separate method so it can be externalized and reused.
private Map<String, Object> createImageParameters(Map<String, Object> context, Image image) {
Map<String, Object> parameters = new HashMap<>();
parameters.put("id", image.getId(context));
parameters.put("style", image.getStyle(context));
parameters.put("width", image.getWidth(context));
parameters.put("height", image.getHeight(context));
parameters.put("border", image.getBorder(context));
String src = image.getSrc(context);
if (UtilValidate.isNotEmpty(src) && request != null && response != null) {
String urlMode = image.getUrlMode();
if ("ofbiz".equalsIgnoreCase(urlMode)) {
boolean fullPath = false;
boolean secure = false;
boolean encode = false;
ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
src = rh.makeLink(request, response, src, fullPath, secure, encode);
} else if ("content".equalsIgnoreCase(urlMode)) {
StringBuilder newURL = new StringBuilder();
ContentUrlTag.appendContentPrefix(request, newURL);
newURL.append(src);
src = newURL.toString();
}
}
parameters.put("src", src);
return parameters;
}
use of org.apache.ofbiz.webapp.control.RequestHandler in project ofbiz-framework by apache.
the class ProductSearchSession method checkDoKeywordOverride.
/**
* A ControlServlet event method used to check to see if there is an override for any of the current keywords in the search
*/
public static final String checkDoKeywordOverride(HttpServletRequest request, HttpServletResponse response) {
HttpSession session = request.getSession();
Delegator delegator = (Delegator) request.getAttribute("delegator");
Map<String, Object> requestParams = UtilHttp.getParameterMap(request);
// get the current productStoreId
String productStoreId = ProductStoreWorker.getProductStoreId(request);
if (productStoreId != null) {
// get a Set of all keywords in the search, if there are any...
Set<String> keywords = new HashSet<>();
List<ProductSearchConstraint> constraintList = ProductSearchOptions.getConstraintList(session);
if (constraintList != null) {
for (ProductSearchConstraint constraint : constraintList) {
if (constraint instanceof KeywordConstraint) {
KeywordConstraint keywordConstraint = (KeywordConstraint) constraint;
Set<String> keywordSet = keywordConstraint.makeFullKeywordSet(delegator);
if (keywordSet != null) {
keywords.addAll(keywordSet);
}
}
}
}
if (keywords.size() > 0) {
List<GenericValue> productStoreKeywordOvrdList = null;
try {
productStoreKeywordOvrdList = EntityQuery.use(delegator).from("ProductStoreKeywordOvrd").where("productStoreId", productStoreId).orderBy("-fromDate").cache(true).filterByDate().queryList();
} catch (GenericEntityException e) {
Debug.logError(e, "Error reading ProductStoreKeywordOvrd list, not doing keyword override", module);
}
if (UtilValidate.isNotEmpty(productStoreKeywordOvrdList)) {
for (GenericValue productStoreKeywordOvrd : productStoreKeywordOvrdList) {
String ovrdKeyword = productStoreKeywordOvrd.getString("keyword");
if (keywords.contains(ovrdKeyword)) {
String targetTypeEnumId = productStoreKeywordOvrd.getString("targetTypeEnumId");
String target = productStoreKeywordOvrd.getString("target");
ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
if ("KOTT_PRODCAT".equals(targetTypeEnumId)) {
String requestName = "/category/~category_id=" + target;
target = rh.makeLink(request, response, requestName, false, false, false);
} else if ("KOTT_PRODUCT".equals(targetTypeEnumId)) {
String requestName = "/product/~product_id=" + target;
target = rh.makeLink(request, response, requestName, false, false, false);
} else if ("KOTT_OFBURL".equals(targetTypeEnumId)) {
target = rh.makeLink(request, response, target, false, false, false);
} else if ("KOTT_AURL".equals(targetTypeEnumId)) {
// do nothing, is absolute URL
} else {
Debug.logError("The targetTypeEnumId [] is not recognized, not doing keyword override", module);
// might as well see if there are any others...
continue;
}
try {
response.sendRedirect(target);
return "none";
} catch (IOException e) {
Debug.logError(e, "Could not send redirect to: " + target, module);
continue;
}
}
}
}
}
}
return "success";
}
use of org.apache.ofbiz.webapp.control.RequestHandler in project ofbiz-framework by apache.
the class SeoTransform method getWriter.
public Writer getWriter(final Writer out, Map args) {
final StringBuffer buf = new StringBuffer();
final boolean fullPath = checkArg(args, "fullPath", false);
final boolean secure = checkArg(args, "secure", false);
final boolean encode = checkArg(args, "encode", true);
return new Writer(out) {
public void write(char[] cbuf, int off, int len) {
buf.append(cbuf, off, len);
}
public void flush() throws IOException {
out.flush();
}
public void close() throws IOException {
try {
Environment env = Environment.getCurrentEnvironment();
BeanModel req = (BeanModel) env.getVariable("request");
BeanModel res = (BeanModel) env.getVariable("response");
Object prefix = env.getVariable("urlPrefix");
if (req != null) {
HttpServletRequest request = (HttpServletRequest) req.getWrappedObject();
ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
HttpServletResponse response = null;
if (res != null) {
response = (HttpServletResponse) res.getWrappedObject();
}
HttpSession session = request.getSession();
GenericValue userLogin = (GenericValue) session.getAttribute("userLogin");
// anonymous shoppers are not logged in
if (userLogin != null && "anonymous".equals(userLogin.getString("userLoginId"))) {
userLogin = null;
}
RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
out.write(seoUrl(rh.makeLink(request, response, buf.toString(), fullPath, secure, encode), userLogin == null));
} else if (prefix != null) {
if (prefix instanceof TemplateScalarModel) {
TemplateScalarModel s = (TemplateScalarModel) prefix;
String prefixString = s.getAsString();
String bufString = buf.toString();
boolean prefixSlash = prefixString.endsWith("/");
boolean bufSlash = bufString.startsWith("/");
if (prefixSlash && bufSlash) {
bufString = bufString.substring(1);
} else if (!prefixSlash && !bufSlash) {
bufString = "/" + bufString;
}
out.write(prefixString + bufString);
}
} else {
out.write(buf.toString());
}
} catch (IOException | TemplateModelException e) {
throw new IOException(e.getMessage());
}
}
};
}
use of org.apache.ofbiz.webapp.control.RequestHandler in project ofbiz-framework by apache.
the class TaskEvents method delegateAndAcceptAssignment.
/**
* Delegate and accept assignment event
*/
public static String delegateAndAcceptAssignment(HttpServletRequest request, HttpServletResponse response) {
ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
Locale locale = UtilHttp.getLocale(request);
if (addToOrderRole(request)) {
try {
EventHandler eh = rh.getEventFactory().getEventHandler("service");
eh.invoke(new Event("service", "", "wfAcceptRoleAssignment", true), null, request, response);
} catch (EventHandlerException e) {
Debug.logError(e, "Invocation error", module);
request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderFailedToInvokeTheWfDelegateAndAcceptAssignmentService", locale));
return "error";
}
return "success";
}
return "error";
}
Aggregations