1 package net.sf.jasperreports.engine.style;
2
25
26
27 import java.util.HashMap;
28 import java.util.List;
29 import java.util.Map;
30
31 import net.sf.jasperreports.engine.JRPropertiesUtil;
32 import net.sf.jasperreports.engine.JRPropertiesUtil.PropertySuffix;
33 import net.sf.jasperreports.engine.JRPropertyExpression;
34 import net.sf.jasperreports.engine.JasperReportsContext;
35
36
39 public final class PropertyStyleProviderFactory implements StyleProviderFactory
40 {
41
42 private static final PropertyStyleProviderFactory INSTANCE = new PropertyStyleProviderFactory();
43
44 private PropertyStyleProviderFactory()
45 {
46 }
47
48
51 public static PropertyStyleProviderFactory getInstance()
52 {
53 return INSTANCE;
54 }
55
56 @Override
57 public StyleProvider getStyleProvider(StyleProviderContext context, JasperReportsContext jasperreportsContext)
58 {
59 Map<String, JRPropertyExpression> stylePropertyExpressions = null;
60 JRPropertyExpression[] propertyExpressions = context.getElement().getPropertyExpressions();
61 if (propertyExpressions != null)
62 {
63 for(JRPropertyExpression propertyExpression : propertyExpressions)
64 {
65 if (propertyExpression.getName().startsWith(PropertyStyleProvider.STYLE_PROPERTY_PREFIX))
66 {
67 if (stylePropertyExpressions == null)
68 {
69 stylePropertyExpressions = new HashMap<String, JRPropertyExpression>();
70 }
71 stylePropertyExpressions.put(propertyExpression.getName(), propertyExpression);
72 }
73 }
74 }
75
76 List<PropertySuffix> styleProperties = JRPropertiesUtil.getProperties(context.getElement(), PropertyStyleProvider.STYLE_PROPERTY_PREFIX);
77 if (
78 stylePropertyExpressions != null
79 || (styleProperties != null && styleProperties.size() > 0)
80 )
81 {
82 return new PropertyStyleProvider(context, stylePropertyExpressions);
83 }
84
85 return null;
86 }
87
88 }
89