1 package jfun.yan.xml.nuts.optional; 2 3 import java.io.File ; 4 import java.io.IOException ; 5 import java.util.Iterator ; 6 import java.util.Properties ; 7 8 import jfun.util.Misc; 9 import jfun.yan.util.Utils; 10 import jfun.yan.util.resource.ClassLoader2ResourceLoader; 11 import jfun.yan.util.resource.OrResourceLoader; 12 import jfun.yan.util.resource.ResourceLoaders; 13 20 public class PropertiesRegisterNut extends AbstractLoopRegisterNut { 21 private String resource; 22 private File file; 23 private String classpath; 24 25 public String getClasspath() { 26 return classpath; 27 } 28 public void setClasspath(String classpath) { 29 this.classpath = classpath; 30 } 31 public File getFile() { 32 return file; 33 } 34 public void setFile(File file) { 35 checkDuplicate("resource", resource); 36 this.file = file; 37 } 38 public String getResource() { 39 return resource; 40 } 41 public void setResource(String resource) { 42 checkDuplicate("file", file); 43 this.resource = resource; 44 } 45 protected Properties readProperties() 46 throws IOException { 47 if(resource!=null){ 48 return Utils.loadResourceProperties( 49 ResourceLoaders.or( 50 this.getNutEnvironment().getResourceLoader(), 51 getNutClassLoader(classpath) 52 ), resource); 53 } 54 else if(file!=null){ 55 return Misc.loadPropertiesFile(file); 56 } 57 else{ 58 throw raise("either file or resource has to be specified."); 59 } 60 } 61 public void eval() 62 throws IOException { 63 final Properties props = readProperties(); 64 for(Iterator it= props.keySet().iterator(); it.hasNext();){ 65 final Object key = it.next(); 66 final Object val = props.get(key); 67 loop(key, key, val); 68 } 69 } 70 } 71 | Popular Tags |