Changeset 1702


Ignore:
Timestamp:
11/06/11 03:02:43 (7 months ago)
Author:
jharrop
Message:

Bug fix: honour no hyperlink creation.
Extend hyperlink creation to  https:// and mailto:
Add hyperlink style in whether processing pkg or part.

Location:
trunk/docx4j/src/main/java/org/docx4j
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/docx4j/src/main/java/org/docx4j/model/datastorage/BindingHandler.java

    r1662 r1702  
    7070         * Configure, how the handler handles links found in Custom XML. 
    7171         *  
    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. 
    7475         *  
    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 
    7880         * content control with SdtPr w:dataBinding and w:text 
    7981         * which contains a w:hyperlink will prevent Word 2007 from 
     
    8385         * behavior of all following calls to {@link #applyBindings}. 
    8486         *  
    85          * @param hyperlinkStyle 
     87         * @param hyperlinkStyleID 
    8688         *            The style to use for hyperlinks (eg Hyperlink) 
    8789         */ 
     
    119121                        // http://forums.opendope.org/Support-components-in-headers-footers-tp2964174p2964174.html 
    120122                         
    121                         if (hyperlinkStyleId !=null  
    122                                         && wordMLPackage.getMainDocumentPart().getPropertyResolver().activateStyle(hyperlinkStyleId)) { 
     123                        if (hyperlinkStyleId !=null) { 
     124                                        wordMLPackage.getMainDocumentPart().getPropertyResolver().activateStyle(hyperlinkStyleId); 
    123125                        }                        
    124126 
     
    144146                                // Binding is a concept which applies more broadly 
    145147                                // than just Word documents. 
     148                         
     149                        if (hyperlinkStyleId !=null && pkg instanceof WordprocessingMLPackage) { 
     150                                ((WordprocessingMLPackage)pkg).getMainDocumentPart().getPropertyResolver().activateStyle(hyperlinkStyleId); 
     151                        } 
    146152                         
    147153                        org.w3c.dom.Document doc = XmlUtils.marshaltoW3CDomDocument( 
     
    327333                private static void processString(JaxbXmlPart sourcePart, DocumentFragment docfrag, String text, RPr rPr) throws JAXBException { 
    328334                         
    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) {                                
    332344                                addRunToDocFrag(sourcePart, docfrag,  text,  rPr); 
    333345                                return; 
  • trunk/docx4j/src/main/java/org/docx4j/samples/ContentControlBindingExtensions.java

    r1656 r1702  
    7777                 
    7878                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"; 
    7981 
    8082//              String inputfilepath = System.getProperty("user.dir") + "/sample-docs/word/databinding/CountryRegions.xml"; 
     
    106108                 
    107109                // Apply the bindings 
    108                 BindingHandler.setHyperlinkStyle("hyperlink");                                           
     110                BindingHandler.setHyperlinkStyle("Hyperlink");                                           
    109111                BindingHandler.applyBindings(wordMLPackage.getMainDocumentPart()); 
    110112                System.out.println( 
     
    119121                rh.removeSDTs(wordMLPackage, Quantifier.ALL); 
    120122                saver.save(filepathprefix + "_stripped.docx"); 
    121                 System.out.println("Saved: " + filepathprefix + "_bound.docx"); 
     123                System.out.println("Saved: " + filepathprefix + "_stripped.docx"); 
    122124        }                
    123125                                 
Note: See TracChangeset for help on using the changeset viewer.