svn commit: r1817617 - /ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1817617 - /ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/

mbrohl
Author: mbrohl
Date: Sat Dec  9 14:54:13 2017
New Revision: 1817617

URL: http://svn.apache.org/viewvc?rev=1817617&view=rev
Log:
Improved: Fixing defects reported by FindBugs, package
org.apache.ofbiz.product.category.ftl.
(OFBIZ-9773)

Thanks Julian Leichert for reporting and providing the patch.

Modified:
    ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/CatalogAltUrlSeoTransform.java
    ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/CatalogUrlSeoTransform.java
    ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/OfbizCatalogAltUrlTransform.java
    ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/SeoTransform.java
    ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/UrlRegexpTransform.java

Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/CatalogAltUrlSeoTransform.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/CatalogAltUrlSeoTransform.java?rev=1817617&r1=1817616&r2=1817617&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/CatalogAltUrlSeoTransform.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/CatalogAltUrlSeoTransform.java Sat Dec  9 14:54:13 2017
@@ -144,9 +144,9 @@ public class CatalogAltUrlSeoTransform i
                         String prefixString = ((StringModel) prefix).getAsString();
                         prefixString = prefixString.replaceAll("/", "/");
                         String contextPath = prefixString;
-                        int lastSlashIndex = prefixString.lastIndexOf("/");
+                        int lastSlashIndex = prefixString.lastIndexOf('/');
                         if (lastSlashIndex > -1 && lastSlashIndex < prefixString.length()) {
-                            contextPath = prefixString.substring(prefixString.lastIndexOf("/"));
+                            contextPath = prefixString.substring(prefixString.lastIndexOf('/'));
                         }
                         if (UtilValidate.isNotEmpty(productId)) {
                             GenericValue product = delegator.findOne("Product", UtilMisc.toMap("productId", productId), false);
@@ -166,7 +166,7 @@ public class CatalogAltUrlSeoTransform i
                                         productId, viewSize, viewIndex, viewSort, searchString);
                             }
                         }
-                        out.write(url.toString());
+                        out.write(url);
                     } else {
                         out.write(buf.toString());
                     }

Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/CatalogUrlSeoTransform.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/CatalogUrlSeoTransform.java?rev=1817617&r1=1817616&r2=1817617&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/CatalogUrlSeoTransform.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/CatalogUrlSeoTransform.java Sat Dec  9 14:54:13 2017
@@ -25,6 +25,7 @@ import java.util.Hashtable;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 
 import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletException;
@@ -526,9 +527,10 @@ public class CatalogUrlSeoTransform impl
                 }
             }
             if (SeoConfigUtil.isCategoryNameEnabled() || pathInfo.startsWith("/" + CatalogUrlServlet.CATEGORY_REQUEST + "/")) {
-                for (String categoryName : categoryNameIdMap.keySet()) {
+                for (Entry<String, String> entry : categoryNameIdMap.entrySet()) {
+                    String categoryName = entry.getKey();
                     if (lastPathElement.startsWith(categoryName)) {
-                        categoryId = categoryNameIdMap.get(categoryName);
+                        categoryId = entry.getValue();
                         if (!lastPathElement.equals(categoryName)) {
                             lastPathElement = lastPathElement.substring(categoryName.length() + URL_HYPHEN.length());
                         }
@@ -637,9 +639,10 @@ public class CatalogUrlSeoTransform impl
                     return false;
                 }
             }
-            for (String categoryName : categoryNameIdMap.keySet()) {
+            for (Entry<String, String> entry : categoryNameIdMap.entrySet()) {
+                String categoryName = entry.getKey();
                 if (lastPathElement.startsWith(categoryName)) {
-                    categoryId = categoryNameIdMap.get(categoryName);
+                    categoryId = entry.getValue();
                     break;
                 }
             }
@@ -696,7 +699,7 @@ public class CatalogUrlSeoTransform impl
 
         if (UtilValidate.isNotEmpty(currentCategoryId)) {
             List<String> trail = null;
-            trail = CategoryWorker.adjustTrail(trail, currentCategoryId, previousCategoryId);
+            trail = CategoryWorker.adjustTrail(null, currentCategoryId, previousCategoryId);
             if (!SeoConfigUtil.isCategoryUrlEnabled(contextPath)) {
                 for (String trailCategoryId: trail) {
                     if ("TOP".equals(trailCategoryId)) continue;
@@ -778,7 +781,7 @@ public class CatalogUrlSeoTransform impl
 
         if (UtilValidate.isNotEmpty(currentCategoryId)) {
             List<String> trail = null;
-            trail = CategoryWorker.adjustTrail(trail, currentCategoryId, previousCategoryId);
+            trail = CategoryWorker.adjustTrail(null, currentCategoryId, previousCategoryId);
             if (trail != null && trail.size() > 1) {
                 String lastCategoryId = trail.get(trail.size() - 1);
                 if (!"TOP".equals(lastCategoryId)) {

Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/OfbizCatalogAltUrlTransform.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/OfbizCatalogAltUrlTransform.java?rev=1817617&r1=1817616&r2=1817617&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/OfbizCatalogAltUrlTransform.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/OfbizCatalogAltUrlTransform.java Sat Dec  9 14:54:13 2017
@@ -140,7 +140,7 @@ public class OfbizCatalogAltUrlTransform
                             CategoryContentWrapper wrapper = new CategoryContentWrapper(dispatcher, productCategory, locale, EntityUtilProperties.getPropertyValue("content", "defaultMimeType", "text/html; charset=utf-8", delegator));
                             url = CatalogUrlFilter.makeCategoryUrl(delegator, wrapper, null, ((StringModel) prefix).getAsString(), previousCategoryId, productCategoryId, productId, viewSize, viewIndex, viewSort, searchString);
                         }
-                        out.write(url.toString());
+                        out.write(url);
                     } else {
                         out.write(buf.toString());
                     }

Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/SeoTransform.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/SeoTransform.java?rev=1817617&r1=1817616&r2=1817617&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/SeoTransform.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/SeoTransform.java Sat Dec  9 14:54:13 2017
@@ -38,6 +38,7 @@ import org.apache.oro.text.regex.Perl5Ma
 import freemarker.core.Environment;
 import freemarker.ext.beans.BeanModel;
 import freemarker.template.SimpleScalar;
+import freemarker.template.TemplateModelException;
 import freemarker.template.TemplateScalarModel;
 import freemarker.template.TemplateTransformModel;
 
@@ -118,7 +119,7 @@ public class SeoTransform implements Tem
                     } else {
                         out.write(buf.toString());
                     }
-                } catch (Exception e) {
+                } catch (IOException | TemplateModelException e) {
                     throw new IOException(e.getMessage());
                 }
             }

Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/UrlRegexpTransform.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/UrlRegexpTransform.java?rev=1817617&r1=1817616&r2=1817617&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/UrlRegexpTransform.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/category/ftl/UrlRegexpTransform.java Sat Dec  9 14:54:13 2017
@@ -38,6 +38,7 @@ import org.apache.oro.text.regex.Perl5Ma
 import freemarker.core.Environment;
 import freemarker.ext.beans.BeanModel;
 import freemarker.template.SimpleScalar;
+import freemarker.template.TemplateModelException;
 import freemarker.template.TemplateScalarModel;
 import freemarker.template.TemplateTransformModel;
 
@@ -118,7 +119,7 @@ public class UrlRegexpTransform implemen
                     } else {
                         out.write(buf.toString());
                     }
-                } catch (Exception e) {
+                } catch (IOException | TemplateModelException e) {
                     throw new IOException(e.getMessage());
                 }
             }