mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged DEV/CMIS_10 to HEAD
18731: SAIL-169: CMIS REST versioning compliance - Rendering of "via" link for working copy and "current-version" and "working-copy" links for documents - Added ability to dereference object IDs in cmisproperty() template function - Fixed broken CMIS index page git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@18896 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -18,7 +18,7 @@
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* FLOSS exception. You should have received a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
@@ -26,14 +26,18 @@ package org.alfresco.repo.cmis.rest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.cmis.CMISInvalidArgumentException;
|
||||
import org.alfresco.cmis.CMISServiceException;
|
||||
import org.alfresco.cmis.CMISServices;
|
||||
import org.alfresco.repo.template.TemplateAssociation;
|
||||
import org.alfresco.repo.template.TemplateNode;
|
||||
import org.alfresco.repo.web.scripts.RepositoryImageResolver;
|
||||
import org.alfresco.service.cmr.repository.TemplateImageResolver;
|
||||
import org.alfresco.service.cmr.repository.TemplateValueConverter;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
|
||||
import freemarker.ext.beans.BeanModel;
|
||||
import freemarker.ext.beans.BeansWrapper;
|
||||
import freemarker.template.TemplateBooleanModel;
|
||||
import freemarker.template.TemplateMethodModelEx;
|
||||
import freemarker.template.TemplateModel;
|
||||
import freemarker.template.TemplateModelException;
|
||||
@@ -42,73 +46,100 @@ import freemarker.template.TemplateScalarModel;
|
||||
/**
|
||||
* Custom FreeMarker Template language method.
|
||||
* <p>
|
||||
* Retrieve the CMIS property value for an Alfresco node
|
||||
* Retrieve the CMIS property value for an Alfresco node and optionally dereferences it as an objectId.
|
||||
* <p>
|
||||
* Usage: cmisproperty(TemplateNode node, String propertyName)
|
||||
*
|
||||
* cmisproperty(TemplateNode node, String propertyName, Boolean asObject)
|
||||
* @author davidc
|
||||
* @author dward
|
||||
*/
|
||||
public final class CMISPropertyValueMethod implements TemplateMethodModelEx
|
||||
public class CMISPropertyValueMethod implements TemplateMethodModelEx
|
||||
{
|
||||
/**
|
||||
* NULL value marker
|
||||
*/
|
||||
public static class NULL {};
|
||||
public static class NULL
|
||||
{
|
||||
};
|
||||
|
||||
public static TemplateModel IS_NULL = new BeanModel(new NULL(), BeansWrapper.getDefaultInstance());
|
||||
|
||||
|
||||
private CMISServices cmisService;
|
||||
private TemplateImageResolver imageResolver;
|
||||
private TemplateValueConverter templateValueConverter;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*/
|
||||
public CMISPropertyValueMethod(CMISServices cmisService)
|
||||
public CMISPropertyValueMethod(CMISServices cmisService, RepositoryImageResolver imageResolver,
|
||||
TemplateValueConverter templateValueConverter)
|
||||
{
|
||||
this.cmisService = cmisService;
|
||||
this.imageResolver = imageResolver.getImageResolver();
|
||||
this.templateValueConverter = templateValueConverter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see freemarker.template.TemplateMethodModel#exec(java.util.List)
|
||||
*/
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object exec(List args) throws TemplateModelException
|
||||
{
|
||||
Object result = null;
|
||||
|
||||
if (args.size() == 2)
|
||||
Object wrapped = null;
|
||||
String propertyName = null;
|
||||
boolean asObject = false;
|
||||
try
|
||||
{
|
||||
Object arg0 = args.get(0);
|
||||
if (arg0 instanceof BeanModel)
|
||||
{
|
||||
// extract property name
|
||||
String propertyName = null;
|
||||
Object arg1 = args.get(1);
|
||||
if (arg1 instanceof TemplateScalarModel)
|
||||
{
|
||||
propertyName = ((TemplateScalarModel)arg1).getAsString();
|
||||
}
|
||||
int i = 0;
|
||||
|
||||
// extract node
|
||||
Object wrapped = ((BeanModel)arg0).getWrappedObject();
|
||||
if (wrapped != null && wrapped instanceof TemplateNode)
|
||||
{
|
||||
// retrieve property value from node
|
||||
try
|
||||
{
|
||||
result = cmisService.getProperty(((TemplateNode)wrapped).getNodeRef(), propertyName);
|
||||
}
|
||||
catch (CMISInvalidArgumentException e)
|
||||
{
|
||||
throw new WebScriptException(e.getStatusCode(), e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
else if (wrapped != null && wrapped instanceof TemplateAssociation)
|
||||
{
|
||||
// retrieve property value from node
|
||||
result = cmisService.getProperty(((TemplateAssociation)wrapped).getAssociationRef(), propertyName);
|
||||
}
|
||||
// extract object
|
||||
Object arg = args.get(i++);
|
||||
if (arg instanceof BeanModel)
|
||||
{
|
||||
wrapped = ((BeanModel) arg).getWrappedObject();
|
||||
}
|
||||
|
||||
// extract property name
|
||||
arg = args.get(i++);
|
||||
if (arg instanceof TemplateScalarModel)
|
||||
{
|
||||
propertyName = ((TemplateScalarModel) arg).getAsString();
|
||||
}
|
||||
|
||||
// extract asObject flag
|
||||
arg = args.get(i++);
|
||||
if (arg instanceof TemplateBooleanModel)
|
||||
{
|
||||
asObject = ((TemplateBooleanModel) arg).getAsBoolean();
|
||||
}
|
||||
}
|
||||
catch (IndexOutOfBoundsException e)
|
||||
{
|
||||
// Ignore optional arguments
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Object result = null;
|
||||
if (wrapped != null && wrapped instanceof TemplateNode)
|
||||
{
|
||||
// retrieve property value from node
|
||||
result = cmisService.getProperty(((TemplateNode) wrapped).getNodeRef(), propertyName);
|
||||
}
|
||||
else if (wrapped != null && wrapped instanceof TemplateAssociation)
|
||||
{
|
||||
// retrieve property value from association
|
||||
result = cmisService.getProperty(((TemplateAssociation) wrapped).getAssociationRef(), propertyName);
|
||||
}
|
||||
if (asObject && result instanceof String)
|
||||
{
|
||||
// convert result to an object if required
|
||||
result = cmisService.getReadableObject((String) result, Object.class);
|
||||
}
|
||||
return result == null ? IS_NULL : templateValueConverter.convertValue(result, imageResolver);
|
||||
}
|
||||
catch (CMISServiceException e)
|
||||
{
|
||||
throw new WebScriptException(e.getStatusCode(), e.getMessage(), e);
|
||||
}
|
||||
|
||||
return result == null ? IS_NULL : result;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user