1 package net.sf.jasperreports.engine.style;
2 /*
3  * JasperReports - Free Java Reporting Library.
4  * Copyright (C) 2001 - 2019 TIBCO Software Inc. All rights reserved.
5  * http://www.jaspersoft.com
6  *
7  * Unless you have purchased a commercial license agreement from Jaspersoft,
8  * the following license terms apply:
9  *
10  * This program is part of JasperReports.
11  *
12  * JasperReports is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * JasperReports is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * along with JasperReports. If not, see <http://www.gnu.org/licenses/>.
24  */

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 /**
37  * @author Teodor Danciu (teodord@users.sourceforge.net)
38  */

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     /**
49      * 
50      */

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