mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
RM-766 (Rule property substitutions missing)
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@53594 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -18,8 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.action.parameter;
|
package org.alfresco.repo.action.parameter;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Locale;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
@@ -32,10 +32,13 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
|||||||
*/
|
*/
|
||||||
public class DateParameterProcessor extends ParameterProcessor
|
public class DateParameterProcessor extends ParameterProcessor
|
||||||
{
|
{
|
||||||
|
private static final String DAY = "day";
|
||||||
|
private static final String WEEK = "week";
|
||||||
private static final String MONTH = "month";
|
private static final String MONTH = "month";
|
||||||
private static final String YEAR = "year";
|
private static final String YEAR = "year";
|
||||||
private static final String SHORT = "short";
|
private static final String SHORT = "short";
|
||||||
private static final String LONG = "long";
|
private static final String LONG = "long";
|
||||||
|
private static final String NUMBER = "number";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.alfresco.repo.action.parameter.ParameterProcessor#process(java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
|
* @see org.alfresco.repo.action.parameter.ParameterProcessor#process(java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
|
||||||
@@ -48,66 +51,125 @@ public class DateParameterProcessor extends ParameterProcessor
|
|||||||
|
|
||||||
// strip the processor name from the value
|
// strip the processor name from the value
|
||||||
value = stripName(value);
|
value = stripName(value);
|
||||||
|
|
||||||
if (value.isEmpty() == false)
|
if (value.isEmpty() == false)
|
||||||
{
|
{
|
||||||
String[] values = value.split("\\.", 2);
|
String[] values = value.split("\\.", 2);
|
||||||
Calendar calendar = Calendar.getInstance();
|
String field = values[0].trim();
|
||||||
int field = getField(values);
|
|
||||||
if (Calendar.YEAR == field)
|
if (DAY.equalsIgnoreCase(field))
|
||||||
{
|
{
|
||||||
result = Integer.toString(calendar.get(field));
|
result = handleDay(values);
|
||||||
|
}
|
||||||
|
else if (MONTH.equalsIgnoreCase(field))
|
||||||
|
{
|
||||||
|
result = handleMonth(values);
|
||||||
|
}
|
||||||
|
else if (YEAR.equalsIgnoreCase(field))
|
||||||
|
{
|
||||||
|
result = handleYear(values);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result = calendar.getDisplayName(field, getStyle(values), Locale.getDefault());
|
throw new AlfrescoRuntimeException("Cannot process the field '" + field + "'.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getField(String[] values)
|
private String handleDay(String[] values)
|
||||||
{
|
{
|
||||||
int result = 0;
|
String style = getStyle(values);
|
||||||
String field = values[0];
|
String pattern;
|
||||||
|
|
||||||
if (MONTH.equals(field) == true)
|
if (SHORT.equalsIgnoreCase(style))
|
||||||
{
|
{
|
||||||
result = Calendar.MONTH;
|
pattern = "EE";
|
||||||
}
|
}
|
||||||
else if (YEAR.equals(field) == true)
|
else if (LONG.equalsIgnoreCase(style))
|
||||||
{
|
{
|
||||||
result = Calendar.YEAR;
|
pattern = "EEEE";
|
||||||
|
}
|
||||||
|
else if (NUMBER.equalsIgnoreCase(style))
|
||||||
|
{
|
||||||
|
pattern = "u";
|
||||||
|
}
|
||||||
|
else if (YEAR.equalsIgnoreCase(style))
|
||||||
|
{
|
||||||
|
pattern = "D";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new AlfrescoRuntimeException("Date component " + field + " is not supported by parameter substitution.");
|
throw new AlfrescoRuntimeException("The pattern 'date.day." + style + "' is not supported!");
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return new SimpleDateFormat(pattern).format(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getStyle(String[] values)
|
private String handleMonth(String[] values)
|
||||||
{
|
{
|
||||||
int result = Calendar.SHORT;
|
String style = getStyle(values);
|
||||||
|
String pattern;
|
||||||
|
|
||||||
if (values.length == 2)
|
if (SHORT.equalsIgnoreCase(style))
|
||||||
{
|
{
|
||||||
String style = values[1];
|
pattern = "MMM";
|
||||||
if (LONG.equals(style) == true)
|
}
|
||||||
{
|
else if (LONG.equalsIgnoreCase(style))
|
||||||
result = Calendar.LONG;
|
{
|
||||||
}
|
pattern = "MMMM";
|
||||||
else if (SHORT.equals(style) == true)
|
}
|
||||||
{
|
else if (NUMBER.equalsIgnoreCase(style))
|
||||||
result = Calendar.SHORT;
|
{
|
||||||
}
|
pattern = "MM";
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
throw new AlfrescoRuntimeException("Style component " + style + " is not supported by parameter substitution.");
|
{
|
||||||
}
|
throw new AlfrescoRuntimeException("The pattern 'date.month." + style + "' is not supported!");
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
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 = "w";
|
||||||
|
}
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user