1 package de.jwi.jgallery.util; 2 3 24 25 import java.io.FileInputStream ; 26 import java.io.FileOutputStream ; 27 import java.io.IOException ; 28 import java.io.InputStream ; 29 import java.util.regex.Matcher ; 30 import java.util.regex.Pattern ; 31 32 39 public class VariablesTransformer 40 { 41 private static String loadFile(InputStream is) throws IOException 42 { 43 byte[] bytes = new byte[is.available()]; 44 is.read(bytes); 45 String s = new String (bytes); 46 return s; 47 } 48 49 public static void main(String [] args) throws IOException 50 { 51 if (args.length<1) 52 { 53 System.out.println(VariablesTransformer.class.getClass().getName() 54 + " <file to transform>"); 55 System.exit(1); 56 } 57 58 InputStream is = VariablesTransformer.class 59 .getResourceAsStream("variables.properties"); 60 61 String vardefs = loadFile(is); 62 63 is = new FileInputStream (args[0]); 64 65 String s = loadFile(is); 66 String old,nuw; 67 68 String regex = "\\$text\\.\\w*"; 70 71 Pattern pattern = Pattern.compile(regex); 72 73 Matcher matcher = pattern.matcher(s); 74 75 String s0 = new String (s); 76 77 while(matcher.find()) 78 { 79 old = "\\" + matcher.group(); 80 int p = old.indexOf('.'); 81 nuw = "<jg:text>" + old.substring(p+1)+ "</jg:text>"; 82 s0 = s0.replaceAll(old,nuw); 83 } 84 85 s = s0; 86 87 89 String [] s1 = vardefs.trim().split("[{}]"); 90 91 for (int i=0;i<s1.length;i+=2) 92 { 93 String clazz = s1[i].trim(); 94 String vars = s1[i+1].trim(); 95 96 String [] v = vars.split("\\s+"); 98 for (int j=0;j<v.length;j++) 99 { 100 old = "\\$"+v[j]; 101 nuw = "\\${"+clazz+"."+v[j]+"}"; 102 s = s.replaceAll(old,nuw); 104 105 old="exists=\""+v[j]+"\""; 106 nuw = "exists=\"\\${"+clazz+"."+v[j]+"}\""; 107 s = s.replaceAll(old,nuw); 108 109 old="exists="+v[j]; 110 nuw = "exists=\"\\${"+clazz+"."+v[j]+"}\""; 111 s = s.replaceAll(old,nuw); 112 113 } 114 } 115 116 System.out.println("\n\n"+s); 117 118 FileOutputStream fos = new FileOutputStream (args[0]+".jsp"); 119 120 s0 = "<%@ taglib uri=\"http://www.jwi.de/jGallery/taglib\" prefix=\"jg\" %>\n\n"; 121 122 fos.write(s0.getBytes()); 123 124 old="href=\"http://www.datadosen.se/jalbum\""; 125 nuw="href=\"\\${folder.generatorurl}\""; 126 s = s.replaceAll(old,nuw); 127 128 old="<ja:include"; 129 nuw="<jsp:include"; 130 s = s.replaceAll(old,nuw); 131 132 old="</ja:include"; 133 nuw="</jsp:include"; 134 s = s.replaceAll(old,nuw); 135 136 old="<ja:"; 137 nuw="<jg:"; 138 s = s.replaceAll(old,nuw); 139 140 old="</ja:"; 141 nuw="</jg:"; 142 s = s.replaceAll(old,nuw); 143 144 145 fos.write(s.getBytes()); 146 fos.close(); 147 148 if (s.indexOf("<jg:eval>")>0) 149 { 150 System.out.println("Please update <jg:eval> Tags with JSP EL."); 151 } 152 153 } 154 } 155 | Popular Tags |