Liferay 6.0.5

com.liferay.portlet
Class RouteImpl

java.lang.Object
  extended by com.liferay.portlet.RouteImpl
All Implemented Interfaces:
Route

public class RouteImpl
extends Object
implements Route


Constructor Summary
RouteImpl(String pattern)
           
 
Method Summary
 void addGeneratedParameter(String name, String pattern)
          Adds a generated parameter to this route.
 void addIgnoredParameter(String name)
          Adds an ignored parameter to this route.
 void addImplicitParameter(String name, String value)
          Adds an implicit parameter to this route.
 void addOverriddenParameter(String name, String value)
          Adds an overridden parameter to this route.
 Map<String,StringParser> getGeneratedParameters()
          Gets the generated parameters for this route.
 Set<String> getIgnoredParameters()
          Gets the ignored parameters for this route.
 Map<String,String> getImplicitParameters()
          Gets the implicit parameters for this route.
 Map<String,String> getOverriddenParameters()
          Gets the overridden parameters for this route.
 String parametersToUrl(Map<String,String> parameters)
          Generates a URL from the parameter map if this route is appropriate.
 boolean urlToParameters(String url, Map<String,String> parameters)
          Populates the parameter map with values parsed from the URL if this route matches.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RouteImpl

public RouteImpl(String pattern)
Method Detail

addGeneratedParameter

public void addGeneratedParameter(String name,
                                  String pattern)
Description copied from interface: Route
Adds a generated parameter to this route.

A generated parameter is never part of the URL, but is constructed from one or more "virtual parameters" using a pattern string. When a URL is parsed, the virtual parameters are populated from the URL, and the generated parameter is then built from its constituent virtual parameters.

When a URL is generated, the opposite process occurs. The generated parameter must have its value passed in through the parameter map. This value is parsed using the pattern string, and the virtual parameters are populated and made available for use in the route pattern string. The value of the generated parameter will not be available in the route pattern; only the values of the virtual parameters may be used.

The following is an example route definition that uses a generated parameter to remove the .jsp extension of the current page from the URL.

 
 <route>
        <pattern>/{jspPageName}/{id:\d+}</pattern>
        <generated-parameter name="jspPage">{jspPageName}.jsp</generated-parameter>
 </route>
 
 

Specified by:
addGeneratedParameter in interface Route
Parameters:
name - the name of the generated parameter
pattern - the pattern string of the generated parameter

addIgnoredParameter

public void addIgnoredParameter(String name)
Description copied from interface: Route
Adds an ignored parameter to this route.

An ignored parameter never appears in the query string regardless of its value. Ignored parameters have no effect on the parsing of URLs.

Specified by:
addIgnoredParameter in interface Route
Parameters:
name - the name of the ignored parameter

addImplicitParameter

public void addImplicitParameter(String name,
                                 String value)
Description copied from interface: Route
Adds an implicit parameter to this route.

An implicit parameter applies in both stages of a route's lifecycle, URL parsing and URL generation. When a URL is parsed, the implicit parameters will be copied onto the parameter map. When a URL is generated from a parameter map, all the implicit parameters will be checked against the parameters in the map. If any do not match or are missing from the parameter map, this route will not be used for generating the URL.

Implicit parameters are matched after all virtual parameters have been populated, and therefore should not match against the value of a generated parameter, as it will not be available.

The most common use of implicit parameters is to specify a parameter that is included statically in the route pattern. For instance, if a custom route is specified for the JSP page "view_profile.jsp", the routes definition could look like the following:

 
 <route>
        <pattern>/profile/view/{id:\d+}</pattern>
        <implicit-parameter name="jspPage">view_profile.jsp</implicit-parameter>
 </route>
 
 

Since the jspPage is specified with a implicit-parameter, this route will only be used to generate URLs if the jspPage is set to "view_profile.jsp". Likewise, when a URL in this format is recognized, the jspPage will automatically be set to "view_profile.jsp".

Specified by:
addImplicitParameter in interface Route
Parameters:
name - the name of the implicit parameter
value - the value of the implicit parameter

addOverriddenParameter

public void addOverriddenParameter(String name,
                                   String value)
Description copied from interface: Route
Adds an overridden parameter to this route.

An overridden parameter is one that should always be set to a certain value when a URL is parsed. Overridden parameters have no effect on the generating of URLs.

If a implicit parameter and an overridden parameter share the same name, the overridden parameter value will take precedence when a URL is parsed. When a URL is generated the implicit parameter value will be checked against the parameter map as usual.

Specified by:
addOverriddenParameter in interface Route
Parameters:
name - the name of the overridden parameter
value - the value of the overridden parameter

getGeneratedParameters

public Map<String,StringParser> getGeneratedParameters()
Description copied from interface: Route
Gets the generated parameters for this route.

Specified by:
getGeneratedParameters in interface Route
Returns:
the generated parameter names and string parsers
See Also:
Route.addGeneratedParameter(String, String)

getIgnoredParameters

public Set<String> getIgnoredParameters()
Description copied from interface: Route
Gets the ignored parameters for this route.

Specified by:
getIgnoredParameters in interface Route
Returns:
the ignored parameter names
See Also:
Route.addIgnoredParameter(String)

getImplicitParameters

public Map<String,String> getImplicitParameters()
Description copied from interface: Route
Gets the implicit parameters for this route.

Specified by:
getImplicitParameters in interface Route
Returns:
the implicit parameter names and values
See Also:
Route.addImplicitParameter(String, String)

getOverriddenParameters

public Map<String,String> getOverriddenParameters()
Description copied from interface: Route
Gets the overridden parameters for this route.

Specified by:
getOverriddenParameters in interface Route
Returns:
the overridden parameter names and values
See Also:
Route.addOverriddenParameter(String, String)

parametersToUrl

public String parametersToUrl(Map<String,String> parameters)
Description copied from interface: Route
Generates a URL from the parameter map if this route is appropriate.

A route is appropriate if:

  1. The values given in parameters for the route's generated parameters match their patterns
  2. The route's implicit parameters all match parameters
  3. Every fragment in the route pattern has a matching value in parameters

Specified by:
parametersToUrl in interface Route
Parameters:
parameters - the parameter map to build the URL from
Returns:
the URL path, or null if this route is not appropriate

urlToParameters

public boolean urlToParameters(String url,
                               Map<String,String> parameters)
Description copied from interface: Route
Populates the parameter map with values parsed from the URL if this route matches.

Generated parameters will be built and added to parameters if possible. If the pattern for a virtual parameter in the generated parameter does not match its pattern in the route, that generated parameter may not be build.

Virtual parameters will not be present in parameters.

Specified by:
urlToParameters in interface Route
Parameters:
url - the URL path to parse
parameters - the parameter map to populate if this route matches the URL
Returns:
true if the route matches; false otherwise

Liferay 6.0.5