Changeset 1732 for trunk/docx4j/src/main
- Timestamp:
- 12/17/11 14:35:42 (5 months ago)
- Location:
- trunk/docx4j/src/main/java/org/docx4j/model/fields
- Files:
-
- 2 added
- 3 edited
-
FieldLocator.java (modified) (1 diff)
-
FieldRef.java (modified) (1 diff)
-
FieldsPreprocessor.java (modified) (2 diffs)
-
merge (added)
-
merge/MailMerger.java (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/docx4j/src/main/java/org/docx4j/model/fields/FieldLocator.java
r1727 r1732 18 18 * it will still be listed just once 19 19 */ 20 List<P> starts = new ArrayList<P>(); 21 20 List<P> starts = new ArrayList<P>(); 21 public List<P> getStarts() { 22 return starts; 23 } 24 22 25 P currentP; 23 26 int depth=0; -
trunk/docx4j/src/main/java/org/docx4j/model/fields/FieldRef.java
r1731 r1732 305 305 306 306 private JAXBElement<Text> instrText; 307 public JAXBElement<Text> getInstrText() { 308 return instrText; 307 // public JAXBElement<Text> getInstrText() { 308 // return instrText; 309 // } 310 public String getInstr() { 311 return instrText.getValue().getValue(); 309 312 } 310 313 public void setInstrText(JAXBElement<Text> instrText) { -
trunk/docx4j/src/main/java/org/docx4j/model/fields/FieldsPreprocessor.java
r1731 r1732 100 100 } 101 101 102 // public static boolean supported(String type) {103 //104 // if (type.contains("MERGEFIELD")) {105 // return true;106 // } else {107 // return false;108 // }109 // }110 102 111 103 public static P canonicalise(P p, List<FieldRef> fieldRefs) { … … 267 259 } 268 260 269 public static void main(String[] args) throws Exception {270 271 WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(272 new java.io.File(273 System.getProperty("user.dir") + "/mergefield1.docx"));274 275 complexifyFields(wordMLPackage.getMainDocumentPart() );276 277 System.out.println(XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true));278 279 // canonicalise280 FieldLocator fl = new FieldLocator();281 new TraversalUtil(wordMLPackage.getMainDocumentPart().getContent(), fl);282 log.info("Found " + fl.starts.size() + " fields ");283 284 List<FieldRef> fieldRefs = new ArrayList<FieldRef>();285 286 for( P p : fl.starts) {287 int index = ((ContentAccessor)p.getParent()).getContent().indexOf(p);288 P newP = canonicalise(p, fieldRefs);289 System.out.println("NewP length: " + newP.getContent().size() );290 ((ContentAccessor)p.getParent()).getContent().set(index, newP);291 }292 293 // Prove we can put something into the results294 int counter = 0;295 for (FieldRef fr : fieldRefs) {296 fr.setResult("Result" + counter);297 counter++;298 299 // If doing an actual mail merge, the begin-separate run is removed, as is the end run300 fr.getParent().getContent().remove(fr.getBeginRun());301 fr.getParent().getContent().remove(fr.getEndRun());302 }303 304 System.out.println(XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true));305 306 wordMLPackage.save(new java.io.File(307 System.getProperty("user.dir") + "/mergefield1-OUT.docx") );308 309 310 }311 261 }
Note: See TracChangeset
for help on using the changeset viewer.
