Changeset 1624
- Timestamp:
- 11/22/11 11:09:17 (12 years ago)
- Location:
- SMC/trunk/SMC/src/eu/clarin/cmdi/mdservice/internal
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
SMC/trunk/SMC/src/eu/clarin/cmdi/mdservice/internal/MDTransformer.java
r1600 r1624 18 18 import java.util.Iterator; 19 19 import java.util.Map; 20 import java.util.Properties; 20 21 import java.util.Set; 21 22 import java.util.Map.Entry; … … 49 50 private URL srcFile ; 50 51 private Map<String, String[]> params; 52 53 private Properties config; 54 private ClassLoader loader = null; 55 51 56 52 57 // don't use singleton!! Bad things happen … … 58 63 //} 59 64 65 public ClassLoader getLoader(){ 66 if (loader == null){ 67 return Utils.class.getClassLoader(); 68 } 69 return loader; 70 } 71 public void configure(String configPath){ 72 config = Utils.createConfig(configPath, null); 73 } 74 public void configure(Properties _config, ClassLoader _loader){ 75 config = _config; 76 loader = _loader; 77 } 60 78 61 79 public URL getSrcFile() { … … 82 100 } 83 101 102 public Properties getConfig(){ 103 if (config == null){ 104 return Utils.getConfig(); 105 } 106 return config; 107 } 84 108 /** 85 109 * Get the path to the xsl file from properties, based on the key (aka format-parameter) … … 90 114 private String getXSLPath (String key) throws NoStylesheetException { 91 115 String xslpath = ""; 92 String xslfilename= Utils.getConfig().getProperty("xsl." + key);116 String xslfilename= getConfig().getProperty("xsl." + key); 93 117 94 118 if (xslfilename!=null) { 95 xslpath = Utils.getConfig().getProperty("scripts.path") + xslfilename;119 xslpath = getConfig().getProperty("scripts.path") + xslfilename; 96 120 } else { 97 121 throw new NoStylesheetException("No Stylesheet found for format-key: " + key); … … 110 134 * @throws NoStylesheetException If the stylesheet could not be located 111 135 */ 136 112 137 private StreamSource getXSLStreamSource (String key) throws NoStylesheetException{ 113 138 114 139 InputStream xslstream; 115 140 116 141 //URL myURL = new URL (getXSLPath(key)); 117 142 //xslstream = myURL.openStream(); 118 143 String xslPath = getXSLPath(key); 119 xslstream = this.getClass().getClassLoader().getResourceAsStream(xslPath);144 xslstream = getLoader().getResourceAsStream(xslPath); 120 145 StreamSource streamSource = new StreamSource(xslstream); 121 146 122 streamSource.setSystemId( this.getClass().getClassLoader().getResource(xslPath).toString());147 streamSource.setSystemId(getLoader().getResource(xslPath).toString()); 123 148 return streamSource ; 124 149 125 150 } 126 151 127 152 public void setTranskey(String key){ 128 153 transkey = key; … … 131 156 public String getTranskey(){ 132 157 //return params.get("x-cmd-format")[0]; 133 158 if (transkey == null & params.containsKey("fullformat")) { 159 transkey = params.get("fullformat")[0] ; 160 } 134 161 if (transkey.equals("") & params.containsKey("fullformat")) { 135 162 transkey = params.get("fullformat")[0] ; -
SMC/trunk/SMC/src/eu/clarin/cmdi/mdservice/internal/Utils.java
r1600 r1624 10 10 import java.io.InputStreamReader; 11 11 import java.io.OutputStream; 12 import java.util.Enumeration; 13 import java.util.Hashtable; 14 import java.util.Iterator; 15 import java.util.Map; 12 16 import java.util.Properties; 13 17 … … 57 61 */ 58 62 private static String config_path = "mdservice.properties"; 63 private static Hashtable<String, Properties> config_hashtable; 64 65 //obsolete 59 66 private static Properties config; 60 67 … … 74 81 public static void loadConfig(String configPath) { 75 82 83 config = createConfig(configPath,Utils.class.getClassLoader()); 84 } 85 86 public static Properties createConfig(String configPath, ClassLoader loader) { 87 88 Properties properties = null; 89 76 90 System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl"); 77 91 InputStream config_file; 78 92 if (loader == null){ 93 loader = Utils.class.getClassLoader(); 94 } 79 95 try { 80 config_file = Utils.class.getClassLoader().getResourceAsStream(configPath);96 config_file = loader.getResourceAsStream(configPath); 81 97 if (config_file == null) { 82 98 log.error("CONFIGURATION ERROR: Properties file not found!"); 83 99 } else { 84 log.debug("Reading configuration from: " + Utils.class.getClassLoader().getResource(configPath));85 config= new Properties();86 config.load(config_file);100 log.debug("Reading configuration from: " + loader.getResource(configPath)); 101 properties = new Properties(); 102 properties.load(config_file); 87 103 } 88 104 … … 90 106 log.error("CONFIGURATION LOAD ERROR: " + e.getLocalizedMessage()); 91 107 } 92 } 93 108 109 return properties; 110 } 111 112 113 public static void loadConfig(String appname, String configPath, ClassLoader loader) { 114 115 if (config_hashtable == null){ 116 config_hashtable = new Hashtable<String, Properties>(); 117 } 118 if (!config_hashtable.containsKey(appname)){ 119 Properties config = createConfig(configPath,loader); 120 config_hashtable.put(appname, config); 121 } 122 123 } 124 94 125 /** 95 126 * Returns application configuration properties. … … 97 128 * @return 98 129 */ 130 //obsolete 99 131 public static Properties getConfig() { 100 132 if (config==null) { … … 103 135 return config; 104 136 } 105 137 public static Properties getAppConfig(String appname){ 138 return config_hashtable.get(appname); 139 } 106 140 /** 107 141 * convenience function to get a config property value … … 110 144 */ 111 145 public static String getConfig(String key) { 112 return getConfig().getProperty(key); 113 } 146 147 //return getConfig().getProperty(key); 148 149 Enumeration keys = config_hashtable.keys(); 150 while (keys.hasMoreElements()) { 151 String _key = (String) keys.nextElement(); 152 if (((Properties)config_hashtable.get(_key)).getProperty(key) != null){ 153 return ((Properties)config_hashtable.get(_key)).getProperty(key); 154 } 155 } 156 return null; 157 158 } 159 114 160 115 161 /** … … 143 189 * @return 144 190 */ 145 public static InputStream load2Stream (String path) { 191 public static InputStream load2Stream (String path) { 192 return load2Stream(path,Utils.class.getClassLoader()); 193 } 194 195 public static InputStream load2Stream (String path, ClassLoader loader) { 146 196 147 197 InputStream file=null; 148 198 if (loader == null){ 199 loader = Utils.class.getClassLoader(); 200 } 149 201 try { 150 file = Utils.class.getClassLoader().getResourceAsStream(path);202 file = loader.getResourceAsStream(path); 151 203 if (file == null) { 152 204 log.error("File not found!: " + path); 153 205 } else { 154 log.debug("Reading in: " + Utils.class.getClassLoader().getResource(path));206 log.debug("Reading in: " + loader.getResource(path)); 155 207 } 156 208 } catch (Exception e) { … … 160 212 return file; 161 213 } 214 162 215 163 216 /**
Note: See TracChangeset
for help on using the changeset viewer.