Skip to content

Commit 9472e96

Browse files
committed
For QA#878, provide services to build a relative URL for a product or category. Add file that was left out of prior commit.
1 parent e4e6273 commit 9472e96

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* #%L
3+
* BroadleafCommerce Common Libraries
4+
* %%
5+
* Copyright (C) 2009 - 2013 Broadleaf Commerce
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
21+
package org.broadleafcommerce.core.web.expression;
22+
23+
import org.broadleafcommerce.common.web.BroadleafRequestContext;
24+
import org.broadleafcommerce.common.web.expression.BroadleafVariableExpression;
25+
import org.broadleafcommerce.core.catalog.domain.Category;
26+
import org.broadleafcommerce.core.catalog.domain.Product;
27+
import org.broadleafcommerce.core.catalog.service.CatalogURLService;
28+
import org.springframework.util.StringUtils;
29+
30+
import javax.annotation.Resource;
31+
32+
/**
33+
* Exposes "blc" to expressions to the Thymeleaf expression context.
34+
*
35+
* This class is intended to be augmented using load time weaving by other modules
36+
* within Broadleaf.
37+
*
38+
* It provides one function (getDate()) primarily just for testing purposes. This can
39+
* be accessed with Thymeleaf as ${#blc.date()}
40+
*
41+
* @author bpolster
42+
*/
43+
public class BLCVariableExpression implements BroadleafVariableExpression {
44+
45+
@Override
46+
public String getName() {
47+
return "blc";
48+
}
49+
50+
@Resource(name = "blCatalogURLService")
51+
protected CatalogURLService catalogURLService;
52+
53+
public String relativeURL(Category category) {
54+
return catalogURLService.buildRelativeCategoryURL(getCurrentUrl(), category);
55+
}
56+
57+
public String relativeURL(Product product) {
58+
return catalogURLService.buildRelativeProductURL(getCurrentUrl(), product);
59+
}
60+
61+
public String relativeURL(String baseUrl, Category category) {
62+
return catalogURLService.buildRelativeCategoryURL(baseUrl, category);
63+
}
64+
65+
public String relativeURL(String baseUrl, Product product) {
66+
return catalogURLService.buildRelativeProductURL(baseUrl, product);
67+
}
68+
69+
protected String getCurrentUrl() {
70+
BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
71+
String currentUrl = "";
72+
if (brc != null && brc.getRequest() != null) {
73+
currentUrl = brc.getRequest().getRequestURI();
74+
75+
if (!StringUtils.isEmpty(brc.getRequest().getQueryString())) {
76+
currentUrl = currentUrl + "?" + brc.getRequest().getQueryString();
77+
}
78+
}
79+
return currentUrl;
80+
}
81+
}

0 commit comments

Comments
 (0)