1
+ /**
2
+ *
3
+ */
1
4
package com .dotmarketing .plugin .business ;
2
- import java .io .File ;
3
- import java .io .FileOutputStream ;
4
- import java .io .IOException ;
5
- import java .io .InputStream ;
6
- import java .io .OutputStream ;
7
- import java .util .ArrayList ;
8
- import java .util .Enumeration ;
9
- import java .util .List ;
10
- import java .util .Properties ;
11
- import java .util .jar .JarEntry ;
12
- import java .util .jar .JarFile ;
13
5
14
- /**
15
- * dotCMS Configuration plugin by ISAAC - The Full Service Internet Agency is licensed
16
- * under a Creative Commons Attribution 3.0 Unported License
17
- * - http://creativecommons.org/licenses/by/3.0/
18
- * - http://www.geekyplugins.com/
19
- *
20
- * @copyright Copyright (c) 2011 ISAAC Software Solutions B.V. (http://www.isaac.nl)
21
- */
6
+ import com .dotcms .business .CloseDBIfOpened ;
7
+ import com .dotcms .business .WrapInTransaction ;
22
8
import com .dotmarketing .beans .Host ;
23
9
import com .dotmarketing .beans .Identifier ;
24
10
import com .dotmarketing .business .APILocator ;
34
20
import com .dotmarketing .util .Logger ;
35
21
import com .dotmarketing .util .UtilMethods ;
36
22
import com .liferay .portal .model .User ;
23
+ import java .io .File ;
24
+ import java .io .IOException ;
25
+ import java .io .InputStream ;
26
+ import java .io .OutputStream ;
27
+ import java .nio .file .Files ;
28
+ import java .util .ArrayList ;
29
+ import java .util .Enumeration ;
30
+ import java .util .List ;
31
+ import java .util .Properties ;
32
+ import java .util .jar .JarEntry ;
33
+ import java .util .jar .JarFile ;
37
34
38
35
/**
39
36
* @author Jason Tesser
@@ -54,36 +51,36 @@ public PluginAPIImplDotCMS() {
54
51
/* (non-Javadoc)
55
52
* @see com.dotmarketing.plugin.business.PluginAPI#delete(com.dotmarketing.plugin.model.Plugin)
56
53
*/
57
- @ Override
54
+ @ WrapInTransaction
58
55
public void delete (Plugin plugin ) throws DotDataException {
59
56
pluginFac .delete (plugin );
60
57
}
61
58
62
- @ Override
59
+ @ WrapInTransaction
63
60
public void deletePluginProperties (String pluginId ) throws DotDataException {
64
61
pluginFac .deletePluginProperties (pluginId );
65
62
}
66
63
67
64
/* (non-Javadoc)
68
65
* @see com.dotmarketing.plugin.business.PluginAPI#loadPlugin(java.lang.String)
69
66
*/
70
- @ Override
67
+ @ CloseDBIfOpened
71
68
public Plugin loadPlugin (String id ) throws DotDataException {
72
69
return pluginFac .loadPlugin (id );
73
70
}
74
71
75
72
/* (non-Javadoc)
76
73
* @see com.dotmarketing.plugin.business.PluginAPI#loadPlugins()
77
74
*/
78
- @ Override
75
+ @ CloseDBIfOpened
79
76
public List <Plugin > findPlugins () throws DotDataException {
80
77
return pluginFac .findPlugins ();
81
78
}
82
79
83
80
/* (non-Javadoc)
84
81
* @see com.dotmarketing.plugin.business.PluginAPI#loadProperty(java.lang.String, java.lang.String)
85
82
*/
86
- @ Override
83
+ @ CloseDBIfOpened
87
84
public String loadProperty (String pluginId , String key ) throws DotDataException {
88
85
PluginProperty pp = pluginFac .loadProperty (pluginId , key );
89
86
if (pp != null ){
@@ -96,15 +93,15 @@ public String loadProperty(String pluginId, String key) throws DotDataException
96
93
/* (non-Javadoc)
97
94
* @see com.dotmarketing.plugin.business.PluginAPI#save(com.dotmarketing.plugin.model.Plugin)
98
95
*/
99
- @ Override
96
+ @ WrapInTransaction
100
97
public void save (Plugin plugin ) throws DotDataException {
101
98
pluginFac .save (plugin );
102
99
}
103
100
104
101
/* (non-Javadoc)
105
102
* @see com.dotmarketing.plugin.business.PluginAPI#saveProperty(java.lang.String, java.lang.String, java.lang.String)
106
103
*/
107
- @ Override
104
+ @ WrapInTransaction
108
105
public void saveProperty (String pluginId , String key , String value ) throws DotDataException {
109
106
PluginProperty pp = pluginFac .loadProperty (pluginId , key );
110
107
if (pp != null && UtilMethods .isSet (pp .getPluginId ())){
@@ -120,9 +117,8 @@ public void saveProperty(String pluginId, String key, String value) throws DotDa
120
117
pluginFac .saveProperty (pp );
121
118
}
122
119
123
- @ Override
124
120
public List <String > loadPluginConfigKeys (String pluginId ) throws DotDataException {
125
- List <String > result = new ArrayList <>();
121
+ List <String > result = new ArrayList <String >();
126
122
try {
127
123
JarFile jar = new JarFile (new File (pluginJarDir .getPath () + File .separator + "plugin-" + pluginId ));
128
124
JarEntry entry = jar .getJarEntry ("conf/plugin-controller.properties" );
@@ -143,7 +139,6 @@ public List<String> loadPluginConfigKeys(String pluginId) throws DotDataExceptio
143
139
}
144
140
}
145
141
146
- @ Override
147
142
public String loadPluginConfigProperty (String pluginId , String key ) throws DotDataException {
148
143
try {
149
144
JarFile jar = new JarFile (new File (pluginJarDir .getPath () + File .separator + "plugin-" + pluginId + ".jar" ));
@@ -160,38 +155,34 @@ public String loadPluginConfigProperty(String pluginId, String key) throws DotDa
160
155
}
161
156
}
162
157
163
- @ Override
164
158
public List <String > getDeployedPluginOrder () {
165
159
return deployedPluginOrder ;
166
160
}
167
161
168
- @ Override
169
162
public File getPluginJarDir () {
170
163
return pluginJarDir ;
171
164
}
172
165
173
- @ Override
174
166
public void setDeployedPluginOrder (List <String > pluginIds ) {
175
167
this .deployedPluginOrder = pluginIds ;
176
168
}
177
169
178
- @ Override
179
170
public void setPluginJarDir (File directory ) throws IOException {
180
171
if (!directory .exists ()){
181
172
throw new IOException ("The directory doesn't exist" );
182
173
}
183
174
this .pluginJarDir = directory ;
184
175
}
185
176
186
- @ Override
177
+ @ CloseDBIfOpened
187
178
public void loadBackEndFiles (String pluginId ) throws IOException , DotDataException {
188
179
try {
189
180
190
181
HostAPI hostAPI = APILocator .getHostAPI ();
191
182
192
183
User systemUser = APILocator .getUserAPI ().getSystemUser ();
193
184
JarFile jar = new JarFile (new File (pluginJarDir .getPath () + File .separator + "plugin-" + pluginId + ".jar" ));
194
- List <Host > hostList = new ArrayList <>();
185
+ List <Host > hostList = new ArrayList <Host >();
195
186
196
187
String hosts = loadPluginConfigProperty (pluginId , "hosts.name" );
197
188
if (UtilMethods .isSet (hosts )){
@@ -223,7 +214,7 @@ public void loadBackEndFiles(String pluginId) throws IOException, DotDataExcepti
223
214
//Create temporary file with the inputstream
224
215
InputStream input = jar .getInputStream (entry );
225
216
File temporaryFile = new File ("file.temp" );
226
- OutputStream output =new FileOutputStream (temporaryFile );
217
+ final OutputStream output = Files . newOutputStream (temporaryFile . toPath () );
227
218
byte buf []=new byte [1024 ];
228
219
int len ;
229
220
while ((len =input .read (buf ))>0 ){
@@ -283,4 +274,4 @@ public void loadBackEndFiles(String pluginId) throws IOException, DotDataExcepti
283
274
}
284
275
}
285
276
286
- }
277
+ }
0 commit comments