info.magnolia.cms.beans.config
Class HostBasedVirtualURIMapping

java.lang.Object
  extended by info.magnolia.cms.beans.config.DefaultVirtualURIMapping
      extended by info.magnolia.cms.beans.config.HostBasedVirtualURIMapping
All Implemented Interfaces:
VirtualURIMapping
Direct Known Subclasses:
HostBasedRegexpVirtualURIMapping

public class HostBasedVirtualURIMapping
extends DefaultVirtualURIMapping

Simple VirtualURI mapping that can forward to a different url depending on the request host name. The "mappings" node contains a list of nodes with "host" and "toURI" properties. See below for a sample configuration:

 [] virtualURIMapping
    [] default
     - class            info.magnolia.cms.beans.config.HostBasedVirtualURIMapping
     - fromURI          /
     - toURI            redirect:/.magnolia/pages/adminCentral.html
       [] mappings
        - [] com
          - host      www.acme.com
          - toURI     forward:/acme/en/index.html
        - [] de
          - host      www.acme.de
          - toURI     forward:/acme/de/index.html
 
For backwards compatibility The "host" property may still be used, it contains a list of uri=destination strings. This technique is deprecated primarily because the properties of a node do not have a deterministic order. See below for a sample configuration of the deprecated approach using 'hosts' node.:
 [] virtualURIMapping
    [] default
     - class            info.magnolia.cms.beans.config.HostBasedVirtualURIMapping
     - fromURI          /
     - toURI            redirect:/.magnolia/pages/adminCentral.html
       [] hosts
        - 1             www.acme.com=forward:/acme/en/index.html
        - 2             www.acme.de=forward:/acme/de/index.html
 


Nested Class Summary
static class HostBasedVirtualURIMapping.HostURIMapping
          HostURIMapping object to receive "mapping" nodes in configuration.
 
Nested classes/interfaces inherited from interface info.magnolia.cms.beans.config.VirtualURIMapping
VirtualURIMapping.MappingResult
 
Field Summary
protected  ArrayList<HostBasedVirtualURIMapping.HostURIMapping> hosts
           
 
Fields inherited from class info.magnolia.cms.beans.config.DefaultVirtualURIMapping
fromURI, pattern, toURI
 
Constructor Summary
HostBasedVirtualURIMapping()
           
 
Method Summary
 void addHost(String mapping)
          Deprecated. 
 void addMapping(HostBasedVirtualURIMapping.HostURIMapping mapping)
          Adds a mapping (used by content2bean).
 List<String> getHosts()
          Deprecated. 
 List<HostBasedVirtualURIMapping.HostURIMapping> getMappings()
           
 VirtualURIMapping.MappingResult mapURI(String uri)
          Maps an incoming URI to a new target URI.
 String toString()
           
protected  String tryToMapHost()
          Choose the mapping host that matches the request host, with the least number of additional characters.
 
Methods inherited from class info.magnolia.cms.beans.config.DefaultVirtualURIMapping
getFromURI, getToURI, setFromURI, setToURI
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

hosts

protected ArrayList<HostBasedVirtualURIMapping.HostURIMapping> hosts
Constructor Detail

HostBasedVirtualURIMapping

public HostBasedVirtualURIMapping()
Method Detail

getMappings

public List<HostBasedVirtualURIMapping.HostURIMapping> getMappings()

addMapping

public void addMapping(HostBasedVirtualURIMapping.HostURIMapping mapping)
Adds a mapping (used by content2bean).

Parameters:
mapping - object.

getHosts

@Deprecated
public List<String> getHosts()
Deprecated. 


addHost

@Deprecated
public void addHost(String mapping)
Deprecated. 

Parameters:
mapping - in the form host=path

mapURI

public VirtualURIMapping.MappingResult mapURI(String uri)
Description copied from interface: VirtualURIMapping
Maps an incoming URI to a new target URI. Returns a VirtualURIMapping.MappingResult describing the new URI and the level of match. The new URI can be prefixed with "redirect:", "permanent:" or "forward:" to trigger either a temporary redirect, a permanent redirect or a forward respectively. For redirects the URI can be absolute or relative within the web application (the context path is added automatically). If the mapping does not apply to the input URI this method returns null.

Specified by:
mapURI in interface VirtualURIMapping
Overrides:
mapURI in class DefaultVirtualURIMapping
Parameters:
uri - the URI of the current request, decoded and without the context path
Returns:
a VirtualURIMapping.MappingResult with the target URI and level or null if the mapping doesn't apply

tryToMapHost

protected String tryToMapHost()
Choose the mapping host that matches the request host, with the least number of additional characters.

Returns:
The URI to map to.

toString

public String toString()
Overrides:
toString in class DefaultVirtualURIMapping


Copyright © 2003–2014 Magnolia International Ltd.. All rights reserved.