Changeset 2430
- Timestamp:
- 11/08/09 21:18:37 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
molgenis/3.3/src/org/molgenis/generators/server/MolgenisResourceCopyGen.java
r2423 r2430 29 29 public class MolgenisResourceCopyGen extends Generator 30 30 { 31 public static final String RESOURCE_FOLDER = "org/molgenis/framework/ui/res/"; 31 public static final String RESOURCE_FOLDER = "org/molgenis/framework/ui/res/"; 32 32 33 @Override 33 34 public String getDescription() … … 39 40 public void generate(Model model, MolgenisOptions options) throws Exception 40 41 { 41 String jarPath = getClass().getResource("").getFile(); 42 jarPath = jarPath.split("!")[0].split("file:")[1]; 42 String jarPath = getClass().getResource("").getFile(); 43 43 44 File target = new File(this.getWebserverPath(options) + "/generated-res"); 44 // System.out.println(jarPath); 45 if (jarPath.contains("!")) 46 { 45 47 48 jarPath = jarPath.split("!")[0].split("file:")[1]; 46 49 47 //check if the target exists otherwise it's created 48 if(!target.exists()) { 49 boolean succes = target.mkdirs(); 50 if(!succes) 51 throw new Exception("can't create /generated-res directory!"); 52 } 50 File target = new File(this.getWebserverPath(options) + "/generated-res"); 53 51 54 JarFile jar = new JarFile(jarPath); 55 Enumeration entries = jar.entries(); 56 while(entries.hasMoreElements()) { 57 JarEntry file = (JarEntry) entries.nextElement(); 58 if(file.getName().contains(RESOURCE_FOLDER)) { 59 if(!file.isDirectory()) { 60 ZipEntry zipEntry = jar.getEntry(file.getName()); 61 InputStream is = jar.getInputStream(zipEntry); 62 String outFilePath = file.getName().replace(RESOURCE_FOLDER, target.getPath() + File.separator); 63 System.out.println(outFilePath); 52 // check if the target exists otherwise it's created 53 if (!target.exists()) 54 { 55 boolean succes = target.mkdirs(); 56 if (!succes) throw new Exception("can't create /generated-res directory!"); 57 } 64 58 65 File dst = new File(outFilePath); 66 dst.mkdirs(); 67 if(dst.exists()) { 68 dst.delete(); 59 JarFile jar = new JarFile(jarPath); 60 Enumeration entries = jar.entries(); 61 while (entries.hasMoreElements()) 62 { 63 JarEntry file = (JarEntry) entries.nextElement(); 64 if (file.getName().contains(RESOURCE_FOLDER)) 65 { 66 if (!file.isDirectory()) 67 { 68 ZipEntry zipEntry = jar.getEntry(file.getName()); 69 InputStream is = jar.getInputStream(zipEntry); 70 String outFilePath = file.getName().replace(RESOURCE_FOLDER, target.getPath() + File.separator); 71 System.out.println(outFilePath); 72 73 File dst = new File(outFilePath); 74 dst.mkdirs(); 75 if (dst.exists()) 76 { 77 dst.delete(); 78 } 79 dst.createNewFile(); 80 copyFile(outFilePath, is, dst); 81 } 82 } 69 83 } 70 dst.createNewFile(); 71 copyFile(outFilePath, is, dst); 72 } 84 85 logger.info("generated " + target); 73 86 } 74 } 75 logger.info("generated " + target); 87 else 88 { 89 // copy the images/scripts/css 90 File source = new File(MolgenisOriginalStyle.class.getResource("res").getFile()); 91 File target = new File(this.getWebserverPath(options) + "/generated-res"); 92 93 // deledeleteDirectory(target); 94 copyDirectory(source, target); 95 logger.info("generated " + target); 96 } 76 97 } 77 98 78 public void copyFile(String srcPath, InputStream in, File dst) throws IOException { 99 public void copyFile(String srcPath, InputStream in, File dst) throws IOException 100 { 79 101 OutputStream out = new FileOutputStream(dst); 80 102 … … 133 155 { 134 156 135 136 157 if (!src.getAbsolutePath().contains(".svn") && !dst.exists()) 137 158 {
Note: See TracChangeset
for help on using the changeset viewer.