Changeset 1656 for trunk/docx4j


Ignore:
Timestamp:
09/11/11 11:31:58 (9 months ago)
Author:
jharrop
Message:

Ensure OpenDoPE output is not broken by comments, footnotes or endnotes.

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  
    2121package org.docx4j.samples; 
    2222 
     23import java.io.File; 
    2324import java.io.FileInputStream; 
    2425import java.util.List; 
     
    3738import org.docx4j.model.datastorage.CustomXmlDataStorageImpl; 
    3839import org.docx4j.model.datastorage.OpenDoPEHandler; 
     40import org.docx4j.model.datastorage.OpenDoPEIntegrity; 
     41import org.docx4j.model.datastorage.RemovalHandler; 
     42import org.docx4j.model.datastorage.RemovalHandler.Quantifier; 
    3943import org.docx4j.openpackaging.io.LoadFromZipFile; 
    4044import org.docx4j.openpackaging.io.SaveToZipFile; 
     
    6973         */ 
    7074        public static void main(String[] args) throws Exception { 
     75 
     76//              String inputfilepath = System.getProperty("user.dir") + "/sample-docs/word/databinding/hyperlink-binding-test.docx"; 
    7177                 
    7278                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"; 
    7579 
    7680//              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"; 
    7981 
    8082//              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"; 
    8383                 
    8484//              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"; 
    8785                 
    8886//              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"; 
    9187                 
    9288                WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));           
    9389                 
     90                String filepathprefix = inputfilepath.substring(0, inputfilepath.lastIndexOf(".")); 
     91                System.out.println(filepathprefix); 
    9492 
    9593                // Process conditionals and repeats 
    9694                OpenDoPEHandler odh = new OpenDoPEHandler(wordMLPackage); 
    9795                odh.preprocess(); 
     96                 
     97                OpenDoPEIntegrity odi = new OpenDoPEIntegrity(); 
     98                odi.process(wordMLPackage); 
     99                 
    98100                System.out.println( 
    99101                                XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true) 
    100102                                );               
    101103                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"); 
    104106                 
    105107                // Apply the bindings 
     108                BindingHandler.setHyperlinkStyle("hyperlink");                                           
    106109                BindingHandler.applyBindings(wordMLPackage.getMainDocumentPart()); 
    107110                System.out.println( 
    108111                                XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true) 
    109112                                ); 
    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"); 
    112115                 
    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                                 
    115124 
    116125} 
Note: See TracChangeset for help on using the changeset viewer.