Changeset 28709
- Timestamp:
- 2013-11-28T15:32:52+13:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/build-src/src/java/org/nzdl/gsdl/ApplyXSLT.java
r28384 r28709 349 349 350 350 } 351 private void translateWithMapping(String xml_file, String xsl_file, String mapping_file, String output_file)throws IOException,TransformerException, TransformerConfigurationException, FileNotFoundException { 352 353 TransformerFactory tFactory = TransformerFactory.newInstance(); 354 Transformer transformer = tFactory.newTransformer(new StreamSource(xsl_file)); 355 356 OutputStreamWriter output = null; 357 if (output_file.equals("")) { 358 output = new OutputStreamWriter(System.out, "UTF-8"); 359 } 360 else{ 361 output = new OutputStreamWriter(new FileOutputStream(output_file), "UTF-8"); 362 } 363 try { 364 Document mapping_doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(mapping_file); 365 Element mapping =mapping_doc.getDocumentElement(); 366 367 transformer.setParameter("mapping",mapping); 368 } catch (Exception e) { 369 System.err.println("Couldn't load in mapping file"); 370 e.printStackTrace(); 371 } 372 setTransformerParams(transformer); // sourcelang and targetlang and any further custom parameters to be passed into the XSLT 373 transformer.transform(new StreamSource(new File(xml_file)),new StreamResult(output)); 374 375 } 351 376 352 377 static public String replaceAll(String source_string, String match_regexp, String replace_string) … … 483 508 core = new ApplyXSLT(sourcelang, targetlang, paramMap); 484 509 try { 485 core.translate(xml_file,xsl_file,output_file); 486 } 510 if (mapping_file.equals("")) { 511 core.translate(xml_file,xsl_file,output_file); 512 } else { 513 core.translateWithMapping(xml_file,xsl_file,mapping_file, output_file); 514 } 515 } 487 516 catch(Exception e){e.printStackTrace();} 488 517 }
Note:
See TracChangeset
for help on using the changeset viewer.