docx4j support for content controls (sdt), especially binding them to Custom XML, including OpenDoPE implementation
by frankf » Fri Nov 04, 2011 7:45 am
I've tested the proposed null hyperLinkStyleId patch discussed in the below post. Seems to work fine. Patch file attached, if you find it useful.
http://www.docx4java.org/forums/data-binding-java-f16/2-7-1-questions-t898.html- Code: Select all
Index: BindingHandler.java
===================================================================
--- BindingHandler.java (revision 1700)
+++ BindingHandler.java (working copy)
@@ -328,7 +328,7 @@
int pos = text.indexOf("http://");
- if (pos==-1) {
+ if (pos==-1 || hyperlinkStyleId == null) {
addRunToDocFrag(sourcePart, docfrag, text, rPr);
return;
}
- Attachments
-
- hyperlink.patch
- handle null hyperlink style id (=>no w:hyperlink)
- (395 Bytes) Downloaded 355 times
-
frankf
-
- Posts: 11
- Joined: Wed Oct 05, 2011 5:42 am
by frankf » Fri Nov 04, 2011 8:56 am
Patch modifed to include https as a hyperlink.
- Code: Select all
Index: BindingHandler.java
===================================================================
--- BindingHandler.java (revision 1700)
+++ BindingHandler.java (working copy)
@@ -69,12 +69,14 @@
/**
* Configure, how the handler handles links found in Custom XML.
*
- * If set to <code>null</code>, strings containing 'http://'
- * are not converted to w:hyperlink. This is the default behavior.
+ * If hyperlinkStyleId is set to <code>null</code>, strings
+ * containing 'http://' or 'https://' are not converted to
+ * w:hyperlink. This is the default behavior.
*
- * If set to <code>true</code>, strings containing 'http://'
- * are converted to w:hyperlink. If you do this, you will
- * need to post-process with RemovalHandler, since a
+ * If hyperlinkStyleId is set to <code>"someWordHyperlinkStyleName"</code>,
+ * strings containing 'http://' or 'https://' are converted to w:hyperlink.
+ * The default Word hyperlink style name is "Hyperlink".
+ * If you do this, you will need to post-process with RemovalHandler, since a
* content control with SdtPr w:dataBinding and w:text
* which contains a w:hyperlink will prevent Word 2007 from
* opening the docx.
@@ -82,7 +84,7 @@
* Due to the architecture of this class, this is a static flag changing the
* behavior of all following calls to {@link #applyBindings}.
*
- * @param hyperlinkStyle
+ * @param hyperlinkStyleID
* The style to use for hyperlinks (eg Hyperlink)
*/
public static void setHyperlinkStyle (
@@ -327,8 +329,11 @@
private static void processString(JaxbXmlPart sourcePart, DocumentFragment docfrag, String text, RPr rPr) throws JAXBException {
int pos = text.indexOf("http://");
+ if (pos==-1) {
+ pos = text.indexOf("https://");
+ }
- if (pos==-1) {
+ if (pos==-1 || hyperlinkStyleId == null) {
addRunToDocFrag(sourcePart, docfrag, text, rPr);
return;
}
- Attachments
-
- hyperlinkWithHttps.patch
- includes both http and https
- (1.91 KiB) Downloaded 373 times
-
frankf
-
- Posts: 11
- Joined: Wed Oct 05, 2011 5:42 am
Return to content controls (w:sdt) and data binding
Who is online
Users browsing this forum: No registered users and 14 guests