com.arsdigita.cms.dispatcher
Class MultilingualItemResolver

java.lang.Object
  extended bycom.arsdigita.cms.dispatcher.AbstractItemResolver
      extended bycom.arsdigita.cms.dispatcher.MultilingualItemResolver
All Implemented Interfaces:
ItemResolver
Direct Known Subclasses:
CategoryItemResolverImpl

public class MultilingualItemResolver
extends AbstractItemResolver
implements ItemResolver

Resolves items to URLs and URLs to items for multiple language variants. Created Mon Jan 20 14:30:03 2003.

Version:
$Id: //cms/dev/src/com/arsdigita/cms/dispatcher/MultilingualItemResolver.java#19 $
Author:
Michael Hanisch

Field Summary
protected static String ITEM_ID
          The string identifying an item's ID in the query string of a URL.
protected static String SEPARATOR
          The separator used in URL query strings; should be either "&" or ";".
static String versionId
           
 
Fields inherited from class com.arsdigita.cms.dispatcher.AbstractItemResolver
TEMPLATE_CONTEXT_PREFIX
 
Constructor Summary
MultilingualItemResolver()
           
 
Method Summary
protected  String generateDraftURL(ContentSection section, BigDecimal itemId)
          Returns content item's draft version URL
 String generateItemURL(com.arsdigita.bebop.PageState state, BigDecimal itemId, String name, ContentSection section, String context)
          Generates a URL for a content item.
 String generateItemURL(com.arsdigita.bebop.PageState state, BigDecimal itemId, String name, ContentSection section, String context, String templateContext)
          Generates a URL for a content item.
 String generateItemURL(com.arsdigita.bebop.PageState state, ContentItem item, ContentSection section, String context)
          Generates a URL for a content item.
 String generateItemURL(com.arsdigita.bebop.PageState state, ContentItem item, ContentSection section, String context, String templateContext)
          Generates a URL for a content item.
protected  String generateLiveURL(ContentSection section, ContentItem item, String templateContext)
          Generate a language-independent URL to the item in the given section.
protected  String generatePreviewURL(ContentSection section, ContentItem item, String templateContext)
          Generate a URL which can be used to preview the item, using the given templateContext.
 String getCurrentContext(com.arsdigita.bebop.PageState state)
          Fetches the current context based on the page state.
 ContentItem getItem(ContentSection section, String url, String context)
          Returns a content item based on section, url, and use context.
protected  ContentItem getItemFromDraftURL(String url)
          Retrieves ITEM_ID parameter from URL and instantiates item according to this ID.
protected  ContentItem getItemFromLangAndBundle(String lang, ContentItem item)
          Finds a language instance of a content item given the bundle, name, and lang string
protected  ContentItem getItemFromLiveURL(String url, Folder parentFolder)
          Returns a content item based on URL relative to the root folder.
 CMSPage getMasterPage(ContentItem item, javax.servlet.http.HttpServletRequest request)
          Returns a master page based on page state (and content section).
protected  String[] getNameAndLangFromURLFrag(String url)
          Returns an array containing the the item's name and lang based on the URL fragment.
 
Methods inherited from class com.arsdigita.cms.dispatcher.AbstractItemResolver
getTemplateFromURL, stripTemplateFromURL
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.arsdigita.cms.dispatcher.ItemResolver
getTemplateFromURL, stripTemplateFromURL
 

Field Detail

versionId

public static final String versionId
See Also:
Constant Field Values

ITEM_ID

protected static final String ITEM_ID
The string identifying an item's ID in the query string of a URL.

See Also:
Constant Field Values

SEPARATOR

protected static final String SEPARATOR
The separator used in URL query strings; should be either "&" or ";".

See Also:
Constant Field Values
Constructor Detail

MultilingualItemResolver

public MultilingualItemResolver()
Method Detail

getItem

public ContentItem getItem(ContentSection section,
                           String url,
                           String context)
Returns a content item based on section, url, and use context.

Specified by:
getItem in interface ItemResolver
Specified by:
getItem in class AbstractItemResolver
Parameters:
section - The current content section
url - The section-relative URL
context - The use context, e.g. ContentItem.LIVE, CMSDispatcher.PREVIEW or ContentItem.DRAFT. See getCurrentContext(com.arsdigita.bebop.PageState).
Returns:
The content item, or null if no such item exists

getCurrentContext

public String getCurrentContext(com.arsdigita.bebop.PageState state)
Fetches the current context based on the page state.

Specified by:
getCurrentContext in interface ItemResolver
Specified by:
getCurrentContext in class AbstractItemResolver
Parameters:
state - the current page state
Returns:
the context of the current URL, such as ContentItem.LIVE or ContentItem.DRAFT
See Also:
ContentItem.LIVE, ContentItem.DRAFT

generateItemURL

public String generateItemURL(com.arsdigita.bebop.PageState state,
                              BigDecimal itemId,
                              String name,
                              ContentSection section,
                              String context)
Generates a URL for a content item.

Specified by:
generateItemURL in interface ItemResolver
Specified by:
generateItemURL in class AbstractItemResolver
Parameters:
itemId - The item ID
name - The name of the content page
state - The page state
section - the content section to which the item belongs
context - the context of the URL, such as "live" or "admin"
Returns:
The URL of the item
See Also:
getCurrentContext(com.arsdigita.bebop.PageState)

generateItemURL

public String generateItemURL(com.arsdigita.bebop.PageState state,
                              BigDecimal itemId,
                              String name,
                              ContentSection section,
                              String context,
                              String templateContext)
Generates a URL for a content item.

Specified by:
generateItemURL in interface ItemResolver
Specified by:
generateItemURL in class AbstractItemResolver
Parameters:
itemId - The item ID
name - The name of the content page
state - The page state
section - the content section to which the item belongs
context - the context of the URL, such as "live" or "admin"
templateContext - the context for the URL, such as "public"
Returns:
The URL of the item
See Also:
getCurrentContext(com.arsdigita.bebop.PageState)

generateItemURL

public String generateItemURL(com.arsdigita.bebop.PageState state,
                              ContentItem item,
                              ContentSection section,
                              String context)
Generates a URL for a content item.

Specified by:
generateItemURL in interface ItemResolver
Specified by:
generateItemURL in class AbstractItemResolver
Parameters:
item - The item
state - The page state
section - the content section to which the item belongs
context - the context of the URL, such as "live" or "admin"
Returns:
The URL of the item
See Also:
getCurrentContext(com.arsdigita.bebop.PageState)

generateItemURL

public String generateItemURL(com.arsdigita.bebop.PageState state,
                              ContentItem item,
                              ContentSection section,
                              String context,
                              String templateContext)
Generates a URL for a content item.

Specified by:
generateItemURL in interface ItemResolver
Specified by:
generateItemURL in class AbstractItemResolver
Parameters:
item - The item
state - The page state
section - the content section to which the item belongs
context - the context of the URL, such as "live" or "admin"
templateContext - the context for the URL, such as "public"
Returns:
The URL of the item
See Also:
getCurrentContext(com.arsdigita.bebop.PageState)

getMasterPage

public CMSPage getMasterPage(ContentItem item,
                             javax.servlet.http.HttpServletRequest request)
                      throws javax.servlet.ServletException
Returns a master page based on page state (and content section).

Specified by:
getMasterPage in interface ItemResolver
Specified by:
getMasterPage in class AbstractItemResolver
Parameters:
item - The content item
request - The HTTP request
Returns:
The master page
Throws:
javax.servlet.ServletException

generateDraftURL

protected String generateDraftURL(ContentSection section,
                                  BigDecimal itemId)
Returns content item's draft version URL

Parameters:
section - The content section to which the item belongs
itemId - The content item's ID
Returns:
generated URL string

generateLiveURL

protected String generateLiveURL(ContentSection section,
                                 ContentItem item,
                                 String templateContext)
Generate a language-independent URL to the item in the given section.

When a client retrieves this URL, the URL is resolved to point to a specific language instance of the item referenced here, i.e. this URL will be resolved to a language-specific URL internally.

Parameters:
section - the ContentSection that contains this item
item - ContentItem for which a URL should be constructed.
templateContext - template context; will be ignored if null
Returns:
a language-independent URL to the item in the given section, which will be presented within the given templateContext

generatePreviewURL

protected String generatePreviewURL(ContentSection section,
                                    ContentItem item,
                                    String templateContext)
Generate a URL which can be used to preview the item, using the given templateContext.

Only a specific language instance can be previewed, meaning there no language negotiation is involved when a request is made to a URL that has been generated by this method.

Parameters:
section - The ContentSection which contains the item
item - The ContentItem for which a URL should be generated.
templateContext - the context that determines which template should render the item when it is previewed; ignored if the argument given here is null
Returns:
a URL which can be used to preview the given item

getItemFromDraftURL

protected ContentItem getItemFromDraftURL(String url)
Retrieves ITEM_ID parameter from URL and instantiates item according to this ID.

Parameters:
url - URL that indicates which item should be retrieved; must contain the ITEM_ID parameter
Returns:
the ContentItem the given url points to, or null if no ID has been found in the url

getItemFromLiveURL

protected ContentItem getItemFromLiveURL(String url,
                                         Folder parentFolder)
Returns a content item based on URL relative to the root folder.

Parameters:
url - The content item url
parentFolder - The parent folder object, url must be relevant to it
Returns:
The Content Item instance, it can also be either Bundle or Folder objects, depending on URL and file language extension

getNameAndLangFromURLFrag

protected String[] getNameAndLangFromURLFrag(String url)
Returns an array containing the the item's name and lang based on the URL fragment.

Returns:
a two-element string array, the first element containing the bundle name, and the second element containing the lang string

getItemFromLangAndBundle

protected ContentItem getItemFromLangAndBundle(String lang,
                                               ContentItem item)
Finds a language instance of a content item given the bundle, name, and lang string

Parameters:
lang - The lang string from the URL
item - The content bundle
Returns:
The negotiated lang instance for the current request.


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 19 2004:2352 UTC