Page 1 of 1

2.7/2.8 patch?

PostPosted: Fri Nov 04, 2011 7:45 am
by frankf
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;
         }

Re: 2.7/2.8 patch?

PostPosted: Fri Nov 04, 2011 8:56 am
by frankf
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;
         }

Re: 2.7/2.8 patch?

PostPosted: Sun Nov 06, 2011 2:13 pm
by jason
Thanks for this; applied - and extended to cover mailto: - as http://www.docx4java.org/trac/docx4j/changeset/1702