Changeset 1404
- Timestamp:
- 02/01/11 02:03:44 (16 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/docx4j/src/main/java/org/docx4j/samples/StripParts.java
r1103 r1404 22 22 23 23 24 import java.io.File; 24 25 import java.net.URI; 25 26 import java.util.ArrayList; … … 38 39 public class StripParts { 39 40 41 42 static boolean save = true; 43 static boolean flatOpcXmlOutput = false; 44 static boolean overwriteInputFile = true; 45 46 static String dir = System.getProperty("user.dir") + "/src/test/resources/AlteredParts/"; 47 static String file = "blagh"; // set to null to process all docx in dir 48 49 static boolean stripPropertiesParts = true; 50 static boolean keepStyles = true; 51 static boolean defaultToDelete = false; 52 40 53 private static Logger log = Logger.getLogger(StripParts.class); 41 54 42 55 /** 43 56 * @param args … … 45 58 public static void main(String[] args) throws Exception { 46 59 47 // Do we want to save output? 48 boolean save = true; 49 boolean flatOpcXmlOutput = true; 50 51 String dir = System.getProperty("user.dir") + "/foo/"; 52 53 String file = "bar"; 54 String inputfilepath = dir + file + ".docx"; 55 56 // If so, whereto? 57 String outputfilepath = null; 58 if (save) { 59 if (flatOpcXmlOutput) { 60 outputfilepath = dir + file + "_OUT.xml"; 61 } else { 62 outputfilepath = dir + file + "_OUT.docx"; 63 } 64 } 60 if (file==null) { 61 62 List<File> filesToProcess = new ArrayList<File>(); 63 File[] filesAndDirs = new File(dir).listFiles(); 64 for (File file : filesAndDirs) { 65 if (file.isFile() 66 && file.getName().endsWith(".docx") ) { 67 filesToProcess.add(file); 68 } 69 } 70 71 for (File file : filesToProcess) { 72 String outputfilepath = null; 73 if (save && overwriteInputFile) { 74 outputfilepath = file.getAbsolutePath(); 75 } 76 77 processFile(file, outputfilepath); 78 79 } 80 81 } else { 82 String inputfilepath = dir + file + ".docx"; 83 84 // If so, whereto? 85 String outputfilepath = null; 86 if (save) { 87 if (overwriteInputFile) { 88 outputfilepath = inputfilepath; 89 } else if (flatOpcXmlOutput) { 90 outputfilepath = dir + file + "_OUT.xml"; 91 } else { 92 outputfilepath = dir + file + "_OUT.docx"; 93 } 94 } 95 96 processFile(new java.io.File(inputfilepath), outputfilepath); 97 } 98 } 99 100 private static void processFile(File inputfile, String outputfilepath) 101 throws Docx4JException { 65 102 66 103 // Open a document from the file system 67 104 // 1. Load the Package - .docx or Flat OPC .xml 68 WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load( new java.io.File(inputfilepath));105 WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(inputfile); 69 106 70 107 // List the parts by walking the rels tree … … 80 117 System.out.println("Saved stripped to " + outputfilepath); 81 118 } else { 82 System.out.println("Stripped parts from " + inputfile path);119 System.out.println("Stripped parts from " + inputfile.getName() ); 83 120 } 84 121 } … … 92 129 StringBuilder sb, String indent) 93 130 throws Docx4JException { 94 95 boolean stripPropertiesParts = true; 96 boolean keepStyles = false; 97 boolean defaultToDelete = false; 98 131 99 132 List<Relationship> deletions = new ArrayList<Relationship>(); 100 133
Note: See TracChangeset
for help on using the changeset viewer.
