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.plugins.jasper.service;
35
36 import fr.paris.lutece.portal.service.spring.SpringContextService;
37 import fr.paris.lutece.portal.service.util.AppLogService;
38 import fr.paris.lutece.portal.service.util.AppPathService;
39
40 import org.springframework.context.ApplicationContext;
41 import org.springframework.context.support.FileSystemXmlApplicationContext;
42
43 import java.io.File;
44
45 import java.util.ArrayList;
46 import java.util.HashMap;
47 import java.util.List;
48 import java.util.Map;
49
50
51
52
53 @SuppressWarnings( "unchecked" )
54 public enum ExportFormatService
55 {
56 INSTANCE;
57
58 private static final String CORE = "core";
59 private static Map<String, ApplicationContext> _mapContext = new HashMap<String, ApplicationContext>( );
60 private static final String PATH_CONF = "/WEB-INF/conf/";
61 private static final String DIR_PLUGINS = "plugins/";
62 private static final String SUFFIX_CONTEXT_FILE = "_context.xml";
63
64
65
66
67
68
69
70
71 private static ApplicationContext getContext( String strContextName )
72 {
73
74 ApplicationContext context = (ApplicationContext) _mapContext.get( strContextName );
75
76 if ( context == null )
77 {
78
79 String strContextFilePath = AppPathService.getAbsolutePathFromRelativePath( PATH_CONF );
80
81 if ( !strContextName.equals( CORE ) )
82 {
83 strContextFilePath += DIR_PLUGINS;
84 }
85
86 String strContextFile = strContextFilePath + strContextName + SUFFIX_CONTEXT_FILE;
87
88 try
89 {
90 if ( strContextName.equals( CORE ) )
91 {
92 context = new FileSystemXmlApplicationContext( "file:" + strContextFile );
93 }
94 else
95 {
96 List<String> listModules = new ArrayList<String>( );
97 File dir = new File( strContextFilePath );
98 String [ ] arrayFiles = dir.list( );
99
100 if ( arrayFiles != null )
101 {
102 for ( int i = 0; i < arrayFiles.length; i++ )
103 {
104 String strPath = arrayFiles [i];
105
106 if ( strPath.startsWith( strContextName ) && strPath.endsWith( "_context.xml" ) )
107 {
108 String strFullPath = "file:" + strContextFilePath + strPath;
109 listModules.add( strFullPath );
110 }
111 }
112 }
113
114 String [ ] arrayModules = new String [ listModules.size( )];
115 listModules.toArray( arrayModules );
116 context = new FileSystemXmlApplicationContext( arrayModules );
117 }
118 }
119 catch( Exception e )
120 {
121 AppLogService.error( "Error retrieving context file : " + e.getMessage( ), e );
122 }
123 finally
124 {
125 _mapContext.put( strContextName, context );
126 }
127
128 _mapContext.put( strContextName, context );
129 }
130
131 return context;
132 }
133
134 public List<ILinkJasperReport> getExportTypes( )
135 {
136 return SpringContextService.getBeansOfType( ILinkJasperReport.class );
137
138 }
139 }