Let git handle line endings for us.

This commit is contained in:
Tom Page
2016-09-21 13:47:25 +01:00
parent 183ee64545
commit d4937aeda4
1030 changed files with 138995 additions and 138966 deletions

View File

@@ -1,132 +1,132 @@
/*
* Copyright (C) 2005-2014 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.action;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionDefinition;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanComponentKind;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
import org.alfresco.repo.action.evaluator.ActionConditionEvaluator;
import org.alfresco.service.cmr.action.ActionConditionDefinition;
import org.alfresco.service.cmr.action.ActionDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
/**
* Extended action service implementation.
*
* @author Roy Wetherall
* @since 2.1
*/
public class ExtendedActionServiceImpl extends ActionServiceImpl implements ApplicationContextAware
{
/** File plan service */
private FilePlanService filePlanService;
/** Application context */
private ApplicationContext extendedApplicationContext;
/**
* @see org.alfresco.repo.action.ActionServiceImpl#setApplicationContext(org.springframework.context.ApplicationContext)
*/
public void setApplicationContext(ApplicationContext applicationContext)
{
super.setApplicationContext(applicationContext);
extendedApplicationContext = applicationContext;
}
/**
* @param filePlanService file plan service
*/
public void setFilePlanService(FilePlanService filePlanService)
{
this.filePlanService = filePlanService;
}
/**
* @see org.alfresco.repo.action.ActionServiceImpl#getActionConditionDefinition(java.lang.String)
*/
public ActionConditionDefinition getActionConditionDefinition(String name)
{
// get direct access to action condition definition (i.e. ignoring public flag of executer)
ActionConditionDefinition definition = null;
Object bean = extendedApplicationContext.getBean(name);
if (bean instanceof ActionConditionEvaluator)
{
ActionConditionEvaluator evaluator = (ActionConditionEvaluator) bean;
definition = evaluator.getActionConditionDefintion();
}
return definition;
}
/**
* @see org.alfresco.repo.action.ActionServiceImpl#getActionDefinitions(org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public List<ActionDefinition> getActionDefinitions(NodeRef nodeRef)
{
List<ActionDefinition> result = null;
// first use the base implementation to get the list of action definitions
List<ActionDefinition> actionDefinitions = super.getActionDefinitions(nodeRef);
if (nodeRef == null)
{
// nothing to filter
result = actionDefinitions;
}
else
{
// get the file component kind of the node reference
FilePlanComponentKind kind = filePlanService.getFilePlanComponentKind(nodeRef);
result = new ArrayList<ActionDefinition>(actionDefinitions.size());
// check each action definition
for (ActionDefinition actionDefinition : actionDefinitions)
{
if (actionDefinition instanceof RecordsManagementActionDefinition)
{
if (kind != null)
{
Set<FilePlanComponentKind> applicableKinds = ((RecordsManagementActionDefinition)actionDefinition).getApplicableKinds();
if (applicableKinds == null || applicableKinds.size() == 0 || applicableKinds.contains(kind))
{
// an RM action can only act on a RM artifact
result.add(actionDefinition);
}
}
}
else
{
if (kind == null)
{
// a non-RM action can only act on a non-RM artifact
result.add(actionDefinition);
}
}
}
}
return result;
}
}
/*
* Copyright (C) 2005-2014 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.action;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionDefinition;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanComponentKind;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
import org.alfresco.repo.action.evaluator.ActionConditionEvaluator;
import org.alfresco.service.cmr.action.ActionConditionDefinition;
import org.alfresco.service.cmr.action.ActionDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
/**
* Extended action service implementation.
*
* @author Roy Wetherall
* @since 2.1
*/
public class ExtendedActionServiceImpl extends ActionServiceImpl implements ApplicationContextAware
{
/** File plan service */
private FilePlanService filePlanService;
/** Application context */
private ApplicationContext extendedApplicationContext;
/**
* @see org.alfresco.repo.action.ActionServiceImpl#setApplicationContext(org.springframework.context.ApplicationContext)
*/
public void setApplicationContext(ApplicationContext applicationContext)
{
super.setApplicationContext(applicationContext);
extendedApplicationContext = applicationContext;
}
/**
* @param filePlanService file plan service
*/
public void setFilePlanService(FilePlanService filePlanService)
{
this.filePlanService = filePlanService;
}
/**
* @see org.alfresco.repo.action.ActionServiceImpl#getActionConditionDefinition(java.lang.String)
*/
public ActionConditionDefinition getActionConditionDefinition(String name)
{
// get direct access to action condition definition (i.e. ignoring public flag of executer)
ActionConditionDefinition definition = null;
Object bean = extendedApplicationContext.getBean(name);
if (bean instanceof ActionConditionEvaluator)
{
ActionConditionEvaluator evaluator = (ActionConditionEvaluator) bean;
definition = evaluator.getActionConditionDefintion();
}
return definition;
}
/**
* @see org.alfresco.repo.action.ActionServiceImpl#getActionDefinitions(org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public List<ActionDefinition> getActionDefinitions(NodeRef nodeRef)
{
List<ActionDefinition> result = null;
// first use the base implementation to get the list of action definitions
List<ActionDefinition> actionDefinitions = super.getActionDefinitions(nodeRef);
if (nodeRef == null)
{
// nothing to filter
result = actionDefinitions;
}
else
{
// get the file component kind of the node reference
FilePlanComponentKind kind = filePlanService.getFilePlanComponentKind(nodeRef);
result = new ArrayList<ActionDefinition>(actionDefinitions.size());
// check each action definition
for (ActionDefinition actionDefinition : actionDefinitions)
{
if (actionDefinition instanceof RecordsManagementActionDefinition)
{
if (kind != null)
{
Set<FilePlanComponentKind> applicableKinds = ((RecordsManagementActionDefinition)actionDefinition).getApplicableKinds();
if (applicableKinds == null || applicableKinds.size() == 0 || applicableKinds.contains(kind))
{
// an RM action can only act on a RM artifact
result.add(actionDefinition);
}
}
}
else
{
if (kind == null)
{
// a non-RM action can only act on a non-RM artifact
result.add(actionDefinition);
}
}
}
}
return result;
}
}

View File

@@ -1,250 +1,250 @@
/*
* Copyright (C) 2005-2014 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.action.parameter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.apache.commons.lang.StringUtils;
/**
* Date parameter processor.
*
* @author Roy Wetherall
* @since 2.1
*/
public class DateParameterProcessor extends ParameterProcessor implements ParameterSubstitutionSuggester
{
private static final String DAY = "day";
private static final String WEEK = "week";
private static final String MONTH = "month";
private static final String YEAR = "year";
private static final String SHORT = "short";
private static final String LONG = "long";
private static final String NUMBER = "number";
private static final String SEP = ".";
private static final String[] ALL_FIELDS_FOR_SUBSTITUTION_QUERY = {
DAY + SEP + SHORT,
DAY,
DAY + SEP + LONG,
DAY + SEP + NUMBER,
DAY + SEP + MONTH,
DAY + SEP + YEAR,
MONTH + SEP + SHORT,
MONTH,
MONTH + SEP + LONG,
MONTH + SEP + NUMBER,
YEAR + SEP + SHORT,
YEAR,
YEAR + SEP + LONG,
YEAR + SEP + WEEK
};
private int maximumNumberSuggestions = DEFAULT_MAXIMUM_NUMBER_SUGGESTIONS;
/**
* @see org.alfresco.repo.action.parameter.ParameterProcessor#process(java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public String process(String value, NodeRef actionedUponNodeRef)
{
// the default position is to return the value un-changed
String result = value;
// strip the processor name from the value
value = stripName(value);
if (!value.isEmpty())
{
String[] values = value.split("\\.", 2);
String field = values[0].trim();
if (DAY.equalsIgnoreCase(field))
{
result = handleDay(values);
}
else if (MONTH.equalsIgnoreCase(field))
{
result = handleMonth(values);
}
else if (YEAR.equalsIgnoreCase(field))
{
result = handleYear(values);
}
else
{
throw new AlfrescoRuntimeException("Cannot process the field '" + field + "'.");
}
}
return result;
}
private String handleDay(String[] values)
{
String style = getStyle(values);
String pattern;
if (SHORT.equalsIgnoreCase(style))
{
pattern = "EE";
}
else if (LONG.equalsIgnoreCase(style))
{
pattern = "EEEE";
}
else if (NUMBER.equalsIgnoreCase(style))
{
pattern = "uu";
}
else if (MONTH.equalsIgnoreCase(style))
{
pattern = "dd";
}
else if (YEAR.equalsIgnoreCase(style))
{
pattern = "DDD";
}
else
{
throw new AlfrescoRuntimeException("The pattern 'date.day." + style + "' is not supported!");
}
return new SimpleDateFormat(pattern).format(new Date());
}
private String handleMonth(String[] values)
{
String style = getStyle(values);
String pattern;
if (SHORT.equalsIgnoreCase(style))
{
pattern = "MMM";
}
else if (LONG.equalsIgnoreCase(style))
{
pattern = "MMMM";
}
else if (NUMBER.equalsIgnoreCase(style))
{
pattern = "MM";
}
else
{
throw new AlfrescoRuntimeException("The pattern 'date.month." + style + "' is not supported!");
}
return new SimpleDateFormat(pattern).format(new Date());
}
private String handleYear(String[] values)
{
String style = getStyle(values);
String pattern;
if (SHORT.equalsIgnoreCase(style))
{
pattern = "yy";
}
else if (LONG.equalsIgnoreCase(style))
{
pattern = "yyyy";
}
else if (WEEK.equalsIgnoreCase(style))
{
pattern = "ww";
}
else
{
throw new AlfrescoRuntimeException("The pattern 'date.year." + style + "' is not supported!");
}
return new SimpleDateFormat(pattern).format(new Date());
}
private String getStyle(String[] values)
{
String style;
if (values.length == 1)
{
style = SHORT;
}
else
{
style = values[1].trim();
}
return style;
}
/**
* Set the maxmimum number of suggestions returned from the global property
*
* @param maximumNumberSuggestions
*/
public void setMaximumNumberSuggestions(int maximumNumberSuggestions)
{
this.maximumNumberSuggestions = (maximumNumberSuggestions <= 0 ? DEFAULT_MAXIMUM_NUMBER_SUGGESTIONS: maximumNumberSuggestions);
}
/* (non-Javadoc)
* @see org.alfresco.repo.action.parameter.ParameterSubstitutionSuggester#getSubstitutionSuggestions(java.lang.String)
*/
@Override
public List<String> getSubstitutionSuggestions(String substitutionFragment)
{
List<String> suggestions = new ArrayList<String>();
String namePrefix = this.getName() + ".";
if(StringUtils.isBlank(substitutionFragment) || this.getName().toLowerCase().contains(substitutionFragment.toLowerCase()))
{
for(String field: ALL_FIELDS_FOR_SUBSTITUTION_QUERY)
{
suggestions.add(namePrefix + field);
if(suggestions.size() >= maximumNumberSuggestions)
{
break;
}
}
}
else
{
for(String field: ALL_FIELDS_FOR_SUBSTITUTION_QUERY)
{
String prefixFieldName = namePrefix + field;
if(prefixFieldName.toLowerCase().contains(substitutionFragment.toLowerCase()))
{
suggestions.add(namePrefix + field);
if(suggestions.size() >= maximumNumberSuggestions)
{
break;
}
}
}
}
return suggestions;
}
}
/*
* Copyright (C) 2005-2014 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.action.parameter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.apache.commons.lang.StringUtils;
/**
* Date parameter processor.
*
* @author Roy Wetherall
* @since 2.1
*/
public class DateParameterProcessor extends ParameterProcessor implements ParameterSubstitutionSuggester
{
private static final String DAY = "day";
private static final String WEEK = "week";
private static final String MONTH = "month";
private static final String YEAR = "year";
private static final String SHORT = "short";
private static final String LONG = "long";
private static final String NUMBER = "number";
private static final String SEP = ".";
private static final String[] ALL_FIELDS_FOR_SUBSTITUTION_QUERY = {
DAY + SEP + SHORT,
DAY,
DAY + SEP + LONG,
DAY + SEP + NUMBER,
DAY + SEP + MONTH,
DAY + SEP + YEAR,
MONTH + SEP + SHORT,
MONTH,
MONTH + SEP + LONG,
MONTH + SEP + NUMBER,
YEAR + SEP + SHORT,
YEAR,
YEAR + SEP + LONG,
YEAR + SEP + WEEK
};
private int maximumNumberSuggestions = DEFAULT_MAXIMUM_NUMBER_SUGGESTIONS;
/**
* @see org.alfresco.repo.action.parameter.ParameterProcessor#process(java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public String process(String value, NodeRef actionedUponNodeRef)
{
// the default position is to return the value un-changed
String result = value;
// strip the processor name from the value
value = stripName(value);
if (!value.isEmpty())
{
String[] values = value.split("\\.", 2);
String field = values[0].trim();
if (DAY.equalsIgnoreCase(field))
{
result = handleDay(values);
}
else if (MONTH.equalsIgnoreCase(field))
{
result = handleMonth(values);
}
else if (YEAR.equalsIgnoreCase(field))
{
result = handleYear(values);
}
else
{
throw new AlfrescoRuntimeException("Cannot process the field '" + field + "'.");
}
}
return result;
}
private String handleDay(String[] values)
{
String style = getStyle(values);
String pattern;
if (SHORT.equalsIgnoreCase(style))
{
pattern = "EE";
}
else if (LONG.equalsIgnoreCase(style))
{
pattern = "EEEE";
}
else if (NUMBER.equalsIgnoreCase(style))
{
pattern = "uu";
}
else if (MONTH.equalsIgnoreCase(style))
{
pattern = "dd";
}
else if (YEAR.equalsIgnoreCase(style))
{
pattern = "DDD";
}
else
{
throw new AlfrescoRuntimeException("The pattern 'date.day." + style + "' is not supported!");
}
return new SimpleDateFormat(pattern).format(new Date());
}
private String handleMonth(String[] values)
{
String style = getStyle(values);
String pattern;
if (SHORT.equalsIgnoreCase(style))
{
pattern = "MMM";
}
else if (LONG.equalsIgnoreCase(style))
{
pattern = "MMMM";
}
else if (NUMBER.equalsIgnoreCase(style))
{
pattern = "MM";
}
else
{
throw new AlfrescoRuntimeException("The pattern 'date.month." + style + "' is not supported!");
}
return new SimpleDateFormat(pattern).format(new Date());
}
private String handleYear(String[] values)
{
String style = getStyle(values);
String pattern;
if (SHORT.equalsIgnoreCase(style))
{
pattern = "yy";
}
else if (LONG.equalsIgnoreCase(style))
{
pattern = "yyyy";
}
else if (WEEK.equalsIgnoreCase(style))
{
pattern = "ww";
}
else
{
throw new AlfrescoRuntimeException("The pattern 'date.year." + style + "' is not supported!");
}
return new SimpleDateFormat(pattern).format(new Date());
}
private String getStyle(String[] values)
{
String style;
if (values.length == 1)
{
style = SHORT;
}
else
{
style = values[1].trim();
}
return style;
}
/**
* Set the maxmimum number of suggestions returned from the global property
*
* @param maximumNumberSuggestions
*/
public void setMaximumNumberSuggestions(int maximumNumberSuggestions)
{
this.maximumNumberSuggestions = (maximumNumberSuggestions <= 0 ? DEFAULT_MAXIMUM_NUMBER_SUGGESTIONS: maximumNumberSuggestions);
}
/* (non-Javadoc)
* @see org.alfresco.repo.action.parameter.ParameterSubstitutionSuggester#getSubstitutionSuggestions(java.lang.String)
*/
@Override
public List<String> getSubstitutionSuggestions(String substitutionFragment)
{
List<String> suggestions = new ArrayList<String>();
String namePrefix = this.getName() + ".";
if(StringUtils.isBlank(substitutionFragment) || this.getName().toLowerCase().contains(substitutionFragment.toLowerCase()))
{
for(String field: ALL_FIELDS_FOR_SUBSTITUTION_QUERY)
{
suggestions.add(namePrefix + field);
if(suggestions.size() >= maximumNumberSuggestions)
{
break;
}
}
}
else
{
for(String field: ALL_FIELDS_FOR_SUBSTITUTION_QUERY)
{
String prefixFieldName = namePrefix + field;
if(prefixFieldName.toLowerCase().contains(substitutionFragment.toLowerCase()))
{
suggestions.add(namePrefix + field);
if(suggestions.size() >= maximumNumberSuggestions)
{
break;
}
}
}
}
return suggestions;
}
}

View File

@@ -1,55 +1,55 @@
/*
* Copyright (C) 2005-2014 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.action.parameter;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* Message parameter processor.
*
* @author Roy Wetherall
* @since 2.1
*/
public class MessageParameterProcessor extends ParameterProcessor
{
/**
* @see org.alfresco.repo.action.parameter.ParameterProcessor#process(java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public String process(String value, NodeRef actionedUponNodeRef)
{
// the default position is to return the value un-changed
String result = value;
// strip the processor name from the value
value = stripName(value);
if (!value.isEmpty())
{
result = I18NUtil.getMessage(value);
if (result == null)
{
throw new AlfrescoRuntimeException("The message parameter processor could not resolve the message for the id " + value);
}
}
return result;
}
}
/*
* Copyright (C) 2005-2014 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.action.parameter;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* Message parameter processor.
*
* @author Roy Wetherall
* @since 2.1
*/
public class MessageParameterProcessor extends ParameterProcessor
{
/**
* @see org.alfresco.repo.action.parameter.ParameterProcessor#process(java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public String process(String value, NodeRef actionedUponNodeRef)
{
// the default position is to return the value un-changed
String result = value;
// strip the processor name from the value
value = stripName(value);
if (!value.isEmpty())
{
result = I18NUtil.getMessage(value);
if (result == null)
{
throw new AlfrescoRuntimeException("The message parameter processor could not resolve the message for the id " + value);
}
}
return result;
}
}

View File

@@ -1,294 +1,294 @@
/*
* Copyright (C) 2005-2014 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.action.parameter;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.lang.ArrayUtils;
/**
* Node parameter processor.
*
* @author Roy Wetherall
* @since 2.1
*/
public class NodeParameterProcessor extends ParameterProcessor implements ParameterSubstitutionSuggester
{
/** Supported data types */
private QName[] supportedDataTypes =
{
DataTypeDefinition.TEXT,
DataTypeDefinition.BOOLEAN,
DataTypeDefinition.DATE,
DataTypeDefinition.DATETIME,
DataTypeDefinition.DOUBLE,
DataTypeDefinition.FLOAT,
DataTypeDefinition.INT,
DataTypeDefinition.MLTEXT
};
private int maximumNumberSuggestions = DEFAULT_MAXIMUM_NUMBER_SUGGESTIONS;
/** Node service */
private NodeService nodeService;
/** Namespace service */
private NamespaceService namespaceService;
/** Dictionary service */
private DictionaryService dictionaryService;
/** Records management admin service */
private RecordsManagementAdminService recordsManagementAdminService;
/** List of definitions (aspects and types) to use for substitution suggestions */
private List<QName> suggestionDefinitions = null;
/**
* @param nodeService node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @param namespaceService namespace service
*/
public void setNamespaceService(NamespaceService namespaceService)
{
this.namespaceService = namespaceService;
}
/**
* @param dictionaryService dictionary service
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* @param recordsManagementAdminService Records management admin service
*/
public void setRecordsManagementAdminService(RecordsManagementAdminService recordsManagementAdminService)
{
this.recordsManagementAdminService = recordsManagementAdminService;
}
/**
* @see org.alfresco.repo.action.parameter.ParameterProcessor#process(java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public String process(String value, NodeRef actionedUponNodeRef)
{
// the default position is to return the value un-changed
String result = value;
// strip the processor name from the value
value = stripName(value);
if (!value.isEmpty())
{
QName qname = QName.createQName(value, namespaceService);
PropertyDefinition propertyDefinition = dictionaryService.getProperty(qname);
if (propertyDefinition == null)
{
throw new AlfrescoRuntimeException("The property " + value + " does not have a property definition.");
}
QName type = propertyDefinition.getDataType().getName();
if (ArrayUtils.contains(supportedDataTypes, type))
{
Serializable propertyValue = nodeService.getProperty(actionedUponNodeRef, qname);
if (propertyValue != null)
{
result = propertyValue.toString();
}
else
{
// set the result to the empty string
result = "";
}
}
else
{
throw new AlfrescoRuntimeException("The property " + value + " is of type " + type.toString() + " which is not supported by parameter substitution.");
}
}
return result;
}
/**
* Set the maxmimum number of suggestions returned from the global property
*
* @param maximumNumberSuggestions
*/
public void setMaximumNumberSuggestions(int maximumNumberSuggestions)
{
this.maximumNumberSuggestions = (maximumNumberSuggestions <= 0 ? DEFAULT_MAXIMUM_NUMBER_SUGGESTIONS: maximumNumberSuggestions);
}
/**
* Add suggestion definition to the list used to get properties suggestions from.
*
* @param definition Type or aspect
*/
public void addSuggestionDefinition(QName definition)
{
if(this.suggestionDefinitions == null)
{
this.suggestionDefinitions = Collections.synchronizedList(new ArrayList<QName>());
}
this.suggestionDefinitions.add(definition);
}
/**
* Get a list of node substitution suggestions for the specified fragment.
*
* @param substitutionFragment The fragment to search for
* @returns A list of node substitution suggestions, for example 'node.cm:title'
*
* @see org.alfresco.repo.action.parameter.ParameterSubstitutionSuggester#getSubstitutionSuggestions(java.lang.String)
*/
@Override
public List<String> getSubstitutionSuggestions(String substitutionFragment)
{
Set<String> suggestionSet = Collections.synchronizedSet(new HashSet<String>());
if(this.suggestionDefinitions != null)
{
for(QName definition : this.suggestionDefinitions)
{
if(getSubstitutionSuggestions(definition, substitutionFragment.toLowerCase(), suggestionSet))
{
break;
}
}
}
List<String> suggestions = new ArrayList<String>();
suggestions.addAll(suggestionSet);
Collections.sort(suggestions);
return suggestions;
}
/**
* Get a list of node substitution suggestions for the given definition and specified fragment.
*
* @param definitionName Definition (aspect or type) to get properties of and the call this method for associated aspects
* @param substitutionFragment Substitution fragment to search for
* @param suggestions The current list of suggestions to which we will add newly found suggestions
*/
private boolean getSubstitutionSuggestions(QName definitionName, String substitutionFragment, Set<String> suggestions)
{
boolean gotMaximumSuggestions = false;
ClassDefinition definition = this.dictionaryService.getAspect(definitionName);
if(definition == null)
{
definition = this.dictionaryService.getType(definitionName);
}
if(definition != null)
{
gotMaximumSuggestions = getSubstitutionSuggestionsForDefinition(definition, substitutionFragment, suggestions);
}
if(recordsManagementAdminService.isCustomisable(definitionName) && !gotMaximumSuggestions)
{
gotMaximumSuggestions = processPropertyDefinitions(recordsManagementAdminService.getCustomPropertyDefinitions(definitionName), substitutionFragment, suggestions);
}
return gotMaximumSuggestions;
}
/**
* Get a list of node substitution suggestions for the given definition and specified fragment. Calls itself recursively for
* associated aspects.
*
* @param definition Definition (aspect or type) to get properties of and the call this method for associated aspects
* @param substitutionFragment Substitution fragment to search for
* @param suggestions The current list of suggestions to which we will add newly found suggestions
*/
private boolean getSubstitutionSuggestionsForDefinition(ClassDefinition definition, String substitutionFragment, Set<String> suggestions)
{
boolean gotMaximumSuggestions = processPropertyDefinitions(definition.getProperties(), substitutionFragment, suggestions);
if(!gotMaximumSuggestions)
{
for(QName defaultAspect : definition.getDefaultAspectNames())
{
gotMaximumSuggestions = getSubstitutionSuggestions(defaultAspect, substitutionFragment, suggestions);
if(gotMaximumSuggestions)
{
break;
}
}
}
return gotMaximumSuggestions;
}
/**
* Process the supplied map of property definitions and add the ones that match the supplied fragment to the list of suggestions.
*
* @param definition Definition (aspect or type) to get properties of and the call this method for associated aspects
* @param substitutionFragment Substitution fragment to search for
* @param suggestions The current list of suggestions to which we will add newly found suggestions
*/
private boolean processPropertyDefinitions(Map<QName, PropertyDefinition> properties, String substitutionFragment, Set<String> suggestions)
{
boolean gotMaximumSuggestions = false;
if (properties != null)
{
for (Map.Entry<QName, PropertyDefinition> entry : properties.entrySet())
{
PropertyDefinition propertyDefinition = entry.getValue();
QName type = propertyDefinition.getDataType().getName();
if(ArrayUtils.contains(supportedDataTypes, type))
{
String suggestion = getName() + "." + entry.getKey().getPrefixString();
if(suggestion.toLowerCase().contains(substitutionFragment))
{
if(suggestions.size() < this.maximumNumberSuggestions)
{
suggestions.add(suggestion);
}
else
{
gotMaximumSuggestions = true;
break;
}
}
}
}
}
return gotMaximumSuggestions;
}
}
/*
* Copyright (C) 2005-2014 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.action.parameter;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.lang.ArrayUtils;
/**
* Node parameter processor.
*
* @author Roy Wetherall
* @since 2.1
*/
public class NodeParameterProcessor extends ParameterProcessor implements ParameterSubstitutionSuggester
{
/** Supported data types */
private QName[] supportedDataTypes =
{
DataTypeDefinition.TEXT,
DataTypeDefinition.BOOLEAN,
DataTypeDefinition.DATE,
DataTypeDefinition.DATETIME,
DataTypeDefinition.DOUBLE,
DataTypeDefinition.FLOAT,
DataTypeDefinition.INT,
DataTypeDefinition.MLTEXT
};
private int maximumNumberSuggestions = DEFAULT_MAXIMUM_NUMBER_SUGGESTIONS;
/** Node service */
private NodeService nodeService;
/** Namespace service */
private NamespaceService namespaceService;
/** Dictionary service */
private DictionaryService dictionaryService;
/** Records management admin service */
private RecordsManagementAdminService recordsManagementAdminService;
/** List of definitions (aspects and types) to use for substitution suggestions */
private List<QName> suggestionDefinitions = null;
/**
* @param nodeService node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @param namespaceService namespace service
*/
public void setNamespaceService(NamespaceService namespaceService)
{
this.namespaceService = namespaceService;
}
/**
* @param dictionaryService dictionary service
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* @param recordsManagementAdminService Records management admin service
*/
public void setRecordsManagementAdminService(RecordsManagementAdminService recordsManagementAdminService)
{
this.recordsManagementAdminService = recordsManagementAdminService;
}
/**
* @see org.alfresco.repo.action.parameter.ParameterProcessor#process(java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public String process(String value, NodeRef actionedUponNodeRef)
{
// the default position is to return the value un-changed
String result = value;
// strip the processor name from the value
value = stripName(value);
if (!value.isEmpty())
{
QName qname = QName.createQName(value, namespaceService);
PropertyDefinition propertyDefinition = dictionaryService.getProperty(qname);
if (propertyDefinition == null)
{
throw new AlfrescoRuntimeException("The property " + value + " does not have a property definition.");
}
QName type = propertyDefinition.getDataType().getName();
if (ArrayUtils.contains(supportedDataTypes, type))
{
Serializable propertyValue = nodeService.getProperty(actionedUponNodeRef, qname);
if (propertyValue != null)
{
result = propertyValue.toString();
}
else
{
// set the result to the empty string
result = "";
}
}
else
{
throw new AlfrescoRuntimeException("The property " + value + " is of type " + type.toString() + " which is not supported by parameter substitution.");
}
}
return result;
}
/**
* Set the maxmimum number of suggestions returned from the global property
*
* @param maximumNumberSuggestions
*/
public void setMaximumNumberSuggestions(int maximumNumberSuggestions)
{
this.maximumNumberSuggestions = (maximumNumberSuggestions <= 0 ? DEFAULT_MAXIMUM_NUMBER_SUGGESTIONS: maximumNumberSuggestions);
}
/**
* Add suggestion definition to the list used to get properties suggestions from.
*
* @param definition Type or aspect
*/
public void addSuggestionDefinition(QName definition)
{
if(this.suggestionDefinitions == null)
{
this.suggestionDefinitions = Collections.synchronizedList(new ArrayList<QName>());
}
this.suggestionDefinitions.add(definition);
}
/**
* Get a list of node substitution suggestions for the specified fragment.
*
* @param substitutionFragment The fragment to search for
* @returns A list of node substitution suggestions, for example 'node.cm:title'
*
* @see org.alfresco.repo.action.parameter.ParameterSubstitutionSuggester#getSubstitutionSuggestions(java.lang.String)
*/
@Override
public List<String> getSubstitutionSuggestions(String substitutionFragment)
{
Set<String> suggestionSet = Collections.synchronizedSet(new HashSet<String>());
if(this.suggestionDefinitions != null)
{
for(QName definition : this.suggestionDefinitions)
{
if(getSubstitutionSuggestions(definition, substitutionFragment.toLowerCase(), suggestionSet))
{
break;
}
}
}
List<String> suggestions = new ArrayList<String>();
suggestions.addAll(suggestionSet);
Collections.sort(suggestions);
return suggestions;
}
/**
* Get a list of node substitution suggestions for the given definition and specified fragment.
*
* @param definitionName Definition (aspect or type) to get properties of and the call this method for associated aspects
* @param substitutionFragment Substitution fragment to search for
* @param suggestions The current list of suggestions to which we will add newly found suggestions
*/
private boolean getSubstitutionSuggestions(QName definitionName, String substitutionFragment, Set<String> suggestions)
{
boolean gotMaximumSuggestions = false;
ClassDefinition definition = this.dictionaryService.getAspect(definitionName);
if(definition == null)
{
definition = this.dictionaryService.getType(definitionName);
}
if(definition != null)
{
gotMaximumSuggestions = getSubstitutionSuggestionsForDefinition(definition, substitutionFragment, suggestions);
}
if(recordsManagementAdminService.isCustomisable(definitionName) && !gotMaximumSuggestions)
{
gotMaximumSuggestions = processPropertyDefinitions(recordsManagementAdminService.getCustomPropertyDefinitions(definitionName), substitutionFragment, suggestions);
}
return gotMaximumSuggestions;
}
/**
* Get a list of node substitution suggestions for the given definition and specified fragment. Calls itself recursively for
* associated aspects.
*
* @param definition Definition (aspect or type) to get properties of and the call this method for associated aspects
* @param substitutionFragment Substitution fragment to search for
* @param suggestions The current list of suggestions to which we will add newly found suggestions
*/
private boolean getSubstitutionSuggestionsForDefinition(ClassDefinition definition, String substitutionFragment, Set<String> suggestions)
{
boolean gotMaximumSuggestions = processPropertyDefinitions(definition.getProperties(), substitutionFragment, suggestions);
if(!gotMaximumSuggestions)
{
for(QName defaultAspect : definition.getDefaultAspectNames())
{
gotMaximumSuggestions = getSubstitutionSuggestions(defaultAspect, substitutionFragment, suggestions);
if(gotMaximumSuggestions)
{
break;
}
}
}
return gotMaximumSuggestions;
}
/**
* Process the supplied map of property definitions and add the ones that match the supplied fragment to the list of suggestions.
*
* @param definition Definition (aspect or type) to get properties of and the call this method for associated aspects
* @param substitutionFragment Substitution fragment to search for
* @param suggestions The current list of suggestions to which we will add newly found suggestions
*/
private boolean processPropertyDefinitions(Map<QName, PropertyDefinition> properties, String substitutionFragment, Set<String> suggestions)
{
boolean gotMaximumSuggestions = false;
if (properties != null)
{
for (Map.Entry<QName, PropertyDefinition> entry : properties.entrySet())
{
PropertyDefinition propertyDefinition = entry.getValue();
QName type = propertyDefinition.getDataType().getName();
if(ArrayUtils.contains(supportedDataTypes, type))
{
String suggestion = getName() + "." + entry.getKey().getPrefixString();
if(suggestion.toLowerCase().contains(substitutionFragment))
{
if(suggestions.size() < this.maximumNumberSuggestions)
{
suggestions.add(suggestion);
}
else
{
gotMaximumSuggestions = true;
break;
}
}
}
}
}
return gotMaximumSuggestions;
}
}

View File

@@ -1,92 +1,92 @@
/*
* Copyright (C) 2005-2014 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.action.parameter;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ParameterCheck;
/**
* Record metadata bootstrap bean.
* <p>
* This method of bootstrapping record metadata aspects into the RecordService deprecates the
* previous practice of extending rma:recordMetaData.
*
* @author Mark Hibbins
* @since 2.2
*/
public class NodeParameterSuggesterBootstrap
{
/** namespace service */
private NamespaceService namespaceService;
/** configured node parameter processor aspect and type names, comma separated */
private String nodeParameterProcessorAspectsNames;
/** node parameter processor */
private NodeParameterProcessor nodeParameterProcessor;
/**
* @param recordMetadataAspects map of record metadata aspects against file plan types
*/
public void setNodeParameterProcessorAspects(String nodeParameterProcessorAspectsNames)
{
this.nodeParameterProcessorAspectsNames = nodeParameterProcessorAspectsNames;
}
/**
* @param namespaceService namespace service
*/
public void setNamespaceService(NamespaceService namespaceService)
{
this.namespaceService = namespaceService;
}
/**
* @param nodeParameterProcessor Node parameter processor
*/
public void setNodeParameterProcessor(NodeParameterProcessor nodeParameterProcessor)
{
this.nodeParameterProcessor = nodeParameterProcessor;
}
/**
* Init method
*/
public void init()
{
ParameterCheck.mandatory("namespaceService", namespaceService);
if (nodeParameterProcessorAspectsNames != null)
{
String[] aspectsNames = this.nodeParameterProcessorAspectsNames.split(",");
for (String name : aspectsNames)
{
if((name != null) && !"".equals(name.trim()))
{
// convert to qname and save it
QName aspect = QName.createQName(name.trim(), namespaceService);
// register with node parameter processor
this.nodeParameterProcessor.addSuggestionDefinition(aspect);
}
}
}
}
}
/*
* Copyright (C) 2005-2014 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.action.parameter;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ParameterCheck;
/**
* Record metadata bootstrap bean.
* <p>
* This method of bootstrapping record metadata aspects into the RecordService deprecates the
* previous practice of extending rma:recordMetaData.
*
* @author Mark Hibbins
* @since 2.2
*/
public class NodeParameterSuggesterBootstrap
{
/** namespace service */
private NamespaceService namespaceService;
/** configured node parameter processor aspect and type names, comma separated */
private String nodeParameterProcessorAspectsNames;
/** node parameter processor */
private NodeParameterProcessor nodeParameterProcessor;
/**
* @param recordMetadataAspects map of record metadata aspects against file plan types
*/
public void setNodeParameterProcessorAspects(String nodeParameterProcessorAspectsNames)
{
this.nodeParameterProcessorAspectsNames = nodeParameterProcessorAspectsNames;
}
/**
* @param namespaceService namespace service
*/
public void setNamespaceService(NamespaceService namespaceService)
{
this.namespaceService = namespaceService;
}
/**
* @param nodeParameterProcessor Node parameter processor
*/
public void setNodeParameterProcessor(NodeParameterProcessor nodeParameterProcessor)
{
this.nodeParameterProcessor = nodeParameterProcessor;
}
/**
* Init method
*/
public void init()
{
ParameterCheck.mandatory("namespaceService", namespaceService);
if (nodeParameterProcessorAspectsNames != null)
{
String[] aspectsNames = this.nodeParameterProcessorAspectsNames.split(",");
for (String name : aspectsNames)
{
if((name != null) && !"".equals(name.trim()))
{
// convert to qname and save it
QName aspect = QName.createQName(name.trim(), namespaceService);
// register with node parameter processor
this.nodeParameterProcessor.addSuggestionDefinition(aspect);
}
}
}
}
}

View File

@@ -1,94 +1,94 @@
/*
* Copyright (C) 2005-2014 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.action.parameter;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Abstract parameter processor implementation.
*
* @author Roy Wetherall
* @since 2.1
*/
public abstract class ParameterProcessor
{
/** Processor name */
private String name;
/** Parameter processor component */
private ParameterProcessorComponent parameterProcessorComponent;
/**
* @return parameter processor name
*/
public String getName()
{
return name;
}
/**
* @param name parameter processor name
*/
public void setName(String name)
{
this.name = name;
}
/**
* @param parameterProcessorComponent parameter processor component
*/
public void setParameterProcessorComponent(ParameterProcessorComponent parameterProcessorComponent)
{
this.parameterProcessorComponent = parameterProcessorComponent;
}
/**
* Init method
*/
public void init()
{
parameterProcessorComponent.register(this);
}
/**
* Process the parameter value.
*
* @param value substitution value
* @param actionedUponNodeRef actioned upon node reference
* @return String processed string, original string if subs string invalid
*/
public abstract String process(String value, NodeRef actionedUponNodeRef);
/**
* Strips the name of the processor from the subs value.
*
* @param value subs value
* @return String subs value with the name and '.' delimiter removed
*/
protected String stripName(String value)
{
String result = "";
String[] values = value.split("\\.", 2);
if (values.length == 2)
{
result = values[1];
}
return result;
}
}
/*
* Copyright (C) 2005-2014 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.action.parameter;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Abstract parameter processor implementation.
*
* @author Roy Wetherall
* @since 2.1
*/
public abstract class ParameterProcessor
{
/** Processor name */
private String name;
/** Parameter processor component */
private ParameterProcessorComponent parameterProcessorComponent;
/**
* @return parameter processor name
*/
public String getName()
{
return name;
}
/**
* @param name parameter processor name
*/
public void setName(String name)
{
this.name = name;
}
/**
* @param parameterProcessorComponent parameter processor component
*/
public void setParameterProcessorComponent(ParameterProcessorComponent parameterProcessorComponent)
{
this.parameterProcessorComponent = parameterProcessorComponent;
}
/**
* Init method
*/
public void init()
{
parameterProcessorComponent.register(this);
}
/**
* Process the parameter value.
*
* @param value substitution value
* @param actionedUponNodeRef actioned upon node reference
* @return String processed string, original string if subs string invalid
*/
public abstract String process(String value, NodeRef actionedUponNodeRef);
/**
* Strips the name of the processor from the subs value.
*
* @param value subs value
* @return String subs value with the name and '.' delimiter removed
*/
protected String stripName(String value)
{
String result = "";
String[] values = value.split("\\.", 2);
if (values.length == 2)
{
result = values[1];
}
return result;
}
}

View File

@@ -1,166 +1,166 @@
/*
* Copyright (C) 2005-2014 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.action.parameter;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.service.cmr.action.ParameterizedItem;
import org.alfresco.service.cmr.action.ParameterizedItemDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Parameter processor component
*
* @author Roy Wetherall
* @since 2.1
*/
public class ParameterProcessorComponent implements ParameterSubstitutionSuggester
{
/** regex used to parse parameters */
private static final String REG_EX_OLD = "\\$\\{([^\\$\\{]+)\\}";
private static final String REG_EX = "\\{([^\\{]+)\\}";
/** registry of parameter processors */
private Map<String, ParameterProcessor> processors = new HashMap<String, ParameterProcessor>(5);
private List<ParameterSubstitutionSuggester> subtitutionSuggesterProcessors = new ArrayList<ParameterSubstitutionSuggester>(5);
/**
* Register parameter processor
*
* @param processor
*/
public void register(ParameterProcessor processor)
{
this.processors.put(processor.getName(), processor);
if(processor instanceof ParameterSubstitutionSuggester)
{
this.subtitutionSuggesterProcessors.add((ParameterSubstitutionSuggester)processor);
}
}
/**
*
* @param ruleItem
* @param ruleItemDefinition
* @param actionedUponNodeRef
*/
public void process(ParameterizedItem ruleItem, ParameterizedItemDefinition ruleItemDefinition, NodeRef actionedUponNodeRef)
{
for (Map.Entry<String, Serializable> entry : ruleItem.getParameterValues().entrySet())
{
String parameterName = entry.getKey();
Object parameterValue = entry.getValue();
// only sub string property values
if (parameterValue instanceof String)
{
// set the updated parameter value
ruleItem.setParameterValue(parameterName, process((String)parameterValue, actionedUponNodeRef));
}
}
}
/**
* Process the value for substitution within the context of the provided node.
*
* @param value value
* @param nodeRef node reference
* @return String resulting value
*/
public String process(String value, NodeRef nodeRef)
{
return process(process(value, nodeRef, REG_EX_OLD), nodeRef, REG_EX);
}
public String process(String value, NodeRef nodeRef, String regExp)
{
// match the substitution pattern
Pattern patt = Pattern.compile(regExp);
Matcher m = patt.matcher(value);
StringBuffer sb = new StringBuffer(value.length());
while (m.find())
{
String text = m.group(1);
// lookup parameter processor to use
ParameterProcessor processor = lookupProcessor(text);
if (processor == null)
{
throw new AlfrescoRuntimeException("A parameter processor has not been found for the substitution string " + text);
}
else
{
// process each substitution value
text = processor.process(text, nodeRef);
}
// append new value
m.appendReplacement(sb, Matcher.quoteReplacement(text));
}
m.appendTail(sb);
return sb.toString();
}
/**
* Return a list of substitution suggestions for the passed string fragment.
*
* @param subtitutionFragment Text fragment to search on.
* @return A list of substitutions that match the substitution fragment.
*/
public List<String> getSubstitutionSuggestions(final String substitutionFragment)
{
List<String> suggestions = new ArrayList<String>();
for (ParameterSubstitutionSuggester suggestor : this.subtitutionSuggesterProcessors)
{
suggestions.addAll(suggestor.getSubstitutionSuggestions(substitutionFragment.toLowerCase()));
}
return suggestions;
}
/**
* Look up parameter processor
*
* @param value
* @return
*/
private ParameterProcessor lookupProcessor(String value)
{
ParameterProcessor result = null;
if (value != null && !value.isEmpty())
{
String[] values = value.split("\\.", 2);
if (values.length != 0)
{
// get the processor from the registered map
result = processors.get(values[0]);
}
}
return result;
}
}
/*
* Copyright (C) 2005-2014 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.action.parameter;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.service.cmr.action.ParameterizedItem;
import org.alfresco.service.cmr.action.ParameterizedItemDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Parameter processor component
*
* @author Roy Wetherall
* @since 2.1
*/
public class ParameterProcessorComponent implements ParameterSubstitutionSuggester
{
/** regex used to parse parameters */
private static final String REG_EX_OLD = "\\$\\{([^\\$\\{]+)\\}";
private static final String REG_EX = "\\{([^\\{]+)\\}";
/** registry of parameter processors */
private Map<String, ParameterProcessor> processors = new HashMap<String, ParameterProcessor>(5);
private List<ParameterSubstitutionSuggester> subtitutionSuggesterProcessors = new ArrayList<ParameterSubstitutionSuggester>(5);
/**
* Register parameter processor
*
* @param processor
*/
public void register(ParameterProcessor processor)
{
this.processors.put(processor.getName(), processor);
if(processor instanceof ParameterSubstitutionSuggester)
{
this.subtitutionSuggesterProcessors.add((ParameterSubstitutionSuggester)processor);
}
}
/**
*
* @param ruleItem
* @param ruleItemDefinition
* @param actionedUponNodeRef
*/
public void process(ParameterizedItem ruleItem, ParameterizedItemDefinition ruleItemDefinition, NodeRef actionedUponNodeRef)
{
for (Map.Entry<String, Serializable> entry : ruleItem.getParameterValues().entrySet())
{
String parameterName = entry.getKey();
Object parameterValue = entry.getValue();
// only sub string property values
if (parameterValue instanceof String)
{
// set the updated parameter value
ruleItem.setParameterValue(parameterName, process((String)parameterValue, actionedUponNodeRef));
}
}
}
/**
* Process the value for substitution within the context of the provided node.
*
* @param value value
* @param nodeRef node reference
* @return String resulting value
*/
public String process(String value, NodeRef nodeRef)
{
return process(process(value, nodeRef, REG_EX_OLD), nodeRef, REG_EX);
}
public String process(String value, NodeRef nodeRef, String regExp)
{
// match the substitution pattern
Pattern patt = Pattern.compile(regExp);
Matcher m = patt.matcher(value);
StringBuffer sb = new StringBuffer(value.length());
while (m.find())
{
String text = m.group(1);
// lookup parameter processor to use
ParameterProcessor processor = lookupProcessor(text);
if (processor == null)
{
throw new AlfrescoRuntimeException("A parameter processor has not been found for the substitution string " + text);
}
else
{
// process each substitution value
text = processor.process(text, nodeRef);
}
// append new value
m.appendReplacement(sb, Matcher.quoteReplacement(text));
}
m.appendTail(sb);
return sb.toString();
}
/**
* Return a list of substitution suggestions for the passed string fragment.
*
* @param subtitutionFragment Text fragment to search on.
* @return A list of substitutions that match the substitution fragment.
*/
public List<String> getSubstitutionSuggestions(final String substitutionFragment)
{
List<String> suggestions = new ArrayList<String>();
for (ParameterSubstitutionSuggester suggestor : this.subtitutionSuggesterProcessors)
{
suggestions.addAll(suggestor.getSubstitutionSuggestions(substitutionFragment.toLowerCase()));
}
return suggestions;
}
/**
* Look up parameter processor
*
* @param value
* @return
*/
private ParameterProcessor lookupProcessor(String value)
{
ParameterProcessor result = null;
if (value != null && !value.isEmpty())
{
String[] values = value.split("\\.", 2);
if (values.length != 0)
{
// get the processor from the registered map
result = processors.get(values[0]);
}
}
return result;
}
}

View File

@@ -1,28 +1,28 @@
/*
* Copyright (C) 2005-2014 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.action.parameter;
import java.util.List;
public interface ParameterSubstitutionSuggester
{
int DEFAULT_MAXIMUM_NUMBER_SUGGESTIONS = 10;
List<String> getSubstitutionSuggestions(final String substitutionFragment);
}
/*
* Copyright (C) 2005-2014 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.action.parameter;
import java.util.List;
public interface ParameterSubstitutionSuggester
{
int DEFAULT_MAXIMUM_NUMBER_SUGGESTIONS = 10;
List<String> getSubstitutionSuggestions(final String substitutionFragment);
}