Changeset 1724 for trunk/docx4j/src


Ignore:
Timestamp:
11/30/11 13:13:03 (6 months ago)
Author:
jharrop
Message:

Setting to determine whether to apply a Word style to the hyperlink.

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

Legend:

Unmodified
Added
Removed
  • trunk/docx4j/src/main/java/org/docx4j/convert/in/xhtml/Importer.java

    r1723 r1724  
    7070        protected static Logger log = Logger.getLogger(Importer.class);          
    7171             
     72        /** 
     73         * Configure, how the Importer styles hyperlinks 
     74         *  
     75         * If hyperlinkStyleId is set to <code>null</code>, hyperlinks are 
     76         * styled using just the CSS. This is the default behavior. 
     77         *  
     78         * If hyperlinkStyleId is set to <code>"someWordHyperlinkStyleName"</code>,  
     79         * strings containing 'http://' or 'https://' or or 'mailto:' are converted to w:hyperlink.   
     80         * The default Word hyperlink style name is "Hyperlink". 
     81         *  
     82         * Due to the architecture of this class, this is a static flag changing the 
     83         * behavior of all following calls. 
     84         *  
     85         * @param hyperlinkStyleID 
     86         *            The style to use for hyperlinks (eg Hyperlink) 
     87         */ 
     88        public static void setHyperlinkStyle ( 
     89                        String hyperlinkStyleID) { 
     90                hyperlinkStyleId = hyperlinkStyleID; 
     91        } 
     92        private static String hyperlinkStyleId = null;   
    7293    private List<Object> imports = new ArrayList<Object>();  
    7394//    public List<Object>  getImportedContent() { 
     
    91112         
    92113        listHelper = new ListHelper(); 
     114         
     115                if (hyperlinkStyleId !=null && wordMLPackage instanceof WordprocessingMLPackage) { 
     116                        ((WordprocessingMLPackage)wordMLPackage).getMainDocumentPart().getPropertyResolver().activateStyle(hyperlinkStyleId); 
     117                } 
     118         
    93119    } 
    94120 
     
    390416                                s.getElement().getAttribute("href"),  
    391417                                addRunProperties( cssMap ), 
    392                                 "Hyperlink",  
    393418                                s.getElement().getAttribute("href"), rp);                                        
    394419                currentP.getContent().add(h); 
     
    416441                                s.getElement().getAttribute("href"), 
    417442                                addRunProperties( cssMap ), 
    418                                 "Hyperlink", theText, rp);                                       
     443                                theText, rp);                                            
    419444                currentP.getContent().add(h); 
    420445                 
     
    499524    } 
    500525 
    501         private Hyperlink createHyperlink(String url, RPr rPr, String style, String linkText, RelationshipsPart rp) { 
     526        private Hyperlink createHyperlink(String url, RPr rPr, String linkText, RelationshipsPart rp) { 
    502527                 
    503528                try { 
     
    522547            "xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" >" + 
    523548            "<w:r>" + 
    524             "<w:rPr>" + 
    525             "<w:rStyle w:val=\"" + style + "\" />" +   
    526             "</w:rPr>" + 
    527549            "<w:t>" + linkText + "</w:t>" + 
    528550            "</w:r>" + 
     
    532554                        R r = (R)hyperlink.getContent().get(0); 
    533555                        r.setRPr(rPr); 
    534                         RStyle rStyle = Context.getWmlObjectFactory().createRStyle(); 
    535                         rStyle.setVal(style); 
    536                         rPr.setRStyle(rStyle ); 
    537                          
     556                        if (hyperlinkStyleId!=null) { 
     557                                RStyle rStyle = Context.getWmlObjectFactory().createRStyle(); 
     558                                rStyle.setVal(hyperlinkStyleId); 
     559                                rPr.setRStyle(rStyle ); 
     560                        } 
    538561                        return hyperlink; 
    539562                         
  • trunk/docx4j/src/main/java/org/docx4j/model/datastorage/BindingHandler.java

    r1722 r1724  
    283283                                }                                
    284284                                 
     285                                Importer.setHyperlinkStyle(hyperlinkStyleId); 
    285286                                String baseUrl = null; 
    286287                                List<Object> results = Importer.convertFromString(unescaped, pkg, baseUrl ); 
Note: See TracChangeset for help on using the changeset viewer.