Ignore:
Timestamp:
11/27/06 12:23:38 (5 years ago)
Author:
sys
Message:

Chargement des xsl à la demande

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Jav_CO/com/scenari/m/co/donnee/WDonneeXsl.java

    r7478 r7519  
    7979 
    8080        /** Template Xsl */ 
    81         protected Templates fTemplate = null; 
     81        protected Object fTemplate = null; 
    8282 
    8383        /** 
     
    170170        public void wSetValue(IHComposantType pCompType, String pValue, IHContextDonnee pContextDonnee) throws Exception { 
    171171                if (pValue != null) { 
    172                         xLoadTemplates(pCompType, pValue, pContextDonnee.hGetDocSource()); 
    173                 } 
    174                 xInitDonneeFc(pCompType); 
     172                        XMLReader vXmlReader = HPoolXmlReader.hGet().hGetXmlReader(true, false); 
     173                        try { 
     174                                IHSource vDocSource = pContextDonnee.hGetDocSource(); 
     175                                TransformerFactory vTransFact = new TransformerFactoryImpl(); 
     176                                vDocSource.hSetAliasResolver((IHAliasResolver) pCompType); 
     177 
     178                                vTransFact.setURIResolver(vDocSource); 
     179                                vXmlReader.setEntityResolver(vDocSource); 
     180                                SAXSource vSource = null; 
     181                                InputSource vInputSource = new InputSource(new StringReader(pValue.trim())); 
     182                                vInputSource.setSystemId(vDocSource.hGetSystemId()); 
     183                                vSource = new SAXSource(vXmlReader, vInputSource); 
     184                                fTemplate = vTransFact.newTemplates(vSource); 
     185                        } catch (Exception e) { 
     186                                fTemplate = null; 
     187                                throw (Exception) HLogMgr.hAddMessage(e, "Echec à la compilation d'un template XSL du composant type '" + pCompType + "':\n" + pValue); 
     188                        } finally { 
     189                                HPoolXmlReader.hGet().hFreeXmlReader(vXmlReader); 
     190                        } 
     191                } 
    175192        } 
    176193 
     
    182199         */ 
    183200        public void wSetValueParRef(IHComposantType pCompType, IHSource pDocSource) throws java.lang.Exception { 
    184                 xLoadTemplates(pCompType, null, pDocSource); 
    185                 xInitDonneeFc(pCompType); 
     201                fTemplate = pDocSource; 
    186202        } 
    187203 
     
    207223        protected final void xGetValue(IHDialog pDialog, IWAgent pAgent, Object pArguments, Result pResult) throws Exception { 
    208224 
    209                 if (fTemplate != null) { 
     225                IWComposant vComposant = pAgent.hGetComposant(); 
     226                Templates vTemplate = xGetTemplate(vComposant.hGetComposantType()); 
     227 
     228                if (vTemplate != null) { 
    210229 
    211230                        // On execute la XSL 
     
    215234                                        vTo = System.currentTimeMillis(); 
    216235                                } 
    217                                 IWComposant vComposant = pAgent.hGetComposant(); 
    218  
    219                                 Transformer vTransformer = fTemplate.newTransformer(); 
     236 
     237                                Transformer vTransformer = vTemplate.newTransformer(); 
    220238 
    221239                                IHSource vResolver = vComposant.hGetUnivers().hGetEspacePublications().hFindSource(null); 
     
    249267 
    250268        /** 
    251          * Initialise la donnee lors de sa déclaration dans la feuille de 
    252          * comportement. 
    253          *  
    254          * @param pCompType 
    255          *            com.scenari.m.co.composant.IHComposantType 
    256          */ 
    257         protected void xInitDonneeFc(IHComposantType pCompType) throws Exception { 
    258         } 
    259  
    260         /** 
    261          * Crée un templates. 
    262          *  
    263          */ 
    264         public final void xLoadTemplates(IHComposantType pCompType, String pContent, IHSource pDocSource) throws Exception { 
    265                 XMLReader vXmlReader = HPoolXmlReader.hGet().hGetXmlReader(true, false); 
    266                 try { 
    267                         TransformerFactory vTransFact = new TransformerFactoryImpl(); 
    268                         pDocSource.hSetAliasResolver((IHAliasResolver) pCompType); 
    269  
    270                         vTransFact.setURIResolver(pDocSource); 
    271                         vXmlReader.setEntityResolver(pDocSource); 
    272                         SAXSource vSource = null; 
    273                         if (pContent == null) { 
    274                                 // Le XSL est en ressource associée 
    275                                 // On mémorise la source et on cherche si ce template a édja été 
    276                                 // calculé. 
    277                                 InputStream vStream = pDocSource.hGetInputStream(); 
    278                                 if (vStream == null) { throw HLogMgr.hNewException("Le fichier template XSL '" + pDocSource + "' est introuvable."); } 
     269         * Récupération du template (compilation si nécessaire). 
     270         * 
     271         */ 
     272        protected synchronized Templates xGetTemplate(IHComposantType pCompType) throws Exception { 
     273                if (fTemplate ==null) return null; 
     274                if (fTemplate instanceof Templates) { 
     275                        //Template déjà compilé 
     276                        return (Templates) fTemplate; 
     277                } else { 
     278                        //Template à compiler 
     279                        IHSource vDocSource = (IHSource) fTemplate; 
     280                        XMLReader vXmlReader = HPoolXmlReader.hGet().hGetXmlReader(true, false); 
     281                        try { 
     282                                TransformerFactory vTransFact = new TransformerFactoryImpl(); 
     283                                vDocSource.hSetAliasResolver((IHAliasResolver) pCompType); 
     284 
     285                                vTransFact.setURIResolver(vDocSource); 
     286                                vXmlReader.setEntityResolver(vDocSource); 
     287                                InputStream vStream = vDocSource.hGetInputStream(); 
     288                                if (vStream == null) { throw HLogMgr.hNewException("Le fichier template XSL '" + vDocSource + "' est introuvable."); } 
    279289                                InputSource vInputSource = new InputSource(vStream); 
    280                                 vInputSource.setSystemId(pDocSource.hGetSystemId()); 
    281                                 vSource = new SAXSource(vXmlReader, vInputSource); 
     290                                vInputSource.setSystemId(vDocSource.hGetSystemId()); 
     291                                SAXSource vSource = new SAXSource(vXmlReader, vInputSource); 
    282292                                try { 
    283293                                        fTemplate = vTransFact.newTemplates(vSource); 
     
    285295                                        vStream.close(); 
    286296                                } 
    287                         } else { 
    288                                 // Le XSL est directement défini dans la feuille de comportement 
    289                                 InputSource vInputSource = new InputSource(new StringReader(pContent.trim())); 
    290                                 vInputSource.setSystemId(pDocSource.hGetSystemId()); 
    291                                 vSource = new SAXSource(vXmlReader, vInputSource); 
    292                                 fTemplate = vTransFact.newTemplates(vSource); 
     297 
     298                        } catch (Exception e) { 
     299                                fTemplate = null; 
     300                                throw (Exception) HLogMgr.hAddMessage(e, "Echec à la compilation d'un template XSL du composant type '" + pCompType + "':\n" + vDocSource.toString()); 
     301                        } finally { 
     302                                HPoolXmlReader.hGet().hFreeXmlReader(vXmlReader); 
    293303                        } 
    294  
    295                 } catch (Exception e) { 
    296                         fTemplate = null; 
    297                         throw (Exception) HLogMgr.hAddMessage(e, "Echec à la compilation d'un template XSL du composant type '" + pCompType + "':\n" + ((pContent == null) ? pDocSource.toString() : pContent)); 
    298                 } finally { 
    299                         HPoolXmlReader.hGet().hFreeXmlReader(vXmlReader); 
     304                        return (Templates)fTemplate; 
    300305                } 
    301306        } 
Note: See TracChangeset for help on using the changeset viewer.