Changeset 1656 for trunk/docx4j
- Timestamp:
- 09/11/11 11:31:58 (9 months ago)
- Location:
- trunk/docx4j/src/main/java/org/docx4j
- Files:
-
- 2 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/docx4j/src/main/java/org/docx4j/samples/ContentControlBindingExtensions.java
r1639 r1656 21 21 package org.docx4j.samples; 22 22 23 import java.io.File; 23 24 import java.io.FileInputStream; 24 25 import java.util.List; … … 37 38 import org.docx4j.model.datastorage.CustomXmlDataStorageImpl; 38 39 import org.docx4j.model.datastorage.OpenDoPEHandler; 40 import org.docx4j.model.datastorage.OpenDoPEIntegrity; 41 import org.docx4j.model.datastorage.RemovalHandler; 42 import org.docx4j.model.datastorage.RemovalHandler.Quantifier; 39 43 import org.docx4j.openpackaging.io.LoadFromZipFile; 40 44 import org.docx4j.openpackaging.io.SaveToZipFile; … … 69 73 */ 70 74 public static void main(String[] args) throws Exception { 75 76 // String inputfilepath = System.getProperty("user.dir") + "/sample-docs/word/databinding/hyperlink-binding-test.docx"; 71 77 72 78 String inputfilepath = System.getProperty("user.dir") + "/sample-docs/word/databinding/invoice.docx"; 73 String save_preprocessed = System.getProperty("user.dir") + "/sample-docs/word/databinding/invoice_preprocessed.xml";74 String save_bound = System.getProperty("user.dir") + "/sample-docs/word/databinding/invoice_bound.xml";75 79 76 80 // String inputfilepath = System.getProperty("user.dir") + "/sample-docs/word/databinding/CountryRegions.xml"; 77 // String save_preprocessed = System.getProperty("user.dir") + "/sample-docs/word/databinding/CountryRegions_preprocessed.xml";78 // String save_bound = System.getProperty("user.dir") + "/sample-docs/word/databinding/CountryRegions_bound.xml";79 81 80 82 // String inputfilepath = System.getProperty("user.dir") + "/sample-docs/word/databinding/IT inventory.docx"; 81 // String save_preprocessed = System.getProperty("user.dir") + "/sample-docs/word/databinding/IT_inventory_preprocessed.xml";82 // String save_bound = System.getProperty("user.dir") + "/sample-docs/word/databinding/IT_inventory_bound.xml";83 83 84 84 // String inputfilepath = "/home/dev/workspace/docx4j/sample-docs/word/databinding/MedicalChartSample.docx"; 85 // String save_preprocessed = System.getProperty("user.dir") + "/sample-docs/word/databinding/MedicalChartSample_preprocessed.xml";86 // String save_bound = System.getProperty("user.dir") + "/sample-docs/word/databinding/MedicalChartSample_bound.xml";87 85 88 86 // String inputfilepath = System.getProperty("user.dir") + "/sample-docs/word/databinding/repeat-containing-condition.docx"; 89 // String save_preprocessed = System.getProperty("user.dir") + "/sample-docs/word/databinding/repeat-containing-condition_preprocessed.xml";90 // String save_bound = System.getProperty("user.dir") + "/sample-docs/word/databinding/repeat-containing-condition_bound.xml";91 87 92 88 WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath)); 93 89 90 String filepathprefix = inputfilepath.substring(0, inputfilepath.lastIndexOf(".")); 91 System.out.println(filepathprefix); 94 92 95 93 // Process conditionals and repeats 96 94 OpenDoPEHandler odh = new OpenDoPEHandler(wordMLPackage); 97 95 odh.preprocess(); 96 97 OpenDoPEIntegrity odi = new OpenDoPEIntegrity(); 98 odi.process(wordMLPackage); 99 98 100 System.out.println( 99 101 XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true) 100 102 ); 101 103 SaveToZipFile saver = new SaveToZipFile(wordMLPackage); 102 saver.save( save_preprocessed);103 System.out.println("Saved: " + save_preprocessed);104 saver.save(filepathprefix + "_preprocessed.docx"); 105 System.out.println("Saved: " + filepathprefix + "_preprocessed.docx"); 104 106 105 107 // Apply the bindings 108 BindingHandler.setHyperlinkStyle("hyperlink"); 106 109 BindingHandler.applyBindings(wordMLPackage.getMainDocumentPart()); 107 110 System.out.println( 108 111 XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true) 109 112 ); 110 saver.save( save_bound);111 System.out.println("Saved: " + save_bound);113 saver.save(filepathprefix + "_bound.docx"); 114 System.out.println("Saved: " + filepathprefix + "_bound.docx"); 112 115 113 } 114 116 // Strip content controls: you MUST do this 117 // if you are processing hyperlinks 118 RemovalHandler rh = new RemovalHandler(); 119 rh.removeSDTs(wordMLPackage, Quantifier.ALL); 120 saver.save(filepathprefix + "_stripped.docx"); 121 System.out.println("Saved: " + filepathprefix + "_bound.docx"); 122 } 123 115 124 116 125 }
Note: See TracChangeset
for help on using the changeset viewer.
