mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud)
75551: Reverse Merge HEAD-BUG-FIX (5.0/Cloud) 74584: Reverse merged HEAD-BUG-FIX (5.0/Cloud) << Requires more work on the EOL branch >> 74416: Merged EOL to HEAD-BUG-FIX (5.0/Cloud) 74309: ACE-2010 EOL Legacy CMIS Inputs (2) in 5.0 - Start replacing references to the original CMIS code with Alfresco and chemistry Open CMIS classes 74342: ACE-2010 EOL Legacy CMIS Inputs (2) in 5.0 - Switch ServiceRegistry over to using Open CMIS classes 74406: ACE-2010 EOL Legacy CMIS Inputs (2) in 5.0 << Compiles and starts Share without error >> - Removed Original CMIS classes from the repository, remote-api and thor - Moved the CMIS.DictionaryBootstrap bean into opencmis-context.xml before removing cmis-api-context.xml - Some code was left under: root\projects\remote-api\source\java\org\alfresco\repo\cmis ...........................................................\client ...........................................................\ws ...........................................................\rest ................................test-java\org\alfresco\repo\cmis ................................................................\ws ................................................................\rest Will have to see if it should be be removed too, or if it is common with OpenCMIS 74407: ACE-2010 EOL Legally CMIS Inputs (2) in 5.0 - Removed left over code under: root\projects\remote-api\source\java\org\alfresco\repo\cmis ................................test-java\org\alfresco\repo\cmis - Removed an authentication URL test in QuickShareRestApiTest which was failing in the same way as the tests above. - Removed CXFAuthenticationSystemTest which appears to be using the original CMIS 74465: Merged EOL (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud) 74464: ACE-2010 EOL Legacey CMIS Inputs (2) in 5.0 - New failure in QuickShareRestApiTest - CXFAuthenticationSystemTest (deleted) was still referenced in MiscSystemTestSuite git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@77489 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.cmis.rest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.cmis.CMISAccessControlService;
|
||||
import org.alfresco.opencmis.CMISAccessControlFormatEnum;
|
||||
import org.alfresco.repo.template.TemplateNode;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
import freemarker.ext.beans.BeanModel;
|
||||
import freemarker.template.TemplateMethodModelEx;
|
||||
import freemarker.template.TemplateModelException;
|
||||
import freemarker.template.TemplateScalarModel;
|
||||
|
||||
/**
|
||||
* Custom FreeMarker Template language method.
|
||||
* <p>
|
||||
* Gets the ACL of a TemplateNode
|
||||
* <p>
|
||||
* Usage: cmisacl(TemplateNode node)
|
||||
* cmisacl(TemplateNode node, String format)
|
||||
*
|
||||
* @author dward
|
||||
*/
|
||||
public class CMISAclMethod implements TemplateMethodModelEx
|
||||
{
|
||||
private CMISAccessControlService accessControlService;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*/
|
||||
public CMISAclMethod(CMISAccessControlService accessControlService)
|
||||
{
|
||||
this.accessControlService = accessControlService;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object exec(List args) throws TemplateModelException
|
||||
{
|
||||
NodeRef nodeRef = null;
|
||||
CMISAccessControlFormatEnum format = CMISAccessControlFormatEnum.REPOSITORY_SPECIFIC_PERMISSIONS;
|
||||
try
|
||||
{
|
||||
int i = 0;
|
||||
// extract node ref
|
||||
Object arg = args.get(i++);
|
||||
if (arg instanceof BeanModel)
|
||||
{
|
||||
Object wrapped = ((BeanModel) arg).getWrappedObject();
|
||||
if (wrapped != null)
|
||||
{
|
||||
if (wrapped instanceof TemplateNode)
|
||||
{
|
||||
nodeRef = ((TemplateNode) wrapped).getNodeRef();
|
||||
}
|
||||
}
|
||||
}
|
||||
// extract format if specified
|
||||
arg = args.get(i++);
|
||||
if (arg instanceof TemplateScalarModel)
|
||||
{
|
||||
format = CMISAccessControlFormatEnum.FACTORY.toEnum(((TemplateScalarModel) arg).getAsString());
|
||||
}
|
||||
}
|
||||
catch (IndexOutOfBoundsException e)
|
||||
{
|
||||
// Ignore optional arguments
|
||||
}
|
||||
|
||||
// query renditions
|
||||
if (nodeRef != null)
|
||||
{
|
||||
return accessControlService.getAcl(nodeRef, format);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.cmis.rest;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.cmis.CMISServices;
|
||||
import org.alfresco.cmis.CMISTypeDefinition;
|
||||
import org.alfresco.repo.template.TemplateNode;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
import freemarker.ext.beans.BeanModel;
|
||||
import freemarker.template.TemplateMethodModelEx;
|
||||
import freemarker.template.TemplateModelException;
|
||||
|
||||
/**
|
||||
* Custom FreeMarker Template language method.
|
||||
* <p>
|
||||
* Gets the type definitions of a TemplateNode's aspects
|
||||
* <p>
|
||||
* Usage: cmisaspects(TemplateNode node)
|
||||
*
|
||||
* @author dward
|
||||
*/
|
||||
public class CMISAspectsMethod implements TemplateMethodModelEx
|
||||
{
|
||||
private CMISServices cmisService;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*/
|
||||
public CMISAspectsMethod(CMISServices cmisService)
|
||||
{
|
||||
this.cmisService = cmisService;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object exec(List args) throws TemplateModelException
|
||||
{
|
||||
NodeRef nodeRef = null;
|
||||
try
|
||||
{
|
||||
int i = 0;
|
||||
// extract node ref
|
||||
Object arg = args.get(i++);
|
||||
if (arg instanceof BeanModel)
|
||||
{
|
||||
Object wrapped = ((BeanModel) arg).getWrappedObject();
|
||||
if (wrapped != null)
|
||||
{
|
||||
if (wrapped instanceof TemplateNode)
|
||||
{
|
||||
nodeRef = ((TemplateNode) wrapped).getNodeRef();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IndexOutOfBoundsException e)
|
||||
{
|
||||
// Ignore optional arguments
|
||||
}
|
||||
|
||||
// query aspects
|
||||
if (nodeRef != null)
|
||||
{
|
||||
return cmisService.getAspects(nodeRef);
|
||||
}
|
||||
|
||||
return Collections.<CMISTypeDefinition> emptySet();
|
||||
}
|
||||
}
|
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.cmis.rest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.cmis.CMISRelationshipDirectionEnum;
|
||||
import org.alfresco.cmis.CMISServiceException;
|
||||
import org.alfresco.cmis.CMISServices;
|
||||
import org.alfresco.repo.template.TemplateNode;
|
||||
import org.alfresco.repo.web.scripts.RepositoryImageResolver;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
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.template.TemplateMethodModelEx;
|
||||
import freemarker.template.TemplateModelException;
|
||||
import freemarker.template.TemplateScalarModel;
|
||||
|
||||
/**
|
||||
* Custom FreeMarker Template language method.
|
||||
* <p>
|
||||
* Gets the associations of a TemplateNode
|
||||
* <p>
|
||||
* Usage: cmisassocs(TemplateNode node, String direction)
|
||||
*
|
||||
* @author dward
|
||||
*/
|
||||
public class CMISAssocsMethod implements TemplateMethodModelEx
|
||||
{
|
||||
private CMISServices cmisService;
|
||||
private TemplateImageResolver imageResolver;
|
||||
private TemplateValueConverter templateValueConverter;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*/
|
||||
public CMISAssocsMethod(CMISServices cmisService, RepositoryImageResolver imageResolver,
|
||||
TemplateValueConverter templateValueConverter)
|
||||
{
|
||||
this.cmisService = cmisService;
|
||||
this.imageResolver = imageResolver.getImageResolver();
|
||||
this.templateValueConverter = templateValueConverter;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object exec(List args) throws TemplateModelException
|
||||
{
|
||||
NodeRef nodeRef = null;
|
||||
CMISRelationshipDirectionEnum direction = CMISRelationshipDirectionEnum.SOURCE;
|
||||
try
|
||||
{
|
||||
int i = 0;
|
||||
// extract node ref
|
||||
Object arg = args.get(i++);
|
||||
if (arg instanceof BeanModel)
|
||||
{
|
||||
Object wrapped = ((BeanModel) arg).getWrappedObject();
|
||||
if (wrapped != null)
|
||||
{
|
||||
if (wrapped instanceof TemplateNode)
|
||||
{
|
||||
nodeRef = ((TemplateNode) wrapped).getNodeRef();
|
||||
}
|
||||
}
|
||||
}
|
||||
// extract direction, if specified
|
||||
arg = args.get(i++);
|
||||
if (arg instanceof TemplateScalarModel)
|
||||
{
|
||||
String strDirection = ((TemplateScalarModel)arg).getAsString();
|
||||
if (strDirection.equalsIgnoreCase(("both")))
|
||||
{
|
||||
direction = CMISRelationshipDirectionEnum.EITHER;
|
||||
}
|
||||
else
|
||||
{
|
||||
direction = CMISRelationshipDirectionEnum.FACTORY.fromLabel(strDirection);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IndexOutOfBoundsException e)
|
||||
{
|
||||
// Ignore optional arguments
|
||||
}
|
||||
|
||||
// query relationships
|
||||
if (nodeRef != null)
|
||||
{
|
||||
AssociationRef[] assocs;
|
||||
try
|
||||
{
|
||||
assocs = cmisService.getRelationships(nodeRef, null, true, direction);
|
||||
}
|
||||
catch (CMISServiceException e)
|
||||
{
|
||||
throw new WebScriptException(e.getStatusCode(), e.getMessage(), e);
|
||||
}
|
||||
return templateValueConverter.convertValue(assocs, imageResolver);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@@ -1,119 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.cmis.rest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.cmis.CMISInvalidArgumentException;
|
||||
import org.alfresco.cmis.CMISServices;
|
||||
import org.alfresco.cmis.CMISTypesFilterEnum;
|
||||
import org.alfresco.repo.template.TemplateNode;
|
||||
import org.alfresco.repo.web.scripts.RepositoryImageResolver;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.TemplateImageResolver;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
|
||||
import freemarker.ext.beans.BeanModel;
|
||||
import freemarker.template.TemplateMethodModelEx;
|
||||
import freemarker.template.TemplateModelException;
|
||||
import freemarker.template.TemplateScalarModel;
|
||||
|
||||
/**
|
||||
* Custom FreeMarker Template language method.
|
||||
* <p>
|
||||
* Lists the (CMIS) children of a TemplateNode
|
||||
* <p>
|
||||
* Usage: cmischildren(TemplateNode node)
|
||||
* cmischildren(TemplateNode node, String typesFilter)
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class CMISChildrenMethod implements TemplateMethodModelEx
|
||||
{
|
||||
private CMISServices cmisService;
|
||||
private ServiceRegistry serviceRegistry;
|
||||
private TemplateImageResolver imageResolver;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*/
|
||||
public CMISChildrenMethod(CMISServices cmisService, ServiceRegistry serviceRegistry, RepositoryImageResolver imageResolver)
|
||||
{
|
||||
this.cmisService = cmisService;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.imageResolver = imageResolver.getImageResolver();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object exec(List args) throws TemplateModelException
|
||||
{
|
||||
TemplateNode[] children = null;
|
||||
|
||||
if (args.size() > 0)
|
||||
{
|
||||
Object arg0 = args.get(0);
|
||||
if (arg0 instanceof BeanModel)
|
||||
{
|
||||
// extract node ref
|
||||
Object wrapped = ((BeanModel)arg0).getWrappedObject();
|
||||
if (wrapped != null)
|
||||
{
|
||||
if (wrapped instanceof TemplateNode)
|
||||
{
|
||||
NodeRef nodeRef = ((TemplateNode)wrapped).getNodeRef();
|
||||
CMISTypesFilterEnum typesFilter = CMISTypesFilterEnum.ANY;
|
||||
if (args.size() > 1)
|
||||
{
|
||||
// extract types filter, if specified
|
||||
Object arg1 = args.get(1);
|
||||
if (arg1 instanceof TemplateScalarModel)
|
||||
{
|
||||
String typesFilterStr = ((TemplateScalarModel)arg1).getAsString();
|
||||
if (typesFilterStr != null && typesFilterStr.length() > 0)
|
||||
{
|
||||
typesFilter = (CMISTypesFilterEnum)CMISTypesFilterEnum.FACTORY.toEnum(typesFilterStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// query children
|
||||
NodeRef[] childNodeRefs;
|
||||
try
|
||||
{
|
||||
childNodeRefs = cmisService.getChildren(nodeRef, typesFilter, null);
|
||||
}
|
||||
catch (CMISInvalidArgumentException e)
|
||||
{
|
||||
throw new WebScriptException(e.getStatusCode(), e.getMessage(), e);
|
||||
}
|
||||
children = new TemplateNode[childNodeRefs.length];
|
||||
for (int i = 0; i < childNodeRefs.length; i++)
|
||||
{
|
||||
children[i] = new TemplateNode(childNodeRefs[i], serviceRegistry, imageResolver);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return children;
|
||||
}
|
||||
|
||||
}
|
@@ -1,139 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.cmis.rest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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;
|
||||
import freemarker.template.TemplateScalarModel;
|
||||
|
||||
/**
|
||||
* Custom FreeMarker Template language method.
|
||||
* <p>
|
||||
* 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 class CMISPropertyValueMethod implements TemplateMethodModelEx
|
||||
{
|
||||
/**
|
||||
* NULL value marker
|
||||
*/
|
||||
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, RepositoryImageResolver imageResolver,
|
||||
TemplateValueConverter templateValueConverter)
|
||||
{
|
||||
this.cmisService = cmisService;
|
||||
this.imageResolver = imageResolver.getImageResolver();
|
||||
this.templateValueConverter = templateValueConverter;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object exec(List args) throws TemplateModelException
|
||||
{
|
||||
Object wrapped = null;
|
||||
String propertyName = null;
|
||||
boolean asObject = false;
|
||||
try
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
// 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, allowing aspect properties
|
||||
result = cmisService.getProperty(((TemplateNode) wrapped).getNodeRef(), null, 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.cmis.rest;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.cmis.CMISResultSet;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.DeclarativeWebScript;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
|
||||
/**
|
||||
* Base Web Script Implementation that ensures query result sets are closed
|
||||
*/
|
||||
public class CMISQueryWebScript extends DeclarativeWebScript
|
||||
{
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeFinallyImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
protected void executeFinallyImpl(WebScriptRequest req, Status status, Cache cache, Map<String, Object> model)
|
||||
{
|
||||
Object object = model.get("resultset");
|
||||
if (object != null && object instanceof CMISResultSet)
|
||||
{
|
||||
CMISResultSet resultSet = (CMISResultSet)object;
|
||||
resultSet.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.cmis.rest;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.cmis.CMISFilterNotValidException;
|
||||
import org.alfresco.cmis.CMISServices;
|
||||
import org.alfresco.repo.template.TemplateNode;
|
||||
import org.alfresco.repo.web.scripts.RepositoryImageResolver;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
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.template.TemplateMethodModelEx;
|
||||
import freemarker.template.TemplateModelException;
|
||||
import freemarker.template.TemplateScalarModel;
|
||||
|
||||
/**
|
||||
* Custom FreeMarker Template language method.
|
||||
* <p>
|
||||
* Gets the renditions of a TemplateNode
|
||||
* <p>
|
||||
* Usage: cmisrenditions(TemplateNode node)
|
||||
* cmisrenditions(TemplateNode node, String renditionFilter)
|
||||
*
|
||||
* @author dward
|
||||
*/
|
||||
public class CMISRenditionsMethod implements TemplateMethodModelEx
|
||||
{
|
||||
private CMISServices cmisService;
|
||||
private TemplateImageResolver imageResolver;
|
||||
private TemplateValueConverter templateValueConverter;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*/
|
||||
public CMISRenditionsMethod(CMISServices cmisService, RepositoryImageResolver imageResolver,
|
||||
TemplateValueConverter templateValueConverter)
|
||||
{
|
||||
this.cmisService = cmisService;
|
||||
this.imageResolver = imageResolver.getImageResolver();
|
||||
this.templateValueConverter = templateValueConverter;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object exec(List args) throws TemplateModelException
|
||||
{
|
||||
NodeRef nodeRef = null;
|
||||
String renditionFilter = null;
|
||||
try
|
||||
{
|
||||
int i = 0;
|
||||
// extract node ref
|
||||
Object arg = args.get(i++);
|
||||
if (arg instanceof BeanModel)
|
||||
{
|
||||
Object wrapped = ((BeanModel) arg).getWrappedObject();
|
||||
if (wrapped != null)
|
||||
{
|
||||
if (wrapped instanceof TemplateNode)
|
||||
{
|
||||
nodeRef = ((TemplateNode) wrapped).getNodeRef();
|
||||
}
|
||||
}
|
||||
}
|
||||
// extract rendition filter, if specified
|
||||
arg = args.get(i++);
|
||||
if (arg instanceof TemplateScalarModel)
|
||||
{
|
||||
renditionFilter = ((TemplateScalarModel) arg).getAsString();
|
||||
}
|
||||
}
|
||||
catch (IndexOutOfBoundsException e)
|
||||
{
|
||||
// Ignore optional arguments
|
||||
}
|
||||
|
||||
// query renditions
|
||||
if (nodeRef != null)
|
||||
{
|
||||
Map<String, Object> renditions;
|
||||
try
|
||||
{
|
||||
renditions = cmisService.getRenditions(nodeRef, renditionFilter);
|
||||
}
|
||||
catch (CMISFilterNotValidException e)
|
||||
{
|
||||
throw new WebScriptException(e.getStatusCode(), e.getMessage(), e);
|
||||
}
|
||||
return templateValueConverter.convertValue(renditions, imageResolver);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.cmis.rest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.cmis.CMISResultSet;
|
||||
import org.alfresco.repo.web.scripts.RepositoryImageResolver;
|
||||
import org.alfresco.repo.web.util.paging.Cursor;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.TemplateImageResolver;
|
||||
|
||||
import freemarker.ext.beans.BeanModel;
|
||||
import freemarker.template.TemplateMethodModelEx;
|
||||
import freemarker.template.TemplateModelException;
|
||||
|
||||
/**
|
||||
* Custom FreeMarker Template language method.
|
||||
* <p>
|
||||
* Creates a CMIS result set that builds TemplateNode on iteration
|
||||
* <p>
|
||||
* Usage: cmisresultset(CMISResultSet resultset)
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public final class CMISResultSetMethod implements TemplateMethodModelEx
|
||||
{
|
||||
private ServiceRegistry serviceRegistry;
|
||||
private TemplateImageResolver imageResolver;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*/
|
||||
public CMISResultSetMethod(ServiceRegistry serviceRegistry, RepositoryImageResolver imageResolver)
|
||||
{
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.imageResolver = imageResolver.getImageResolver();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see freemarker.template.TemplateMethodModel#exec(java.util.List)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object exec(List args) throws TemplateModelException
|
||||
{
|
||||
CMISTemplateResultSet resultSet = null;
|
||||
|
||||
if (args.size() > 0)
|
||||
{
|
||||
Object arg0 = args.get(0);
|
||||
if (arg0 instanceof BeanModel)
|
||||
{
|
||||
// extract cmis result set
|
||||
Object wrapped = ((BeanModel)arg0).getWrappedObject();
|
||||
if (wrapped != null)
|
||||
{
|
||||
if (wrapped instanceof CMISResultSet)
|
||||
{
|
||||
Cursor cursor = null;
|
||||
if (args.size() == 2)
|
||||
{
|
||||
Object arg1 = args.get(1);
|
||||
if (arg1 instanceof BeanModel)
|
||||
{
|
||||
Object wrapped1 = ((BeanModel)arg1).getWrappedObject();
|
||||
if (wrapped1 != null && wrapped1 instanceof Cursor)
|
||||
{
|
||||
cursor = (Cursor)wrapped1;
|
||||
}
|
||||
}
|
||||
}
|
||||
resultSet = new CMISTemplateResultSet((CMISResultSet)wrapped, cursor, serviceRegistry, imageResolver);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resultSet;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -1,312 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.cmis.rest;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import org.alfresco.cmis.CMISPropertyDefinition;
|
||||
import org.alfresco.cmis.CMISResultSet;
|
||||
import org.alfresco.cmis.CMISResultSetColumn;
|
||||
import org.alfresco.cmis.CMISResultSetMetaData;
|
||||
import org.alfresco.cmis.CMISResultSetRow;
|
||||
import org.alfresco.repo.template.TemplateNode;
|
||||
import org.alfresco.repo.web.util.paging.Cursor;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.TemplateImageResolver;
|
||||
|
||||
import freemarker.core.Environment;
|
||||
import freemarker.template.SimpleCollection;
|
||||
import freemarker.template.TemplateCollectionModel;
|
||||
import freemarker.template.TemplateModelException;
|
||||
|
||||
|
||||
/**
|
||||
* CMIS Result Set for use in Freemarker
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class CMISTemplateResultSet implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 2245418238171563934L;
|
||||
|
||||
private CMISResultSet resultSet;
|
||||
private Cursor cursor;
|
||||
private ServiceRegistry serviceRegistry;
|
||||
private TemplateImageResolver imageResolver;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param resultSet
|
||||
* @param serviceRegistry
|
||||
* @param imageResolver
|
||||
*/
|
||||
public CMISTemplateResultSet(CMISResultSet resultSet, Cursor cursor, ServiceRegistry serviceRegistry, TemplateImageResolver imageResolver)
|
||||
{
|
||||
this.resultSet = resultSet;
|
||||
this.cursor = cursor;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.imageResolver = imageResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return result set meta-data
|
||||
*/
|
||||
public CMISResultSetMetaData getMetaData()
|
||||
{
|
||||
return resultSet.getMetaData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return result set length
|
||||
*/
|
||||
public int getLength()
|
||||
{
|
||||
return resultSet.getLength();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return start index within full result set
|
||||
*/
|
||||
public int getStart()
|
||||
{
|
||||
return resultSet.getStart();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return selectors
|
||||
*/
|
||||
public String[] getSelectors()
|
||||
{
|
||||
return resultSet.getMetaData().getSelectorNames();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return result set rows
|
||||
* @throws TemplateModelException
|
||||
*/
|
||||
public TemplateCollectionModel getRows()
|
||||
throws TemplateModelException
|
||||
{
|
||||
return new SimpleCollection(new TemplateIterator(resultSet.iterator()), Environment.getCurrentEnvironment().getObjectWrapper());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Result Set Iterator
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class TemplateIterator implements Iterator<TemplateIterator.TemplateRow>
|
||||
{
|
||||
private Iterator<CMISResultSetRow> iter;
|
||||
private int idx = 0;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param iter
|
||||
*/
|
||||
public TemplateIterator(Iterator<CMISResultSetRow> iter)
|
||||
{
|
||||
this.iter = iter;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Iterator#hasNext()
|
||||
*/
|
||||
public boolean hasNext()
|
||||
{
|
||||
return (cursor == null || idx < cursor.getRowCount()) && iter.hasNext();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Iterator#next()
|
||||
*/
|
||||
public TemplateRow next()
|
||||
{
|
||||
if (!hasNext())
|
||||
{
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
try
|
||||
{
|
||||
return new TemplateRow(iter.next());
|
||||
}
|
||||
finally
|
||||
{
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Iterator#remove()
|
||||
*/
|
||||
public void remove()
|
||||
{
|
||||
iter.remove();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Template Row
|
||||
*/
|
||||
public class TemplateRow
|
||||
{
|
||||
private CMISResultSetRow row;
|
||||
private Map<String, TemplateNode> nodes = null;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param row
|
||||
*/
|
||||
public TemplateRow(CMISResultSetRow row)
|
||||
{
|
||||
this.row = row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a map of serializable column values with the column name as the key
|
||||
*/
|
||||
public Map<String, Serializable> getValues()
|
||||
{
|
||||
return row.getValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return nodes associated with row
|
||||
*/
|
||||
public Collection<TemplateNode> getNodes()
|
||||
{
|
||||
Map<String, TemplateNode> nodes = buildNodes();
|
||||
return nodes.size() == 0 ? null : nodes.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return node (if there is only a single node associated with the row), otherwise null
|
||||
*/
|
||||
public TemplateNode getNode()
|
||||
{
|
||||
try
|
||||
{
|
||||
NodeRef nodeRef = row.getNodeRef();
|
||||
return new TemplateNode(nodeRef, serviceRegistry, imageResolver);
|
||||
}
|
||||
catch(UnsupportedOperationException e) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a map of Template Nodes for the nodes associated with this row
|
||||
*
|
||||
* @return templates nodes indexed by selector
|
||||
*/
|
||||
private Map<String, TemplateNode> buildNodes()
|
||||
{
|
||||
if (nodes == null)
|
||||
{
|
||||
Map<String, NodeRef> nodeRefs = row.getNodeRefs();
|
||||
if (nodeRefs == null || nodeRefs.size() == 0)
|
||||
{
|
||||
nodes = Collections.emptyMap();
|
||||
}
|
||||
else
|
||||
{
|
||||
HashMap<String, TemplateNode> templateNodes = new HashMap<String, TemplateNode>();
|
||||
for (Map.Entry<String, NodeRef> entry : nodeRefs.entrySet())
|
||||
{
|
||||
templateNodes.put(entry.getKey(), new TemplateNode(entry.getValue(), serviceRegistry, imageResolver));
|
||||
}
|
||||
nodes = templateNodes;
|
||||
}
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets column type for specified column name
|
||||
*
|
||||
* @param colName column name
|
||||
* @return column type
|
||||
*/
|
||||
public String getColumnType(String colName)
|
||||
{
|
||||
CMISResultSetColumn col = resultSet.getMetaData().getColumn(colName);
|
||||
return col == null ? null : col.getCMISDataType().getLabel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets property definition for specified column name
|
||||
*
|
||||
* @param colName column name
|
||||
* @return property definition (or null, if not applicable)
|
||||
*/
|
||||
public CMISPropertyDefinition getPropertyDefinition(String colName)
|
||||
{
|
||||
CMISResultSetColumn col = resultSet.getMetaData().getColumn(colName);
|
||||
return col == null ? null : col.getCMISPropertyDefinition();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets node for specified selector
|
||||
*
|
||||
* @param selector
|
||||
* @return template node
|
||||
*/
|
||||
public TemplateNode getSelectorNode(String selector)
|
||||
{
|
||||
return nodes.get(selector);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return overall score
|
||||
*/
|
||||
public float getScore()
|
||||
{
|
||||
return row.getScore();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a map of selector name to score
|
||||
*/
|
||||
public Float getSelectorScore(String selector)
|
||||
{
|
||||
return row.getScore(selector);
|
||||
}
|
||||
|
||||
/**
|
||||
* NOTE: If you want the overall position in paged results you have to add the skipCount for the result set
|
||||
*
|
||||
* @return row index
|
||||
*/
|
||||
public int getIndex()
|
||||
{
|
||||
return row.getIndex();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.cmis.rest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.cmis.CMISDictionaryService;
|
||||
import org.alfresco.cmis.CMISScope;
|
||||
import org.alfresco.cmis.CMISTypeDefinition;
|
||||
import org.alfresco.repo.template.TemplateAssociation;
|
||||
import org.alfresco.repo.template.TemplateNode;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
import freemarker.ext.beans.BeanModel;
|
||||
import freemarker.template.TemplateMethodModelEx;
|
||||
import freemarker.template.TemplateModelException;
|
||||
|
||||
/**
|
||||
* Custom FreeMarker Template language method.
|
||||
* <p>
|
||||
* Retrieve the CMIS Type Definition for an Alfresco node
|
||||
* <p>
|
||||
* Usage: cmistype(TemplateNode node)
|
||||
* cmistype(QName nodeType)
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class CMISTypeDefinitionMethod implements TemplateMethodModelEx
|
||||
{
|
||||
private static CMISScope[] EMPTY_SCOPES = new CMISScope[] {};
|
||||
private CMISDictionaryService dictionaryService;
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*/
|
||||
public CMISTypeDefinitionMethod(CMISDictionaryService dictionaryService)
|
||||
{
|
||||
this.dictionaryService = dictionaryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see freemarker.template.TemplateMethodModel#exec(java.util.List)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object exec(List args) throws TemplateModelException
|
||||
{
|
||||
CMISTypeDefinition result = null;
|
||||
|
||||
if (args.size() == 1)
|
||||
{
|
||||
Object arg0 = args.get(0);
|
||||
if (arg0 instanceof BeanModel)
|
||||
{
|
||||
// extract node type qname
|
||||
CMISScope[] matchingScopes = EMPTY_SCOPES;
|
||||
QName nodeType = null;
|
||||
Object wrapped = ((BeanModel)arg0).getWrappedObject();
|
||||
if (wrapped != null)
|
||||
{
|
||||
if (wrapped instanceof TemplateNode)
|
||||
{
|
||||
nodeType = ((TemplateNode)wrapped).getType();
|
||||
}
|
||||
else if (wrapped instanceof TemplateAssociation)
|
||||
{
|
||||
nodeType = ((TemplateAssociation)wrapped).getTypeQName();
|
||||
matchingScopes = new CMISScope[] { CMISScope.RELATIONSHIP };
|
||||
}
|
||||
else if (wrapped instanceof QName)
|
||||
{
|
||||
nodeType = (QName)wrapped;
|
||||
}
|
||||
else if (wrapped instanceof CMISTypeDefinition)
|
||||
{
|
||||
result = ((CMISTypeDefinition)wrapped).getBaseType();
|
||||
}
|
||||
}
|
||||
|
||||
// convert to CMIS type
|
||||
if (nodeType != null)
|
||||
{
|
||||
result = dictionaryService.findTypeForClass(nodeType, matchingScopes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user