mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-1144 & RM-1145 - changes to file to action
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@61046 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -19,7 +19,9 @@
|
||||
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;
|
||||
@@ -30,7 +32,7 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class DateParameterProcessor extends ParameterProcessor
|
||||
public class DateParameterProcessor extends ParameterProcessor implements ParameterSubstitutionSuggester
|
||||
{
|
||||
private static final String DAY = "day";
|
||||
private static final String WEEK = "week";
|
||||
@@ -39,6 +41,27 @@ public class DateParameterProcessor extends ParameterProcessor
|
||||
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,
|
||||
DAY + SEP + SHORT,
|
||||
DAY + SEP + LONG,
|
||||
DAY + SEP + NUMBER,
|
||||
WEEK,
|
||||
WEEK + SEP + SHORT,
|
||||
WEEK + SEP + LONG,
|
||||
WEEK + SEP + NUMBER,
|
||||
MONTH,
|
||||
MONTH + SEP + SHORT,
|
||||
MONTH + SEP + LONG,
|
||||
MONTH + SEP + NUMBER,
|
||||
YEAR,
|
||||
YEAR + SEP + SHORT,
|
||||
YEAR + SEP + LONG,
|
||||
YEAR + SEP + NUMBER
|
||||
};
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.action.parameter.ParameterProcessor#process(java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
|
||||
@@ -172,4 +195,28 @@ public class DateParameterProcessor extends ParameterProcessor
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSubstitutionSuggestions(String substitutionFragment)
|
||||
{
|
||||
List<String> suggestions = new ArrayList<String>();
|
||||
String namePrefix = this.getName() + ".";
|
||||
if(this.getName().toLowerCase().contains(substitutionFragment.toLowerCase()))
|
||||
{
|
||||
for(String field: ALL_FIELDS_FOR_SUBSTITUTION_QUERY) {
|
||||
suggestions.add(namePrefix + field);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(String field: ALL_FIELDS_FOR_SUBSTITUTION_QUERY) {
|
||||
String prefixFieldName = namePrefix + field;
|
||||
if(prefixFieldName.toLowerCase().contains(substitutionFragment.toLowerCase()))
|
||||
{
|
||||
suggestions.add(namePrefix + field);
|
||||
}
|
||||
}
|
||||
}
|
||||
return suggestions;
|
||||
}
|
||||
}
|
||||
|
@@ -19,7 +19,9 @@
|
||||
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;
|
||||
@@ -28,6 +30,7 @@ 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;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
/**
|
||||
* Parameter processor component
|
||||
@@ -35,13 +38,15 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class ParameterProcessorComponent
|
||||
public class ParameterProcessorComponent implements ParameterSubstitutionSuggester
|
||||
{
|
||||
/** regex used to parse parameters */
|
||||
private static final String REG_EX = "\\$\\{([^\\$\\{]+)\\}";
|
||||
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
|
||||
@@ -51,6 +56,10 @@ public class ParameterProcessorComponent
|
||||
public void register(ParameterProcessor processor)
|
||||
{
|
||||
this.processors.put(processor.getName(), processor);
|
||||
if(processor instanceof ParameterSubstitutionSuggester)
|
||||
{
|
||||
this.subtitutionSuggesterProcessors.add((ParameterSubstitutionSuggester)processor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,9 +92,14 @@ public class ParameterProcessorComponent
|
||||
* @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(REG_EX);
|
||||
Pattern patt = Pattern.compile(regExp);
|
||||
Matcher m = patt.matcher(value);
|
||||
StringBuffer sb = new StringBuffer(value.length());
|
||||
|
||||
@@ -112,6 +126,25 @@ public class ParameterProcessorComponent
|
||||
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>();
|
||||
if (StringUtils.isNotBlank(substitutionFragment))
|
||||
{
|
||||
for (ParameterSubstitutionSuggester suggestor : this.subtitutionSuggesterProcessors)
|
||||
{
|
||||
suggestions.addAll(suggestor.getSubstitutionSuggestions(substitutionFragment.toLowerCase()));
|
||||
}
|
||||
}
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up parameter processor
|
||||
*
|
||||
|
Reference in New Issue
Block a user