public class UrlBeautifier
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
UrlBeautifier.UrlBeautificationException |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
PARAM_REPLACEMENT |
static java.lang.String |
SEARCH_NAVIGATION_NAME |
| Modifier and Type | Method and Description |
|---|---|
void |
addRefinementMapping(char pToken,
java.lang.String pName)
Set up a mapping for a refinement. |
void |
addReplacementRule(char pTarget,
java.lang.Character pReplacement)
Adds a new replacement rule that will be applied to the search term and mapped refinements. |
void |
addReplacementRule(char pTarget,
java.lang.Character pReplacement,
java.lang.String pRefinementName)
Adds a new replacement rule that will only be applied to the specified refinement. |
void |
clearSavedFields()
Clean up all mappings. |
protected Query |
createQuery() |
static void |
createUrlBeautifier(java.lang.String name)
Create a UrlBeautifier and store it for the lifetime of this JVM under the name specified. |
Query |
fromUrl(java.lang.String uri)
Convert a URI into a query object. |
Query |
fromUrl(java.lang.String url,
Query defaultQuery)
Convert a URI into a query object. |
java.lang.String |
getAppend()
Return the current appended URL segment
|
java.lang.String |
getRefinementsQueryParameterName() |
static java.util.Map<java.lang.String,UrlBeautifier> |
getUrlBeautifiers()
Get a map of UrlBeautifiers keyed by name. |
void |
setAppend(java.lang.String pAppend)
Quite often URLs need to end with specific extensions to map to the correct controller in the backend. |
void |
setRefinementsQueryParameterName(java.lang.String pRefinementsQueryParameterName)
Sets the name of the query parameter with which non-mapped refinements will show up in the query string. |
void |
setSearchMapping(char pToken)
Set the mapping from a search term to a path segment. |
java.lang.String |
toUrl(java.lang.String searchString,
java.util.Map<java.lang.String,Navigation> navigations)
Convert a search term and a list of refinements into a beautified URL. |
java.lang.String |
toUrl(java.lang.String searchString,
java.lang.String existingRefinements)
Deprecated.
Use
#toUrl(String, Map ()} |
public static final java.lang.String PARAM_REPLACEMENT
public static final java.lang.String SEARCH_NAVIGATION_NAME
public static void createUrlBeautifier(java.lang.String name)
Create a UrlBeautifier and store it for the lifetime of this JVM under the name specified.
name - The handle back to this UrlBeautifierpublic static java.util.Map<java.lang.String,UrlBeautifier> getUrlBeautifiers()
Get a map of UrlBeautifiers keyed by name.
@Deprecated
public java.lang.String toUrl(java.lang.String searchString,
java.lang.String existingRefinements)
throws UrlBeautifier.UrlBeautificationException
#toUrl(String, Map) ()}
Convert a search term and a list of refinements into a beautified URL.
Each refinement that has a mapping will be turned into a path segment.
If a mapping has been created for search, the search term will also be
placed into a URL path segment.
searchString - The current search state.existingRefinements - The current refinement stateUrlBeautifier.UrlBeautificationExceptionprotected Query createQuery()
public java.lang.String toUrl(java.lang.String searchString,
java.util.Map<java.lang.String,Navigation> navigations)
throws UrlBeautifier.UrlBeautificationException
Convert a search term and a list of refinements into a beautified URL.
Each refinement that has a mapping will be turned into a path segment.
If a mapping has been created for search, the search term will also be
placed into a URL path segment.
searchString - The current search state.navigations - The current refinement stateUrlBeautifier.UrlBeautificationExceptionpublic Query fromUrl(java.lang.String uri) throws UrlBeautifier.UrlBeautificationException
Convert a URI into a query object. Mappings will be converted to the
correct search and refinement state.
uri - The URI to parse into a query objectUrlBeautifier.UrlBeautificationExceptionpublic Query fromUrl(java.lang.String url, Query defaultQuery) throws UrlBeautifier.UrlBeautificationException
Convert a URI into a query object. Mappings will be converted to the
correct search and refinement state.
url - The URI to parse into a query objectdefaultQuery - The default query to use if this URL does not correctly parse.UrlBeautifier.UrlBeautificationExceptionpublic void setSearchMapping(char pToken)
Set the mapping from a search term to a path segment.
Note: you cannot use vowels for mapping tokens to prevent dictionary word creation.
The order in which this method is called determines where in the URL the search term will show up.
pToken - The single letter to represent search in the lookup.public void addRefinementMapping(char pToken,
java.lang.String pName)
Set up a mapping for a refinement.
Note: you cannot use vowels for mapping tokens to prevent dictionary word creation.
The order in which this method is called determines where in the URL the refinements will show up.
pToken - The single letter to represent this refinement in the lookup.pName - The name of the navigation that will be mapped using this
token.public void clearSavedFields()
Clean up all mappings.
public java.lang.String getAppend()
Return the current appended URL segment
public void setAppend(java.lang.String pAppend)
Quite often URLs need to end with specific extensions to map to the correct controller in the backend.
Here you can set this value.
For example:
/index.html
pAppend - The value to append to each beautified URL.public java.lang.String getRefinementsQueryParameterName()
public void setRefinementsQueryParameterName(java.lang.String pRefinementsQueryParameterName)
Sets the name of the query parameter with which non-mapped refinements will show up in the query string.
This includes ranges which are never mapped to beautified URLs.
pRefinementsQueryParameterName - The name of the query parameter to use.public void addReplacementRule(char pTarget,
java.lang.Character pReplacement)
Adds a new replacement rule that will be applied to the search term and mapped refinements. The original
search term and refinements will be put back into the query object.
If pReplacement is null the target character will be removed.
Note: Replacements that are chained may still contain the original target character.
For example:
addReplacementRule('x','y');
addReplacementRule('z','x');
The result of this may contain x's in the final result.
www.example.com/xyz will become www.example.com/yyz after the first replacement and www.example.com/yyx
after the second replacement.
pTarget - The char values to be replacedpReplacement - The replacement char valuepublic void addReplacementRule(char pTarget,
java.lang.Character pReplacement,
java.lang.String pRefinementName)
Adds a new replacement rule that will only be applied to the specified refinement. The original
search term and refinements will be put back into the query object.
If pReplacement is null the target character will be removed.
Note: Replacements that are chained may still contain the original target character.
For example:
addReplacementRule('x', 'y', "brand");
addReplacementRule('z', 'x', "brand");
The result of this may contain x's in the final result.
www.example.com/xyz/b will become www.example.com/yyz/b after the first replacement and www.example.com/yyx/b
after the second replacement.
pTarget - The char values to be replacedpReplacement - The replacement char valuepRefinementName - The name of the refinement that this replacement should be applied to.Copyright © 2013–2016 GroupBy Inc.. All rights reserved.