com.arsdigita.cms
Interface TemplateManager

All Known Implementing Classes:
DefaultTemplateManager

public interface TemplateManager

Manages the association between publishable content items and templates in a content section.

Many sites offer alternative views of the same content item depending on device or browser, or on user preference. For example, a site may have "plain" and "fancy" versions of its pages. The fancy versions would be the defaults, while the plain versions would be appropriate for users with low-bandwidth connections, older browsers, or a distaste for flashy appurtenances. In this the case the selection might be made based on a cookie.

Another common example is the "printable" version of a page. In this case a query variable might be more appropriate.

In general, the process for resolving a template involves two steps:

  1. The template resolver examines specific properties of the item, the content section, and/or the request itself and selects an appropriate context. A context is simply a token such as "plain" or "fancy".
  2. Based on the selected context, the template resolver identifies an appropriate template for the item. This is a three-step process: (1) the resolver queries for an association between the item and a specific template for the selected context; (2) if no such association exists, the resolver queries the item's content type for a default template to use in the selected context; (3) if a default template is not found, return null (at which point the dispatcher should probably give up and return a 404 error).

Version:
$Revision: #8 $ $DateTime: 2004/04/07 16:07:11 $
Author:
Karl Goldstein (karlg@arsdigita.com), Stanislav Freidin (sfreidin@arsdigita.com)

Field Summary
static String PUBLIC_CONTEXT
          The default use context for templates
static String versionId
           
 
Method Summary
 void addTemplate(ContentItem item, Template template, String context)
          Assign a template to the item in the given context.
 void addTemplate(ContentSection section, ContentType type, Template template, String context)
          Add a template to the given content type for the given content section.
 void addTemplate(ContentSection section, ContentType type, Template template, String context, boolean isDefault)
          Add a template to the given content type for the given content section.
 com.arsdigita.cms.ItemTemplateCollection getContextsWithTypes(ContentItem item)
          Retrieve all use context/mime type combinations along with possibly null template for the item in that pair.
 Template getDefaultTemplate(ContentSection section, ContentType type, String context)
          Deprecated. Use getDefaultTemplate(ContentSection, ContentType, String, MimeType)
 Template getDefaultTemplate(ContentSection section, ContentType type, String context, com.arsdigita.mimetypes.MimeType mimeType)
          Get the default template for the given section, type and use context
 Template getTemplate(ContentItem item, String context)
          Retrieve a template for the item in the given use context.
 TemplateCollection getTemplates(ContentItem item)
          Retrieve all templates for the content item, along with their use contexts
 TemplateCollection getTemplates(ContentSection section, ContentType type)
          Get all the templates within the given section and type
 TemplateCollection getTemplates(ContentSection section, ContentType type, String context)
          Get all the templates within the given section, type and context
 TemplateCollection getUseContexts(ContentItem item)
          Retrieve a collection of all use contexts for the item, along with the templates assigned to each use context (if any).
 void removeTemplate(ContentItem item, Template template, String context)
          Unassign a template from the item in the given context.
 void removeTemplate(ContentSection section, ContentType type, Template template, String context)
          Remove the specified template from the content type in the given context.
 void setDefaultTemplate(ContentSection section, ContentType type, Template template, String context)
          Designate the given template as the default template within its use context.
 

Field Detail

versionId

public static final String versionId
See Also:
Constant Field Values

PUBLIC_CONTEXT

public static final String PUBLIC_CONTEXT
The default use context for templates

See Also:
Constant Field Values
Method Detail

addTemplate

public void addTemplate(ContentItem item,
                        Template template,
                        String context)
Assign a template to the item in the given context. Overrides any previous template assignment.

Parameters:
item - the content item
template - the template to be assigned
context - the use context for the template, such as "public" or "abridged".

removeTemplate

public void removeTemplate(ContentItem item,
                           Template template,
                           String context)
Unassign a template from the item in the given context. Do nothing if the template is not assigned to the item.

Parameters:
item - the content item
template - the template to be unassigned
context - the use context for the template, such as "public" or "abridged".

addTemplate

public void addTemplate(ContentSection section,
                        ContentType type,
                        Template template,
                        String context)
Add a template to the given content type for the given content section. The template could be used to render any item of the content type. If the given context for the section contains no templates, the new template will be made the default.

Parameters:
section - the content section to which the template will belong
type - the content type to which the template will belong
template - the template to be added
context - the use context for the template, such as "public" or "abridged".

removeTemplate

public void removeTemplate(ContentSection section,
                           ContentType type,
                           Template template,
                           String context)
Remove the specified template from the content type in the given context. Do nothing if no such template is associated.

Parameters:
section - the content section to which the template belongs
type - the content type to which the template belongs
template - the template to be removed
context - the use context for the template, such as "public" or "abridged".

addTemplate

public void addTemplate(ContentSection section,
                        ContentType type,
                        Template template,
                        String context,
                        boolean isDefault)
Add a template to the given content type for the given content section. The template could be used to render any item of the content type

Parameters:
section - the content section to which the template will belong
type - the content type to which the template will belong
template - the template to be added
context - the use context for the template, such as "public" or "abridged".
isDefault - if true, new content items of the given type will use this template by default when they are rendered within the specified use context

setDefaultTemplate

public void setDefaultTemplate(ContentSection section,
                               ContentType type,
                               Template template,
                               String context)
Designate the given template as the default template within its use context. new content items of the given type will use this template by default when they are rendered within the use context. Note that addTemplate(com.arsdigita.cms.ContentItem, com.arsdigita.cms.Template, java.lang.String) must first be called to actually add the template to.

Parameters:
section - the content section where the template resides
type - the content type to which the template belongs
template - the template which will be made default
context - the use context in which the template will be made default

getTemplate

public Template getTemplate(ContentItem item,
                            String context)
Retrieve a template for the item in the given use context.

Parameters:
item - the content item
context - the use context for the template, such as "public" or "abridged".
Returns:
the template assigned to the item in the given context, or null if no such template is assigned

getTemplates

public TemplateCollection getTemplates(ContentItem item)
Retrieve all templates for the content item, along with their use contexts

Parameters:
item - the content item
Returns:
a TemplateCollection of all the templates assigned to the item
See Also:
getUseContexts(com.arsdigita.cms.ContentItem)

getUseContexts

public TemplateCollection getUseContexts(ContentItem item)
Retrieve a collection of all use contexts for the item, along with the templates assigned to each use context (if any). Unlike getTemplates(ContentItem), the collection returned by this method will include all use contexts for an item, even those use contexts to which no template is yet assigned.

Parameters:
item - the content item
Returns:
a TemplateCollection of all the templates assigned to the item

getContextsWithTypes

public com.arsdigita.cms.ItemTemplateCollection getContextsWithTypes(ContentItem item)
Retrieve all use context/mime type combinations along with possibly null template for the item in that pair. This returns one row for each use context/mime type pair. So, you could get 4 rows if there is public/jsp, public/xsl, alternate/jsp, and alternate/xsl. This is because there can be one template per context/mime-type pair


getDefaultTemplate

public Template getDefaultTemplate(ContentSection section,
                                   ContentType type,
                                   String context)
Deprecated. Use getDefaultTemplate(ContentSection, ContentType, String, MimeType)

Get the default template for the given section, type and use context

Parameters:
section - the content section to which the template belongs
type - the content type to which the template belongs
context - the use context for the template, such as "public" or "abridged".
Returns:
the default template for the given section, type and context, or null if no such template exists

getDefaultTemplate

public Template getDefaultTemplate(ContentSection section,
                                   ContentType type,
                                   String context,
                                   com.arsdigita.mimetypes.MimeType mimeType)
Get the default template for the given section, type and use context

Parameters:
section - the content section to which the template belongs
type - the content type to which the template belongs
context - the use context for the template, such as "public" or "abridged".
mimeType - The mime type of the template that is desired.
Returns:
the default template for the given section, type, context, and mime type or null if no such template exists

getTemplates

public TemplateCollection getTemplates(ContentSection section,
                                       ContentType type)
Get all the templates within the given section and type

Parameters:
section - the content section
type - the content type
Returns:
a collection of templates for the given section, type and context; an empty collection if there are no such templates

getTemplates

public TemplateCollection getTemplates(ContentSection section,
                                       ContentType type,
                                       String context)
Get all the templates within the given section, type and context

Parameters:
section - the content section
type - the content type
context - the use context
Returns:
a collection of templates for the given section, type and context; an empty collection if there are no such templates


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