com.jalios.jcms.servlet
Class FriendlyURLFilter

java.lang.Object
  extended by com.jalios.jcms.servlet.JcmsServletFilter
      extended by com.jalios.jcms.servlet.FriendlyURLFilter
All Implemented Interfaces:
Serializable, javax.servlet.Filter

public class FriendlyURLFilter
extends JcmsServletFilter
implements javax.servlet.Filter, Serializable

This filter allow Friendly URLs to be used to access JCMS data. It filter every request and look for the matching url to redirect to the associated Data.

Since:
jcms-5.5.0
Version:
$Revision: 38181 $
Author:
Olivier Jaquemet
See Also:
Serialized Form

Field Summary
static String REVISION
           
 
Constructor Summary
FriendlyURLFilter()
           
 
Method Summary
static boolean addFriendlyURL(Data data, String friendlyURL)
          Add the given friendlyURLSet to the friendly urls of the servlet.
static String buildCleanURL(String str)
          Method to clean the given string to have a proper URL.
Convert to CamelCase (keeping '/' separator)
 void destroy()
           
 void doFilter(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res, javax.servlet.FilterChain chain)
          The main filter method.
static String generateFriendlyURL(Category cat, String lang)
          Build and return a friendly url that can be added later to the friendly urls Servlet Filter.
static String generateFriendlyURL(Publication pub, String lang)
          Build and return a friendly url that can be added later to the friendly urls Servlet Filter.
static Data getDataFromFriendlyURL(String friendlyURL)
          Return the data associated with the given friendly URL.
static HashMap getDataToFriendlyURLSetMap()
           
static TreeSet getFriendlyURLSet(Data data)
          Return a set of friendly urls associated with the given data
static HashMap getFriendlyURLToDataMap()
           
static FriendlyURLFilter getInstance()
           
 void init(javax.servlet.FilterConfig config)
           
static void initAfterLoad()
          This method is called after the loading of the store (therefore after all specificied Data's FriendlyURL have been updated in this servlet) to generate FriendlyURL for the remaining Datas.
static boolean isFriendlyURLAvailable(Data data, String friendlyURL)
          Check if the given friendly URL is available, that is either : the Friendly URL is not in the Friendly URLs of the servlet or else the Friendly URL is already there with the same data
 boolean isFriendlyURLAvailable(String id, String friendlyURL)
          Check if the given friendly URL is available, that is either : the Friendly URL is not in the Friendly URLs of the servlet or else the Friendly URL is already there with the same data
Instance method, to be used by rpc call in doEditCommonPubAttribute.
 boolean isFriendlyURLValid(String friendlyURL)
          Check if the given friendly url is valid.
static boolean removeDataFriendlyURL(Data data)
          Remove the given data and all its associated friendly url.
static boolean removeFriendlyURL(String friendlyURL)
          Remove the given friendly url.
 
Methods inherited from class com.jalios.jcms.servlet.JcmsServletFilter
endFilter, initJSONBridge, processFilter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REVISION

public static final String REVISION
See Also:
Constant Field Values
Constructor Detail

FriendlyURLFilter

public FriendlyURLFilter()
Method Detail

doFilter

public void doFilter(javax.servlet.ServletRequest req,
                     javax.servlet.ServletResponse res,
                     javax.servlet.FilterChain chain)
              throws IOException,
                     javax.servlet.ServletException
The main filter method.

Specified by:
doFilter in interface javax.servlet.Filter
Throws:
IOException
javax.servlet.ServletException

generateFriendlyURL

public static String generateFriendlyURL(Category cat,
                                         String lang)
Build and return a friendly url that can be added later to the friendly urls Servlet Filter.
This method does not check for availabilty of the built friendlyURL.

Parameters:
cat - the Category to build a url for
lang - the lang in which to build a url
Returns:
a friendlyURL

generateFriendlyURL

public static String generateFriendlyURL(Publication pub,
                                         String lang)
Build and return a friendly url that can be added later to the friendly urls Servlet Filter.
This method do not check for availabilty of the built friendly url.

Parameters:
pub - the Publication to build a url for
lang - the lang in which to build a url
Returns:
a friendly url or null if the url could not be build in the given language

buildCleanURL

public static String buildCleanURL(String str)
Method to clean the given string to have a proper URL.
Convert to CamelCase (keeping '/' separator)

Parameters:
str - the string to clean
Returns:
the cleaned string

isFriendlyURLAvailable

public boolean isFriendlyURLAvailable(String id,
                                      String friendlyURL)
Check if the given friendly URL is available, that is either :
Instance method, to be used by rpc call in doEditCommonPubAttribute.

Parameters:
id - the id of the data associated with the friendly url
friendlyURL - the friendlyURL for which to check availability
Returns:
true if available, false otherwise

isFriendlyURLValid

public boolean isFriendlyURLValid(String friendlyURL)
Check if the given friendly url is valid.
Instance method, to be used by rpc call in doEditCommonPubAttribute.

Parameters:
friendlyURL - the friendly url to check
Returns:
true if friendly URL is a valid one, false otherwise

isFriendlyURLAvailable

public static boolean isFriendlyURLAvailable(Data data,
                                             String friendlyURL)
Check if the given friendly URL is available, that is either :

Parameters:
data - the data associated with the friendly url
friendlyURL - the friendlyURL for which to check availability
Returns:
true if available, false otherwise

getFriendlyURLSet

public static TreeSet getFriendlyURLSet(Data data)
Return a set of friendly urls associated with the given data

Parameters:
data - the data of which to retrieve friendly urls
Returns:
a Set of String

getDataFromFriendlyURL

public static Data getDataFromFriendlyURL(String friendlyURL)
Return the data associated with the given friendly URL.

Parameters:
friendlyURL - the friendly URL to test
Returns:
the associated Data or null.

addFriendlyURL

public static boolean addFriendlyURL(Data data,
                                     String friendlyURL)
Add the given friendlyURLSet to the friendly urls of the servlet.
Check the friendly url is available.

Parameters:
data - the data associated with the friendly url
friendlyURL - the friendly url
Returns:
true if the friendlyURL was added or was already there, false otherwise.

removeDataFriendlyURL

public static boolean removeDataFriendlyURL(Data data)
Remove the given data and all its associated friendly url.

Parameters:
data - the data to remove from the servlet.
Returns:
true if the data was removed, false if it was not there.

removeFriendlyURL

public static boolean removeFriendlyURL(String friendlyURL)
Remove the given friendly url.

Parameters:
friendlyURL - the friendly url to remove
Returns:
true if the friendly url was removed, false if it was not there.

getFriendlyURLToDataMap

public static HashMap getFriendlyURLToDataMap()
Returns:
a copy of the HashMap associating FriendlyURL with a Data

getDataToFriendlyURLSetMap

public static HashMap getDataToFriendlyURLSetMap()
Returns:
a copy of the HashMap associating Data with a FriendlyURL Set

init

public void init(javax.servlet.FilterConfig config)
Specified by:
init in interface javax.servlet.Filter

destroy

public void destroy()
Specified by:
destroy in interface javax.servlet.Filter

getInstance

public static FriendlyURLFilter getInstance()
Returns:
the singleton

initAfterLoad

public static void initAfterLoad()
This method is called after the loading of the store (therefore after all specificied Data's FriendlyURL have been updated in this servlet) to generate FriendlyURL for the remaining Datas.



Copyright © 2001-2010 Jalios SA. All Rights Reserved.