You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2013/10/31 15:06:50 UTC
svn commit: r1537495 - in
/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category:
./ ftl/
Author: jleroux
Date: Thu Oct 31 14:06:50 2013
New Revision: 1537495
URL: http://svn.apache.org/r1537495
Log:
A patch from Shi Jinghai for "Proposal: URL-Generation Changes" https://issues.apache.org/jira/browse/OFBIZ-5312
1. Merged UrlUtil.java into SeoUrlUtil.java
2. Merged UrlRegexpConfigUtil.java into SeoConfigUtil.java
3. Changed all DEFAULT_MASK to READ_ONLY_MASK as it's suggested in Perl5Compiler javadoc
4. Replaced RequestHandler.getDefaultServerRootUrl in CatalogAltUrlSeoTransform.java with OfbizUrlBuilder methods
jleroux: after a complete review, I
* replaced all tabs by 4 spaces
* removed empty lines in variables declarations
* formatted some expressions to stay on same line
I noticed that UrlRegexpConfigUtil.getForwardPatterns() has been replaced by SeoConfigUtil.getSeoPatterns(), I guess it's ok since done twice and seems not a wrong C/P
Removed:
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/UrlRegexpConfigUtil.java
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/UrlUtil.java
Modified:
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/SeoConfigUtil.java
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/SeoContextFilter.java
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/SeoUrlUtil.java
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/UrlRegexpContextFilter.java
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/ftl/CatalogAltUrlSeoTransform.java
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/ftl/CatalogUrlSeoTransform.java
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/ftl/SeoTransform.java
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/ftl/UrlRegexpTransform.java
Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/SeoConfigUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/SeoConfigUtil.java?rev=1537495&r1=1537494&r2=1537495&view=diff
==============================================================================
--- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/SeoConfigUtil.java (original)
+++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/SeoConfigUtil.java Thu Oct 31 14:06:50 2013
@@ -20,6 +20,7 @@ package org.ofbiz.product.category;
import java.io.FileInputStream;
import java.io.IOException;
+import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -30,11 +31,13 @@ import javax.xml.parsers.ParserConfigura
import javolution.util.FastList;
import javolution.util.FastMap;
+import javolution.util.FastSet;
import org.apache.oro.text.regex.MalformedPatternException;
import org.apache.oro.text.regex.Pattern;
import org.apache.oro.text.regex.Perl5Compiler;
import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.StringUtil;
import org.ofbiz.base.util.UtilURL;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.base.util.UtilXml;
@@ -48,14 +51,13 @@ import org.xml.sax.SAXException;
*
*/
public class SeoConfigUtil {
-
private static final String module = SeoConfigUtil.class.getName();
private static Perl5Compiler perlCompiler = new Perl5Compiler();
private static boolean isInitialed = false;
- private static boolean debug = false;
private static boolean categoryUrlEnabled = true;
private static boolean categoryNameEnabled = false;
private static String categoryUrlSuffix = null;
+ public static final String DEFAULT_REGEXP = "^.*/.*$";
private static Pattern regexpIfMatch = null;
private static boolean useUrlRegexp = false;
private static boolean jSessionIdAnonEnabled = false;
@@ -63,16 +65,13 @@ public class SeoConfigUtil {
private static Map<String, String> seoReplacements = null;
private static Map<String, Pattern> seoPatterns = null;
private static Map<String, String> forwardReplacements = null;
- private static Map<String, Pattern> forwardPatterns = null;
private static Map<String, Integer> forwardResponseCodes = null;
- private static Map<String, String> nameFilters = null;
+ private static Map<String, String> charFilters = null;
private static List<Pattern> userExceptionPatterns = null;
private static Set<String> allowedContextPaths = null;
private static Map<String, String> specialProductIds = null;
- public static final String DEFAULT_REGEXP = "^.*/.*$";
public static final String ELEMENT_REGEXPIFMATCH = "regexpifmatch";
- public static final String ELEMENT_DEBUG = "debug";
- public static final String ELEMENT_CONFIG = "config";
+ public static final String ELEMENT_URL_CONFIG = "url-config";
public static final String ELEMENT_DESCRIPTION = "description";
public static final String ELEMENT_FORWARD = "forward";
public static final String ELEMENT_SEO = "seo";
@@ -84,9 +83,13 @@ public class SeoConfigUtil {
public static final String ELEMENT_VALUE = "value";
public static final String ELEMENT_USER = "user";
public static final String ELEMENT_EXCEPTIONS = "exceptions";
- public static final String ELEMENT_NAME_FILTERS = "name-filters";
- public static final String ELEMENT_FILTER = "filter";
+ public static final String ELEMENT_CHAR_FILTERS = "char-filters";
+ public static final String ELEMENT_CHAR_FILTER = "char-filter";
public static final String ELEMENT_CHARACTER_PATTERN = "character-pattern";
+ public static final String ELEMENT_CATEGORY_URL = "category-url";
+ public static final String ELEMENT_ALLOWED_CONTEXT_PATHS = "allowed-context-paths";
+ public static final String ELEMENT_CATEGORY_NAME = "category-name";
+ public static final String ELEMENT_CATEGORY_URL_SUFFIX = "category-url-suffix";
public static final String SEO_CONFIG_FILENAME = "SeoConfig.xml";
public static final int DEFAULT_RESPONSECODE = HttpServletResponse.SC_MOVED_PERMANENTLY;
public static final String DEFAULT_ANONYMOUS_VALUE = "disable";
@@ -94,6 +97,7 @@ public class SeoConfigUtil {
public static final String DEFAULT_CATEGORY_URL_VALUE = "enable";
public static final String DEFAULT_CATEGORY_NAME_VALUE = "disable";
public static final String ALLOWED_CONTEXT_PATHS_SEPERATOR = ":";
+
/**
* Initialize url regular express configuration.
*
@@ -105,26 +109,78 @@ public class SeoConfigUtil {
seoPatterns = new HashMap<String, Pattern>();
seoReplacements = new HashMap<String, String>();
forwardReplacements = new HashMap<String, String>();
- forwardPatterns = new HashMap<String, Pattern>();
forwardResponseCodes = new HashMap<String, Integer>();
userExceptionPatterns = FastList.newInstance();
specialProductIds = FastMap.newInstance();
- nameFilters = FastMap.newInstance();
+ charFilters = FastMap.newInstance();
try {
- Document configDoc = UtilXml.readXmlDocument(UtilURL.fromResource(SEO_CONFIG_FILENAME), false);
+ URL seoConfigFilename = UtilURL.fromResource(SEO_CONFIG_FILENAME);
+ Document configDoc = UtilXml.readXmlDocument(seoConfigFilename, false);
Element rootElement = configDoc.getDocumentElement();
String regexIfMatch = UtilXml.childElementValue(rootElement, ELEMENT_REGEXPIFMATCH, DEFAULT_REGEXP);
+ Debug.logInfo("Parsing " + regexIfMatch, module);
try {
- regexpIfMatch = perlCompiler.compile(regexIfMatch, Perl5Compiler.DEFAULT_MASK);
+ regexpIfMatch = perlCompiler.compile(regexIfMatch, Perl5Compiler.READ_ONLY_MASK);
} catch (MalformedPatternException e1) {
- Debug.logWarning(e1, module);
+ Debug.logWarning(e1, "Error while parsing " + regexIfMatch, module);
+ }
+
+ // parse category-url element
+ try {
+ Element categoryUrlElement = UtilXml.firstChildElement(rootElement, ELEMENT_CATEGORY_URL);
+ Debug.logInfo("Parsing " + ELEMENT_CATEGORY_URL + " [" + (categoryUrlElement != null) + "]:", module);
+ if (categoryUrlElement != null) {
+ String enableCategoryUrlValue = UtilXml.childElementValue(categoryUrlElement, ELEMENT_VALUE, DEFAULT_CATEGORY_URL_VALUE);
+ if (DEFAULT_CATEGORY_URL_VALUE.equalsIgnoreCase(enableCategoryUrlValue)) {
+ categoryUrlEnabled = true;
+ } else {
+ categoryUrlEnabled = false;
+ }
+
+ if (categoryUrlEnabled) {
+ String allowedContextValue = UtilXml.childElementValue(categoryUrlElement, ELEMENT_ALLOWED_CONTEXT_PATHS, null);
+ allowedContextPaths = FastSet.newInstance();
+ if (UtilValidate.isNotEmpty(allowedContextValue)) {
+ List<String> allowedContextPathList = StringUtil.split(allowedContextValue, ALLOWED_CONTEXT_PATHS_SEPERATOR);
+ for (String path : allowedContextPathList) {
+ if (UtilValidate.isNotEmpty(path)) {
+ path = path.trim();
+ if (!allowedContextPaths.contains(path)) {
+ allowedContextPaths.add(path);
+ Debug.logInfo(" " + ELEMENT_ALLOWED_CONTEXT_PATHS + ": " + path, module);
+ }
+ }
+ }
+ }
+
+ String categoryNameValue = UtilXml.childElementValue(categoryUrlElement, ELEMENT_CATEGORY_NAME, DEFAULT_CATEGORY_NAME_VALUE);
+ if (DEFAULT_CATEGORY_NAME_VALUE.equalsIgnoreCase(categoryNameValue)) {
+ categoryNameEnabled = false;
+ } else {
+ categoryNameEnabled = true;
+ }
+ Debug.logInfo(" " + ELEMENT_CATEGORY_NAME + ": " + categoryNameEnabled, module);
+
+ categoryUrlSuffix = UtilXml.childElementValue(categoryUrlElement, ELEMENT_CATEGORY_URL_SUFFIX, null);
+ if (UtilValidate.isNotEmpty(categoryUrlSuffix)) {
+ categoryUrlSuffix = categoryUrlSuffix.trim();
+ if (categoryUrlSuffix.contains("/")) {
+ categoryUrlSuffix = null;
+ }
+ }
+ Debug.logInfo(" " + ELEMENT_CATEGORY_URL_SUFFIX + ": " + categoryUrlSuffix, module);
+ }
+ }
+ } catch (NullPointerException e) {
+ // no "category-url" element
+ Debug.logWarning("No category-url element found in " + seoConfigFilename.toString(), module);
}
- debug = Boolean.parseBoolean(UtilXml.childElementValue(rootElement, ELEMENT_DEBUG, "false"));
// parse jsessionid element
try {
Element jSessionId = UtilXml.firstChildElement(rootElement, ELEMENT_JSESSIONID);
+ Debug.logInfo("Parsing " + ELEMENT_JSESSIONID + " [" + (jSessionId != null) + "]:", module);
if (jSessionId != null) {
Element anonymous = UtilXml.firstChildElement(jSessionId, ELEMENT_ANONYMOUS);
if (anonymous != null) {
@@ -134,7 +190,10 @@ public class SeoConfigUtil {
} else {
jSessionIdAnonEnabled = true;
}
+ } else {
+ jSessionIdAnonEnabled = Boolean.valueOf(DEFAULT_ANONYMOUS_VALUE).booleanValue();
}
+ Debug.logInfo(" " + ELEMENT_ANONYMOUS + ": " + jSessionIdAnonEnabled, module);
Element user = UtilXml.firstChildElement(jSessionId, ELEMENT_USER);
if (user != null) {
@@ -144,96 +203,116 @@ public class SeoConfigUtil {
} else {
jSessionIdUserEnabled = true;
}
+
Element exceptions = UtilXml.firstChildElement(user, ELEMENT_EXCEPTIONS);
if (exceptions != null) {
+ Debug.logInfo(" " + ELEMENT_EXCEPTIONS + ": ", module);
List<? extends Element> exceptionUrlPatterns = UtilXml.childElementList(exceptions, ELEMENT_URLPATTERN);
for (int i = 0; i < exceptionUrlPatterns.size(); i++) {
Element element = (Element) exceptionUrlPatterns.get(i);
String urlpattern = element.getTextContent();
if (UtilValidate.isNotEmpty(urlpattern)) {
try {
- Pattern pattern = perlCompiler.compile(urlpattern, Perl5Compiler.DEFAULT_MASK);
+ Pattern pattern = perlCompiler.compile(urlpattern, Perl5Compiler.READ_ONLY_MASK);
userExceptionPatterns.add(pattern);
+ Debug.logInfo(" " + ELEMENT_URLPATTERN + ": " + urlpattern, module);
} catch (MalformedPatternException e) {
- Debug.logWarning(e, "skip this url replacement if any error happened", module);
+ Debug.logWarning("Can NOT parse " + urlpattern + " in element " + ELEMENT_URLPATTERN + " of " + ELEMENT_EXCEPTIONS + ". Error: " + e.getMessage(), module);
}
}
}
}
+ } else {
+ jSessionIdUserEnabled = Boolean.valueOf(DEFAULT_USER_VALUE).booleanValue();
}
+ Debug.logInfo(" " + ELEMENT_USER + ": " + jSessionIdUserEnabled, module);
}
} catch (NullPointerException e) {
- Debug.logWarning(e, "no \"jsessionid\" element", module);
+ Debug.logWarning("No jsessionid element found in " + seoConfigFilename.toString(), module);
}
- // parse name-filters elements
+ // parse url-config elements
try {
- NodeList nameFilterNodes = rootElement.getElementsByTagName(ELEMENT_FILTER);
- for (int i = 0; i < nameFilterNodes.getLength(); i++) {
- Element element = (Element) nameFilterNodes.item(i);
- String charaterPattern = UtilXml.childElementValue(element, ELEMENT_CHARACTER_PATTERN, null);
- String replacement = UtilXml.childElementValue(element, ELEMENT_REPLACEMENT, null);
- if (UtilValidate.isNotEmpty(charaterPattern) && UtilValidate.isNotEmpty(replacement)) {
- try {
- perlCompiler.compile(charaterPattern, Perl5Compiler.DEFAULT_MASK);
- nameFilters.put(charaterPattern,replacement);
- } catch (MalformedPatternException e) {
- Debug.logWarning(e, "skip this filter (character-pattern replacement) if any error happened", module);
- }
+ NodeList configs = rootElement.getElementsByTagName(ELEMENT_URL_CONFIG);
+ Debug.logInfo("Parsing " + ELEMENT_URL_CONFIG, module);
+ for (int j = 0; j < configs.getLength(); j++) {
+ Element config = (Element) configs.item(j);
+ String urlpattern = UtilXml.childElementValue(config, ELEMENT_URLPATTERN, null);
+ if (UtilValidate.isEmpty(urlpattern)) {
+ continue;
}
- }
- } catch (NullPointerException e) {
- Debug.logWarning(e, "no \"name-filters\" element", module);
- }
-
- // parse config elements
- try {
- // construct seo patterns
- NodeList seos = rootElement.getElementsByTagName(ELEMENT_SEO);
- for (int i = 0; i < seos.getLength(); i++) {
- Element element = (Element) seos.item(i);
- String urlpattern = UtilXml.childElementValue(element, ELEMENT_URLPATTERN, null);
- String replacement = UtilXml.childElementValue(element, ELEMENT_REPLACEMENT, null);
- if (UtilValidate.isNotEmpty(urlpattern) && UtilValidate.isNotEmpty(replacement)) {
- try {
- Pattern pattern = perlCompiler.compile(urlpattern, Perl5Compiler.DEFAULT_MASK);
+ Debug.logInfo(" " + ELEMENT_URLPATTERN + ": " + urlpattern, module);
+ Pattern pattern;
+ try {
+ pattern = perlCompiler.compile(urlpattern, Perl5Compiler.READ_ONLY_MASK);
+ seoPatterns.put(urlpattern, pattern);
+ } catch (MalformedPatternException e) {
+ Debug.logWarning("Error while creating parttern for seo url-pattern: " + urlpattern, module);
+ continue;
+ }
+
+ // construct seo patterns
+ Element seo = UtilXml.firstChildElement(config, ELEMENT_SEO);
+ if (UtilValidate.isNotEmpty(seo)) {
+ String replacement = UtilXml.childElementValue(seo, ELEMENT_REPLACEMENT, null);
+ if (UtilValidate.isNotEmpty(replacement)) {
seoReplacements.put(urlpattern, replacement);
- seoPatterns.put(urlpattern, pattern);
- } catch (MalformedPatternException e) {
- Debug.logWarning(e, "skip this url replacement if any error happened", module);
+ Debug.logInfo(" " + ELEMENT_SEO + " " + ELEMENT_REPLACEMENT + ": " + replacement, module);
}
}
- }
- // construct forward patterns
- NodeList forwards = rootElement.getElementsByTagName(ELEMENT_FORWARD);
- for (int i = 0; i < forwards.getLength(); i++) {
- Element element = (Element) forwards.item(i);
- String urlpattern = UtilXml.childElementValue(element, ELEMENT_URLPATTERN, null);
- String replacement = UtilXml.childElementValue(element, ELEMENT_REPLACEMENT, null);
- String responseCode = UtilXml.childElementValue(element, ELEMENT_RESPONSECODE, String.valueOf(DEFAULT_RESPONSECODE));
- if (UtilValidate.isNotEmpty(urlpattern) && UtilValidate.isNotEmpty(replacement)) {
- try {
- Pattern pattern = perlCompiler.compile(urlpattern, Perl5Compiler.DEFAULT_MASK);
+ // construct forward patterns
+ Element forward = UtilXml.firstChildElement(config, ELEMENT_FORWARD);
+ if (UtilValidate.isNotEmpty(forward)) {
+ String replacement = UtilXml.childElementValue(forward, ELEMENT_REPLACEMENT, null);
+ String responseCode = UtilXml.childElementValue(forward,
+ ELEMENT_RESPONSECODE, String.valueOf(DEFAULT_RESPONSECODE));
+ if (UtilValidate.isNotEmpty(replacement)) {
forwardReplacements.put(urlpattern, replacement);
- forwardPatterns.put(urlpattern, pattern);
+ Debug.logInfo(" " + ELEMENT_FORWARD + " " + ELEMENT_REPLACEMENT + ": " + replacement, module);
if (UtilValidate.isNotEmpty(responseCode)) {
Integer responseCodeInt = DEFAULT_RESPONSECODE;
try {
responseCodeInt = Integer.valueOf(responseCode);
} catch (NumberFormatException nfe) {
- Debug.logWarning(nfe, module);
+ Debug.logWarning(nfe, "Error while parsing response code number: " + responseCode, module);
}
forwardResponseCodes.put(urlpattern, responseCodeInt);
+ Debug.logInfo(" " + ELEMENT_FORWARD + " " + ELEMENT_RESPONSECODE + ": " + responseCodeInt, module);
}
- } catch (MalformedPatternException e) {
- Debug.logWarning(e, "skip this url replacement if any error happened", module);
}
}
}
+ } catch (NullPointerException e) {
+ // no "url-config" element
+ Debug.logWarning("No " + ELEMENT_URL_CONFIG + " element found in " + seoConfigFilename.toString(), module);
+ }
+ // parse char-filters elements
+ try {
+ NodeList nameFilterNodes = rootElement
+ .getElementsByTagName(ELEMENT_CHAR_FILTER);
+ Debug.logInfo("Parsing " + ELEMENT_CHAR_FILTER + ": ", module);
+ for (int i = 0; i < nameFilterNodes.getLength(); i++) {
+ Element element = (Element) nameFilterNodes.item(i);
+ String charaterPattern = UtilXml.childElementValue(element, ELEMENT_CHARACTER_PATTERN, null);
+ String replacement = UtilXml.childElementValue(element, ELEMENT_REPLACEMENT, null);
+ if (UtilValidate.isNotEmpty(charaterPattern)
+ && UtilValidate.isNotEmpty(replacement)) {
+ try {
+ perlCompiler.compile(charaterPattern, Perl5Compiler.READ_ONLY_MASK);
+ charFilters.put(charaterPattern, replacement);
+ Debug.logInfo(" " + ELEMENT_CHARACTER_PATTERN + ": " + charaterPattern, module);
+ Debug.logInfo(" " + ELEMENT_REPLACEMENT + ": " + replacement, module);
+ } catch (MalformedPatternException e) {
+ // skip this filter (character-pattern replacement) if any error happened
+ Debug.logWarning(e, "Error while parsing " + ELEMENT_CHARACTER_PATTERN + ": " + charaterPattern, module);
+ }
+ }
+ }
} catch (NullPointerException e) {
- Debug.logWarning(e, "no \"config\" element", module);
+ // no "char-filters" element
+ Debug.logWarning("No " + ELEMENT_CHAR_FILTER + " element found in " + seoConfigFilename.toString(), module);
}
} catch (SAXException e) {
result = "error";
@@ -274,15 +353,6 @@ public class SeoConfigUtil {
}
/**
- * Check whether debug is enabled.
- *
- * @return a boolean value to indicate whether debug is enabled.
- */
- public static boolean isDebugEnabled() {
- return debug;
- }
-
- /**
* Check whether url regexp should be used.
*
* @return a boolean value to indicate whether url regexp should be used.
@@ -377,12 +447,12 @@ public class SeoConfigUtil {
}
/**
- * Get name filters.
+ * Get char filters.
*
- * @return name filters (java.util.Map<String, String>)
+ * @return char filters (java.util.Map<String, String>)
*/
- public static Map<String, String> getNameFilters() {
- return nameFilters;
+ public static Map<String, String> getCharFilters() {
+ return charFilters;
}
/**
@@ -404,15 +474,6 @@ public class SeoConfigUtil {
}
/**
- * Get forward url pattern configures.
- *
- * @return forward url pattern configures (java.util.Map<String, Pattern>)
- */
- public static Map<String, Pattern> getForwardPatterns() {
- return forwardPatterns;
- }
-
- /**
* Get forward replacement configures.
*
* @return forward replacement configures (java.util.Map<String, String>)
@@ -470,5 +531,4 @@ public class SeoConfigUtil {
public static String getSpecialProductId(String productId) {
return specialProductIds.get(productId);
}
-
}
Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/SeoContextFilter.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/SeoContextFilter.java?rev=1537495&r1=1537494&r2=1537495&view=diff
==============================================================================
--- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/SeoContextFilter.java (original)
+++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/SeoContextFilter.java Thu Oct 31 14:06:50 2013
@@ -337,11 +337,11 @@ public class SeoContextFilter extends Co
boolean foundMatch = false;
Integer responseCodeInt = null;
- if (SeoConfigUtil.checkUseUrlRegexp() && SeoConfigUtil.getForwardPatterns() != null && SeoConfigUtil.getForwardReplacements() != null) {
- Iterator<String> keys = SeoConfigUtil.getForwardPatterns().keySet().iterator();
+ if (SeoConfigUtil.checkUseUrlRegexp() && SeoConfigUtil.getSeoPatterns() != null && SeoConfigUtil.getForwardReplacements() != null) {
+ Iterator<String> keys = SeoConfigUtil.getSeoPatterns().keySet().iterator();
while (keys.hasNext()) {
String key = keys.next();
- Pattern pattern = SeoConfigUtil.getForwardPatterns().get(key);
+ Pattern pattern = SeoConfigUtil.getSeoPatterns().get(key);
String replacement = SeoConfigUtil.getForwardReplacements().get(key);
if (matcher.matches(uri, pattern)) {
for (int i = matcher.getMatch().groups(); i > 0; i--) {
@@ -362,7 +362,7 @@ public class SeoContextFilter extends Co
response.setStatus(responseCodeInt.intValue());
}
response.setHeader("Location", uri);
- } else if (SeoConfigUtil.isDebugEnabled()) {
+ } else {
Debug.logInfo("Can NOT forward this url: " + uri, module);
}
return foundMatch;
Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/SeoUrlUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/SeoUrlUtil.java?rev=1537495&r1=1537494&r2=1537495&view=diff
==============================================================================
--- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/SeoUrlUtil.java (original)
+++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/SeoUrlUtil.java Thu Oct 31 14:06:50 2013
@@ -25,8 +25,8 @@ public class SeoUrlUtil {
if (UtilValidate.isEmpty(url)) {
url = "";
}
- for (String characterPattern : SeoConfigUtil.getNameFilters().keySet()) {
- url = url.replaceAll(characterPattern, SeoConfigUtil.getNameFilters().get(characterPattern));
+ for (String characterPattern : SeoConfigUtil.getCharFilters().keySet()) {
+ url = url.replaceAll(characterPattern, SeoConfigUtil.getCharFilters().get(characterPattern));
}
return url;
}
Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/UrlRegexpContextFilter.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/UrlRegexpContextFilter.java?rev=1537495&r1=1537494&r2=1537495&view=diff
==============================================================================
--- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/UrlRegexpContextFilter.java (original)
+++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/UrlRegexpContextFilter.java Thu Oct 31 14:06:50 2013
@@ -247,7 +247,7 @@ public class UrlRegexpContextFilter exte
rd.forward(request, response);
} else {
// redirect with url change in browser
- httpResponse.setStatus(UrlRegexpConfigUtil.DEFAULT_RESPONSECODE);
+ httpResponse.setStatus(SeoConfigUtil.DEFAULT_RESPONSECODE);
httpResponse.setHeader("Location", redirectPath);
}
}
Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/ftl/CatalogAltUrlSeoTransform.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/ftl/CatalogAltUrlSeoTransform.java?rev=1537495&r1=1537494&r2=1537495&view=diff
==============================================================================
--- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/ftl/CatalogAltUrlSeoTransform.java (original)
+++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/ftl/CatalogAltUrlSeoTransform.java Thu Oct 31 14:06:50 2013
@@ -25,6 +25,7 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest;
+import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.base.util.template.FreeMarkerWorker;
@@ -33,10 +34,11 @@ import org.ofbiz.entity.GenericEntityExc
import org.ofbiz.entity.GenericValue;
import org.ofbiz.product.category.CatalogUrlFilter;
import org.ofbiz.product.category.CategoryContentWrapper;
-import org.ofbiz.product.category.UrlRegexpConfigUtil;
+import org.ofbiz.product.category.SeoConfigUtil;
import org.ofbiz.product.product.ProductContentWrapper;
import org.ofbiz.service.LocalDispatcher;
-import org.ofbiz.webapp.control.RequestHandler;
+import org.ofbiz.webapp.OfbizUrlBuilder;
+import org.ofbiz.webapp.control.WebAppConfigurationException;
import freemarker.core.Environment;
import freemarker.ext.beans.BeanModel;
@@ -111,13 +113,13 @@ public class CatalogAltUrlSeoTransform i
HttpServletRequest request = (HttpServletRequest) req.getWrappedObject();
StringBuilder newURL = new StringBuilder();
if (UtilValidate.isNotEmpty(productId)) {
- if (UrlRegexpConfigUtil.isCategoryUrlEnabled(request.getContextPath())) {
+ if (SeoConfigUtil.isCategoryUrlEnabled(request.getContextPath())) {
url = CatalogUrlSeoTransform.makeProductUrl(request, productId, productCategoryId, previousCategoryId);
} else {
url = CatalogUrlFilter.makeProductUrl(request, previousCategoryId, productCategoryId, productId);
}
} else {
- if (UrlRegexpConfigUtil.isCategoryUrlEnabled(request.getContextPath())) {
+ if (SeoConfigUtil.isCategoryUrlEnabled(request.getContextPath())) {
url = CatalogUrlSeoTransform.makeCategoryUrl(request, productCategoryId, previousCategoryId, viewSize, viewIndex, viewSort, searchString);
} else {
url = CatalogUrlFilter.makeCategoryUrl(request, previousCategoryId, productCategoryId, productId, viewSize, viewIndex, viewSort, searchString);
@@ -125,8 +127,12 @@ public class CatalogAltUrlSeoTransform i
}
// make the link
if (fullPath) {
- String serverRootUrl = RequestHandler.getDefaultServerRootUrl(request, secure);
- newURL.append(serverRootUrl);
+ try {
+ OfbizUrlBuilder builder = OfbizUrlBuilder.from(request);
+ builder.buildHostPart(newURL, "", secure);
+ } catch (WebAppConfigurationException e) {
+ Debug.logError(e.getMessage(), module);
+ }
}
newURL.append(url);
out.write(newURL.toString());
Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/ftl/CatalogUrlSeoTransform.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/ftl/CatalogUrlSeoTransform.java?rev=1537495&r1=1537494&r2=1537495&view=diff
==============================================================================
--- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/ftl/CatalogUrlSeoTransform.java (original)
+++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/ftl/CatalogUrlSeoTransform.java Thu Oct 31 14:06:50 2013
@@ -51,9 +51,8 @@ import org.ofbiz.entity.condition.Entity
import org.ofbiz.product.category.CatalogUrlServlet;
import org.ofbiz.product.category.CategoryContentWrapper;
import org.ofbiz.product.category.CategoryWorker;
+import org.ofbiz.product.category.SeoConfigUtil;
import org.ofbiz.product.category.SeoUrlUtil;
-import org.ofbiz.product.category.UrlRegexpConfigUtil;
-import org.ofbiz.product.category.UrlUtil;
import org.ofbiz.product.product.ProductContentWrapper;
import freemarker.core.Environment;
@@ -66,20 +65,20 @@ import freemarker.template.TemplateTrans
public class CatalogUrlSeoTransform implements TemplateTransformModel {
public final static String module = CatalogUrlSeoTransform.class.getName();
- private static Map<String, String> m_categoryNameIdMap = null;
- private static Map<String, String> m_categoryIdNameMap = null;
- private static boolean m_categoryMapInitialed = false;
- private static final String m_asciiRegexp = "^[0-9-_a-zA-Z]*$";
- private static Perl5Compiler m_perlCompiler = new Perl5Compiler();
- private static Pattern m_asciiPattern = null;
+ private static Map<String, String> categoryNameIdMap = null;
+ private static Map<String, String> categoryIdNameMap = null;
+ private static boolean categoryMapInitialed = false;
+ private static final String asciiRegexp = "^[0-9-_a-zA-Z]*$";
+ private static Pattern asciiPattern = null;
public static final String URL_HYPHEN = "-";
static {
- if (!UrlRegexpConfigUtil.isInitialed()) {
- UrlRegexpConfigUtil.init();
+ if (!SeoConfigUtil.isInitialed()) {
+ SeoConfigUtil.init();
}
try {
- m_asciiPattern = m_perlCompiler.compile(m_asciiRegexp, Perl5Compiler.DEFAULT_MASK);
+ Perl5Compiler perlCompiler = new Perl5Compiler();
+ asciiPattern = perlCompiler.compile(asciiRegexp, Perl5Compiler.READ_ONLY_MASK);
} catch (MalformedPatternException e1) {
Debug.logWarning(e1, module);
}
@@ -130,7 +129,7 @@ public class CatalogUrlSeoTransform impl
}
String catalogUrl = "";
- if (UrlRegexpConfigUtil.isCategoryUrlEnabled(request.getContextPath())) {
+ if (SeoConfigUtil.isCategoryUrlEnabled(request.getContextPath())) {
if (UtilValidate.isEmpty(productId)) {
catalogUrl = makeCategoryUrl(request, currentCategoryId, previousCategoryId, null, null, null, null);
} else {
@@ -154,7 +153,7 @@ public class CatalogUrlSeoTransform impl
* @return a boolean value to indicate whether the category map has been initialized.
*/
public static boolean isCategoryMapInitialed() {
- return m_categoryMapInitialed;
+ return categoryMapInitialed;
}
/**
@@ -163,7 +162,7 @@ public class CatalogUrlSeoTransform impl
* @return the category name/id map
*/
public static Map<String, String> getCategoryNameIdMap() {
- return m_categoryNameIdMap;
+ return categoryNameIdMap;
}
/**
@@ -172,7 +171,7 @@ public class CatalogUrlSeoTransform impl
* @return the category id/name map
*/
public static Map<String, String> getCategoryIdNameMap() {
- return m_categoryIdNameMap;
+ return categoryIdNameMap;
}
/**
@@ -189,9 +188,9 @@ public class CatalogUrlSeoTransform impl
}
public static synchronized void initCategoryMap(HttpServletRequest request, Delegator delegator) {
- if (UrlRegexpConfigUtil.checkCategoryUrl()) {
- m_categoryNameIdMap = FastMap.newInstance();
- m_categoryIdNameMap = FastMap.newInstance();
+ if (SeoConfigUtil.checkCategoryUrl()) {
+ categoryNameIdMap = FastMap.newInstance();
+ categoryIdNameMap = FastMap.newInstance();
Perl5Matcher matcher = new Perl5Matcher();
try {
@@ -202,8 +201,8 @@ public class CatalogUrlSeoTransform impl
String categoryIdName = null;
String categoryId = category.getString("productCategoryId");
if (UtilValidate.isNotEmpty(categoryName)) {
- categoryName = UrlUtil.replaceSpecialCharsUrl(categoryName.trim().toLowerCase());
- if (matcher.matches(categoryName, m_asciiPattern)) {
+ categoryName = SeoUrlUtil.replaceSpecialCharsUrl(categoryName.trim().toLowerCase());
+ if (matcher.matches(categoryName, asciiPattern)) {
categoryIdName = categoryName.toLowerCase().replaceAll(" ", URL_HYPHEN);
categoryNameId = categoryIdName + URL_HYPHEN + categoryId.trim().toLowerCase().replaceAll(" ", URL_HYPHEN);
} else {
@@ -215,28 +214,28 @@ public class CatalogUrlSeoTransform impl
CategoryContentWrapper wrapper = new CategoryContentWrapper(productCategory, request);
StringWrapper alternativeUrl = wrapper.get("ALTERNATIVE_URL");
if (UtilValidate.isNotEmpty(alternativeUrl) && UtilValidate.isNotEmpty(alternativeUrl.toString())) {
- categoryIdName = UrlUtil.replaceSpecialCharsUrl(alternativeUrl.toString());
+ categoryIdName = SeoUrlUtil.replaceSpecialCharsUrl(alternativeUrl.toString());
categoryNameId = categoryIdName + URL_HYPHEN + categoryId.trim().toLowerCase().replaceAll(" ", URL_HYPHEN);
} else {
categoryNameId = categoryId.trim().toLowerCase().replaceAll(" ", URL_HYPHEN);
categoryIdName = categoryNameId;
}
}
- if (m_categoryNameIdMap.containsKey(categoryNameId)) {
+ if (categoryNameIdMap.containsKey(categoryNameId)) {
categoryNameId = categoryId.trim().toLowerCase().replaceAll(" ", URL_HYPHEN);
categoryIdName = categoryNameId;
}
- if (!matcher.matches(categoryNameId, m_asciiPattern) || m_categoryNameIdMap.containsKey(categoryNameId)) {
+ if (!matcher.matches(categoryNameId, asciiPattern) || categoryNameIdMap.containsKey(categoryNameId)) {
continue;
}
- m_categoryNameIdMap.put(categoryNameId, categoryId);
- m_categoryIdNameMap.put(categoryId, categoryIdName);
+ categoryNameIdMap.put(categoryNameId, categoryId);
+ categoryIdNameMap.put(categoryId, categoryIdName);
}
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
}
- m_categoryMapInitialed = true;
+ categoryMapInitialed = true;
}
/**
@@ -271,7 +270,7 @@ public class CatalogUrlSeoTransform impl
if (UtilValidate.isNotEmpty(currentCategoryId)) {
List<String> trail = CategoryWorker.getTrail(request);
trail = CategoryWorker.adjustTrail(trail, currentCategoryId, previousCategoryId);
- if (!UrlRegexpConfigUtil.isCategoryUrlEnabled(contextPath)) {
+ if (!SeoConfigUtil.isCategoryUrlEnabled(contextPath)) {
for (String trailCategoryId: trail) {
if ("TOP".equals(trailCategoryId)) continue;
urlBuilder.append("/");
@@ -281,7 +280,7 @@ public class CatalogUrlSeoTransform impl
if (trail.size() > 1) {
String lastCategoryId = trail.get(trail.size() - 1);
if (!"TOP".equals(lastCategoryId)) {
- if (UrlRegexpConfigUtil.isCategoryNameEnabled()) {
+ if (SeoConfigUtil.isCategoryNameEnabled()) {
String categoryName = CatalogUrlSeoTransform.getCategoryIdNameMap().get(lastCategoryId);
if (UtilValidate.isNotEmpty(categoryName)) {
urlBuilder.append(categoryName);
@@ -298,14 +297,14 @@ public class CatalogUrlSeoTransform impl
if (UtilValidate.isNotEmpty(productId)) {
if (product != null) {
String productName = product.getString("productName");
- productName = UrlUtil.replaceSpecialCharsUrl(productName);
+ productName = SeoUrlUtil.replaceSpecialCharsUrl(productName);
if (UtilValidate.isNotEmpty(productName)) {
urlBuilder.append(productName + URL_HYPHEN);
} else {
ProductContentWrapper wrapper = new ProductContentWrapper(product, request);
StringWrapper alternativeUrl = wrapper.get("ALTERNATIVE_URL");
if (UtilValidate.isNotEmpty(alternativeUrl) && UtilValidate.isNotEmpty(alternativeUrl.toString())) {
- productName = UrlUtil.replaceSpecialCharsUrl(alternativeUrl.toString());
+ productName = SeoUrlUtil.replaceSpecialCharsUrl(alternativeUrl.toString());
if (UtilValidate.isNotEmpty(productName)) {
urlBuilder.append(productName + URL_HYPHEN);
}
@@ -313,15 +312,15 @@ public class CatalogUrlSeoTransform impl
}
}
try {
- UrlRegexpConfigUtil.addSpecialProductId(productId);
+ SeoConfigUtil.addSpecialProductId(productId);
urlBuilder.append(productId.toLowerCase());
} catch (Exception e) {
urlBuilder.append(productId);
}
}
- if (!urlBuilder.toString().endsWith("/") && UtilValidate.isNotEmpty(UrlRegexpConfigUtil.getCategoryUrlSuffix())) {
- urlBuilder.append(UrlRegexpConfigUtil.getCategoryUrlSuffix());
+ if (!urlBuilder.toString().endsWith("/") && UtilValidate.isNotEmpty(SeoConfigUtil.getCategoryUrlSuffix())) {
+ urlBuilder.append(SeoConfigUtil.getCategoryUrlSuffix());
}
return urlBuilder.toString();
@@ -363,8 +362,8 @@ public class CatalogUrlSeoTransform impl
}
}
- if (!urlBuilder.toString().endsWith("/") && UtilValidate.isNotEmpty(UrlRegexpConfigUtil.getCategoryUrlSuffix())) {
- urlBuilder.append(UrlRegexpConfigUtil.getCategoryUrlSuffix());
+ if (!urlBuilder.toString().endsWith("/") && UtilValidate.isNotEmpty(SeoConfigUtil.getCategoryUrlSuffix())) {
+ urlBuilder.append(SeoConfigUtil.getCategoryUrlSuffix());
}
// append view index
@@ -413,7 +412,7 @@ public class CatalogUrlSeoTransform impl
if (urlBuilder.charAt(urlBuilder.length() - 1) != '/') {
urlBuilder.append("/");
}
- if (!UrlRegexpConfigUtil.isCategoryUrlEnabled(contextPath)) {
+ if (!SeoConfigUtil.isCategoryUrlEnabled(contextPath)) {
urlBuilder.append(CatalogUrlServlet.CATALOG_URL_MOUNT_POINT);
} else {
urlBuilder.append(CatalogUrlServlet.PRODUCT_REQUEST + "/");
@@ -421,7 +420,7 @@ public class CatalogUrlSeoTransform impl
if (UtilValidate.isNotEmpty(currentCategoryId)) {
trail = CategoryWorker.adjustTrail(trail, currentCategoryId, previousCategoryId);
- if (!UrlRegexpConfigUtil.isCategoryUrlEnabled(contextPath)) {
+ if (!SeoConfigUtil.isCategoryUrlEnabled(contextPath)) {
for (String trailCategoryId: trail) {
if ("TOP".equals(trailCategoryId)) continue;
urlBuilder.append("/");
@@ -431,7 +430,7 @@ public class CatalogUrlSeoTransform impl
if (trail.size() > 1) {
String lastCategoryId = trail.get(trail.size() - 1);
if (!"TOP".equals(lastCategoryId)) {
- if (UrlRegexpConfigUtil.isCategoryNameEnabled()) {
+ if (SeoConfigUtil.isCategoryNameEnabled()) {
String categoryName = CatalogUrlSeoTransform.getCategoryIdNameMap().get(lastCategoryId);
if (UtilValidate.isNotEmpty(categoryName)) {
urlBuilder.append(categoryName + URL_HYPHEN);
@@ -443,10 +442,10 @@ public class CatalogUrlSeoTransform impl
}
if (UtilValidate.isNotEmpty(productId)) {
- if (!UrlRegexpConfigUtil.isCategoryUrlEnabled(contextPath)) {
+ if (!SeoConfigUtil.isCategoryUrlEnabled(contextPath)) {
urlBuilder.append("/p_");
} else {
- productName = UrlUtil.replaceSpecialCharsUrl(productName);
+ productName = SeoUrlUtil.replaceSpecialCharsUrl(productName);
if (UtilValidate.isNotEmpty(productName)) {
urlBuilder.append(productName + URL_HYPHEN);
}
@@ -454,8 +453,8 @@ public class CatalogUrlSeoTransform impl
urlBuilder.append(productId);
}
- if (!urlBuilder.toString().endsWith("/") && UtilValidate.isNotEmpty(UrlRegexpConfigUtil.getCategoryUrlSuffix())) {
- urlBuilder.append(UrlRegexpConfigUtil.getCategoryUrlSuffix());
+ if (!urlBuilder.toString().endsWith("/") && UtilValidate.isNotEmpty(SeoConfigUtil.getCategoryUrlSuffix())) {
+ urlBuilder.append(SeoConfigUtil.getCategoryUrlSuffix());
}
return urlBuilder.toString();
@@ -472,7 +471,7 @@ public class CatalogUrlSeoTransform impl
String niceName = null;
if (UtilValidate.isNotEmpty(name)) {
name = name.trim().toLowerCase().replaceAll(" ", URL_HYPHEN);
- if (UtilValidate.isNotEmpty(name) && matcher.matches(name, m_asciiPattern)) {
+ if (UtilValidate.isNotEmpty(name) && matcher.matches(name, asciiPattern)) {
niceName = name;
}
}
@@ -503,7 +502,7 @@ public class CatalogUrlSeoTransform impl
initCategoryMap(request, delegator);
}
- if (!UrlRegexpConfigUtil.isCategoryUrlEnabled(contextPath)) {
+ if (!SeoConfigUtil.isCategoryUrlEnabled(contextPath)) {
return false;
}
List<String> pathElements = StringUtil.split(pathInfo, "/");
@@ -522,17 +521,17 @@ public class CatalogUrlSeoTransform impl
String categoryId = null;
String productId = null;
if (UtilValidate.isNotEmpty(lastPathElement)) {
- if (UtilValidate.isNotEmpty(UrlRegexpConfigUtil.getCategoryUrlSuffix())) {
- if (lastPathElement.endsWith(UrlRegexpConfigUtil.getCategoryUrlSuffix())) {
- lastPathElement = lastPathElement.substring(0, lastPathElement.length() - UrlRegexpConfigUtil.getCategoryUrlSuffix().length());
+ if (UtilValidate.isNotEmpty(SeoConfigUtil.getCategoryUrlSuffix())) {
+ if (lastPathElement.endsWith(SeoConfigUtil.getCategoryUrlSuffix())) {
+ lastPathElement = lastPathElement.substring(0, lastPathElement.length() - SeoConfigUtil.getCategoryUrlSuffix().length());
} else {
return false;
}
}
- if (UrlRegexpConfigUtil.isCategoryNameEnabled() || pathInfo.startsWith("/" + CatalogUrlServlet.CATEGORY_REQUEST + "/")) {
- for (String categoryName : m_categoryNameIdMap.keySet()) {
+ if (SeoConfigUtil.isCategoryNameEnabled() || pathInfo.startsWith("/" + CatalogUrlServlet.CATEGORY_REQUEST + "/")) {
+ for (String categoryName : categoryNameIdMap.keySet()) {
if (lastPathElement.startsWith(categoryName)) {
- categoryId = m_categoryNameIdMap.get(categoryName);
+ categoryId = categoryNameIdMap.get(categoryName);
if (!lastPathElement.equals(categoryName)) {
lastPathElement = lastPathElement.substring(categoryName.length() + URL_HYPHEN.length());
}
@@ -561,8 +560,8 @@ public class CatalogUrlSeoTransform impl
try {
List<EntityExpr> exprs = FastList.newInstance();
exprs.add(EntityCondition.makeCondition("productId", EntityOperator.EQUALS, lastPathElement));
- if (UrlRegexpConfigUtil.isSpecialProductId(tempProductId)) {
- exprs.add(EntityCondition.makeCondition("productId", EntityOperator.EQUALS, UrlRegexpConfigUtil.getSpecialProductId(tempProductId)));
+ if (SeoConfigUtil.isSpecialProductId(tempProductId)) {
+ exprs.add(EntityCondition.makeCondition("productId", EntityOperator.EQUALS, SeoConfigUtil.getSpecialProductId(tempProductId)));
} else {
exprs.add(EntityCondition.makeCondition("productId", EntityOperator.EQUALS, tempProductId.toUpperCase()));
}
@@ -627,7 +626,7 @@ public class CatalogUrlSeoTransform impl
if (!isCategoryMapInitialed()) {
initCategoryMap(request);
}
- if (!UrlRegexpConfigUtil.isCategoryUrlEnabled(contextPath)) {
+ if (!SeoConfigUtil.isCategoryUrlEnabled(contextPath)) {
return false;
}
List<String> pathElements = StringUtil.split(pathInfo, "/");
@@ -637,16 +636,16 @@ public class CatalogUrlSeoTransform impl
String lastPathElement = pathElements.get(pathElements.size() - 1);
String categoryId = null;
if (UtilValidate.isNotEmpty(lastPathElement)) {
- if (UtilValidate.isNotEmpty(UrlRegexpConfigUtil.getCategoryUrlSuffix())) {
- if (lastPathElement.endsWith(UrlRegexpConfigUtil.getCategoryUrlSuffix())) {
- lastPathElement = lastPathElement.substring(0, lastPathElement.length() - UrlRegexpConfigUtil.getCategoryUrlSuffix().length());
+ if (UtilValidate.isNotEmpty(SeoConfigUtil.getCategoryUrlSuffix())) {
+ if (lastPathElement.endsWith(SeoConfigUtil.getCategoryUrlSuffix())) {
+ lastPathElement = lastPathElement.substring(0, lastPathElement.length() - SeoConfigUtil.getCategoryUrlSuffix().length());
} else {
return false;
}
}
- for (String categoryName : m_categoryNameIdMap.keySet()) {
+ for (String categoryName : categoryNameIdMap.keySet()) {
if (lastPathElement.startsWith(categoryName)) {
- categoryId = m_categoryNameIdMap.get(categoryName);
+ categoryId = categoryNameIdMap.get(categoryName);
break;
}
}
Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/ftl/SeoTransform.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/ftl/SeoTransform.java?rev=1537495&r1=1537494&r2=1537495&view=diff
==============================================================================
--- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/ftl/SeoTransform.java (original)
+++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/ftl/SeoTransform.java Thu Oct 31 14:06:50 2013
@@ -174,8 +174,8 @@ public class SeoTransform implements Tem
break;
}
}
- if (!foundMatch && SeoConfigUtil.isDebugEnabled()) {
- Debug.logInfo("Can NOT find a seo transform pattern for this url: " + url, module);
+ if (!foundMatch) {
+ Debug.logVerbose("Can NOT find a seo transform pattern for this url: " + url, module);
}
}
return url;
Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/ftl/UrlRegexpTransform.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/ftl/UrlRegexpTransform.java?rev=1537495&r1=1537494&r2=1537495&view=diff
==============================================================================
--- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/ftl/UrlRegexpTransform.java (original)
+++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/ftl/UrlRegexpTransform.java Thu Oct 31 14:06:50 2013
@@ -32,7 +32,7 @@ import org.apache.oro.text.regex.Pattern
import org.apache.oro.text.regex.Perl5Matcher;
import org.ofbiz.base.util.Debug;
import org.ofbiz.entity.GenericValue;
-import org.ofbiz.product.category.UrlRegexpConfigUtil;
+import org.ofbiz.product.category.SeoConfigUtil;
import org.ofbiz.webapp.control.RequestHandler;
import freemarker.core.Environment;
@@ -137,24 +137,24 @@ public class UrlRegexpTransform implemen
*/
public static String seoUrl(String url, boolean isAnon) {
Perl5Matcher matcher = new Perl5Matcher();
- if (UrlRegexpConfigUtil.checkUseUrlRegexp() && matcher.matches(url, UrlRegexpConfigUtil.getGeneralRegexpPattern())) {
- Iterator<String> keys = UrlRegexpConfigUtil.getSeoPatterns().keySet().iterator();
+ if (SeoConfigUtil.checkUseUrlRegexp() && matcher.matches(url, SeoConfigUtil.getGeneralRegexpPattern())) {
+ Iterator<String> keys = SeoConfigUtil.getSeoPatterns().keySet().iterator();
boolean foundMatch = false;
while (keys.hasNext()) {
String key = keys.next();
- Pattern pattern = UrlRegexpConfigUtil.getSeoPatterns().get(key);
+ Pattern pattern = SeoConfigUtil.getSeoPatterns().get(key);
if (pattern.getPattern().contains(";jsessionid=")) {
if (isAnon) {
- if (UrlRegexpConfigUtil.isJSessionIdAnonEnabled()) {
+ if (SeoConfigUtil.isJSessionIdAnonEnabled()) {
continue;
}
} else {
- if (UrlRegexpConfigUtil.isJSessionIdUserEnabled()) {
+ if (SeoConfigUtil.isJSessionIdUserEnabled()) {
continue;
} else {
boolean foundException = false;
- for (int i = 0; i < UrlRegexpConfigUtil.getUserExceptionPatterns().size(); i++) {
- if (matcher.matches(url, UrlRegexpConfigUtil.getUserExceptionPatterns().get(i))) {
+ for (int i = 0; i < SeoConfigUtil.getUserExceptionPatterns().size(); i++) {
+ if (matcher.matches(url, SeoConfigUtil.getUserExceptionPatterns().get(i))) {
foundException = true;
break;
}
@@ -165,7 +165,7 @@ public class UrlRegexpTransform implemen
}
}
}
- String replacement = UrlRegexpConfigUtil.getSeoReplacements().get(key);
+ String replacement = SeoConfigUtil.getSeoReplacements().get(key);
if (matcher.matches(url, pattern)) {
for (int i = 1; i < matcher.getMatch().groups(); i++) {
replacement = replacement.replaceAll("\\$" + i, matcher.getMatch().group(i));
@@ -176,15 +176,15 @@ public class UrlRegexpTransform implemen
break;
}
}
- if (!foundMatch && UrlRegexpConfigUtil.isDebugEnabled()) {
- Debug.logInfo("Can NOT find a seo transform pattern for this url: " + url, module);
+ if (!foundMatch) {
+ Debug.logVerbose("Can NOT find a seo transform pattern for this url: " + url, module);
}
}
return url;
}
static {
- UrlRegexpConfigUtil.init();
+ SeoConfigUtil.init();
}
/**
@@ -198,19 +198,19 @@ public class UrlRegexpTransform implemen
Perl5Matcher matcher = new Perl5Matcher();
boolean foundMatch = false;
Integer responseCodeInt = null;
- if (UrlRegexpConfigUtil.checkUseUrlRegexp() && UrlRegexpConfigUtil.getForwardPatterns() != null && UrlRegexpConfigUtil.getForwardReplacements() != null) {
- Iterator<String> keys = UrlRegexpConfigUtil.getForwardPatterns().keySet().iterator();
+ if (SeoConfigUtil.checkUseUrlRegexp() && SeoConfigUtil.getSeoPatterns() != null && SeoConfigUtil.getForwardReplacements() != null) {
+ Iterator<String> keys = SeoConfigUtil.getSeoPatterns().keySet().iterator();
while (keys.hasNext()) {
String key = keys.next();
- Pattern pattern = UrlRegexpConfigUtil.getForwardPatterns().get(key);
- String replacement = UrlRegexpConfigUtil.getForwardReplacements().get(key);
+ Pattern pattern = SeoConfigUtil.getSeoPatterns().get(key);
+ String replacement = SeoConfigUtil.getForwardReplacements().get(key);
if (matcher.matches(uri, pattern)) {
for (int i = 1; i < matcher.getMatch().groups(); i++) {
replacement = replacement.replaceAll("\\$" + i, matcher.getMatch().group(i));
}
// break if found any matcher
uri = replacement;
- responseCodeInt = UrlRegexpConfigUtil.getForwardResponseCodes().get(key);
+ responseCodeInt = SeoConfigUtil.getForwardResponseCodes().get(key);
foundMatch = true;
break;
}
@@ -218,12 +218,12 @@ public class UrlRegexpTransform implemen
}
if (foundMatch) {
if (responseCodeInt == null) {
- response.setStatus(UrlRegexpConfigUtil.DEFAULT_RESPONSECODE);
+ response.setStatus(SeoConfigUtil.DEFAULT_RESPONSECODE);
} else {
response.setStatus(responseCodeInt.intValue());
}
response.setHeader("Location", uri);
- } else if (UrlRegexpConfigUtil.isDebugEnabled()) {
+ } else {
Debug.logInfo("Can NOT forward this url: " + uri, module);
}
return foundMatch;