Author: jacopoc
Date: Tue Sep 6 07:09:03 2016 New Revision: 1759368 URL: http://svn.apache.org/viewvc?rev=1759368&view=rev Log: OFBIZ-8142 Additional cleanups related to OFBiz servlet filters * introduced a constant for the "control" mount point * moved public fields and methods from the ContentUrlFilter to the OfbizContentAltUrlTransforms and made them private (since they are only used by this class) * no more need for the UrlServletHelper to extend the ContextFilter Modified: ofbiz/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentUrlFilter.java ofbiz/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/OfbizContentAltUrlTransforms.java ofbiz/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/CatalogUrlFilter.java ofbiz/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/CatalogUrlServlet.java ofbiz/trunk/framework/common/src/main/java/org/apache/ofbiz/common/UrlServletHelper.java ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java Modified: ofbiz/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentUrlFilter.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentUrlFilter.java?rev=1759368&r1=1759367&r2=1759368&view=diff ============================================================================== --- ofbiz/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentUrlFilter.java (original) +++ ofbiz/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentUrlFilter.java Tue Sep 6 07:09:03 2016 @@ -31,7 +31,6 @@ import javax.servlet.http.HttpServletReq import javax.servlet.http.HttpServletResponse; import org.apache.ofbiz.base.util.Debug; -import org.apache.ofbiz.base.util.UtilCodec; import org.apache.ofbiz.base.util.UtilHttp; import org.apache.ofbiz.base.util.UtilValidate; import org.apache.ofbiz.common.UrlServletHelper; @@ -43,12 +42,7 @@ import org.apache.ofbiz.webapp.control.C public class ContentUrlFilter extends ContextFilter { public final static String module = ContentUrlFilter.class.getName(); - - public static final String CONTROL_MOUNT_POINT = "control"; - protected static String defaultLocaleString = null; - protected static String redirectUrl = null; - public static String defaultViewRequest = "contentViewInfo"; - + @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; @@ -86,7 +80,7 @@ public class ContentUrlFilter extends Co } if (UtilValidate.isNotEmpty(urlContentId)) { StringBuilder urlBuilder = new StringBuilder(); - urlBuilder.append("/" + CONTROL_MOUNT_POINT); + urlBuilder.append("/" + WebAppUtil.CONTROL_MOUNT_POINT); urlBuilder.append("/" + config.getInitParameter("viewRequest") + "?contentId=" + urlContentId); WebAppUtil.setAttributesFromRequestBody(request); @@ -104,60 +98,4 @@ public class ContentUrlFilter extends Co // we're done checking; continue on chain.doFilter(request, response); } - - public static String makeContentAltUrl(HttpServletRequest request, HttpServletResponse response, String contentId, String viewContent) { - if (UtilValidate.isEmpty(contentId)) { - return null; - } - Delegator delegator = (Delegator) request.getAttribute("delegator"); - String url = null; - try { - GenericValue contentAssocDataResource = EntityQuery.use(delegator) - .select("contentIdStart", "drObjectInfo", "dataResourceId", "caFromDate", "caThruDate", "caCreatedDate") - .from("ContentAssocDataResourceViewTo") - .where("caContentAssocTypeId", "ALTERNATIVE_URL", - "caThruDate", null, - "contentIdStart", contentId) - .orderBy("-caFromDate") - .queryFirst(); - if (contentAssocDataResource != null) { - url = contentAssocDataResource.getString("drObjectInfo"); - url = UtilCodec.getDecoder("url").decode(url); - String mountPoint = request.getContextPath(); - if (!(mountPoint.equals("/")) && !(mountPoint.equals(""))) { - url = mountPoint + url; - } - } - } catch (Exception e) { - Debug.logWarning("[Exception] : " + e.getMessage(), module); - } - - if (UtilValidate.isEmpty(url)) { - if (UtilValidate.isEmpty(viewContent)) { - viewContent = defaultViewRequest; - } - url = makeContentUrl(request, response, contentId, viewContent); - } - return url; - } - - public static String makeContentUrl(HttpServletRequest request, HttpServletResponse response, String contentId, String viewContent) { - if (UtilValidate.isEmpty(contentId)) { - return null; - } - StringBuilder urlBuilder = new StringBuilder(); - urlBuilder.append(request.getSession().getServletContext().getContextPath()); - if (urlBuilder.length() == 0 || urlBuilder.charAt(urlBuilder.length() - 1) != '/') { - urlBuilder.append("/"); - } - urlBuilder.append(CONTROL_MOUNT_POINT); - - if (UtilValidate.isNotEmpty(viewContent)) { - urlBuilder.append("/" + viewContent); - } else { - urlBuilder.append("/" + defaultViewRequest); - } - urlBuilder.append("?contentId=" + contentId); - return urlBuilder.toString(); - } } Modified: ofbiz/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/OfbizContentAltUrlTransforms.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/OfbizContentAltUrlTransforms.java?rev=1759368&r1=1759367&r2=1759368&view=diff ============================================================================== --- ofbiz/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/OfbizContentAltUrlTransforms.java (original) +++ ofbiz/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/OfbizContentAltUrlTransforms.java Tue Sep 6 07:09:03 2016 @@ -26,8 +26,9 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.ofbiz.base.util.Debug; +import org.apache.ofbiz.base.util.UtilCodec; import org.apache.ofbiz.base.util.UtilValidate; -import org.apache.ofbiz.content.content.ContentUrlFilter; import freemarker.core.Environment; import freemarker.ext.beans.BeanModel; @@ -37,9 +38,15 @@ import freemarker.template.SimpleNumber; import freemarker.template.SimpleScalar; import freemarker.template.TemplateModelException; import freemarker.template.TemplateTransformModel; +import org.apache.ofbiz.entity.Delegator; +import org.apache.ofbiz.entity.GenericValue; +import org.apache.ofbiz.entity.util.EntityQuery; +import org.apache.ofbiz.webapp.WebAppUtil; public class OfbizContentAltUrlTransforms implements TemplateTransformModel { public final static String module = OfbizContentAltUrlTransforms.class.getName(); + private static final String defaultViewRequest = "contentViewInfo"; + public String getStringArg(Map args, String key) { Object o = args.get(key); if (o instanceof SimpleScalar) { @@ -86,7 +93,7 @@ public class OfbizContentAltUrlTransform } String url = ""; if (UtilValidate.isNotEmpty(contentId)) { - url = ContentUrlFilter.makeContentAltUrl(request, response, contentId, viewContent); + url = makeContentAltUrl(request, response, contentId, viewContent); } out.write(url); } @@ -96,4 +103,61 @@ public class OfbizContentAltUrlTransform } }; } + + private static String makeContentAltUrl(HttpServletRequest request, HttpServletResponse response, String contentId, String viewContent) { + if (UtilValidate.isEmpty(contentId)) { + return null; + } + Delegator delegator = (Delegator) request.getAttribute("delegator"); + String url = null; + try { + GenericValue contentAssocDataResource = EntityQuery.use(delegator) + .select("contentIdStart", "drObjectInfo", "dataResourceId", "caFromDate", "caThruDate", "caCreatedDate") + .from("ContentAssocDataResourceViewTo") + .where("caContentAssocTypeId", "ALTERNATIVE_URL", + "caThruDate", null, + "contentIdStart", contentId) + .orderBy("-caFromDate") + .queryFirst(); + if (contentAssocDataResource != null) { + url = contentAssocDataResource.getString("drObjectInfo"); + url = UtilCodec.getDecoder("url").decode(url); + String mountPoint = request.getContextPath(); + if (!(mountPoint.equals("/")) && !(mountPoint.equals(""))) { + url = mountPoint + url; + } + } + } catch (Exception e) { + Debug.logWarning("[Exception] : " + e.getMessage(), module); + } + + if (UtilValidate.isEmpty(url)) { + if (UtilValidate.isEmpty(viewContent)) { + viewContent = defaultViewRequest; + } + url = makeContentUrl(request, response, contentId, viewContent); + } + return url; + } + + private static String makeContentUrl(HttpServletRequest request, HttpServletResponse response, String contentId, String viewContent) { + if (UtilValidate.isEmpty(contentId)) { + return null; + } + StringBuilder urlBuilder = new StringBuilder(); + urlBuilder.append(request.getSession().getServletContext().getContextPath()); + if (urlBuilder.length() == 0 || urlBuilder.charAt(urlBuilder.length() - 1) != '/') { + urlBuilder.append("/"); + } + urlBuilder.append(WebAppUtil.CONTROL_MOUNT_POINT); + + if (UtilValidate.isNotEmpty(viewContent)) { + urlBuilder.append("/" + viewContent); + } else { + urlBuilder.append("/" + defaultViewRequest); + } + urlBuilder.append("?contentId=" + contentId); + return urlBuilder.toString(); + } + } Modified: ofbiz/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/CatalogUrlFilter.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/CatalogUrlFilter.java?rev=1759368&r1=1759367&r2=1759368&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/CatalogUrlFilter.java (original) +++ ofbiz/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/CatalogUrlFilter.java Tue Sep 6 07:09:03 2016 @@ -51,7 +51,6 @@ public class CatalogUrlFilter extends Co public final static String module = CatalogUrlFilter.class.getName(); - public static final String CONTROL_MOUNT_POINT = "control"; public static final String PRODUCT_REQUEST = "product"; public static final String CATEGORY_REQUEST = "category"; @@ -205,7 +204,7 @@ public class CatalogUrlFilter extends Co // generate forward URL StringBuilder urlBuilder = new StringBuilder(); - urlBuilder.append("/" + CONTROL_MOUNT_POINT); + urlBuilder.append("/" + WebAppUtil.CONTROL_MOUNT_POINT); if (UtilValidate.isNotEmpty(productId)) { try { Modified: ofbiz/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/CatalogUrlServlet.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/CatalogUrlServlet.java?rev=1759368&r1=1759367&r2=1759368&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/CatalogUrlServlet.java (original) +++ ofbiz/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/CatalogUrlServlet.java Tue Sep 6 07:09:03 2016 @@ -36,6 +36,7 @@ import org.apache.ofbiz.entity.Delegator import org.apache.ofbiz.entity.GenericEntityException; import org.apache.ofbiz.entity.GenericValue; import org.apache.ofbiz.entity.util.EntityQuery; +import org.apache.ofbiz.webapp.WebAppUtil; /** * ControlServlet.java - Master servlet for the web application. @@ -46,7 +47,6 @@ public class CatalogUrlServlet extends H public static final String module = CatalogUrlServlet.class.getName(); public static final String CATALOG_URL_MOUNT_POINT = "products"; - public static final String CONTROL_MOUNT_POINT = "control"; public static final String PRODUCT_REQUEST = "product"; public static final String CATEGORY_REQUEST = "category"; @@ -84,7 +84,7 @@ public class CatalogUrlServlet extends H String categoryId = null; if (pathElements == null) { - RequestDispatcher rd = request.getRequestDispatcher("/" + CONTROL_MOUNT_POINT + "/main"); + RequestDispatcher rd = request.getRequestDispatcher("/" + WebAppUtil.CONTROL_MOUNT_POINT + "/main"); rd.forward(request, response); } else { try { @@ -149,7 +149,7 @@ public class CatalogUrlServlet extends H request.setAttribute("productId", productId); } - RequestDispatcher rd = request.getRequestDispatcher("/" + CONTROL_MOUNT_POINT + "/" + (productId != null ? PRODUCT_REQUEST : CATEGORY_REQUEST)); + RequestDispatcher rd = request.getRequestDispatcher("/" + WebAppUtil.CONTROL_MOUNT_POINT + "/" + (productId != null ? PRODUCT_REQUEST : CATEGORY_REQUEST)); rd.forward(request, response); } } Modified: ofbiz/trunk/framework/common/src/main/java/org/apache/ofbiz/common/UrlServletHelper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/main/java/org/apache/ofbiz/common/UrlServletHelper.java?rev=1759368&r1=1759367&r2=1759368&view=diff ============================================================================== --- ofbiz/trunk/framework/common/src/main/java/org/apache/ofbiz/common/UrlServletHelper.java (original) +++ ofbiz/trunk/framework/common/src/main/java/org/apache/ofbiz/common/UrlServletHelper.java Tue Sep 6 07:09:03 2016 @@ -39,10 +39,9 @@ import org.apache.ofbiz.entity.GenericVa import org.apache.ofbiz.entity.util.EntityQuery; import org.apache.ofbiz.entity.util.EntityUtil; import org.apache.ofbiz.webapp.WebAppUtil; -import org.apache.ofbiz.webapp.control.ContextFilter; import org.apache.ofbiz.webapp.website.WebSiteWorker; -public final class UrlServletHelper extends ContextFilter { +public final class UrlServletHelper { public final static String module = UrlServletHelper.class.getName(); Modified: ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java?rev=1759368&r1=1759367&r2=1759368&view=diff ============================================================================== --- ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java (original) +++ ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java Tue Sep 6 07:09:03 2016 @@ -64,6 +64,7 @@ import org.xml.sax.helpers.DefaultHandle public final class WebAppUtil { public static final String module = WebAppUtil.class.getName(); + public static final String CONTROL_MOUNT_POINT = "control"; private static final String webAppFileName = "/WEB-INF/web.xml"; private static final UtilCache<String, WebXml> webXmlCache = UtilCache.createUtilCache("webapp.WebXml"); |
Free forum by Nabble | Edit this page |