Changeset 1702
- Timestamp:
- 11/06/11 03:02:43 (7 months ago)
- Location:
- trunk/docx4j/src/main/java/org/docx4j
- Files:
-
- 2 edited
-
model/datastorage/BindingHandler.java (modified) (5 diffs)
-
samples/ContentControlBindingExtensions.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/docx4j/src/main/java/org/docx4j/model/datastorage/BindingHandler.java
r1662 r1702 70 70 * Configure, how the handler handles links found in Custom XML. 71 71 * 72 * If set to <code>null</code>, strings containing 'http://' 73 * are not converted to w:hyperlink. This is the default behavior. 72 * If hyperlinkStyleId is set to <code>null</code>, strings 73 * containing 'http://' or 'https://' are not converted to 74 * w:hyperlink. This is the default behavior. 74 75 * 75 * If set to <code>true</code>, strings containing 'http://' 76 * are converted to w:hyperlink. If you do this, you will 77 * need to post-process with RemovalHandler, since a 76 * If hyperlinkStyleId is set to <code>"someWordHyperlinkStyleName"</code>, 77 * strings containing 'http://' or 'https://' or or 'mailto:' are converted to w:hyperlink. 78 * The default Word hyperlink style name is "Hyperlink". 79 * If you do this, you will need to post-process with RemovalHandler, since a 78 80 * content control with SdtPr w:dataBinding and w:text 79 81 * which contains a w:hyperlink will prevent Word 2007 from … … 83 85 * behavior of all following calls to {@link #applyBindings}. 84 86 * 85 * @param hyperlinkStyle 87 * @param hyperlinkStyleID 86 88 * The style to use for hyperlinks (eg Hyperlink) 87 89 */ … … 119 121 // http://forums.opendope.org/Support-components-in-headers-footers-tp2964174p2964174.html 120 122 121 if (hyperlinkStyleId !=null 122 && wordMLPackage.getMainDocumentPart().getPropertyResolver().activateStyle(hyperlinkStyleId)) {123 if (hyperlinkStyleId !=null) { 124 wordMLPackage.getMainDocumentPart().getPropertyResolver().activateStyle(hyperlinkStyleId); 123 125 } 124 126 … … 144 146 // Binding is a concept which applies more broadly 145 147 // than just Word documents. 148 149 if (hyperlinkStyleId !=null && pkg instanceof WordprocessingMLPackage) { 150 ((WordprocessingMLPackage)pkg).getMainDocumentPart().getPropertyResolver().activateStyle(hyperlinkStyleId); 151 } 146 152 147 153 org.w3c.dom.Document doc = XmlUtils.marshaltoW3CDomDocument( … … 327 333 private static void processString(JaxbXmlPart sourcePart, DocumentFragment docfrag, String text, RPr rPr) throws JAXBException { 328 334 329 int pos = text.indexOf("http://"); 330 331 if (pos==-1) { 335 // Since we'll calculate min, we don't want -1 for no match 336 int NOT_FOUND = 99999; 337 int pos1 = text.indexOf("http://")==-1 ? NOT_FOUND : text.indexOf("http://"); 338 int pos2 = text.indexOf("https://")==-1 ? NOT_FOUND : text.indexOf("https://"); 339 int pos3 = text.indexOf("mailto:")==-1 ? NOT_FOUND : text.indexOf("mailto:"); 340 341 int pos = Math.min(pos1, Math.min(pos2, pos3)); 342 343 if (pos==NOT_FOUND || hyperlinkStyleId == null) { 332 344 addRunToDocFrag(sourcePart, docfrag, text, rPr); 333 345 return; -
trunk/docx4j/src/main/java/org/docx4j/samples/ContentControlBindingExtensions.java
r1656 r1702 77 77 78 78 String inputfilepath = System.getProperty("user.dir") + "/sample-docs/word/databinding/invoice.docx"; 79 80 // String inputfilepath = System.getProperty("user.dir") + "/src/test/resources/OpenDoPE/hyperlinks.docx"; 79 81 80 82 // String inputfilepath = System.getProperty("user.dir") + "/sample-docs/word/databinding/CountryRegions.xml"; … … 106 108 107 109 // Apply the bindings 108 BindingHandler.setHyperlinkStyle(" hyperlink");110 BindingHandler.setHyperlinkStyle("Hyperlink"); 109 111 BindingHandler.applyBindings(wordMLPackage.getMainDocumentPart()); 110 112 System.out.println( … … 119 121 rh.removeSDTs(wordMLPackage, Quantifier.ALL); 120 122 saver.save(filepathprefix + "_stripped.docx"); 121 System.out.println("Saved: " + filepathprefix + "_ bound.docx");123 System.out.println("Saved: " + filepathprefix + "_stripped.docx"); 122 124 } 123 125
Note: See TracChangeset
for help on using the changeset viewer.
