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.dbpage.business;
35
36 import fr.paris.lutece.plugins.dbpage.business.section.DbPageSection;
37 import fr.paris.lutece.plugins.dbpage.business.section.DbSectionService;
38 import fr.paris.lutece.portal.service.plugin.Plugin;
39 import fr.paris.lutece.portal.service.plugin.PluginService;
40 import fr.paris.lutece.portal.service.resource.Resource;
41 import fr.paris.lutece.portal.service.resource.ResourceLoader;
42
43 import java.util.ArrayList;
44 import java.util.Collection;
45 import java.util.List;
46
47
48
49
50
51 public class DbPageLoaderDatabase implements ResourceLoader
52 {
53 private Plugin _plugin;
54 private String _strPluginName = "dbpage";
55
56
57
58
59
60 public Collection<DbPage> getResources( )
61 {
62 if ( _plugin == null )
63 {
64 _plugin = PluginService.getPlugin( _strPluginName );
65 }
66
67 List<DbPage> listPages = new ArrayList<DbPage>( );
68 List<DbPageDatabase> listDbPages = DbPageDatabaseHome.findDbPageDatabasesList( _plugin );
69
70 for ( DbPageDatabase dbDatabasePage : listDbPages )
71 {
72 DbPage dbPage = loadPage( dbDatabasePage.getParamName( ) );
73 listPages.add( dbPage );
74 }
75
76 return listPages;
77 }
78
79
80
81
82
83
84 public Resource getResource( String strPageId )
85 {
86 Resource resource = null;
87
88 resource = loadPage( strPageId );
89
90 return resource;
91 }
92
93
94
95
96
97
98 private DbPage loadPage( String strPageName )
99 {
100 if ( _plugin == null )
101 {
102 _plugin = PluginService.getPlugin( _strPluginName );
103 }
104
105 DbPageDatabase dbPageDatabase = DbPageDatabaseHome.findByName( strPageName, _plugin );
106
107 if ( dbPageDatabase == null )
108 {
109 return null;
110 }
111
112 DbPage dbPage = new DbPage( );
113 dbPage.setName( dbPageDatabase.getParamName( ) );
114 dbPage.setTitle( dbPageDatabase.getTitle( ) );
115 dbPage.setWorkgroup( dbPageDatabase.getWorkgroup( ) );
116
117 int nSections = DbPageDatabaseSectionHome.countNumberSections( dbPageDatabase.getId( ), _plugin );
118 dbPage.setNbSection( nSections );
119
120 List<DbPageSection> listSections = new ArrayList<DbPageSection>( );
121 List<DbPageDatabaseSection> listSectionsDb = DbPageDatabaseSectionHome.findDbPageDatabaseSectionsList( _plugin );
122
123 for ( DbPageDatabaseSection dbSection : listSectionsDb )
124 {
125 DbPageSection dbPageSection = null;
126
127 if ( dbSection.getIdPage( ) == dbPageDatabase.getId( ) )
128 {
129 String strIdType = dbSection.getIdType( );
130
131 dbPageSection = DbSectionService.INSTANCE.findById( strIdType );
132
133 dbPageSection.setTitle( dbSection.getTitle( ) );
134 dbPageSection.setSql( dbSection.getSql( ) );
135 dbPageSection.setDbPool( dbSection.getPool( ) );
136 dbPageSection.setRole( dbSection.getRole( ) );
137
138 String strTemplatePath = dbSection.getTemplatePath( );
139
140 dbPageSection.setTemplatePath( strTemplatePath );
141
142
143 String strColumnsName = dbSection.getColumn( );
144
145 if ( strColumnsName != null )
146 {
147 List<String> aColumnsName = new ArrayList<String>( );
148
149 while ( !strColumnsName.equals( "" ) )
150 {
151 int nPos = strColumnsName.indexOf( "," );
152
153 if ( nPos != -1 )
154 {
155 String strValue = strColumnsName.substring( 0, nPos );
156 strValue = strValue.trim( );
157 strColumnsName = strColumnsName.substring( nPos + 1 );
158 aColumnsName.add( strValue );
159 }
160 else
161 {
162 aColumnsName.add( strColumnsName.trim( ) );
163 strColumnsName = "";
164 }
165
166 dbPageSection.setColumnNames( aColumnsName );
167 }
168 }
169 }
170
171 if ( dbPageSection != null )
172 {
173 listSections.add( dbPageSection );
174 }
175 }
176
177 dbPage.setListSection( listSections );
178
179 return dbPage;
180 }
181 }