Permalink
Browse files

Merge remote-tracking branch 'upstream/trunk' into trunk

  • Loading branch information...
2 parents a3c81c9 + f9b96ab commit f3c300e8eb4735a6ca2450899196930796f4e01b @samhamilton samhamilton committed Aug 12, 2011
View
@@ -37,7 +37,6 @@
<classpathentry kind="lib" path="framework/base/lib/ical4j-1.0-rc2.jar"/>
<classpathentry kind="lib" path="framework/base/lib/icu4j-4_4.jar"/>
<classpathentry kind="lib" path="framework/base/lib/ivy-2.2.0.jar"/>
- <classpathentry kind="lib" path="framework/base/lib/jakarta-regexp-1.5.jar"/>
<classpathentry kind="lib" path="framework/base/lib/javolution-5.4.3.jar"/>
<classpathentry kind="lib" path="framework/base/lib/jcip-annotations-1.0.jar"/>
<classpathentry kind="lib" path="framework/base/lib/jdbm-1.0-SNAPSHOT.jar"/>
@@ -36,9 +36,9 @@ if (invoiceTypeId) {
LESS_THAN(dueDate: UtilDateTime.nowTimestamp())
}
if ("PURCHASE_INVOICE".equals(invoiceTypeId)) {
- invoiceStatusesCondition = exprBldr.IN(statusId: ["INVOICE_RECEIVED", "INVOICE_IN_PROCESS"])
+ invoiceStatusesCondition = exprBldr.IN(statusId: ["INVOICE_RECEIVED", "INVOICE_IN_PROCESS", "INVOICE_READY"])
} else if ("SALES_INVOICE".equals(invoiceTypeId)) {
- invoiceStatusesCondition = exprBldr.IN(statusId: ["INVOICE_SENT", "INVOICE_APPROVED"])
+ invoiceStatusesCondition = exprBldr.IN(statusId: ["INVOICE_SENT", "INVOICE_APPROVED", "INVOICE_READY"])
}
expr = exprBldr.AND([expr, invoiceStatusesCondition]);
@@ -53,6 +53,7 @@ if (invoiceTypeId) {
}
invoicesCond = exprBldr.AND(invoiceStatusesCondition) {
+ EQUALS(invoiceTypeId: invoiceTypeId)
GREATER_THAN_EQUAL_TO(dueDate: UtilDateTime.nowTimestamp())
}
EntityFindOptions findOptions = new EntityFindOptions();
@@ -648,6 +648,10 @@
<value xml:lang="zh">内容</value>
<value xml:lang="zh_TW">內容</value>
</property>
+ <property key="ContentContents">
+ <value xml:lang="en">Contents</value>
+ <value xml:lang="fr">Contenus</value>
+ </property>
<property key="ContentContentCreatingError">
<value xml:lang="en">Error creating content in ${serviceName}</value>
<value xml:lang="fr">Erreur de création du document dans le service ${serviceName}</value>
@@ -338,66 +338,76 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
public static String makeCategoryUrl(HttpServletRequest request, String previousCategoryId, String productCategoryId, String productId, String viewSize, String viewIndex, String viewSort, String searchString) {
Delegator delegator = (Delegator) request.getAttribute("delegator");
- String url = null;
try {
GenericValue productCategory = delegator.findOne("ProductCategory", UtilMisc.toMap("productCategoryId", productCategoryId), true);
CategoryContentWrapper wrapper = new CategoryContentWrapper(productCategory, request);
- StringWrapper alternativeUrl = wrapper.get("ALTERNATIVE_URL");
-
- if (UtilValidate.isNotEmpty(alternativeUrl) && UtilValidate.isNotEmpty(alternativeUrl.toString())) {
- StringBuilder urlBuilder = new StringBuilder();
- urlBuilder.append(request.getSession().getServletContext().getContextPath());
- if (urlBuilder.charAt(urlBuilder.length() - 1) != '/') {
- urlBuilder.append("/");
- }
- // append alternative URL
- url = UrlServletHelper.invalidCharacter(alternativeUrl.toString());
- urlBuilder.append(url);
- if (UtilValidate.isNotEmpty(productCategoryId)) {
- urlBuilder.append("-");
- urlBuilder.append(productCategoryId);
- urlBuilder.append("-c");
- }
- // append view index
- if (UtilValidate.isNotEmpty(viewIndex)) {
- if (!urlBuilder.toString().endsWith("?") && !urlBuilder.toString().endsWith("&")) {
- urlBuilder.append("?");
- }
- urlBuilder.append("viewIndex=" + viewIndex + "&");
- }
- // append view size
- if (UtilValidate.isNotEmpty(viewSize)) {
- if (!urlBuilder.toString().endsWith("?") && !urlBuilder.toString().endsWith("&")) {
- urlBuilder.append("?");
- }
- urlBuilder.append("viewSize=" + viewSize + "&");
+ List<String> trail = CategoryWorker.getTrail(request);
+ return makeCategoryUrl(delegator, wrapper, trail, request.getSession().getServletContext().getContextPath(), previousCategoryId, productCategoryId, productId, viewSize, viewIndex, viewSort, searchString);
+ } catch (GenericEntityException e) {
+ Debug.logWarning(e, "Cannot create category's URL for: " + productCategoryId, module);
+ return redirectUrl;
+ }
+ }
+
+ public static String makeCategoryUrl(Delegator delegator, CategoryContentWrapper wrapper, List<String> trail, String contextPath, String previousCategoryId, String productCategoryId, String productId, String viewSize, String viewIndex, String viewSort, String searchString) {
+ String url = "";
+ StringWrapper alternativeUrl = wrapper.get("ALTERNATIVE_URL");
+
+ if (UtilValidate.isNotEmpty(alternativeUrl) && UtilValidate.isNotEmpty(alternativeUrl.toString())) {
+ StringBuilder urlBuilder = new StringBuilder();
+ urlBuilder.append(contextPath);
+ if (urlBuilder.charAt(urlBuilder.length() - 1) != '/') {
+ urlBuilder.append("/");
+ }
+ // append alternative URL
+ url = UrlServletHelper.invalidCharacter(alternativeUrl.toString());
+ urlBuilder.append(url);
+ if (UtilValidate.isNotEmpty(productCategoryId)) {
+ urlBuilder.append("-");
+ urlBuilder.append(productCategoryId);
+ urlBuilder.append("-c");
+ }
+ // append view index
+ if (UtilValidate.isNotEmpty(viewIndex)) {
+ if (!urlBuilder.toString().endsWith("?") && !urlBuilder.toString().endsWith("&")) {
+ urlBuilder.append("?");
}
- // append view sort
- if (UtilValidate.isNotEmpty(viewSort)) {
- if (!urlBuilder.toString().endsWith("?") && !urlBuilder.toString().endsWith("&")) {
- urlBuilder.append("?");
- }
- urlBuilder.append("viewSort=" + viewSort + "&");
+ urlBuilder.append("viewIndex=" + viewIndex + "&");
+ }
+ // append view size
+ if (UtilValidate.isNotEmpty(viewSize)) {
+ if (!urlBuilder.toString().endsWith("?") && !urlBuilder.toString().endsWith("&")) {
+ urlBuilder.append("?");
}
- // append search string
- if (UtilValidate.isNotEmpty(searchString)) {
- if (!urlBuilder.toString().endsWith("?") && !urlBuilder.toString().endsWith("&")) {
- urlBuilder.append("?");
- }
- urlBuilder.append("searchString=" + searchString + "&");
+ urlBuilder.append("viewSize=" + viewSize + "&");
+ }
+ // append view sort
+ if (UtilValidate.isNotEmpty(viewSort)) {
+ if (!urlBuilder.toString().endsWith("?") && !urlBuilder.toString().endsWith("&")) {
+ urlBuilder.append("?");
}
- if (urlBuilder.toString().endsWith("&")) {
- return urlBuilder.toString().substring(0, urlBuilder.toString().length()-1);
+ urlBuilder.append("viewSort=" + viewSort + "&");
+ }
+ // append search string
+ if (UtilValidate.isNotEmpty(searchString)) {
+ if (!urlBuilder.toString().endsWith("?") && !urlBuilder.toString().endsWith("&")) {
+ urlBuilder.append("?");
}
-
- return urlBuilder.toString();
- } else {
- return CatalogUrlServlet.makeCatalogUrl(request, productId, productCategoryId, previousCategoryId);
+ urlBuilder.append("searchString=" + searchString + "&");
}
- } catch (GenericEntityException e) {
- Debug.logWarning(e, "Cannot create category's URL for: " + productCategoryId, module);
- return redirectUrl;
+ if (urlBuilder.toString().endsWith("&")) {
+ return urlBuilder.toString().substring(0, urlBuilder.toString().length()-1);
+ }
+
+ url = urlBuilder.toString();
+ } else {
+ if(UtilValidate.isEmpty(trail)){
+ trail = FastList.newInstance();
+ }
+ url = CatalogUrlServlet.makeCatalogUrl(contextPath, trail, productId, productCategoryId, previousCategoryId);
}
+
+ return url;
}
public static String makeProductUrl(HttpServletRequest request, String previousCategoryId, String productCategoryId, String productId) {
@@ -406,29 +416,39 @@ public static String makeProductUrl(HttpServletRequest request, String previousC
try {
GenericValue product = delegator.findOne("Product", UtilMisc.toMap("productId", productId), true);
ProductContentWrapper wrapper = new ProductContentWrapper(product, request);
- StringWrapper alternativeUrl = wrapper.get("ALTERNATIVE_URL");
- if (UtilValidate.isNotEmpty(alternativeUrl) && UtilValidate.isNotEmpty(alternativeUrl.toString())) {
- StringBuilder urlBuilder = new StringBuilder();
- urlBuilder.append(request.getSession().getServletContext().getContextPath());
- if (urlBuilder.charAt(urlBuilder.length() - 1) != '/') {
- urlBuilder.append("/");
- }
- // append alternative URL
- url = UrlServletHelper.invalidCharacter(alternativeUrl.toString());
- urlBuilder.append(url);
- if (UtilValidate.isNotEmpty(productId)) {
- urlBuilder.append("-");
- urlBuilder.append(productId);
- urlBuilder.append("-p");
- }
- return urlBuilder.toString();
- } else {
- return CatalogUrlServlet.makeCatalogUrl(request, productId, productCategoryId, previousCategoryId);
- }
+ List<String> trail = CategoryWorker.getTrail(request);
+ url = makeProductUrl(delegator, wrapper, trail, request.getSession().getServletContext().getContextPath(), previousCategoryId, productCategoryId, productId);
} catch (GenericEntityException e) {
Debug.logWarning(e, "Cannot create product's URL for: " + productId, module);
return redirectUrl;
}
+ return url;
+ }
+
+ public static String makeProductUrl(Delegator delegator, ProductContentWrapper wrapper,List<String> trail, String contextPath, String previousCategoryId, String productCategoryId, String productId) {
+ String url = "";
+ StringWrapper alternativeUrl = wrapper.get("ALTERNATIVE_URL");
+ if (UtilValidate.isNotEmpty(alternativeUrl) && UtilValidate.isNotEmpty(alternativeUrl.toString())) {
+ StringBuilder urlBuilder = new StringBuilder();
+ urlBuilder.append(contextPath);
+ if (urlBuilder.charAt(urlBuilder.length() - 1) != '/') {
+ urlBuilder.append("/");
+ }
+ // append alternative URL
+ url = UrlServletHelper.invalidCharacter(alternativeUrl.toString());
+ urlBuilder.append(url);
+ if (UtilValidate.isNotEmpty(productId)) {
+ urlBuilder.append("-");
+ urlBuilder.append(productId);
+ urlBuilder.append("-p");
+ }
+ url = urlBuilder.toString();
+ } else {
+ if(UtilValidate.isEmpty(trail)){
+ trail = FastList.newInstance();
+ }
+ url = CatalogUrlServlet.makeCatalogUrl(contextPath, trail, productId, productCategoryId, previousCategoryId);
+ }
+ return url;
}
-
}
@@ -179,4 +179,29 @@ public static String makeCatalogUrl(HttpServletRequest request, String productId
return urlBuilder.toString();
}
+
+ public static String makeCatalogUrl(String contextPath, List<String> crumb, String productId, String currentCategoryId, String previousCategoryId) {
+ StringBuilder urlBuilder = new StringBuilder();
+ urlBuilder.append(contextPath);
+ if (urlBuilder.charAt(urlBuilder.length() - 1) != '/') {
+ urlBuilder.append("/");
+ }
+ urlBuilder.append(CATALOG_URL_MOUNT_POINT);
+
+ if (UtilValidate.isNotEmpty(currentCategoryId)) {
+ crumb = CategoryWorker.adjustTrail(crumb, currentCategoryId, previousCategoryId);
+ for (String trailCategoryId: crumb) {
+ if ("TOP".equals(trailCategoryId)) continue;
+ urlBuilder.append("/");
+ urlBuilder.append(trailCategoryId);
+ }
+ }
+
+ if (UtilValidate.isNotEmpty(productId)) {
+ urlBuilder.append("/p_");
+ urlBuilder.append(productId);
+ }
+
+ return urlBuilder.toString();
+ }
}
@@ -20,12 +20,22 @@
import java.io.IOException;
import java.io.Writer;
+import java.util.Locale;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
+import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.base.util.template.FreeMarkerWorker;
+import org.ofbiz.entity.Delegator;
+import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.product.product.ProductContentWrapper;
+import org.ofbiz.service.LocalDispatcher;
+import org.ofbiz.webapp.control.RequestHandler;
+
import freemarker.core.Environment;
import freemarker.ext.beans.BeanModel;
import freemarker.ext.beans.NumberModel;
@@ -53,11 +63,27 @@ public String getStringArg(Map args, String key) {
return null;
}
+ public boolean checkArg(Map args, String key, boolean defaultValue) {
+ if (!args.containsKey(key)) {
+ return defaultValue;
+ } else {
+ Object o = args.get(key);
+ if (o instanceof SimpleScalar) {
+ SimpleScalar s = (SimpleScalar) o;
+ return "true".equalsIgnoreCase(s.getAsString());
+ }
+ return defaultValue;
+ }
+ }
+
@Override
@SuppressWarnings("unchecked")
public Writer getWriter(final Writer out, final Map args)
throws TemplateModelException, IOException {
final StringBuilder buf = new StringBuilder();
+ final boolean fullPath = checkArg(args, "fullPath", false);
+ final boolean secure = checkArg(args, "secure", false);
+
return new Writer(out) {
public void write(char[] cbuf, int off, int len) throws IOException {
@@ -70,28 +96,54 @@ public void flush() throws IOException {
public void close() throws IOException {
try {
- Environment env = Environment.getCurrentEnvironment();
- BeanModel req = (BeanModel) env.getVariable("request");
- if (req != null) {
+ Environment env = Environment.getCurrentEnvironment();
+ BeanModel req = (BeanModel) env.getVariable("request");
String previousCategoryId = getStringArg(args, "previousCategoryId");
String productCategoryId = getStringArg(args, "productCategoryId");
String productId = getStringArg(args, "productId");
-
- HttpServletRequest request = (HttpServletRequest) req.getWrappedObject();
String url = "";
- if (UtilValidate.isNotEmpty(productId)) {
- url = CatalogUrlFilter.makeProductUrl(request, previousCategoryId, productCategoryId, productId);
+
+ Object prefix = env.getVariable("urlPrefix");
+ String viewSize = getStringArg(args, "viewSize");
+ String viewIndex = getStringArg(args, "viewIndex");
+ String viewSort = getStringArg(args, "viewSort");
+ String searchString = getStringArg(args, "searchString");
+ if (req != null) {
+ HttpServletRequest request = (HttpServletRequest) req.getWrappedObject();
+ StringBuilder newURL = new StringBuilder();
+ if (UtilValidate.isNotEmpty(productId)) {
+ url = CatalogUrlFilter.makeProductUrl(request, previousCategoryId, productCategoryId, productId);
+ } else {
+ url = CatalogUrlFilter.makeCategoryUrl(request, previousCategoryId, productCategoryId, productId, viewSize, viewIndex, viewSort, searchString);
+ }
+ // make the link
+ if (fullPath){
+ String serverRootUrl = RequestHandler.getDefaultServerRootUrl(request, secure);
+ newURL.append(serverRootUrl);
+ }
+ newURL.append(url);
+ out.write(newURL.toString());
+ } else if (prefix != null) {
+ Delegator delegator = FreeMarkerWorker.getWrappedObject("delegator", env);
+ LocalDispatcher dispatcher = FreeMarkerWorker.getWrappedObject("dispatcher", env);
+ Locale locale = (Locale) args.get("locale");
+ if (UtilValidate.isNotEmpty(productId)) {
+ GenericValue product = delegator.findOne("Product", UtilMisc.toMap("productId", productId), false);
+ ProductContentWrapper wrapper = new ProductContentWrapper(dispatcher, product, locale, "text/html");
+ url = CatalogUrlFilter.makeProductUrl(delegator, wrapper, null, ((StringModel) prefix).getAsString(), previousCategoryId, productCategoryId, productId);
+ } else {
+ GenericValue productCategory = delegator.findOne("ProductCategory", UtilMisc.toMap("productCategoryId", productCategoryId), false);
+ CategoryContentWrapper wrapper = new CategoryContentWrapper(dispatcher, productCategory, locale, "text/html");
+ url = CatalogUrlFilter.makeCategoryUrl(delegator, wrapper, null, ((StringModel) prefix).getAsString(), previousCategoryId, productCategoryId, productId, viewSize, viewIndex, viewSort, searchString);
+ }
+ out.write(url.toString());
} else {
- String viewSize = getStringArg(args, "viewSize");
- String viewIndex = getStringArg(args, "viewIndex");
- String viewSort = getStringArg(args, "viewSort");
- String searchString = getStringArg(args, "searchString");
- url = CatalogUrlFilter.makeCategoryUrl(request, previousCategoryId, productCategoryId, productId, viewSize, viewIndex, viewSort, searchString);
+ out.write(buf.toString());
}
- out.write(url);
- }
} catch (TemplateModelException e) {
throw new IOException(e.getMessage());
+ } catch (GenericEntityException e) {
+ throw new IOException(e.getMessage());
}
}
};
Oops, something went wrong.

0 comments on commit f3c300e

Please sign in to comment.