]>
git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/provisioning/FileProvider.java
6751e09f8fc7579420cb767aa77bd510ec1a9451
1 package org
.argeo
.slc
.web
.mvc
.provisioning
;
3 import java
.io
.InputStream
;
4 import java
.io
.OutputStream
;
6 import org
.apache
.commons
.io
.IOUtils
;
7 import org
.apache
.commons
.logging
.Log
;
8 import org
.apache
.commons
.logging
.LogFactory
;
9 import org
.argeo
.slc
.SlcException
;
10 import org
.springframework
.core
.io
.Resource
;
12 public class FileProvider
{
13 private final static Log log
= LogFactory
.getLog(FileProvider
.class);
15 private Resource base
;
17 public void read(String distribution
, String name
, String version
,
19 Resource bundle
= getBundle(distribution
, name
, version
);
20 InputStream in
= null;
22 in
= bundle
.getInputStream();
23 IOUtils
.copy(in
, out
);
24 } catch (Exception e
) {
25 throw new SlcException("Cannot read bundle for " + name
+ " ("
28 IOUtils
.closeQuietly(in
);
32 public Resource
getBundle(String distribution
, String name
, String version
) {
34 String shortVersion
= version
;
35 int indR
= version
.indexOf("-r");
37 shortVersion
= version
.substring(0, indR
);
40 int indS
= shortVersion
.indexOf(".SNAPSHOT");
42 StringBuffer buf
= new StringBuffer(shortVersion
);
43 buf
.setCharAt(indS
, '-');
44 shortVersion
= buf
.toString();
47 if (log
.isDebugEnabled())
48 log
.debug("Short version for " + name
+ ": " + shortVersion
);
50 Resource res
= base
.createRelative("lib/" + name
+ "-"
51 + shortVersion
+ ".jar");
53 } catch (Exception e
) {
54 throw new SlcException("Cannot get bundle for " + name
+ " ("
59 public void setBase(Resource base
) {