- Timestamp:
- 2012-10-17T13:51:35+13:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/XSLTUtil.java
r26315 r26325 19 19 package org.greenstone.gsdl3.util; 20 20 21 import java.io.ByteArrayInputStream; 21 22 import java.io.File; 22 23 import java.text.SimpleDateFormat; … … 26 27 import java.util.HashMap; 27 28 import java.util.Locale; 29 30 import javax.xml.parsers.DocumentBuilder; 31 import javax.xml.parsers.DocumentBuilderFactory; 28 32 29 33 import net.tanesha.recaptcha.ReCaptcha; … … 50 54 _stringVariables.put(name, value); 51 55 } 52 56 53 57 public static String getString(String name) 54 58 { 55 59 return _stringVariables.get(name); 56 60 } 57 61 58 62 /* some tests */ 59 63 public static boolean equals(String s1, String s2) … … 292 296 } 293 297 294 public static StringgetCollectionText(String collection, String site_name, String lang, String key)295 { 296 297 } 298 299 public static StringgetCollectionText(String collection, String site_name, String lang, String key, String args_str)300 301 302 303 304 305 args = StringUtils.split(args_str, ";");306 307 308 309 298 public static Node getCollectionText(String collection, String site_name, String lang, String key) 299 { 300 return getCollectionTextWithArgs(collection, site_name, lang, key, null); 301 } 302 303 public static Node getCollectionText(String collection, String site_name, String lang, String key, String args_str) 304 { 305 306 String[] args = null; 307 if (args_str != null && !args_str.equals("")) 308 { 309 args = StringUtils.split(args_str, ";"); 310 } 311 312 return getCollectionTextWithArgs(collection, site_name, lang, key, args); 313 } 310 314 311 315 // xslt didn't like calling the function with Node varargs, so have this hack for now 312 public static StringgetCollectionTextWithDOM(String collection, String site_name, String lang, String key, Node n1)316 public static Node getCollectionTextWithDOM(String collection, String site_name, String lang, String key, Node n1) 313 317 { 314 318 return getCollectionTextWithDOMMulti(collection, site_name, lang, key, n1); 315 319 } 316 320 317 public static StringgetCollectionTextWithDOM(String collection, String site_name, String lang, String key, Node n1, Node n2)321 public static Node getCollectionTextWithDOM(String collection, String site_name, String lang, String key, Node n1, Node n2) 318 322 { 319 323 return getCollectionTextWithDOMMulti(collection, site_name, lang, key, n1, n2); 320 324 } 321 325 322 public static StringgetCollectionTextWithDOM(String collection, String site_name, String lang, String key, Node n1, Node n2, Node n3)326 public static Node getCollectionTextWithDOM(String collection, String site_name, String lang, String key, Node n1, Node n2, Node n3) 323 327 { 324 328 return getCollectionTextWithDOMMulti(collection, site_name, lang, key, n1, n2, n3); 325 329 } 326 330 327 public static StringgetCollectionTextWithDOM(String collection, String site_name, String lang, String key, Node n1, Node n2, Node n3, Node n4)331 public static Node getCollectionTextWithDOM(String collection, String site_name, String lang, String key, Node n1, Node n2, Node n3, Node n4) 328 332 { 329 333 return getCollectionTextWithDOMMulti(collection, site_name, lang, key, n1, n2, n3, n4); 330 334 } 331 335 332 public static StringgetCollectionTextWithDOMMulti(String collection, String site_name, String lang, String key, Node... nodes)336 public static Node getCollectionTextWithDOMMulti(String collection, String site_name, String lang, String key, Node... nodes) 333 337 { 334 338 int num_nodes = nodes.length; … … 340 344 for (int i = 0; i < num_nodes; i++) 341 345 { 342 343 346 String node_str = XMLConverter.getString(nodes[i]); 344 347 args[i] = node_str; … … 348 351 } 349 352 350 public static String getCollectionTextWithArgs(String collection, String site_name, String lang, String key, String [] args) { 351 352 CollectionClassLoader class_loader = new CollectionClassLoader(XSLTUtil.class.getClassLoader(), GSFile.siteHome(GlobalProperties.getGSDL3Home(), site_name), collection); 353 Dictionary dict = new Dictionary(collection, lang, class_loader); 354 String result = dict.get(key, args); 355 if (result != null) 356 { 357 return result; 358 } 359 return "text:" + collection + ":" + key; 360 353 public static Node getCollectionTextWithArgs(String collection, String site_name, String lang, String key, String[] args) 354 { 355 try 356 { 357 DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 358 359 CollectionClassLoader class_loader = new CollectionClassLoader(XSLTUtil.class.getClassLoader(), GSFile.siteHome(GlobalProperties.getGSDL3Home(), site_name), collection); 360 Dictionary dict = new Dictionary(collection, lang, class_loader); 361 String result = dict.get(key, args); 362 if (result != null) 363 { 364 return docBuilder.parse(new ByteArrayInputStream(("<fragment>" + result + "</fragment>").getBytes())).getDocumentElement(); 365 } 366 return docBuilder.parse(new ByteArrayInputStream(("<fragment>" + "text:" + collection + ":" + key + "</fragment>").getBytes())).getDocumentElement(); 367 } 368 catch (Exception ex) 369 { 370 return null; 371 } 361 372 } 362 373
Note:
See TracChangeset
for help on using the changeset viewer.