1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.portal.service.regularexpression;
35
36 import fr.paris.lutece.portal.business.regularexpression.RegularExpression;
37 import fr.paris.lutece.portal.service.plugin.PluginService;
38 import fr.paris.lutece.portal.service.spring.SpringContextService;
39
40 import org.springframework.beans.factory.BeanDefinitionStoreException;
41 import org.springframework.beans.factory.CannotLoadBeanClassException;
42 import org.springframework.beans.factory.NoSuchBeanDefinitionException;
43
44 import java.util.List;
45
46
47
48
49
50
51 public final class RegularExpressionService
52 {
53 private static final String PLUGIN_REGULAR_EXPRESSION_NAME = "regularexpression";
54 private static volatile RegularExpressionService _singleton;
55 private boolean _bServiceAvailable = true;
56 private IRegularExpressionService _service;
57
58
59
60
61 private RegularExpressionService( )
62 {
63 try
64 {
65 _service = SpringContextService.getBean( "regularExpressionService" );
66 _bServiceAvailable = _service != null;
67 }
68 catch ( BeanDefinitionStoreException e )
69 {
70 _bServiceAvailable = false;
71 }
72 catch ( NoSuchBeanDefinitionException e )
73 {
74 _bServiceAvailable = false;
75 }
76 catch ( CannotLoadBeanClassException e )
77 {
78 _bServiceAvailable = false;
79 }
80 }
81
82
83
84
85
86 public static RegularExpressionService getInstance( )
87 {
88 if ( _singleton == null )
89 {
90 _singleton = new RegularExpressionService( );
91 }
92
93 return _singleton;
94 }
95
96
97
98
99
100 public boolean isAvailable( )
101 {
102 return _bServiceAvailable && PluginService.isPluginEnable( PLUGIN_REGULAR_EXPRESSION_NAME );
103 }
104
105
106
107
108
109
110 boolean isPatternValide( String strPattern )
111 {
112 return isAvailable( ) ? _service.isPatternValide( strPattern ) : false;
113 }
114
115
116
117
118
119
120 boolean isPatternValide( RegularExpression regularExpression )
121 {
122 return isAvailable( ) ? _service.isPatternValide( regularExpression ) : false;
123 }
124
125
126
127
128
129
130
131 public boolean isMatches( String strValueToTest, String strPattern )
132 {
133 return isAvailable( ) ? _service.isMatches( strValueToTest, strPattern ) : false;
134 }
135
136
137
138
139
140
141
142 public boolean isMatches( String strValueToTest, RegularExpression regularExpression )
143 {
144 return isAvailable( ) ? _service.isMatches( strValueToTest, regularExpression ) : false;
145 }
146
147
148
149
150
151
152 public RegularExpression getRegularExpressionByKey( int nKey )
153 {
154 return isAvailable( ) ? _service.getRegularExpressionByKey( nKey ) : null;
155 }
156
157
158
159
160
161 public List<RegularExpression> getAllRegularExpression( )
162 {
163 return isAvailable( ) ? _service.getAllRegularExpression( ) : null;
164 }
165 }