Ignore:
Timestamp:
08/30/11 15:53:03 (9 months ago)
Author:
jharrop
Message:

 http:// to hyperlink conversion is only done if you expressly set it.
Methods to process MDP and headers/footers.

Location:
trunk/docx4j/src/main/java/org/docx4j/model/datastorage
Files:
3 edited

Legend:

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

    r1645 r1647  
    99import javax.xml.bind.JAXBException; 
    1010import javax.xml.bind.Unmarshaller; 
    11 import javax.xml.parsers.DocumentBuilderFactory; 
    1211import javax.xml.transform.Source; 
    1312import javax.xml.transform.Templates; 
     
    2322import org.docx4j.dml.wordprocessingDrawing.Inline; 
    2423import org.docx4j.jaxb.Context; 
    25 import org.docx4j.jaxb.NamespacePrefixMappings; 
    2624import org.docx4j.openpackaging.exceptions.Docx4JException; 
    2725import org.docx4j.openpackaging.packages.WordprocessingMLPackage; 
    2826import org.docx4j.openpackaging.parts.CustomXmlDataStoragePart; 
    29 import org.docx4j.openpackaging.parts.DefaultXmlPart; 
    3027import org.docx4j.openpackaging.parts.JaxbXmlPart; 
    31 import org.docx4j.openpackaging.parts.XmlPart; 
    3228import org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage; 
     29import org.docx4j.openpackaging.parts.WordprocessingML.FooterPart; 
     30import org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart; 
    3331import org.docx4j.openpackaging.parts.relationships.Namespaces; 
    34 import org.docx4j.wml.CTSimpleField; 
     32import org.docx4j.openpackaging.parts.relationships.RelationshipsPart; 
     33import org.docx4j.relationships.Relationship; 
     34import org.docx4j.wml.P.Hyperlink; 
    3535import org.docx4j.wml.RPr; 
    36 import org.docx4j.wml.P.Hyperlink; 
    3736import org.w3c.dom.Document; 
    3837import org.w3c.dom.DocumentFragment; 
     
    6261                xPath = xPathFactory.newXPath();                 
    6362        } 
     63 
     64 
     65        /** 
     66         * Configure, how the handler handles links found in Custom XML. 
     67         *  
     68         * If set to <code>null</code>, strings containing 'http://' 
     69         * are not converted to w:hyperlink. This is the default behavior. 
     70         *  
     71         * If set to <code>true</code>, strings containing 'http://' 
     72         * are converted to w:hyperlink.  If you do this, you will 
     73         * need to post-process with RemovalHandler, since a 
     74         * content control with SdtPr w:dataBinding and w:text 
     75         * which contains a w:hyperlink will prevent Word 2007 from 
     76         * opening the docx. 
     77         *  
     78         * Due to the architecture of this class, this is a static flag changing the 
     79         * behavior of all following calls to {@link #applyBindings}. 
     80         *  
     81         * @param hyperlinkStyle 
     82         *            The style to use for hyperlinks (eg Hyperlink) 
     83         */ 
     84        public static void setHyperlinkStyle ( 
     85                        String hyperlinkStyleID) { 
     86                hyperlinkStyleId = hyperlinkStyleID; 
     87        } 
     88        private static String hyperlinkStyleId = null; 
    6489         
    6590         
     
    84109         */ 
    85110                 
     111                public static void applyBindings(WordprocessingMLPackage wordMLPackage) throws Docx4JException { 
     112 
     113                        // A component can apply in both the main document part, 
     114                        // and in headers/footers. See further 
     115                        // http://forums.opendope.org/Support-components-in-headers-footers-tp2964174p2964174.html 
     116                         
     117                        if (hyperlinkStyleId !=null  
     118                                        && wordMLPackage.getMainDocumentPart().getPropertyResolver().activateStyle(hyperlinkStyleId)) { 
     119                        }                        
     120 
     121                        applyBindings(wordMLPackage.getMainDocumentPart()); 
     122         
     123                        // Add headers/footers 
     124                        RelationshipsPart rp = wordMLPackage.getMainDocumentPart() 
     125                                        .getRelationshipsPart(); 
     126                        for (Relationship r : rp.getRelationships().getRelationship()) { 
     127         
     128                                if (r.getType().equals(Namespaces.HEADER)) { 
     129                                        applyBindings((HeaderPart) rp.getPart(r)); 
     130                                } else if (r.getType().equals(Namespaces.FOOTER)) { 
     131                                        applyBindings((FooterPart) rp.getPart(r)); 
     132                                } 
     133                        } 
     134                } 
     135         
    86136                public static void applyBindings(JaxbXmlPart part) throws Docx4JException { 
    87137                         
     
    341391            "<w:r>" + 
    342392            "<w:rPr>" + 
    343             "<w:rStyle w:val=\"Hyperlink\" />" +  // TODO: enable this style in the document! 
     393            "<w:rStyle w:val=\"" + hyperlinkStyleId + "\" />" +  // TODO: enable this style in the document! 
    344394            "</w:rPr>" + 
    345395            "<w:t>" + url + "</w:t>" + 
  • trunk/docx4j/src/main/java/org/docx4j/model/datastorage/OpenDoPEHandler.java

    r1641 r1647  
    219219        } 
    220220 
    221         private Set<ContentAccessor> getParts(WordprocessingMLPackage srcPackage) { 
     221        protected static Set<ContentAccessor> getParts(WordprocessingMLPackage srcPackage) { 
    222222 
    223223                Set<ContentAccessor> partList = new HashSet<ContentAccessor>(); 
  • trunk/docx4j/src/main/java/org/docx4j/model/datastorage/RemovalHandler.java

    r1579 r1647  
    3737import org.docx4j.jaxb.Context; 
    3838import org.docx4j.openpackaging.exceptions.Docx4JException; 
     39import org.docx4j.openpackaging.packages.WordprocessingMLPackage; 
    3940import org.docx4j.openpackaging.parts.JaxbXmlPart; 
     41import org.docx4j.openpackaging.parts.WordprocessingML.FooterPart; 
     42import org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart; 
     43import org.docx4j.openpackaging.parts.relationships.Namespaces; 
     44import org.docx4j.openpackaging.parts.relationships.RelationshipsPart; 
     45import org.docx4j.relationships.Relationship; 
    4046import org.w3c.dom.Document; 
    4147 
     
    9197        } 
    9298 
     99        public void removeSDTs(WordprocessingMLPackage wordMLPackage, 
     100                        final Quantifier quantifier, final String... keys) throws Docx4JException { 
     101 
     102                // A component can apply in both the main document part, 
     103                // and in headers/footers. See further 
     104                // http://forums.opendope.org/Support-components-in-headers-footers-tp2964174p2964174.html 
     105                 
     106 
     107                removeSDTs(wordMLPackage.getMainDocumentPart(), quantifier, keys); 
     108 
     109                // Add headers/footers 
     110                RelationshipsPart rp = wordMLPackage.getMainDocumentPart() 
     111                                .getRelationshipsPart(); 
     112                for (Relationship r : rp.getRelationships().getRelationship()) { 
     113 
     114                        if (r.getType().equals(Namespaces.HEADER)) { 
     115                                removeSDTs((HeaderPart) rp.getPart(r), quantifier, keys); 
     116                        } else if (r.getType().equals(Namespaces.FOOTER)) { 
     117                                removeSDTs((FooterPart) rp.getPart(r), quantifier, keys); 
     118                        } 
     119                } 
     120        } 
     121         
    93122        /** 
    94123         * Removes Structured Document Tags from a document part, preserving their 
Note: See TracChangeset for help on using the changeset viewer.