Big honkin' merge from head. Sheesh!

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3617 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-08-27 01:01:30 +00:00
parent e2c66899cc
commit 8031cc6574
322 changed files with 20776 additions and 6550 deletions

View File

@@ -18,10 +18,17 @@ package org.alfresco.repo.template;
import java.io.IOException;
import java.io.Writer;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.TemplateException;
import org.alfresco.service.cmr.repository.TemplateImageResolver;
import org.alfresco.service.cmr.repository.TemplateNode;
import org.alfresco.service.cmr.repository.TemplateProcessor;
import org.apache.log4j.Logger;
@@ -32,7 +39,17 @@ import freemarker.template.Template;
import freemarker.template.TemplateExceptionHandler;
/**
* FreeMarker implementation the template processor interface
* FreeMarker implementation of the template processor interface.
* <p>
* Service to process FreeMarker template files loaded from various sources including
* the classpath, repository and directly from a String.
* <p>
* The template is processed against a data model generally consisting of a map of
* named objects. FreeMarker can natively handle any POJO objects using standard bean
* notation syntax. It has support for walking List objects. A 'standard' data model
* helper is provided to help generate an object model containing well known objects
* such as the Company Home, User Home and current User nodes. It also provides helpful
* util classes to process Date objects and repository specific custom methods.
*
* @author Kevin Roast
*/
@@ -47,9 +64,6 @@ public class FreeMarkerProcessor implements TemplateProcessor
/** Pseudo path to String based template */
private static final String PATH = "string://fixed";
/** FreeMarker processor configuration */
private Configuration config = null;
/** The permission-safe node service */
private NodeService nodeService;
@@ -83,25 +97,21 @@ public class FreeMarkerProcessor implements TemplateProcessor
*/
private Configuration getConfig()
{
if (this.config == null)
{
Configuration config = new Configuration();
// setup template cache
config.setCacheStorage(new MruCacheStorage(20, 0));
// use our custom loader to find templates on the ClassPath
config.setTemplateLoader(new ClassPathRepoTemplateLoader(nodeService, contentService));
// use our custom object wrapper that can deal with QNameMap objects directly
config.setObjectWrapper(new QNameAwareObjectWrapper());
// rethrow any exception so we can deal with them
config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
this.config = config;
}
return this.config;
Configuration config = new Configuration();
// setup template cache
config.setCacheStorage(new MruCacheStorage(2, 0));
// use our custom loader to find templates on the ClassPath
config.setTemplateLoader(new ClassPathRepoTemplateLoader(nodeService, contentService));
// use our custom object wrapper that can deal with QNameMap objects directly
config.setObjectWrapper(new QNameAwareObjectWrapper());
// rethrow any exception so we can deal with them
config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
return config;
}
/**
@@ -116,6 +126,9 @@ public class FreeMarkerProcessor implements TemplateProcessor
{
Configuration config = new Configuration();
// setup template cache
config.setCacheStorage(new MruCacheStorage(2, 0));
// use our custom loader to load a template directly from a String
StringTemplateLoader stringTemplateLoader = new StringTemplateLoader();
stringTemplateLoader.putTemplate(path, template);
@@ -243,4 +256,56 @@ public class FreeMarkerProcessor implements TemplateProcessor
throw new TemplateException(MSG_ERROR_TEMPLATE_IO, new Object[] {template}, ioerr);
}
}
/**
* Create the default data-model available to templates as global objects.
* <p>
* 'companyhome' - the Company Home node<br>
* 'userhome' - the current user home space node<br>
* 'person' - the node representing the current user Person<br>
* 'template' - the node representing the template itself (may not be available)
* <p>
* Also adds various helper util objects and methods.
*
* @param services ServiceRegistry
* @param person The current user Person Node
* @param companyHome The CompanyHome ref
* @param userHome The User home space ref
* @param template Optional ref to the template itself
* @param resolver Image resolver to resolve icon images etc.
*
* @return A Map of Templatable Node objects and util objects.
*/
public static Map<String, Object> buildDefaultModel(
ServiceRegistry services,
NodeRef person, NodeRef companyHome, NodeRef userHome, NodeRef template,
TemplateImageResolver imageResolver)
{
Map<String, Object> model = new HashMap<String, Object>(16, 1.0f);
// supply the Company Home space as "companyhome"
model.put("companyhome", new TemplateNode(companyHome, services, imageResolver));
// supply the users Home Space as "userhome"
model.put("userhome", new TemplateNode(userHome, services, imageResolver));
// supply the current user Node as "person"
model.put("person", new TemplateNode(person, services, imageResolver));
// add the template itself as "template" if it comes from content on a node
if (template != null)
{
model.put("template", new TemplateNode(template, services, imageResolver));
}
// current date/time is useful to have and isn't supplied by FreeMarker by default
model.put("date", new Date());
// add custom method objects
model.put("hasAspect", new HasAspectMethod());
model.put("message", new I18NMessageMethod());
model.put("dateCompare", new DateCompareMethod());
return model;
}
}

View File

@@ -28,7 +28,7 @@ import org.alfresco.service.cmr.repository.TemplateNode;
*
* @author Kevin Roast
*/
public final class NamePathResultsMap extends BasePathResultsMap
public class NamePathResultsMap extends BasePathResultsMap
{
/**
* Constructor

View File

@@ -0,0 +1,62 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.repo.template;
import java.util.List;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.TemplateNode;
/**
* Provides functionality to execute a Lucene search for a single node by NodeRef.
*
* @author Kevin Roast
*/
public class NodeSearchResultsMap extends BaseSearchResultsMap
{
/**
* Constructor
*
* @param parent The parent TemplateNode to execute searches from
* @param services The ServiceRegistry to use
*/
public NodeSearchResultsMap(TemplateNode parent, ServiceRegistry services)
{
super(parent, services);
}
/**
* @see org.alfresco.repo.template.BaseTemplateMap#get(java.lang.Object)
*/
public Object get(Object key)
{
TemplateNode result = null;
if (key != null)
{
String ref = key.toString().replace(":", "\\:");
ref = ref.replace("/", "\\/");
List<TemplateNode> results = query(ref);
if (results.size() == 1)
{
result = results.get(0);
}
}
return result;
}
}

View File

@@ -25,7 +25,7 @@ import org.alfresco.service.cmr.repository.TemplateNode;
*
* @author Kevin Roast
*/
public final class XPathResultsMap extends BasePathResultsMap
public class XPathResultsMap extends BasePathResultsMap
{
/**
* Constructor